def validate_payment_form(self): """Try to validate and then process the DirectPayment form.""" form = self.payment_form_cls(self.request.POST) if form.is_valid(): success = form.process(self.request, self.item) if success: payment_was_successful.send(sender=self.item) return HttpResponseRedirect(self.success_url) else: self.context['errors'] = self.errors['processing'] self.context[self.form_context_name] = form self.context.setdefault("errors", self.errors['form']) return render_to_response(self.payment_template, self.context, RequestContext(self.request))
def validate_confirm_form(self): """ Third and final step of ExpressCheckout. Request has pressed the confirmation but and we can send the final confirmation to PayPal using the data from the POST'ed form. """ wpp = PayPalWPP(self.request) pp_data = dict(token=self.request.POST['token'], payerid=self.request.POST['PayerID']) self.item.update(pp_data) # @@@ This check and call could be moved into PayPalWPP. if self.is_recurring(): success = wpp.createRecurringPaymentsProfile(self.item) else: success = wpp.doExpressCheckoutPayment(self.item) if success: payment_was_successful.send(sender=self.item) return HttpResponseRedirect(self.success_url) else: self.context['errors'] = self.errors['processing'] return self.render_payment_form()