def transaction_refund(request, uuid): contrib = get_object_or_404(Contribution, uuid=uuid, type=amo.CONTRIB_PURCHASE) if contrib.has_refund(): messages.error(request, _('A refund has already been processed.')) return redirect(reverse('lookup.transaction_summary', args=[uuid])) form = TransactionRefundForm(request.POST) if not form.is_valid(): messages.error(request, str(form.errors)) return redirect(reverse('lookup.transaction_summary', args=[uuid])) try: res = client.api.bango.refund.post({'uuid': contrib.transaction_id}) except (HttpClientError, HttpServerError): # Either doing something not supposed to or Solitude had an issue. log.exception('Refund error: %s' % uuid) messages.error( request, _('You cannot make a refund request for this transaction.')) return redirect(reverse('lookup.transaction_summary', args=[uuid])) if res['status'] == STATUS_PENDING: # Create pending Refund. contrib.enqueue_refund( status=amo.REFUND_PENDING, refund_reason=form.cleaned_data['refund_reason'], user=request.amo_user) log.info('Refund pending: %s' % uuid) email_buyer_refund_pending(contrib) messages.success( request, _('Refund for this transaction now pending.')) elif res['status'] == STATUS_COMPLETED: # Create approved Refund. contrib.enqueue_refund( status=amo.REFUND_APPROVED, refund_reason=form.cleaned_data['refund_reason'], user=request.amo_user) log.info('Refund approved: %s' % uuid) email_buyer_refund_approved(contrib) messages.success( request, _('Refund for this transaction successfully approved.')) elif res['status'] == STATUS_FAILED: # Bango no like. log.error('Refund failed: %s' % uuid) messages.error( request, _('Refund request for this transaction failed.')) return redirect(reverse('lookup.transaction_summary', args=[uuid]))
def transaction_refund(request, tx_uuid): contrib = get_object_or_404(Contribution, uuid=tx_uuid, type=amo.CONTRIB_PURCHASE) refund_contribs = contrib.get_refund_contribs() refund_contrib = refund_contribs[0] if refund_contribs.exists() else None if refund_contrib: messages.error(request, _("A refund has already been processed.")) return redirect(reverse("lookup.transaction_summary", args=[tx_uuid])) form = TransactionRefundForm(request.POST) if not form.is_valid(): return jingo.render( request, "lookup/transaction_summary.html", dict( {"uuid": tx_uuid, "tx_refund_form": form, "tx_form": TransactionSearchForm()}.items() + _transaction_summary(tx_uuid).items() ), ) data = {"uuid": contrib.transaction_id, "manual": form.cleaned_data["manual"]} if settings.BANGO_FAKE_REFUNDS: data["fake_response_status"] = {"responseCode": form.cleaned_data["fake"]} try: res = client.api.bango.refund.post(data) except (HttpClientError, HttpServerError): # Either doing something not supposed to or Solitude had an issue. log.exception("Refund error: %s" % tx_uuid) messages.error(request, _("You cannot make a refund request for this transaction.")) return redirect(reverse("lookup.transaction_summary", args=[tx_uuid])) if res["status"] in [PENDING, COMPLETED]: # Create refund Contribution by cloning the payment Contribution. refund_contrib = Contribution.objects.get(id=contrib.id) refund_contrib.id = None refund_contrib.save() refund_contrib.update( type=amo.CONTRIB_REFUND, related=contrib, uuid=hashlib.md5(str(uuid.uuid4())).hexdigest(), amount=-refund_contrib.amount if refund_contrib.amount else None, transaction_id=res["uuid"], ) if res["status"] == PENDING: # Create pending Refund. refund_contrib.enqueue_refund( amo.REFUND_PENDING, request.amo_user, refund_reason=form.cleaned_data["refund_reason"] ) log.info("Refund pending: %s" % tx_uuid) email_buyer_refund_pending(contrib) messages.success(request, _("Refund for this transaction now pending.")) elif res["status"] == COMPLETED: # Create approved Refund. refund_contrib.enqueue_refund( amo.REFUND_APPROVED, request.amo_user, refund_reason=form.cleaned_data["refund_reason"] ) log.info("Refund approved: %s" % tx_uuid) email_buyer_refund_approved(contrib) messages.success(request, _("Refund for this transaction successfully approved.")) elif res["status"] == FAILED: # Bango no like. log.error("Refund failed: %s" % tx_uuid) messages.error(request, _("Refund request for this transaction failed.")) return redirect(reverse("lookup.transaction_summary", args=[tx_uuid]))
def transaction_refund(request, tx_uuid): contrib = get_object_or_404(Contribution, uuid=tx_uuid, type=amo.CONTRIB_PURCHASE) refund_contribs = contrib.get_refund_contribs() refund_contrib = refund_contribs[0] if refund_contribs.exists() else None if refund_contrib: messages.error(request, _('A refund has already been processed.')) return redirect(reverse('lookup.transaction_summary', args=[tx_uuid])) form = TransactionRefundForm(request.POST) if not form.is_valid(): return jingo.render( request, 'lookup/transaction_summary.html', dict({ 'uuid': tx_uuid, 'tx_refund_form': form, 'tx_form': TransactionSearchForm() }.items() + _transaction_summary(tx_uuid).items())) try: res = client.api.bango.refund.post({'uuid': contrib.transaction_id}) except (HttpClientError, HttpServerError): # Either doing something not supposed to or Solitude had an issue. log.exception('Refund error: %s' % tx_uuid) messages.error( request, _('You cannot make a refund request for this transaction.')) return redirect(reverse('lookup.transaction_summary', args=[tx_uuid])) if res['status'] in [PENDING, COMPLETED]: # Create refund Contribution by cloning the payment Contribution. refund_contrib = Contribution.objects.get(id=contrib.id) refund_contrib.id = None refund_contrib.save() refund_contrib.update( type=amo.CONTRIB_REFUND, related=contrib, uuid=hashlib.md5(str(uuid.uuid4())).hexdigest(), amount=-refund_contrib.amount if refund_contrib.amount else None, transaction_id=client.get(res['transaction'])['uuid']) if res['status'] == PENDING: # Create pending Refund. refund_contrib.enqueue_refund( amo.REFUND_PENDING, request.amo_user, refund_reason=form.cleaned_data['refund_reason']) log.info('Refund pending: %s' % tx_uuid) email_buyer_refund_pending(contrib) messages.success(request, _('Refund for this transaction now pending.')) elif res['status'] == COMPLETED: # Create approved Refund. refund_contrib.enqueue_refund( amo.REFUND_APPROVED, request.amo_user, refund_reason=form.cleaned_data['refund_reason']) log.info('Refund approved: %s' % tx_uuid) email_buyer_refund_approved(contrib) messages.success( request, _('Refund for this transaction successfully approved.')) elif res['status'] == FAILED: # Bango no like. log.error('Refund failed: %s' % tx_uuid) messages.error(request, _('Refund request for this transaction failed.')) return redirect(reverse('lookup.transaction_summary', args=[tx_uuid]))
def transaction_refund(request, tx_uuid): contrib = get_object_or_404(Contribution, uuid=tx_uuid, type=amo.CONTRIB_PURCHASE) refund_contribs = contrib.get_refund_contribs() refund_contrib = refund_contribs[0] if refund_contribs.exists() else None if refund_contrib: messages.error(request, _('A refund has already been processed.')) return redirect(reverse('lookup.transaction_summary', args=[tx_uuid])) form = TransactionRefundForm(request.POST) if not form.is_valid(): messages.error(request, str(form.errors)) return redirect(reverse('lookup.transaction_summary', args=[tx_uuid])) try: res = client.api.bango.refund.post({'uuid': contrib.transaction_id}) except (HttpClientError, HttpServerError): # Either doing something not supposed to or Solitude had an issue. log.exception('Refund error: %s' % tx_uuid) messages.error( request, _('You cannot make a refund request for this transaction.')) return redirect(reverse('lookup.transaction_summary', args=[tx_uuid])) if res['status'] in [PENDING, COMPLETED]: # Create refund Contribution by cloning the payment Contribution. refund_contrib = Contribution.objects.get(id=contrib.id) refund_contrib.id = None refund_contrib.save() refund_contrib.update( type=amo.CONTRIB_REFUND, related=contrib, uuid=hashlib.md5(str(uuid.uuid4())).hexdigest(), amount=-refund_contrib.amount if refund_contrib.amount else None, transaction_id=client.get(res['transaction'])['uuid']) if res['status'] == PENDING: # Create pending Refund. refund_contrib.enqueue_refund( amo.REFUND_PENDING, request.amo_user, refund_reason=form.cleaned_data['refund_reason']) log.info('Refund pending: %s' % tx_uuid) email_buyer_refund_pending(contrib) messages.success( request, _('Refund for this transaction now pending.')) elif res['status'] == COMPLETED: # Create approved Refund. refund_contrib.enqueue_refund( amo.REFUND_APPROVED, request.amo_user, refund_reason=form.cleaned_data['refund_reason']) log.info('Refund approved: %s' % tx_uuid) email_buyer_refund_approved(contrib) messages.success( request, _('Refund for this transaction successfully approved.')) elif res['status'] == FAILED: # Bango no like. log.error('Refund failed: %s' % tx_uuid) messages.error( request, _('Refund request for this transaction failed.')) return redirect(reverse('lookup.transaction_summary', args=[tx_uuid]))