Ejemplo n.º 1
0
def issue_refund(request, addon_id, addon, webapp=False):
    txn_id = request.REQUEST.get("transaction_id")
    if not txn_id:
        raise http.Http404
    form_enabled = True
    contribution = get_object_or_404(
        Contribution, transaction_id=txn_id, type__in=[amo.CONTRIB_PURCHASE, amo.CONTRIB_INAPP]
    )

    if hasattr(contribution, "refund") and contribution.refund.status not in (amo.REFUND_PENDING, amo.REFUND_FAILED):
        # If it's not pending, we've already taken action.
        messages.error(request, _("Refund already processed."))
        form_enabled = False

    elif request.method == "POST":
        if "issue" in request.POST:
            if waffle.flag_is_active(request, "solitude-payments"):
                try:
                    response = client.post_refund(data={"uuid": contribution.transaction_id})
                except client.Error, e:
                    contribution.record_failed_refund(e)
                    paypal_log.error("Refund failed for: %s" % txn_id, exc_info=True)
                    messages.error(request, _("There was an error with " "the refund."))
                    return redirect(addon.get_dev_url("refunds"))
                results = response["response"]

            else:
                # TODO(solitude): remove this.
                try:
                    results = paypal.refund(contribution.paykey)
                except PaypalError, e:
                    contribution.record_failed_refund(e)
                    paypal_log.error("Refund failed for: %s" % txn_id, exc_info=True)
                    messages.error(request, _("There was an error with " "the refund."))
                    return redirect(addon.get_dev_url("refunds"))

            for res in results:
                if res["refundStatus"] == "ALREADY_REVERSED_OR_REFUNDED":
                    paypal_log.debug(
                        "Refund attempt for already-refunded paykey: %s, %s"
                        % (contribution.paykey, res["receiver.email"])
                    )
                    messages.error(request, _("Refund was previously issued; " "no action taken."))
                    return redirect(addon.get_dev_url("refunds"))
                elif res["refundStatus"] == "NO_API_ACCESS_TO_RECEIVER":
                    paypal_log.debug(
                        "Refund attempt for product %s with no "
                        "refund token: %s, %s" % (contribution.addon.pk, contribution.paykey, res["receiver.email"])
                    )
                    messages.error(
                        request,
                        _("A refund can't be issued at this time. We've " "notified an admin; please try again later."),
                    )
                    return redirect(addon.get_dev_url("refunds"))

            contribution.mail_approved()
            amo.log(amo.LOG.REFUND_GRANTED, addon, contribution.user)
            refund = contribution.enqueue_refund(amo.REFUND_APPROVED)
            paypal_log.info("Refund %r issued for contribution %r" % (refund.pk, contribution.pk))
            messages.success(request, _("Refund issued."))
Ejemplo n.º 2
0
def refund_reason(request, contribution, wizard):
    addon = contribution.addon
    if not 'request' in wizard.get_progress():
        return redirect('support', contribution.pk, 'request')

    if contribution.transaction_id is None:
        messages.error(
            request,
            _('A refund cannot be applied for yet. Please try again later. '
              'If this error persists contact [email protected].'))
        paypal_log.info('Refund requested for contribution with no '
                        'transaction_id: %r' % contribution.pk)
        return redirect('account.purchases')

    if contribution.is_refunded():
        messages.error(request, _('This has already been refunded.'))
        paypal_log.info('Already refunded: %s' % contribution.pk)
        return redirect('account.purchases')

    if contribution.is_instant_refund():
        if waffle.flag_is_active(request, 'solitude-payments'):
            try:
                client.post_refund(data={'uuid': contribution.transaction_id})
            except client.Error, e:
                paypal_log.error('Paypal error with refund', exc_info=True)
                messages.error(
                    request,
                    _('There was an error with your '
                      'instant refund.'))
                contribution.record_failed_refund(e, request.amo_user)
                return redirect('account.purchases')
        else:
            # TODO(solitude): remove this.
            try:
                paypal.refund(contribution.paykey)
            except PaypalError, e:
                paypal_log.error('Paypal error with refund', exc_info=True)
                messages.error(
                    request,
                    _('There was an error with your '
                      'instant refund.'))
                contribution.record_failed_refund(e, request.amo_user)
                return redirect('account.purchases')
Ejemplo n.º 3
0
def refund_reason(request, contribution, wizard):
    addon = contribution.addon
    if not "request" in wizard.get_progress():
        return redirect("support", contribution.pk, "request")

    if contribution.transaction_id is None:
        messages.error(
            request,
            _(
                "A refund cannot be applied for yet. Please try again later. "
                "If this error persists contact [email protected]."
            ),
        )
        paypal_log.info("Refund requested for contribution with no " "transaction_id: %r" % contribution.pk)
        return redirect("account.purchases")

    if contribution.is_refunded():
        messages.error(request, _("This has already been refunded."))
        paypal_log.info("Already refunded: %s" % contribution.pk)
        return redirect("account.purchases")

    if contribution.is_instant_refund():
        if waffle.flag_is_active(request, "solitude-payments"):
            try:
                client.post_refund(data={"uuid": contribution.transaction_id})
            except client.Error, e:
                paypal_log.error("Paypal error with refund", exc_info=True)
                messages.error(request, _("There was an error with your " "instant refund."))
                contribution.record_failed_refund(e)
                return redirect("account.purchases")
        else:
            # TODO(solitude): remove this.
            try:
                paypal.refund(contribution.paykey)
            except PaypalError, e:
                paypal_log.error("Paypal error with refund", exc_info=True)
                messages.error(request, _("There was an error with your " "instant refund."))
                contribution.record_failed_refund(e)
                return redirect("account.purchases")
Ejemplo n.º 4
0
def refund_reason(request, contribution, wizard):
    addon = contribution.addon
    if not 'request' in wizard.get_progress():
        return redirect('support', contribution.pk, 'request')

    if contribution.transaction_id is None:
        messages.error(request,
            _('A refund cannot be applied for yet. Please try again later. '
              'If this error persists contact [email protected].'))
        paypal_log.info('Refund requested for contribution with no '
                        'transaction_id: %r' % contribution.pk)
        return redirect('account.purchases')

    if contribution.is_refunded():
        messages.error(request, _('This has already been refunded.'))
        paypal_log.info('Already refunded: %s' % contribution.pk)
        return redirect('account.purchases')

    if contribution.is_instant_refund():
        if waffle.flag_is_active(request, 'solitude-payments'):
            try:
                client.post_refund(data={'uuid': contribution.transaction_id})
            except client.Error, e:
                paypal_log.error('Paypal error with refund', exc_info=True)
                messages.error(request, _('There was an error with your '
                                          'instant refund.'))
                contribution.record_failed_refund(e, request.amo_user)
                return redirect('account.purchases')
        else:
            # TODO(solitude): remove this.
            try:
                paypal.refund(contribution.paykey)
            except PaypalError, e:
                paypal_log.error('Paypal error with refund', exc_info=True)
                messages.error(request, _('There was an error with your '
                                          'instant refund.'))
                contribution.record_failed_refund(e, request.amo_user)
                return redirect('account.purchases')