def transaction_search(request): tx_form = TransactionSearchForm(request.GET) if tx_form.is_valid(): return redirect(reverse('lookup.transaction_summary', args=[tx_form.cleaned_data['q']])) else: return render(request, 'lookup/home.html', {'tx_form': tx_form})
def transaction_summary(request, tx_uuid): tx_data = _transaction_summary(tx_uuid) if not tx_data: raise Http404 tx_form = TransactionSearchForm() tx_refund_form = TransactionRefundForm() return render(request, 'lookup/transaction_summary.html', dict({'uuid': tx_uuid, 'tx_form': tx_form, 'tx_refund_form': tx_refund_form}.items() + tx_data.items()))
def transaction_search(request): tx_form = TransactionSearchForm(request.GET) if tx_form.is_valid(): return redirect(reverse("lookup.transaction_summary", args=[tx_form.cleaned_data["q"]])) else: return jingo.render(request, "lookup/home.html", {"tx_form": tx_form})
def home(request): tx_form = TransactionSearchForm() return jingo.render(request, 'lookup/home.html', {'tx_form': tx_form})
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 check_valid(self, data, valid=True): form = TransactionSearchForm(data) eq_(form.is_valid(), valid)
def check_valid(self, valid): form = TransactionSearchForm(self.data) eq_(form.is_valid(), valid)