-
Notifications
You must be signed in to change notification settings - Fork 0
/
payment_service.py
61 lines (49 loc) · 2.28 KB
/
payment_service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
This is test file
File : authorizenet.py
Description: API tool
Created On: 3-Feb-2016
Created By: [email protected]
"""
#importing the packages
from authorizenet import apicontractsv1
from authorizenet.apicontrollers import *
from decimal import *
class AuthorizeClient:
def __init__(self):
#Authenticating the merchant
self.merchantAuth = apicontractsv1.merchantAuthenticationType()
self.merchantAuth.name = '66BPb7jx'
self.merchantAuth.transactionKey = '3355gugw5HAdBr8x'
def make_payment(self, ccNumber, ccExpire, amount):
#CC details
creditCard = apicontractsv1.creditCardType()
creditCard.cardNumber = ccNumber
creditCard.expirationDate = ccExpire
#Making the payment type
payment = apicontractsv1.paymentType()
payment.creditCard = creditCard
#Setting the amount and transaction type
transactionrequest = apicontractsv1.transactionRequestType()
transactionrequest.transactionType = "authCaptureTransaction"
transactionrequest.amount = Decimal (amount)
transactionrequest.payment = payment
#creating the transaction request
createtransactionrequest = apicontractsv1.createTransactionRequest()
createtransactionrequest.merchantAuthentication = self.merchantAuth
createtransactionrequest.refId = "MerchantID-0001"
createtransactionrequest.transactionRequest = transactionrequest
createtransactioncontroller = createTransactionController(createtransactionrequest)
createtransactioncontroller.execute()
#Getting the response from the controller
response = createtransactioncontroller.getresponse()
#Checking the status code.
if (response.messages.resultCode=="Ok"):
#function to update
print "avsResultCode=", response.transactionResponse.avsResultCode
statusCode = {'error': False, 'resultcode': response.messages.resultCode}
else:
print "response code: %s" % response.messages.resultCode
print "error =", response.transactionResponse.errors.error
statusCode = {'error': True, 'resultcode': response.messages.resultCode}
return statusCode