Skip to content

Commit e46607b

Browse files
authored
Merge pull request #48 from kapilkumar99/Python_Chase_Pay_sample_code
Create create-a-chase-pay-transaction.py
2 parents e48f6d4 + d45f9d8 commit e46607b

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import os, sys
2+
import imp
3+
4+
from authorizenet import apicontractsv1
5+
from authorizenet.apicontrollers import *
6+
from authorizenet.constants import constants
7+
from decimal import *
8+
9+
def create_a_chase_pay_transaction():
10+
merchantAuth = apicontractsv1.merchantAuthenticationType()
11+
merchantAuth.name = constants.apiLoginId
12+
merchantAuth.transactionKey = constants.transactionKey
13+
14+
creditCard = apicontractsv1.creditCardType()
15+
creditCard.cardNumber = "4111111111111111"
16+
creditCard.expirationDate = "2020-12"
17+
creditCard.cardCode="999"
18+
# Set the token specific info
19+
creditCard.isPaymentToken = True
20+
creditCard.cryptogram = "EjRWeJASNFZ4kBI0VniQEjRWeJA="
21+
creditCard.tokenRequestorName="CHASE_PAY"
22+
creditCard.tokenRequestorId="12345678901"
23+
creditCard.tokenRequestorEci="07"
24+
25+
payment = apicontractsv1.paymentType()
26+
payment.creditCard = creditCard
27+
28+
transactionrequest = apicontractsv1.transactionRequestType()
29+
transactionrequest.transactionType = "authCaptureTransaction"
30+
transactionrequest.amount = Decimal ('1.50')
31+
transactionrequest.payment = payment
32+
33+
createtransactionrequest = apicontractsv1.createTransactionRequest()
34+
createtransactionrequest.merchantAuthentication = merchantAuth
35+
createtransactionrequest.refId = "MerchantID-0001"
36+
createtransactionrequest.transactionRequest = transactionrequest
37+
38+
createtransactioncontroller = createTransactionController(createtransactionrequest)
39+
createtransactioncontroller.execute()
40+
41+
response = createtransactioncontroller.getresponse()
42+
43+
if response is not None:
44+
if response.messages.resultCode == "Ok":
45+
if hasattr(response.transactionResponse, 'messages') == True:
46+
print ('Successfully created transaction with Transaction ID: %s' % response.transactionResponse.transId)
47+
print ('Transaction Response Code: %s' % response.transactionResponse.responseCode)
48+
print ('Message Code: %s' % response.transactionResponse.messages.message[0].code)
49+
print ('Description: %s' % response.transactionResponse.messages.message[0].description)
50+
else:
51+
print ('Failed Transaction.')
52+
if hasattr(response.transactionResponse, 'errors') == True:
53+
print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode))
54+
print ('Error message: %s' % response.transactionResponse.errors.error[0].errorText)
55+
else:
56+
print ('Failed Transaction.')
57+
if hasattr(response, 'transactionResponse') == True and hasattr(response.transactionResponse, 'errors') == True:
58+
print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode))
59+
print ('Error message: %s' % response.transactionResponse.errors.error[0].errorText)
60+
else:
61+
print ('Error Code: %s' % response.messages.message[0]['code'].text)
62+
print ('Error message: %s' % response.messages.message[0]['text'].text)
63+
else:
64+
print ('Failed to get response.')
65+
if hasattr(response, 'transactionResponse') == True and hasattr(response.transactionResponse, 'errors') == True:
66+
print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode))
67+
print ('Error message: %s' % response.transactionResponse.errors.error[0].errorText)
68+
return response
69+
70+
if(os.path.basename(__file__) == os.path.basename(sys.argv[0])):
71+
create_a_chase_pay_transaction()

0 commit comments

Comments
 (0)