Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add authorizenet payments
Michal Ociepka002628136cf9
diff --git a/order/views.py b/order/views.pyindex 7290951dba..441fe34a04 100644--- a/order/views.py+++ b/order/views.py@@ -2,6 +2,7 @@ from django.contrib import messagesfrom django.shortcuts import redirect, get_object_or_404from django.template.response import TemplateResponsefrom order.models import Order+from payment import authorizenetfrom payment.forms import PaymentForm@@ -12,5 +13,6 @@ def payment(request, token):order.payment_status = 'complete'order.save()messages.success(request, 'Your order was successfully processed')+ authorizenet(order, form.cleaned_data)return redirect('home')- return TemplateResponse(request, 'order/payment.html', {'form': form })+ return TemplateResponse(request, 'order/payment.html', {'form': form})diff --git a/payment/__init__.py b/payment/__init__.pyindex e69de29bb2..20a0a1414e 100644--- a/payment/__init__.py+++ b/payment/__init__.py@@ -0,0 +1,41 @@+from authorizenet.utils import process_payment+from django.utils.translation import ugettext+import urllib2+++class PaymentFailure(Exception):+ def __init__(self, error_message):+ super(PaymentFailure, self).__init__(error_message)+ self.error_message = error_message+++def authorizenet(order, cleaned_data, capture=True):+ trans_type = 'AUTH_CAPTURE' if capture else 'AUTH_ONLY'+ address = order.billing_address+ data = {+ 'card_num': cleaned_data['number'],+ 'exp_date': cleaned_data['expiration'],+ 'amount': order.get_total().gross,+ 'type': trans_type,+ 'first_name': address.first_name,+ 'last_name': address.last_name,+ 'company': address.company_name,+ 'address': '%s %s' % (address.street_address_1,+ address.street_address_2),+ 'city': address.city,+ 'state': address.country_area,+ 'zip': address.postal_code,+ 'country': address.country,+ 'phone': address.phone+ }+ if cleaned_data['cvv2']:+ data['card_code'] = cleaned_data['cvv2']+ if order.user:+ data['cust_id'] = str(order.user.id)+ data['email'] = order.user.email+ try:+ response = process_payment(data, {})+ except urllib2.URLError:+ raise PaymentFailure(ugettext('Could not connect to the gateway.'))+ if not response.is_approved:+ raise PaymentFailure(response.response_reason_text)diff --git a/saleor/settings.py b/saleor/settings.pyindex a085a76e07..b62121dceb 100644--- a/saleor/settings.py+++ b/saleor/settings.py@@ -91,6 +91,7 @@ INSTALLED_APPS = ['south','django_prices','mptt',+ 'authorizenet',# Local apps'saleor',