def validate_payment_form(self): payment_form = self.payment_form_class(self.request.POST) billing_form = self.billing_form_class(self.request.POST) if self.shipping_form_class: shipping_form = self.shipping_form_class(self.request.POST) #if shipping for exists also validate it if payment_form.is_valid() and billing_form.is_valid() and (not self.shipping_form_class or shipping_form.is_valid()): if not self.shipping_form_class: args = payment_form, billing_form else: args = payment_form, billing_form, shipping_form form_data = combine_form_data(*args) response = process_payment(form_data, self.extra_data) self.context['response'] = response if response.is_approved: return direct_to_template(self.request, self.success_template, self.context) else: self.context['errors'] = self.processing_error self.context['payment_form'] = payment_form self.context['billing_form'] = billing_form if self.shipping_form_class: self.context['shipping_form'] = shipping_form self.context.setdefault('errors', self.form_error) return direct_to_template(self.request, self.payment_template, self.context)
def confirm(self, order): v = order.paymentvariant.get_subtype_instance() trans_type = self.capture and 'AUTH_CAPTURE' or 'AUTH_ONLY' data = { 'card_num': v.cc_number, 'exp_date': v.cc_expiration, 'amount': order.total().gross, 'invoice_num': order.pk, 'type': trans_type, } if v.cc_cvv2: data['card_code'] = v.cc_cvv2 data.update(self.get_billing_data(order)) data.update(self.get_shipping_data(order)) data = dict((k, unidecode(v) if isinstance(v, unicode) else v) for k, v in data.items()) try: response = process_payment(data, {}) except urllib2.URLError: raise PaymentFailure(_("Could not connect to the gateway.")) v.cc_cvv2 = '' # Forget the CVV2 number immediately after the transaction v.response = response v.save() if not response.is_approved: raise PaymentFailure(response.response_reason_text)
def confirm(self, order, typ=None): v = order.paymentvariant.get_subtype_instance() trans_type = self.capture and 'AUTH_CAPTURE' or 'AUTH_ONLY' data = { 'card_num': v.cc_number, 'exp_date': v.cc_expiration, 'amount': order.get_total().gross, 'invoice_num': order.pk, 'type': trans_type, } if v.cc_cvv2: data['card_code'] = v.cc_cvv2 data.update(self.get_billing_data(order)) data.update(self.get_shipping_data(order)) data = dict((k, unidecode(v) if isinstance(v, unicode) else v) for k, v in data.items()) try: response = process_payment(data, {}) except urllib2.URLError: raise PaymentFailure(ugettext("Could not connect to the gateway.")) v.cc_cvv2 = '' # Forget the CVV2 number immediately after the transaction v.response = response v.save() if not response.is_approved: raise PaymentFailure(response.response_reason_text)
def validate_payment_form(self): payment_form = self.payment_form_class(self.request.POST) billing_form = self.billing_form_class(self.request.POST) if self.shipping_form_class: shipping_form = self.shipping_form_class(self.request.POST) #if shipping for exists also validate it if payment_form.is_valid() and billing_form.is_valid() and ( not self.shipping_form_class or shipping_form.is_valid()): if not self.shipping_form_class: args = payment_form, billing_form else: args = payment_form, billing_form, shipping_form form_data = combine_form_data(*args) response = process_payment(form_data, self.extra_data) self.context['response'] = response if response.is_approved: return direct_to_template(self.request, self.success_template, self.context) else: self.context['errors'] = self.processing_error self.context['payment_form'] = payment_form self.context['billing_form'] = billing_form if self.shipping_form_class: self.context['shipping_form'] = shipping_form self.context.setdefault('errors', self.form_error) return direct_to_template(self.request, self.payment_template, self.context)
def validate_payment_form(self): payment_form = self.payment_form_class(self.request.POST) billing_form = self.billing_form_class(self.request.POST) if payment_form.is_valid() and billing_form.is_valid(): form_data = combine_form_data(payment_form, billing_form) response = process_payment(form_data, self.extra_data) self.context['response'] = response if response.is_approved: return direct_to_template(self.request, self.success_template, self.context) else: self.context['errors'] = self.processing_error self.context['payment_form'] = payment_form self.context['billing_form'] = billing_form self.context.setdefault('errors', self.form_error) return direct_to_template(self.request, self.payment_template, self.context)
def validate_payment_form(self): payment_form = self.payment_form_class(self.request.POST) billing_form = self.billing_form_class(self.request.POST) if payment_form.is_valid() and billing_form.is_valid(): from authorizenet.utils import process_payment, combine_form_data form_data = combine_form_data(payment_form, billing_form) response = process_payment(form_data, self.extra_data) self.context["response"] = response if response.is_approved: return render_to_response( self.success_template, self.context, context_instance=RequestContext(self.request) ) else: self.context["errors"] = self.processing_error self.context["payment_form"] = payment_form self.context["billing_form"] = billing_form self.context.setdefault("errors", self.form_error) return render_to_response(self.payment_template, self.context, context_instance=RequestContext(self.request))