Skip to content

Commit bde25ab

Browse files
author
Sunny Raj Rathod
authored
Merge pull request AuthorizeNet#26 from sunnyrajrathod/master
- Adding sample codes for new APIs.
2 parents 7eecbd7 + cdf6edb commit bde25ab

File tree

5 files changed

+134
-7
lines changed

5 files changed

+134
-7
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import os, sys
2+
import imp
3+
4+
from authorizenet import apicontractsv1
5+
from authorizenet.apicontrollers import *
6+
constants = imp.load_source('modulename', 'constants.py')
7+
from decimal import *
8+
9+
def get_hosted_payment_page(amount):
10+
merchantAuth = apicontractsv1.merchantAuthenticationType()
11+
merchantAuth.name = constants.apiLoginId
12+
merchantAuth.transactionKey = constants.transactionKey
13+
14+
setting1 = apicontractsv1.settingType()
15+
setting1.settingName = apicontractsv1.settingNameEnum.hostedPaymentButtonOptions
16+
setting1.settingValue = "{\"text\": \"Pay\"}"
17+
18+
setting2 = apicontractsv1.settingType()
19+
setting2.settingName = apicontractsv1.settingNameEnum.hostedPaymentOrderOptions
20+
setting2.settingValue = "{\"show\": false}"
21+
22+
settings = apicontractsv1.ArrayOfSetting()
23+
settings.setting.append(setting1)
24+
settings.setting.append(setting2)
25+
26+
transactionrequest = apicontractsv1.transactionRequestType()
27+
transactionrequest.transactionType = "authCaptureTransaction"
28+
transactionrequest.amount = amount
29+
30+
paymentPageRequest = apicontractsv1.getHostedPaymentPageRequest()
31+
paymentPageRequest.merchantAuthentication = merchantAuth
32+
paymentPageRequest.transactionRequest = transactionrequest
33+
paymentPageRequest.hostedProfileSettings = settings
34+
35+
paymentPageController = getHostedPaymentPageController(paymentPageRequest)
36+
37+
paymentPageController.execute()
38+
39+
paymentPageResponse = paymentPageController.getresponse()
40+
41+
if paymentPageResponse is not None:
42+
if paymentPageResponse.messages.resultCode == apicontractsv1.messageTypeEnum.Ok:
43+
print('Successfully got hosted payment page!')
44+
45+
print('Token : %s' % paymentPageResponse.token)
46+
47+
if paymentPageResponse.messages:
48+
print('Message Code : %s' % paymentPageResponse.messages.message[0]['code'].text)
49+
print('Message Text : %s' % paymentPageResponse.messages.message[0]['text'].text)
50+
else:
51+
if paymentPageResponse.messages:
52+
print('Failed to get batch statistics.\nCode:%s \nText:%s' % (paymentPageResponse.messages.message[0]['code'].text,paymentPageResponse.messages.message[0]['text'].text))
53+
54+
return paymentPageResponse
55+
56+
if(os.path.basename(__file__) == os.path.basename(sys.argv[0])):
57+
get_hosted_payment_page(constants.amount)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import os, sys
2+
import imp
3+
4+
from authorizenet import apicontractsv1
5+
from authorizenet.apicontrollers import *
6+
constants = imp.load_source('modulename', 'constants.py')
7+
from decimal import *
8+
9+
def update_held_transaction(transactionId):
10+
merchantAuth = apicontractsv1.merchantAuthenticationType()
11+
merchantAuth.name = constants.apiLoginId
12+
merchantAuth.transactionKey = constants.transactionKey
13+
14+
requesttype = apicontractsv1.heldTransactionRequestType()
15+
requesttype.action = "approve"
16+
requesttype.refTransId = transactionId
17+
18+
transactionrequest = apicontractsv1.updateHeldTransactionRequest()
19+
transactionrequest.merchantAuthentication = merchantAuth
20+
transactionrequest.heldTransactionRequest = requesttype
21+
22+
transactionRequestController = updateHeldTransactionController(transactionrequest)
23+
transactionRequestController.execute()
24+
25+
response = transactionRequestController.getresponse()
26+
27+
if response is not None:
28+
if response.messages.resultCode == "Ok":
29+
if hasattr(response.transactionResponse, 'messages') == True:
30+
print ('Successfully updated transaction with Transaction ID: %s' % response.transactionResponse.transId);
31+
print ('Transaction Response Code: %s' % response.transactionResponse.responseCode);
32+
print ('Message Code: %s' % response.transactionResponse.messages.message[0].code);
33+
print ('Description: %s' % response.transactionResponse.messages.message[0].description);
34+
else:
35+
print ('Failed Transaction.');
36+
if hasattr(response.transactionResponse, 'errors') == True:
37+
print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode));
38+
print ('Error message: %s' % response.transactionResponse.errors.error[0].errorText);
39+
else:
40+
print ('Failed Transaction.');
41+
if hasattr(response, 'transactionResponse') == True and hasattr(response.transactionResponse, 'errors') == True:
42+
print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode));
43+
print ('Error message: %s' % response.transactionResponse.errors.error[0].errorText);
44+
else:
45+
print ('Error Code: %s' % response.messages.message[0]['code'].text);
46+
print ('Error message: %s' % response.messages.message[0]['text'].text);
47+
else:
48+
print ('Null Response.');
49+
50+
return response
51+
52+
if(os.path.basename(__file__) == os.path.basename(sys.argv[0])):
53+
update_held_transaction(constants.transactionId)

TransactionReporting/get-merchant-details.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ def get_merchant_details():
2222

2323
if response is not None:
2424
if response.messages.resultCode == "Ok":
25-
print "Merchant Name: ", response.merchantName
26-
print "Gateway ID: ", response.gatewayId
27-
print "Processors: ",
25+
print("Merchant Name: ", response.merchantName)
26+
print("Gateway ID: ", response.gatewayId)
27+
print("Processors: "),
2828
for processor in response.processors.processor:
29-
print processor.name, "; ",
29+
print(processor.name, "; "),
3030
else:
31-
print "Failed Transaction."
31+
print ("Failed Transaction.")
3232
else:
33-
print "Null Response."
33+
print ("Null Response.")
3434

3535
return response
3636

list_of_sample_codes.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,6 @@ get_unsettled_transaction_list 1 0
5151
create_visa_checkout_transaction 1 0
5252
decrypt_visa_checkout_data 1 0
5353
get_customer_profile_ids 1 1
54-
get_merchant_details 0 1
54+
get_merchant_details 0 1
55+
update_held_transaction 0 0
56+
get_hosted_payment_page 0 1

test-runner.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,21 @@ def decrypt_visa_checkout_data(self):
580580
modl = imp.load_source('modulename', 'VisaCheckout/decrypt-visa-checkout-data.py')
581581
return modl.decrypt_visa_checkout_data()
582582

583+
def get_merchant_details(self):
584+
print("get_merchant_details")
585+
modl = imp.load_source('modulename', 'TransactionReporting/get-merchant-details.py')
586+
return modl.get_merchant_details()
587+
588+
def get_hosted_payment_page(self):
589+
print("get_hosted_payment_page")
590+
modl = imp.load_source('modulename', 'PaymentTransactions/get-hosted-payment-page.py')
591+
return modl.get_hosted_payment_page(self.getAmount())
592+
593+
def update_held_transaction(self):
594+
print("update_held_transaction")
595+
modl = imp.load_source('modulename', 'PaymentTransactions/update-held-transaction.py')
596+
return modl.update_held_transaction("12345")
597+
583598
def validate_response(self, response):
584599
if(response is None):
585600
return False

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy