Created
October 4, 2016 10:33
-
-
Save maxmoriss/4a00b4ca79c9ca5eb6f03140995f09b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! -*- coding: utf-8 -*- | |
| import logging | |
| import hashlib | |
| from urlparse import urlparse, parse_qs | |
| import requests | |
| from django.conf import settings | |
| log = logging.getLogger(__name__) | |
| def get_preauth_form_url(self, order): | |
| """ Return url with preauth form """ | |
| m = hashlib.sha1() | |
| m.update('%d%d%f%s%s' % ( | |
| settings.ARIUS_ENDPOINTID, order.id, order.amount, order.user, | |
| settings.ARIUS_MERCHANT_CONTROL) | |
| ) | |
| control = m.hexdigest() | |
| data = { | |
| 'client_orderid': order.id, | |
| 'order_desc': order.descr, | |
| 'first_name': order.user.first_name, | |
| 'last_name': order.user.last_name, | |
| 'address1': order.user.address, | |
| 'city': order.user.city, | |
| 'zip_code': order.user.zip_code, | |
| 'country': order.user.country, | |
| 'phone': order.user.phone, | |
| 'email': order.user, | |
| 'amount': order.amount, | |
| 'currency': settings.ARIUS_CURRENCY, | |
| 'ipaddress': self.request.META['REMOTE_ADDR'], | |
| 'control': control, | |
| 'redirect_url': settings.ARIUS_REDIRECT_URL | |
| } | |
| try: | |
| r = requests.post('%s%s%d' % (settings.ARIUS_API_URL, 'preauth-form/', | |
| settings.ARIUS_ENDPOINTID), data=data) | |
| response = parse_qs(r.content) | |
| order.serial_number = response['serial-number'][0] | |
| order.paynet_order_id = response['paynet-order-id'][0] | |
| order.status = 'PREAUTH' | |
| order.save() | |
| return response['redirect-url'] | |
| except requests.exceptions.ConnectTimeout: | |
| log.error('preauth-form request failed, server is not response') | |
| return False | |
| def get_transaction_status(self, order): | |
| """ Check transaction status """ | |
| m = hashlib.sha1() | |
| m.update('%s%d%s%s' % ( | |
| settings.ARIUS_LOGIN, order['merchant-order-id'], order['paynet-order-id'], | |
| settings.ARIUS_MERCHANT_CONTROL) | |
| ) | |
| control = m.hexdigest() | |
| data = { | |
| 'login': settings.ARIUS_LOGIN, | |
| 'client_orderid': order['merchant-order-id'], | |
| 'orderid': order['paynet-order-id'], | |
| 'control': control, | |
| 'by-request-sn': order['serial-number'] | |
| } | |
| try: | |
| r = requests.post('%s%s%d' % (settings.ARIUS_API_URL, 'status/', | |
| settings.ARIUS_ENDPOINTID), data=data) | |
| response = parse_qs(r.content) | |
| order.status = 'APPROVED' | |
| order.save() | |
| return response['status'][0] | |
| except requests.exceptions.ConnectTimeout: | |
| log.error('status request failed, server is not response') | |
| return False | |
| def register_card(self, order): | |
| """ Get card refference """ | |
| m = hashlib.sha1() | |
| m.update('%s%d%s%s' % ( | |
| settings.ARIUS_LOGIN, order['merchant-order-id'], order['paynet-order-id'], | |
| settings.ARIUS_MERCHANT_CONTROL) | |
| ) | |
| control = m.hexdigest() | |
| data = { | |
| 'login': settings.ARIUS_LOGIN, | |
| 'client_orderid': order['merchant-order-id'], | |
| 'orderid': order['paynet-order-id'], | |
| 'control': control | |
| } | |
| try: | |
| r = requests.post('%s%s%d' % (settings.ARIUS_API_URL, 'create-card-ref/', | |
| settings.ARIUS_ENDPOINTID), data=data) | |
| response = parse_qs(r.content) | |
| if response['status'][0] == 'approved': | |
| user.card_ref_id = response['card-ref-id'][0] | |
| user.save() | |
| return user.card_ref_id | |
| else: | |
| log.error('Error during register card. Error code: %s, Error message: %s' % | |
| (response['error-code'][0], response['error-message'][0])) | |
| return False | |
| except requests.exceptions.ConnectTimeout: | |
| log.error('create-card-ref request failed, server is not response') | |
| return False | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment