def pay_status(request, config_pk, status): tpl_path = 'inapp_pay/' with transaction.commit_on_success(): cfg = get_object_or_404(InappConfig, pk=config_pk) uuid_ = None try: uuid_ = str(request.GET['uuid']) cnt = Contribution.objects.get(uuid=uuid_) except (KeyError, UnicodeEncodeError, ValueError, Contribution.DoesNotExist), exc: log.error('PayPal returned invalid uuid %r from in-app payment' % uuid_, exc_info=True) inapp_cef.log(request, cfg.addon, 'inapp_pay_status', 'PayPal or someone sent invalid uuid %r for ' 'in-app pay config %r; exception: %s: %s' % (uuid_, cfg.pk, exc.__class__.__name__, exc), severity=4) return render_error(request, exc) payment = InappPayment.objects.get(config=cfg, contribution=cnt) if status == 'complete': cnt.update(type=amo.CONTRIB_INAPP) tpl = tpl_path + 'complete.html' action = 'PAY_COMPLETE' elif status == 'cancel': tpl = tpl_path + 'payment_cancel.html' action = 'PAY_CANCEL' else: raise ValueError('Unexpected status: %r' % status)
def reset_in_app_config(request, addon_id, addon, config_id, webapp=True): if addon.premium_type not in amo.ADDON_INAPPS: messages.error(request, 'Your app does not use payments.') return redirect(addon.get_dev_url('payments')) cfg = get_object_or_404(InappConfig, addon=addon, status=amo.INAPP_STATUS_ACTIVE) msg = ('user reset in-app payment config %s; ' 'key: %r; app: %s' % (cfg.pk, cfg.public_key, addon.pk)) log.info(msg) inapp_cef.log(request, addon, 'inapp_reset', msg, severity=6) cfg.update(status=amo.INAPP_STATUS_REVOKED) kw = dict(addon=cfg.addon, status=amo.INAPP_STATUS_ACTIVE, postback_url=cfg.postback_url, chargeback_url=cfg.chargeback_url, public_key=InappConfig.generate_public_key()) new_cfg = InappConfig.objects.create(**kw) new_cfg.set_private_key(InappConfig.generate_private_key()) messages.success( request, _('Old credentials revoked; ' 'new credentials were generated successfully.')) return redirect(addon.get_dev_url('in_app_config'))
def log(cls, request, action_name, user=None, config=None, exc_class=None, app_public_key=None): if action_name == 'EXCEPTION': app = config.addon if config else 'unknown' inapp_cef.log(request, app, 'inapp_pay_error', 'Encountered exception during in-app ' 'payment flow: %s' % (exc_class or 'unknown'), severity=4) cls.objects.create(session_key=request.session.session_key, user=user, action=cls._actions[action_name], config=config, app_public_key=app_public_key, exception=cls._exceptions[exc_class] if exc_class else None)
def reset_in_app_config(request, addon_id, addon, config_id, webapp=True): if addon.premium_type not in amo.ADDON_INAPPS: messages.error(request, "Your app does not use payments.") return redirect(addon.get_dev_url("payments")) cfg = get_object_or_404(InappConfig, addon=addon, status=amo.INAPP_STATUS_ACTIVE) msg = "user reset in-app payment config %s; " "key: %r; app: %s" % (cfg.pk, cfg.public_key, addon.pk) log.info(msg) inapp_cef.log(request, addon, "inapp_reset", msg, severity=6) cfg.update(status=amo.INAPP_STATUS_REVOKED) kw = dict( addon=cfg.addon, status=amo.INAPP_STATUS_ACTIVE, postback_url=cfg.postback_url, chargeback_url=cfg.chargeback_url, public_key=InappConfig.generate_public_key(), ) new_cfg = InappConfig.objects.create(**kw) new_cfg.set_private_key(InappConfig.generate_private_key()) messages.success(request, _("Old credentials revoked; " "new credentials were generated successfully.")) return redirect(addon.get_dev_url("in_app_config"))
def log(cls, request, action_name, user=None, config=None, exc_class=None, app_public_key=None): if action_name == 'EXCEPTION': app = config.addon if config else 'unknown' inapp_cef.log(request, app, 'inapp_pay_error', 'Encountered exception during in-app ' 'payment flow: %s' % (exc_class or 'unknown'), severity=4) cls.objects.create( session_key=request.session.session_key, user=user, action=cls._actions[action_name], config=config, app_public_key=app_public_key, exception=cls._exceptions[exc_class] if exc_class else None)