def obj_create(self, bundle, request=None, **kwargs): bundle = super(HiPayInvoice, self).obj_create(bundle, request, **kwargs) # Go on pay it for real response = simplepayment(bundle.obj.invoice, sender_host=request.get_host(), secure=request.is_secure(), internal_transid=bundle.obj.pk) if response['status'] == 'Accepted': bundle.obj.redirect_url = response['message'] bundle.obj.save() return bundle
def hipay_invoice(request, invoice_id): current_user = Users.objects.get(email=request.user.email) invoices = [c.invoices_set.all() for c in current_user.clients_set.all()] if not invoices: raise Http404 qs = reduce(operator.or_,invoices) invoice = get_object_or_404(qs, pk=invoice_id) tr = InvoiceTransaction(invoice=invoice) tr.save() response = hipay.simplepayment(invoice, sender_host=request.get_host(), secure=request.is_secure(), internal_transid=tr.pk) if response['status'] == 'Accepted': tr.redirect_url = response['message'] tr.save() return redirect(response['message']) else: tr.delete() raise ValueError(response)