def charge_credit_card(amount): merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = constants.apiLoginId merchantAuth.transactionKey = constants.transactionKey creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = "4111111111111111" creditCard.expirationDate = "2020-12" payment = apicontractsv1.paymentType() payment.creditCard = creditCard transactionrequest = apicontractsv1.transactionRequestType() transactionrequest.transactionType = "authCaptureTransaction" transactionrequest.amount = amount transactionrequest.payment = payment createtransactionrequest = apicontractsv1.createTransactionRequest() createtransactionrequest.merchantAuthentication = merchantAuth createtransactionrequest.refId = "MerchantID-0001" createtransactionrequest.transactionRequest = transactionrequest createtransactioncontroller = createTransactionController( createtransactionrequest) createtransactioncontroller.execute() response = createtransactioncontroller.getresponse() if (response.messages.resultCode == "Ok"): print "Transaction ID : %s" % response.transactionResponse.transId else: print "response code: %s" % response.messages.resultCode return response
def charge(card_number, expiration_date, amount, merchant_id): merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = '4K24xbCW' merchantAuth.transactionKey = '8m39rKgQ92C4MRvx' creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = card_number creditCard.expirationDate = expiration_date payment = apicontractsv1.paymentType() payment.creditCard = creditCard transactionrequest = apicontractsv1.transactionRequestType() transactionrequest.transactionType = "authCaptureTransaction" transactionrequest.amount = Decimal(amount) transactionrequest.payment = payment createtransactionrequest = apicontractsv1.createTransactionRequest() createtransactionrequest.merchantAuthentication = merchantAuth createtransactionrequest.refId = merchant_id createtransactionrequest.transactionRequest = transactionrequest createtransactioncontroller = createTransactionController( createtransactionrequest) createtransactioncontroller.execute() response = createtransactioncontroller.getresponse() if (response.messages.resultCode == "Ok"): return (True, "Transaction ID : %s" % response.transactionResponse.transId) else: return (False, "response code: %s" % response.messages.resultCode)
def creds(self, cardNumber, exp_date, amount_to_take): creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = cardNumber creditCard.expirationDate = exp_date payment = apicontractsv1.paymentType() payment.creditCard = creditCard transactionrequest = apicontractsv1.transactionRequestType() transactionrequest.transactionType = "authCaptureTransaction" transactionrequest.amount = Decimal(amount_to_take) transactionrequest.payment = payment createtransactionrequest = apicontractsv1.createTransactionRequest() createtransactionrequest.merchantAuthentication = self.merchantAuth createtransactionrequest.refId = "MerchantID-0001" createtransactionrequest.transactionRequest = transactionrequest createtransactioncontroller = createTransactionController( createtransactionrequest) createtransactioncontroller.execute() response = createtransactioncontroller.getresponse() if (response.messages.resultCode == "Ok"): print("Transaction ID : %s" % response.transactionResponse.transId) else: print("response code: %s" % response.messages.resultCode)
def create_chase_pay_transaction(): merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = constants.apiLoginId merchantAuth.transactionKey = constants.transactionKey creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = "4111111111111111" creditCard.expirationDate = "2020-12" creditCard.cardCode="999" # Set the token specific info creditCard.isPaymentToken = True creditCard.cryptogram = "EjRWeJASNFZ4kBI0VniQEjRWeJA=" creditCard.tokenRequestorName="CHASE_PAY" creditCard.tokenRequestorId="12345678901" creditCard.tokenRequestorEci="07" payment = apicontractsv1.paymentType() payment.creditCard = creditCard transactionrequest = apicontractsv1.transactionRequestType() transactionrequest.transactionType = "authCaptureTransaction" transactionrequest.amount = Decimal ('1.50') transactionrequest.payment = payment createtransactionrequest = apicontractsv1.createTransactionRequest() createtransactionrequest.merchantAuthentication = merchantAuth createtransactionrequest.refId = "MerchantID-0001" createtransactionrequest.transactionRequest = transactionrequest createtransactioncontroller = createTransactionController(createtransactionrequest) createtransactioncontroller.execute() response = createtransactioncontroller.getresponse() if response is not None: if response.messages.resultCode == "Ok": if hasattr(response.transactionResponse, 'messages') == True: print ('Successfully created transaction with Transaction ID: %s' % response.transactionResponse.transId) print ('Transaction Response Code: %s' % response.transactionResponse.responseCode) print ('Message Code: %s' % response.transactionResponse.messages.message[0].code) print ('Description: %s' % response.transactionResponse.messages.message[0].description) else: print ('Failed Transaction.') if hasattr(response.transactionResponse, 'errors') == True: print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode)) print ('Error message: %s' % response.transactionResponse.errors.error[0].errorText) else: print ('Failed Transaction.') if hasattr(response, 'transactionResponse') == True and hasattr(response.transactionResponse, 'errors') == True: print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode)) print ('Error message: %s' % response.transactionResponse.errors.error[0].errorText) else: print ('Error Code: %s' % response.messages.message[0]['code'].text) print ('Error message: %s' % response.messages.message[0]['text'].text) else: print ('Failed to get response.') if hasattr(response, 'transactionResponse') == True and hasattr(response.transactionResponse, 'errors') == True: print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode)) print ('Error message: %s' % response.transactionResponse.errors.error[0].errorText) return response
def payment(name, key, card_number, expiration_date, amount, merchant_id): merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = name merchantAuth.transactionKey = key creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = card_number creditCard.expirationDate = expiration_date payment = apicontractsv1.paymentType() payment.creditCard = creditCard transactionrequest = apicontractsv1.transactionRequestType() transactionrequest.transactionType = "authCaptureTransaction" transactionrequest.amount = Decimal(amount) transactionrequest.payment = payment createtransactionrequest = apicontractsv1.createTransactionRequest() createtransactionrequest.merchantAuthentication = merchantAuth createtransactionrequest.refId = merchant_id createtransactionrequest.transactionRequest = transactionrequest createtransactioncontroller = createTransactionController( createtransactionrequest) createtransactioncontroller.execute() response = createtransactioncontroller.getresponse() if (response.messages.resultCode == "Ok"): return response.transactionResponse.transId print("Transaction ID : %s" % response.transactionResponse.transId) else: return response.messages.resultCode print("response code: %s" % response.messages.resultCode)
def purchase(card, amount): authorization = apicontractsv1.merchantAuthenticationType() authorization.name = get_api_login_id() authorization.transactionKey = get_transaction_id() card_info = apicontractsv1.creditCardType() card_info.cardNumber = card.number card_info.expirationDate = card.expiration_date card_info.cardCode = card.code payment = apicontractsv1.paymentType() payment.creditCard = card_info request_info = apicontractsv1.transactionRequestType() request_info.transactionType = "authCaptureTransaction" request_info.amount = Decimal(amount) request_info.payment = payment request = apicontractsv1.createTransactionRequest() request.merchantAuthentication = authorization request.refId = "MerchantID-0001" request.transactionRequest = request_info controller = createTransactionController(request) controller.execute() api_response = controller.getresponse() response = response_options(api_response) return response
def send(self, card_number, expiration, amount): """ send the payment and return the transactionID or Error""" merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = self.merchant_id merchantAuth.transactionKey = self.merchant_key creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = card_number # 5424000000000015 creditCard.expirationDate = expiration payment = apicontractsv1.paymentType() payment.creditCard = creditCard transactionrequest = apicontractsv1.transactionRequestType() transactionrequest.transactionType ="authCaptureTransaction" transactionrequest.amount = Decimal(amount) transactionrequest.payment = payment createtransactionrequest = apicontractsv1.createTransactionRequest() createtransactionrequest.merchantAuthentication = merchantAuth createtransactionrequest.refId ="MerchantID-0001" createtransactionrequest.transactionRequest = transactionrequest createtransactioncontroller = createTransactionController(createtransactionrequest) createtransactioncontroller.execute() response = createtransactioncontroller.getresponse() if (response.messages.resultCode=="Ok"): return response.transactionResponse else: return response.messages.resultCode
def testchargeCreditCard(self): creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = "4111111111111111" creditCard.expirationDate = "2020-12" payment = apicontractsv1.paymentType() payment.creditCard = creditCard transactionrequest = apicontractsv1.transactionRequestType() transactionrequest.transactionType = "authCaptureTransaction" transactionrequest.amount = Decimal( str(round(random.random() * 100, 2))) transactionrequest.payment = payment createtransactionrequest = apicontractsv1.createTransactionRequest() createtransactionrequest.merchantAuthentication = self.merchantAuthentication createtransactionrequest.refId = "MerchantID-0001" createtransactionrequest.transactionRequest = transactionrequest createtransactioncontroller = createTransactionController( createtransactionrequest) createtransactioncontroller.execute() response = createtransactioncontroller.getresponse() if hasattr(response, 'messages') == True: if hasattr(response.messages, 'resultCode') == True: self.assertEquals('Ok', response.messages.resultCode) if hasattr(response, 'transactionResponse') == True: if hasattr(response.transactionResponse, 'transId') == True: createdTransactionId = response.transactionResponse.transId return str(createdTransactionId)
def test_create_customer_profile(self): """ Create customer profile and payment methods """ customer = CustomerFactory() credit_card = CreditCard() profile = apicontractsv1.customerProfileType() profile.merchantCustomerId = customer['ref_id'] profile.description = '%s %s' % (customer['first_name'], customer['last_name']) profile.email = customer['email'] card = apicontractsv1.creditCardType() card.cardNumber = credit_card['card_number'] card.expirationDate = credit_card['expire_date'].strftime('%Y-%m') payment_profile = apicontractsv1.customerPaymentProfileType() payment_profile.customerType = 'individual' payment = apicontractsv1.paymentType() payment.creditCard = card payment_profile.payment = payment profile.paymentProfiles = [payment_profile] create_profile_request = apicontractsv1.createCustomerProfileRequest() create_profile_request.merchantAuthentication = self.merchant create_profile_request.profile = profile controller = apicontrollers.CreateCustomerProfileController(create_profile_request) response = controller.execute() rc = etree.tostring(response.root) response.get_element_text('ns:customerProfileId') # response.customerPaymentProfileIdList.numericString[0] print(response)
def charge_credit_card(card, amount): merchant_auth = apicontractsv1.merchantAuthenticationType() merchant_auth.name = settings.get_api_login_id() merchant_auth.transactionKey = settings.get_transaction_id() credit_card = apicontractsv1.creditCardType() credit_card.cardNumber = card.number credit_card.expirationDate = card.expiration_date credit_card.cardCode = card.code payment = apicontractsv1.paymentType() payment.creditCard = credit_card transaction_request = apicontractsv1.transactionRequestType() transaction_request.transactionType = "authCaptureTransaction" transaction_request.amount = Decimal(amount) transaction_request.payment = payment request = apicontractsv1.createTransactionRequest() request.merchantAuthentication = merchant_auth request.refId = "MerchantID-0001" request.transactionRequest = transaction_request transaction_controller = createTransactionController(request) transaction_controller.execute() api_response = transaction_controller.getresponse() response = response_mapper(api_response) return response
def charge(card_number, expiration_date, amount, merchant_id): creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = card_number creditCard.expirationDate = expiration_date payment = apicontractsv1.paymentType() payment.creditCard = creditCard transactionrequest = apicontractsv1.transactionRequestType() transactionrequest.transactionType = "authCaptureTransaction" transactionrequest.amount = amount transactionrequest.payment = payment createtransactionrequest = apicontractsv1.createTransactionRequest() createtransactionrequest.merchantAuthentication = merchantAuth createtransactionrequest.refId = merchant_id createtransactionrequest.transactionRequest = transactionrequest createtransactioncontroller = createTransactionController( createtransactionrequest) createtransactioncontroller.execute() response = createtransactioncontroller.getresponse() if (response.messages.resultCode == "Ok"): print "Transaction ID : %s" % response.transactionResponse.transId else: print "response code: %s" % response.messages.resultCode
def authorize_credit_card(): merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = CONSTANTS.apiLoginId merchantAuth.transactionKey = CONSTANTS.transactionKey creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = cardNumber creditCard.expirationDate = expirationDate payment = apicontractsv1.paymentType() payment.creditCard = creditCard transactionrequest = apicontractsv1.transactionRequestType() transactionrequest.transactionType = "authCaptureTransaction" transactionrequest.amount = Decimal(amount) transactionrequest.payment = payment createtransactionrequest = apicontractsv1.createTransactionRequest() createtransactionrequest.merchantAuthentication = merchantAuth createtransactionrequest.refId = "MerchantID-0001" createtransactionrequest.transactionRequest = transactionrequest createtransactioncontroller = createTransactionController( createtransactionrequest) createtransactioncontroller.execute() response = createtransactioncontroller.getresponse() if (response.messages.resultCode == "Ok"): print("Transaction ID : %s" % response.transactionResponse.transId) else: print("response code: %s" % response.messages.resultCode)
def refund_payment(self, payment): # Init transaction self.transaction = self.create_transaction() self.transaction_type = self.create_transaction_type( self.transaction_types[TransactionTypes.REFUND]) self.transaction_type.amount = self.to_valid_decimal(payment.amount) self.transaction_type.refTransId = payment.transaction creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = ast.literal_eval( payment.result['raw']).get('accountNumber')[-4:] creditCard.expirationDate = "XXXX" payment_type = apicontractsv1.paymentType() payment_type.creditCard = creditCard self.transaction_type.payment = payment_type self.transaction.transactionRequest = self.transaction_type self.controller = createTransactionController(self.transaction) self.set_controller_api_endpoint() self.controller.execute() response = self.controller.getresponse() self.check_response(response) if self.transaction_submitted: self.update_invoice_status(Invoice.InvoiceStatus.REFUNDED)
def test_capture_transaction(self): credit_card = CreditCard() order = OrderFactory() card = apicontractsv1.creditCardType() card.cardNumber = credit_card['card_number'] card.expirationDate = credit_card['expire_date'].strftime('%Y-%m') payment = apicontractsv1.paymentType() payment.creditCard = card transaction = apicontractsv1.transactionRequestType() transaction.transactionType = "authCaptureTransaction" transaction.amount = order['amount'] transaction.payment = payment request = apicontractsv1.createTransactionRequest() request.merchantAuthentication = self.merchant request.refId = order['ref_id'] request.transactionRequest = transaction controller = apicontrollers.CreateTransactionController(request) response = controller.execute() print(response)
def creditCardPayment(request): creditCard = apicontractsv1.creditCardType() form = CreditCardForm() if request.method == 'POST': form = CreditCardForm(request.POST) if form.is_valid(): try: creditCard_num = form.cleaned_data['creditCard_num'] except (ValidationError): return render(request, 'new/card.html', { 'error_message': "Invalid Card", }) try: expirationDate = form.cleaned_data['expirationDate'] amount = form.cleaned_data['amount'] creditCard.cardNumber = str(creditCard_num) creditCard.expirationDate = str(expirationDate) payment = apicontractsv1.paymentType() payment.creditCard = creditCard transactionrequest = apicontractsv1.transactionRequestType() transactionrequest.transactionType = "authCaptureTransaction" transactionrequest.amount = amount transactionrequest.payment = payment #code from api createtransactionrequestapicontractsv1.createTransactionRequest( ) createtransactionrequest.merchantAuthentication = merchantAuth createtransactionrequest.refId = "MerchantID01" createtransactionrequest.transactionRequest = transactionrequest createtransactioncontroller = createTransactionController( createtransactionrequest) createtransactioncontroller.execute() response = createtransactioncontroller.getresponse() if (response.messages.resultCode == "Ok"): message = "Transaction ID : %s" % response.transactionResponse.transId else: message = "response code: %s" % response.messages.resultCode return render( request, 'new/card.html', {"message": message}, ) except (ValidationError): return render(request, 'new/card.html', { 'error_message': "Card Expired!", }) return render( request, 'new/card.html', )
def setUp(self): utility.helper.setpropertyfile('anet_python_sdk_properties.ini') self.amount = str(round(random.random() * 100, 2)) self.merchantAuthentication = apicontractsv1.merchantAuthenticationType( ) self.merchantAuthentication.name = utility.helper.getproperty( 'api.login.id') self.merchantAuthentication.transactionKey = utility.helper.getproperty( 'transaction.key') self.ref_id = 'Sample' self.dateOne = datetime.date(2020, 8, 30) self.interval = CTD_ANON() self.interval.length = 1 self.interval.unit = 'months' self.paymentScheduleOne = apicontractsv1.paymentScheduleType() self.paymentScheduleOne.interval = self.interval self.paymentScheduleOne.startDate = self.dateOne self.paymentScheduleOne.totalOccurrences = 12 self.paymentScheduleOne.trialOccurrences = 1 self.creditCardOne = apicontractsv1.creditCardType() self.creditCardOne.cardNumber = "4111111111111111" self.creditCardOne.expirationDate = "2020-12" self.payment = apicontractsv1.paymentType() self.payment.creditCard = self.creditCardOne self.customerOne = apicontractsv1.nameAndAddressType() self.customerOne.firstName = "John" self.customerOne.lastName = "Smith" self.customerData = apicontractsv1.customerDataType() self.customerData.id = "99999456654" self.subscriptionOne = apicontractsv1.ARBSubscriptionType() self.subscriptionOne.paymentSchedule = self.paymentScheduleOne self.subscriptionOne.amount = Decimal( str(round(random.random() * 100, 2))) self.subscriptionOne.trialAmount = Decimal('0.03') self.subscriptionOne.payment = self.payment self.subscriptionOne.billTo = self.customerOne self.order = apicontractsv1.orderType() self.order.invoiceNumber = "INV-21345" self.order.description = "Product description" self.billTo = apicontractsv1.customerAddressType() self.billTo.firstName = "Ellen" self.billTo.lastName = "Johnson" self.billTo.company = "Souveniropolis" self.billTo.address = "14 Main St" self.billTo.city = "Seattle" self.billTo.state = "WA" self.billTo.zip = "98122" self.billTo.country = "USA"
def setUp(self): utility.helper.setpropertyfile('anet_python_sdk_properties.ini') self.amount = str(round(random.random()*100, 2)) self.merchantAuthentication = apicontractsv1.merchantAuthenticationType() self.merchantAuthentication.name = helper.getproperty('api_login_id') self.merchantAuthentication.transactionKey = helper.getproperty('transaction_key') self.ref_id = 'Sample' self.dateOne = datetime.date(2020, 8, 30) self.interval = CTD_ANON() self.interval.length = 1 self.interval.unit = 'months' self.paymentScheduleOne = apicontractsv1.paymentScheduleType() self.paymentScheduleOne.interval = self.interval self.paymentScheduleOne.startDate = self.dateOne self.paymentScheduleOne.totalOccurrences = 12 self.paymentScheduleOne.trialOccurrences = 1 self.creditCardOne = apicontractsv1.creditCardType() self.creditCardOne.cardNumber = "4111111111111111" self.creditCardOne.expirationDate = "2020-12" self.payment = apicontractsv1.paymentType() self.payment.creditCard = self.creditCardOne self.customerOne = apicontractsv1.nameAndAddressType() self.customerOne.firstName = "John" self.customerOne.lastName = "Smith" self.customerData = apicontractsv1.customerDataType() self.customerData.id = "99999456654" self.subscriptionOne = apicontractsv1.ARBSubscriptionType() self.subscriptionOne.paymentSchedule = self.paymentScheduleOne self.subscriptionOne.amount = Decimal(self.amount) self.subscriptionOne.trialAmount = Decimal ('0.03') self.subscriptionOne.payment = self.payment self.subscriptionOne.billTo = self.customerOne self.order = apicontractsv1.orderType() self.order.invoiceNumber = "INV-21345" self.order.description = "Product description" self.billTo = apicontractsv1.customerAddressType() self.billTo.firstName = "Ellen" self.billTo.lastName = "Johnson" self.billTo.company = "Souveniropolis" self.billTo.address = "14 Main St" self.billTo.city = "Seattle" self.billTo.state = "WA" self.billTo.zip = "98122" self.billTo.country = "USA"
def create_credit_card_payment(self): """ Creates and credit card payment type instance form the payment information set. """ creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = self.payment_info.data.get('card_number') creditCard.expirationDate = "-".join([self.payment_info.data.get('expire_year'), self.payment_info.data.get('expire_month')]) creditCard.cardCode = str(self.payment_info.data.get('cvv_number')) return creditCard
def capture_funds_authorized_through_another_channel(): amount = str(round(random.random()*100, 2)) merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = constants.apiLoginId merchantAuth.transactionKey = constants.transactionKey creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = "4111111111111111" creditCard.expirationDate = "2035-12" payment = apicontractsv1.paymentType() payment.creditCard = creditCard transactionrequest = apicontractsv1.transactionRequestType() transactionrequest.transactionType = "captureOnlyTransaction" transactionrequest.amount = Decimal (amount) transactionrequest.payment = payment transactionrequest.authCode = "ROHNFQ" createtransactionrequest = apicontractsv1.createTransactionRequest() createtransactionrequest.merchantAuthentication = merchantAuth createtransactionrequest.refId = "MerchantID-0001" createtransactionrequest.transactionRequest = transactionrequest createtransactioncontroller = createTransactionController(createtransactionrequest) createtransactioncontroller.execute() response = createtransactioncontroller.getresponse() if response is not None: if response.messages.resultCode == "Ok": if hasattr(response.transactionResponse, 'messages') == True: print ('Successfully created transaction with Transaction ID: %s' % response.transactionResponse.transId) print ('Transaction Response Code: %s' % response.transactionResponse.responseCode) print ('Message Code: %s' % response.transactionResponse.messages.message[0].code) print ('Description: %s' % response.transactionResponse.messages.message[0].description) else: print ('Failed Transaction.') if hasattr(response.transactionResponse, 'errors') == True: print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode)) print ('Error message: %s' % response.transactionResponse.errors.error[0].errorText) else: print ('Failed Transaction.') if hasattr(response, 'transactionResponse') == True and hasattr(response.transactionResponse, 'errors') == True: print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode)) print ('Error message: %s' % response.transactionResponse.errors.error[0].errorText) else: print ('Error Code: %s' % response.messages.message[0]['code'].text) print ('Error message: %s' % response.messages.message[0]['text'].text) else: print ('Null Response.') return response
def create_subscription(amount, days): # Setting the merchant details merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = constants.apiLoginId merchantAuth.transactionKey = constants.transactionKey # Setting payment schedule paymentschedule = apicontractsv1.paymentScheduleType() paymentschedule.interval = apicontractsv1.paymentScheduleTypeInterval( ) #apicontractsv1.CTD_ANON() #modified by krgupta paymentschedule.interval.length = days paymentschedule.interval.unit = apicontractsv1.ARBSubscriptionUnitEnum.days paymentschedule.startDate = datetime(2021, 12, 30) paymentschedule.totalOccurrences = 12 paymentschedule.trialOccurrences = 1 # Giving the credit card info creditcard = apicontractsv1.creditCardType() creditcard.cardNumber = "4111111111111111" creditcard.expirationDate = "2035-12" payment = apicontractsv1.paymentType() payment.creditCard = creditcard # Setting billing information billto = apicontractsv1.nameAndAddressType() billto.firstName = "John" billto.lastName = "Smith" # Setting subscription details subscription = apicontractsv1.ARBSubscriptionType() subscription.name = "Sample Subscription" subscription.paymentSchedule = paymentschedule subscription.amount = amount subscription.trialAmount = Decimal('0.00') subscription.billTo = billto subscription.payment = payment # Creating the request request = apicontractsv1.ARBCreateSubscriptionRequest() request.merchantAuthentication = merchantAuth request.subscription = subscription # Creating and executing the controller controller = ARBCreateSubscriptionController(request) controller.execute() # Getting the response response = controller.getresponse() if (response.messages.resultCode == "Ok"): print("SUCCESS:") print("Message Code : %s" % response.messages.message[0]['code'].text) print("Message text : %s" % str(response.messages.message[0]['text'].text)) print("Subscription ID : %s" % response.subscriptionId) else: print("ERROR:") print("Message Code : %s" % response.messages.message[0]['code'].text) print("Message text : %s" % response.messages.message[0]['text'].text) return response
def capture_funds_authorized_through_another_channel(): amount = str(round(random.random()*100, 2)) merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = constants.apiLoginId merchantAuth.transactionKey = constants.transactionKey creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = "4111111111111111" creditCard.expirationDate = "2020-12" payment = apicontractsv1.paymentType() payment.creditCard = creditCard transactionrequest = apicontractsv1.transactionRequestType() transactionrequest.transactionType = "captureOnlyTransaction" transactionrequest.amount = Decimal (amount) transactionrequest.payment = payment transactionrequest.authCode = "ROHNFQ" createtransactionrequest = apicontractsv1.createTransactionRequest() createtransactionrequest.merchantAuthentication = merchantAuth createtransactionrequest.refId = "MerchantID-0001" createtransactionrequest.transactionRequest = transactionrequest createtransactioncontroller = createTransactionController(createtransactionrequest) createtransactioncontroller.execute() response = createtransactioncontroller.getresponse() if response is not None: if response.messages.resultCode == "Ok": if hasattr(response.transactionResponse, 'messages') == True: print ('Successfully created transaction with Transaction ID: %s' % response.transactionResponse.transId) print ('Transaction Response Code: %s' % response.transactionResponse.responseCode) print ('Message Code: %s' % response.transactionResponse.messages.message[0].code) print ('Description: %s' % response.transactionResponse.messages.message[0].description) else: print ('Failed Transaction.') if hasattr(response.transactionResponse, 'errors') == True: print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode)) print ('Error message: %s' % response.transactionResponse.errors.error[0].errorText) else: print ('Failed Transaction.') if hasattr(response, 'transactionResponse') == True and hasattr(response.transactionResponse, 'errors') == True: print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode)) print ('Error message: %s' % response.transactionResponse.errors.error[0].errorText) else: print ('Error Code: %s' % response.messages.message[0]['code'].text) print ('Error message: %s' % response.messages.message[0]['text'].text) else: print ('Null Response.') return response
def refund_transaction(refTransId): merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = constants.apiLoginId merchantAuth.transactionKey = constants.transactionKey creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = "0015" creditCard.expirationDate = "XXXX" payment = apicontractsv1.paymentType() payment.creditCard = creditCard transactionrequest = apicontractsv1.transactionRequestType() transactionrequest.transactionType = "refundTransaction" transactionrequest.amount = Decimal ('2.55') #set refTransId to transId of a settled transaction transactionrequest.refTransId = refTransId transactionrequest.payment = payment createtransactionrequest = apicontractsv1.createTransactionRequest() createtransactionrequest.merchantAuthentication = merchantAuth createtransactionrequest.refId = "MerchantID-0001" createtransactionrequest.transactionRequest = transactionrequest createtransactioncontroller = createTransactionController(createtransactionrequest) createtransactioncontroller.execute() response = createtransactioncontroller.getresponse() if response is not None: if response.messages.resultCode == "Ok": if hasattr(response.transactionResponse, 'messages') == True: print ('Successfully created transaction with Transaction ID: %s' % response.transactionResponse.transId); print ('Transaction Response Code: %s' % response.transactionResponse.responseCode); print ('Message Code: %s' % response.transactionResponse.messages.message[0].code); print ('Description: %s' % response.transactionResponse.messages.message[0].description); else: print ('Failed Transaction.'); if hasattr(response.transactionResponse, 'errors') == True: print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode)); print ('Error message: %s' % response.transactionResponse.errors.error[0].errorText); else: print ('Failed Transaction.'); if hasattr(response, 'transactionResponse') == True and hasattr(response.transactionResponse, 'errors') == True: print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode)); print ('Error message: %s' % response.transactionResponse.errors.error[0].errorText); else: print ('Error Code: %s' % response.messages.message[0]['code'].text); print ('Error message: %s' % response.messages.message[0]['text'].text); else: print ('Null Response.'); return response
def charge_tokenized_credit_card(): merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = constants.apiLoginId merchantAuth.transactionKey = constants.transactionKey creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = "4111111111111111" creditCard.expirationDate = "2020-12" # Set the token specific info creditCard.isPaymentToken = True creditCard.cryptogram = "EjRWeJASNFZ4kBI0VniQEjRWeJA=" payment = apicontractsv1.paymentType() payment.creditCard = creditCard transactionrequest = apicontractsv1.transactionRequestType() transactionrequest.transactionType = "authCaptureTransaction" transactionrequest.amount = Decimal ('1.5') transactionrequest.payment = payment createtransactionrequest = apicontractsv1.createTransactionRequest() createtransactionrequest.merchantAuthentication = merchantAuth createtransactionrequest.refId = "MerchantID-0001" createtransactionrequest.transactionRequest = transactionrequest createtransactioncontroller = createTransactionController(createtransactionrequest) createtransactioncontroller.execute() response = createtransactioncontroller.getresponse() if response is not None: if response.messages.resultCode == "Ok": if hasattr(response.transactionResponse, 'messages') == True: print ('Successfully created transaction with Transaction ID: %s' % response.transactionResponse.transId) print ('Transaction Response Code: %s' % response.transactionResponse.responseCode) print ('Message Code: %s' % response.transactionResponse.messages.message[0].code) print ('Description: %s' % response.transactionResponse.messages.message[0].description) else: print ('Failed Transaction.') if hasattr(response.transactionResponse, 'errors') == True: print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode)) print ('Error message: %s' % response.transactionResponse.errors.error[0].errorText) else: print ('Failed Transaction.') if hasattr(response, 'transactionResponse') == True and hasattr(response.transactionResponse, 'errors') == True: print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode)) print ('Error message: %s' % response.transactionResponse.errors.error[0].errorText) else: print ('Error Code: %s' % response.messages.message[0]['code'].text) print ('Error message: %s' % response.messages.message[0]['text'].text) else: print ('Null Response.') return response
def create_subscription(amount, days): # Setting the merchant details merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = constants.apiLoginId merchantAuth.transactionKey = constants.transactionKey # Setting payment schedule paymentschedule = apicontractsv1.paymentScheduleType() paymentschedule.interval = apicontractsv1.paymentScheduleTypeInterval() #apicontractsv1.CTD_ANON() #modified by krgupta paymentschedule.interval.length = days paymentschedule.interval.unit = apicontractsv1.ARBSubscriptionUnitEnum.days paymentschedule.startDate = datetime(2020, 8, 30) paymentschedule.totalOccurrences = 12 paymentschedule.trialOccurrences = 1 # Giving the credit card info creditcard = apicontractsv1.creditCardType() creditcard.cardNumber = "4111111111111111" creditcard.expirationDate = "2020-12" payment = apicontractsv1.paymentType() payment.creditCard = creditcard # Setting billing information billto = apicontractsv1.nameAndAddressType() billto.firstName = "John" billto.lastName = "Smith" # Setting subscription details subscription = apicontractsv1.ARBSubscriptionType() subscription.name = "Sample Subscription" subscription.paymentSchedule = paymentschedule subscription.amount = amount subscription.trialAmount = Decimal('0.00') subscription.billTo = billto subscription.payment = payment # Creating the request request = apicontractsv1.ARBCreateSubscriptionRequest() request.merchantAuthentication = merchantAuth request.subscription = subscription # Creating and executing the controller controller = ARBCreateSubscriptionController(request) controller.execute() # Getting the response response = controller.getresponse() if (response.messages.resultCode=="Ok"): print ("SUCCESS:") print ("Message Code : %s" % response.messages.message[0]['code'].text) print ("Message text : %s" % str(response.messages.message[0]['text'].text)) print ("Subscription ID : %s" % response.subscriptionId) else: print ("ERROR:") print ("Message Code : %s" % response.messages.message[0]['code'].text) print ("Message text : %s" % response.messages.message[0]['text'].text) return response
def make_creditCard(credit_card, expiration_date, card_code): """Create a payment object with credit card details""" payment = apicontractsv1.paymentType() creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = credit_card creditCard.expirationDate = expiration_date creditCard.cardCode = card_code payment.creditCard = creditCard return payment
def charge_credit_card(amount): merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = constants.apiLoginId merchantAuth.transactionKey = constants.transactionKey creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = "4111111111111111" creditCard.expirationDate = "2020-12" payment = apicontractsv1.paymentType() payment.creditCard = creditCard transactionrequest = apicontractsv1.transactionRequestType() transactionrequest.transactionType = "authCaptureTransaction" transactionrequest.amount = amount transactionrequest.payment = payment createtransactionrequest = apicontractsv1.createTransactionRequest() createtransactionrequest.merchantAuthentication = merchantAuth createtransactionrequest.refId = "MerchantID-0001" createtransactionrequest.transactionRequest = transactionrequest createtransactioncontroller = createTransactionController(createtransactionrequest) createtransactioncontroller.execute() response = createtransactioncontroller.getresponse() if response is not None: if response.messages.resultCode == "Ok": if hasattr(response.transactionResponse, 'messages') == True: print ('Successfully created transaction with Transaction ID: %s' % response.transactionResponse.transId); print ('Transaction Response Code: %s' % response.transactionResponse.responseCode); print ('Message Code: %s' % response.transactionResponse.messages.message[0].code); print ('Description: %s' % response.transactionResponse.messages.message[0].description); else: print ('Failed Transaction.'); if hasattr(response.transactionResponse, 'errors') == True: print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode)); print ('Error message: %s' % response.transactionResponse.errors.error[0].errorText); else: print ('Failed Transaction.'); if hasattr(response, 'transactionResponse') == True and hasattr(response.transactionResponse, 'errors') == True: print ('Error Code: %s' % str(response.transactionResponse.errors.error[0].errorCode)); print ('Error message: %s' % response.transactionResponse.errors.error[0].errorText); else: print ('Error Code: %s' % response.messages.message[0]['code'].text); print ('Error message: %s' % response.messages.message[0]['text'].text); else: print ('Null Response.'); return response
def _create_credit_card(self, customer): """ Create a Credit Card element that can be applied to an Authorize.net Transaction Request. :param customer: A silver customer. :returns apicontractsv1.creditCardType instance: """ cc = apicontractsv1.creditCardType() cc.cardNumber = customer.meta.get('cardNumber') cc.expirationDate = customer.meta.get('expirationDate') cc.cardCode = customer.meta.get('cardCode') return cc
def update_customer_payment_profile(customerProfileId, customerPaymentProfileId): merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = constants.apiLoginId merchantAuth.transactionKey = constants.transactionKey creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = "4111111111111111" creditCard.expirationDate = "2020-12" payment = apicontractsv1.paymentType() payment.creditCard = creditCard paymentProfile = apicontractsv1.customerPaymentProfileExType() paymentProfile.billTo = apicontractsv1.customerAddressType() paymentProfile.billTo.firstName = "John" paymentProfile.billTo.lastName = "Doe" paymentProfile.billTo.address = "123 Main St." paymentProfile.billTo.city = "Bellevue" paymentProfile.billTo.state = "WA" paymentProfile.billTo.zip = "98004" paymentProfile.billTo.country = "USA" paymentProfile.billTo.phoneNumber = "000-000-000" paymentProfile.payment = payment paymentProfile.customerPaymentProfileId = customerPaymentProfileId updateCustomerPaymentProfile = apicontractsv1.updateCustomerPaymentProfileRequest( ) updateCustomerPaymentProfile.merchantAuthentication = merchantAuth updateCustomerPaymentProfile.paymentProfile = paymentProfile updateCustomerPaymentProfile.customerProfileId = customerProfileId updateCustomerPaymentProfile.validationMode = apicontractsv1.validationModeEnum.liveMode controller = updateCustomerPaymentProfileController( updateCustomerPaymentProfile) controller.execute() response = controller.getresponse() if (response.messages.resultCode == "Ok"): print("Successfully updated customer payment profile with id %s" % updateCustomerPaymentProfile.paymentProfile. customerPaymentProfileId) else: print(response.messages.message[0]['text'].text) print("Failed to update customer with customer payment profile id %s" % updateCustomerPaymentProfile.paymentProfile. customerPaymentProfileId) return response
def refund(payment_information: PaymentData, cc_last_digits: str, config: GatewayConfig) -> GatewayResponse: merchant_auth = _get_merchant_auth(config.connection_params) credit_card = apicontractsv1.creditCardType() credit_card.cardNumber = cc_last_digits credit_card.expirationDate = "XXXX" payment = apicontractsv1.paymentType() payment.creditCard = credit_card transaction_request = apicontractsv1.transactionRequestType() transaction_request.transactionType = "refundTransaction" transaction_request.amount = payment_information.amount transaction_request.currencyCode = payment_information.currency # set refTransId to transId of a settled transaction transaction_request.refTransId = payment_information.token transaction_request.payment = payment create_transaction_request = apicontractsv1.createTransactionRequest() create_transaction_request.merchantAuthentication = merchant_auth create_transaction_request.transactionRequest = transaction_request response = _make_request(create_transaction_request, config.connection_params) ( success, error, transaction_id, transaction_response, raw_response, ) = _handle_authorize_net_response(response) payment_method_info = _authorize_net_account_to_payment_method_info( transaction_response) return GatewayResponse( is_success=success, action_required=False, transaction_id=transaction_id, amount=payment_information.amount, currency=payment_information.currency, error=error, payment_method_info=payment_method_info, kind=TransactionKind.REFUND, raw_response=raw_response, customer_id=payment_information.customer_id, )
def authpayment(): invoice = request.form.get('invoice') amount = request.form.get('amount') card_name = request.form.get('card_name') card_number = request.form.get('card_number') expiry = request.form.get('expiry') cvv = request.form.get('cvv') merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = '86UGvvLF6N' merchantAuth.transactionKey = '3q6vX7mw74JV37mR' creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = card_number creditCard.expirationDate = expiry creditCard.cardCode = cvv payment = apicontractsv1.paymentType() payment.creditCard = creditCard transactionrequest = apicontractsv1.transactionRequestType() transactionrequest.transactionType = "authCaptureTransaction" transactionrequest.amount = Decimal(amount) transactionrequest.payment = payment createtransactionrequest = apicontractsv1.createTransactionRequest() createtransactionrequest.merchantAuthentication = merchantAuth createtransactionrequest.refId = invoice createtransactionrequest.transactionRequest = transactionrequest createtransactioncontroller = createTransactionController( createtransactionrequest) createtransactioncontroller.execute() response = createtransactioncontroller.getresponse() if (response.messages.resultCode == "Ok"): print("Transaction ID : %s" % response.transactionResponse.transId) orders = CustomerOrder.query.filter_by( customer_id=current_user.id, invoice=invoice).order_by(CustomerOrder.id.desc()).first() orders.status = 'Paid' db.session.commit() return redirect(url_for('thanks')) else: print("response code: %s" % response.messages.resultCode) flash(f'Failed with code { response.messages.resultCode }', 'error') return redirect(url_for('orders', invoice=invoice))
def verify(self, signup, **params): if not conf['enable_billing']: return 0 amount = Decimal('1.00') merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = self.conf['api_login'] merchantAuth.transactionKey = self.conf['api_transact_key'] creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = decrypt(conf['database']['cipher_key'], signup.billing_cc_number) creditCard.expirationDate = signup.billing_cc_expire payment = apicontractsv1.paymentType() payment.creditCard = creditCard transactionrequest = apicontractsv1.transactionRequestType() transactionrequest.transactionType = "authOnlyTransaction" transactionrequest.amount = Decimal('1.00') transactionrequest.payment = payment createtransactionrequest = apicontractsv1.createTransactionRequest() createtransactionrequest.merchantAuthentication = merchantAuth #createtransactionrequest.refId = "MerchantID-00003" # % str(randint(1, 99999)) createtransactionrequest.transactionRequest = transactionrequest createtransactioncontroller = createTransactionController( createtransactionrequest) for i in xrange(3): # do 3 attempts try: createtransactioncontroller.execute() break except: pass response = createtransactioncontroller.getresponse() # store authorize.net response in extra print resp2dict(response) signup.extra['authnet'] = resp2dict(response) return 1 if (response.messages.resultCode == "Ok" and response.transactionResponse.responseCode == 1) else -1
def createCustomerPaymentProfile(customerInfo): merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = '4urP8Y47' merchantAuth.transactionKey = '538g4Tg2uMBte3W8' creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = "6011000000000012" # for the sake of testing this doesn't change creditCard.expirationDate = "2021-12" # this too payment = apicontractsv1.paymentType() payment.creditCard = creditCard billTo = apicontractsv1.customerAddressType() billTo.firstName = customerInfo["firstName"] billTo.lastName = customerInfo["lastName"] profile = apicontractsv1.customerPaymentProfileType() profile.payment = payment profile.billTo = billTo createCustomerPaymentProfile = apicontractsv1.createCustomerPaymentProfileRequest( ) createCustomerPaymentProfile.merchantAuthentication = merchantAuth createCustomerPaymentProfile.paymentProfile = profile customerProfileId = customerInfo[ "customerId"] # grab the same info from the dictionary but place it in their variable print( "customerProfileId in createCustomerPaymentProfile. customerProfileId = %s" % customerProfileId) createCustomerPaymentProfile.customerProfileId = str(customerProfileId) controller = createCustomerPaymentProfileController( createCustomerPaymentProfile) controller.execute() response = controller.getresponse() if (response.messages.resultCode == "Ok"): print("Successfully created a customer payment profile with id: %s" % response.customerPaymentProfileId) else: print("Failed to create customer payment profile %s" % response.messages.message[0]['text'].text) return response.customerPaymentProfileId
def update_subscription(subscriptionId): merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = constants.apiLoginId merchantAuth.transactionKey = constants.transactionKey creditcard = apicontractsv1.creditCardType() creditcard.cardNumber = "4111111111111111" creditcard.expirationDate = "2020-12" payment = apicontractsv1.paymentType() payment.creditCard = creditcard #set profile information profile = apicontractsv1.customerProfileIdType() profile.customerProfileId = "121212"; profile.customerPaymentProfileId = "131313"; profile.customerAddressId = "141414"; subscription = apicontractsv1.ARBSubscriptionType() subscription.payment = payment #to update customer profile information #subscription.profile = profile request = apicontractsv1.ARBUpdateSubscriptionRequest() request.merchantAuthentication = merchantAuth request.refId = "Sample" request.subscriptionId = subscriptionId request.subscription = subscription controller = ARBUpdateSubscriptionController(request) controller.execute() response = controller.getresponse() if (response.messages.resultCode=="Ok"): print ("SUCCESS") print ("Message Code : %s" % response.messages.message[0]['code'].text) print ("Message text : %s" % response.messages.message[0]['text'].text) else: print ("ERROR") print ("Message Code : %s" % response.messages.message[0]['code'].text) print ("Message text : %s" % response.messages.message[0]['text'].text) return response
def update_customer_payment_profile(customerProfileId, customerPaymentProfileId): merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = constants.apiLoginId merchantAuth.transactionKey = constants.transactionKey creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = "4111111111111111" creditCard.expirationDate = "2020-12" payment = apicontractsv1.paymentType() payment.creditCard = creditCard paymentProfile = apicontractsv1.customerPaymentProfileExType() paymentProfile.billTo = apicontractsv1.customerAddressType() paymentProfile.billTo.firstName = "John" paymentProfile.billTo.lastName = "Doe" paymentProfile.billTo.address = "123 Main St." paymentProfile.billTo.city = "Bellevue" paymentProfile.billTo.state = "WA" paymentProfile.billTo.zip = "98004" paymentProfile.billTo.country = "USA" paymentProfile.billTo.phoneNumber = "000-000-000" paymentProfile.payment = payment paymentProfile.customerPaymentProfileId = customerPaymentProfileId updateCustomerPaymentProfile = apicontractsv1.updateCustomerPaymentProfileRequest() updateCustomerPaymentProfile.merchantAuthentication = merchantAuth updateCustomerPaymentProfile.paymentProfile = paymentProfile updateCustomerPaymentProfile.customerProfileId = customerProfileId updateCustomerPaymentProfile.validationMode = apicontractsv1.validationModeEnum.liveMode controller = updateCustomerPaymentProfileController(updateCustomerPaymentProfile) controller.execute() response = controller.getresponse() if (response.messages.resultCode=="Ok"): print ("Successfully updated customer payment profile with id %s" % updateCustomerPaymentProfile.paymentProfile.customerPaymentProfileId) else: print (response.messages.message[0]['text'].text) print ("Failed to update customer with customer payment profile id %s" % updateCustomerPaymentProfile.paymentProfile.customerPaymentProfileId) return response
def create_customer_payment_profile(customerProfileId): merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = constants.apiLoginId merchantAuth.transactionKey = constants.transactionKey creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = "4111111111111111" creditCard.expirationDate = "2035-12" payment = apicontractsv1.paymentType() payment.creditCard = creditCard billTo = apicontractsv1.customerAddressType() billTo.firstName = "John" billTo.lastName = "Snow" profile = apicontractsv1.customerPaymentProfileType() profile.payment = payment profile.billTo = billTo createCustomerPaymentProfile = apicontractsv1.createCustomerPaymentProfileRequest( ) createCustomerPaymentProfile.merchantAuthentication = merchantAuth createCustomerPaymentProfile.paymentProfile = profile print( "customerProfileId in create_customer_payment_profile. customerProfileId = %s" % customerProfileId) createCustomerPaymentProfile.customerProfileId = str(customerProfileId) controller = createCustomerPaymentProfileController( createCustomerPaymentProfile) controller.execute() response = controller.getresponse() if (response.messages.resultCode == "Ok"): print("Successfully created a customer payment profile with id: %s" % response.customerPaymentProfileId) else: print("Failed to create customer payment profile %s" % response.messages.message[0]['text'].text) return response
def refund_transaction(refTransId): merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = constants.apiLoginId merchantAuth.transactionKey = constants.transactionKey creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = "0015" creditCard.expirationDate = "XXXX" payment = apicontractsv1.paymentType() payment.creditCard = creditCard transactionrequest = apicontractsv1.transactionRequestType() transactionrequest.transactionType = "refundTransaction" transactionrequest.amount = Decimal('2.55') #set refTransId to transId of a settled transaction transactionrequest.refTransId = refTransId transactionrequest.payment = payment createtransactionrequest = apicontractsv1.createTransactionRequest() createtransactionrequest.merchantAuthentication = merchantAuth createtransactionrequest.refId = "MerchantID-0001" createtransactionrequest.transactionRequest = transactionrequest createtransactioncontroller = createTransactionController( createtransactionrequest) createtransactioncontroller.execute() response = createtransactioncontroller.getresponse() if (response.messages.resultCode == "Ok"): print "Transaction ID : %s" % response.transactionResponse.transId else: print "response code: %s" % response.messages.resultCode print "Message code: %s" % response.messages.message[0].code print "Message text: %s" % response.messages.message[0].text print "Transaction Error Code: %s" % response.transactionResponse.errors.error[ 0].errorCode print "Transaction Error Text: %s" % response.transactionResponse.errors.error[ 0].errorText return response
def create_saved_payment(self, credit_card, address=None, profile_id=None): """ Creates a payment profile. """ creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = credit_card.card_number creditCard.expirationDate = '{0.exp_year}-{0.exp_month:0>2}'.format(credit_card) creditCard.cardCode = credit_card.cvv payment = apicontractsv1.paymentType() payment.creditCard = creditCard billTo = apicontractsv1.customerAddressType() if credit_card.first_name: billTo.firstName = credit_card.first_name if credit_card.last_name: billTo.lastName = credit_card.last_name profile = apicontractsv1.customerPaymentProfileType() profile.payment = payment profile.billTo = billTo self._address_to_profile(address, profile) if profile_id: createCustomerPaymentProfile = apicontractsv1.createCustomerPaymentProfileRequest() createCustomerPaymentProfile.merchantAuthentication = self.merchantAuth createCustomerPaymentProfile.paymentProfile = profile createCustomerPaymentProfile.customerProfileId = str(profile_id) controller = createCustomerPaymentProfileController(createCustomerPaymentProfile) if not self.debug: controller.setenvironment(constants.PRODUCTION) controller.execute() response = controller.getresponse() if response.messages.resultCode == "Ok": return response.customerPaymentProfileId else: raise AuthorizeResponseError( "Failed to create customer payment profile %s" % response.messages.message[0]['text'].text) else: return profile
def refund_transaction(refTransId): merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = constants.apiLoginId merchantAuth.transactionKey = constants.transactionKey creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = "0015" creditCard.expirationDate = "XXXX" payment = apicontractsv1.paymentType() payment.creditCard = creditCard transactionrequest = apicontractsv1.transactionRequestType() transactionrequest.transactionType = "refundTransaction" transactionrequest.amount = Decimal ('2.55') #set refTransId to transId of a settled transaction transactionrequest.refTransId = refTransId transactionrequest.payment = payment createtransactionrequest = apicontractsv1.createTransactionRequest() createtransactionrequest.merchantAuthentication = merchantAuth createtransactionrequest.refId = "MerchantID-0001" createtransactionrequest.transactionRequest = transactionrequest createtransactioncontroller = createTransactionController(createtransactionrequest) createtransactioncontroller.execute() response = createtransactioncontroller.getresponse() if (response.messages.resultCode=="Ok"): print "Transaction ID : %s" % response.transactionResponse.transId else: print "response code: %s" % response.messages.resultCode print "Message code: %s" % response.messages.message[0]['code'].text print "Message text: %s" % response.messages.message[0]['text'].text print "Transaction Error Code: %s" % response.transactionResponse.errors.error[0].errorCode print "Transaction Error Text: %s" % response.transactionResponse.errors.error[0].errorText return response
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
def create_customer_payment_profile(customerProfileId): merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = constants.apiLoginId merchantAuth.transactionKey = constants.transactionKey creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = "4111111111111111" creditCard.expirationDate = "2020-12" payment = apicontractsv1.paymentType() payment.creditCard = creditCard billTo = apicontractsv1.customerAddressType() billTo.firstName = "John" billTo.lastName = "Snow" profile = apicontractsv1.customerPaymentProfileType() profile.payment = payment profile.billTo = billTo createCustomerPaymentProfile = apicontractsv1.createCustomerPaymentProfileRequest() createCustomerPaymentProfile.merchantAuthentication = merchantAuth createCustomerPaymentProfile.paymentProfile = profile print("customerProfileId in create_customer_payment_profile. customerProfileId = %s" %customerProfileId) createCustomerPaymentProfile.customerProfileId = str(customerProfileId) controller = createCustomerPaymentProfileController(createCustomerPaymentProfile) controller.execute() response = controller.getresponse() if (response.messages.resultCode=="Ok"): print("Successfully created a customer payment profile with id: %s" % response.customerPaymentProfileId) else: print("Failed to create customer payment profile %s" % response.messages.message[0]['text'].text) return response
def capture_funds_authorized_through_another_channel(): amount = str(round(random.random()*100, 2)) merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = constants.apiLoginId merchantAuth.transactionKey = constants.transactionKey creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = "4111111111111111" creditCard.expirationDate = "2020-12" payment = apicontractsv1.paymentType() payment.creditCard = creditCard transactionrequest = apicontractsv1.transactionRequestType() transactionrequest.transactionType = "captureOnlyTransaction" transactionrequest.amount = Decimal (amount) transactionrequest.payment = payment transactionrequest.authCode = "ROHNFQ" createtransactionrequest = apicontractsv1.createTransactionRequest() createtransactionrequest.merchantAuthentication = merchantAuth createtransactionrequest.refId = "MerchantID-0001" createtransactionrequest.transactionRequest = transactionrequest createtransactioncontroller = createTransactionController(createtransactionrequest) createtransactioncontroller.execute() response = createtransactioncontroller.getresponse() if (response.messages.resultCode=="Ok"): print "Transaction ID : %s" % response.transactionResponse.transId else: print "response code: %s" % response.messages.resultCode return response
def testchargeCreditCard(self): creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = "4111111111111111" creditCard.expirationDate = "2020-12" payment = apicontractsv1.paymentType() payment.creditCard = creditCard transactionrequest = apicontractsv1.transactionRequestType() transactionrequest.transactionType = "authCaptureTransaction" transactionrequest.amount = Decimal(str(round(random.random()*100, 2))) transactionrequest.payment = payment createtransactionrequest = apicontractsv1.createTransactionRequest() createtransactionrequest.merchantAuthentication = self.merchantAuthentication createtransactionrequest.refId = "MerchantID-0001" createtransactionrequest.transactionRequest = transactionrequest createtransactioncontroller = createTransactionController(createtransactionrequest) createtransactioncontroller.execute() response = createtransactioncontroller.getresponse() if hasattr(response, 'messages') == True: if hasattr(response.messages, 'resultCode') == True: self.assertEquals('Ok', response.messages.resultCode) if hasattr(response, 'transactionResponse') == True: if hasattr(response.transactionResponse, 'transId') == True: createdTransactionId = response.transactionResponse.transId return str(createdTransactionId)
from authorizenet import apicontractsv1 from authorizenet.apicontrollers import * merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = '5KP3u95bQpv' merchantAuth.transactionKey = '4Ktq966gC55GAX7S' creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = "4111111111111111" creditCard.expirationDate = "2020-12" payment = apicontractsv1.paymentType() payment.creditCard = creditCard profile = apicontractsv1.customerPaymentProfileType() profile.payment = payment createCustomerPaymentProfile = apicontractsv1.createCustomerPaymentProfileRequest() createCustomerPaymentProfile.merchantAuthentication = merchantAuth createCustomerPaymentProfile.paymentProfile = profile createCustomerPaymentProfile.customerProfileId = '36731856' createCustomerPaymentProfileController = createCustomerPaymentProfileController(createCustomerPaymentProfile) createCustomerPaymentProfileController.execute() response = createCustomerPaymentProfileController.getresponse() if (response.messages.resultCode=="Ok"): print "Successfully created a customer payment profile with id: %s" % response.customerPaymentProfileId else: print "Failed to create customer payment profile %s" % response.messages.message[0].text
def charge_credit_card(amount): """ Charge a credit card """ # Create a merchantAuthenticationType object with authentication details # retrieved from the constants file merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = CONSTANTS.apiLoginId merchantAuth.transactionKey = CONSTANTS.transactionKey # Create the payment data for a credit card creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = "4111111111111111" creditCard.expirationDate = "2020-12" creditCard.cardCode = "123" # Add the payment data to a paymentType object payment = apicontractsv1.paymentType() payment.creditCard = creditCard # Create order information order = apicontractsv1.orderType() order.invoiceNumber = "10101" order.description = "Golf Shirts" # Set the customer's Bill To address customerAddress = apicontractsv1.customerAddressType() customerAddress.firstName = "Ellen" customerAddress.lastName = "Johnson" customerAddress.company = "Souveniropolis" customerAddress.address = "14 Main Street" customerAddress.city = "Pecan Springs" customerAddress.state = "TX" customerAddress.zip = "44628" customerAddress.country = "USA" # Set the customer's identifying information customerData = apicontractsv1.customerDataType() customerData.type = "individual" customerData.id = "99999456654" customerData.email = "*****@*****.**" # Add values for transaction settings duplicateWindowSetting = apicontractsv1.settingType() duplicateWindowSetting.settingName = "duplicateWindow" duplicateWindowSetting.settingValue = "600" settings = apicontractsv1.ArrayOfSetting() settings.setting.append(duplicateWindowSetting) # setup individual line items line_item_1 = apicontractsv1.lineItemType() line_item_1.itemId = "12345" line_item_1.name = "first" line_item_1.description = "Here's the first line item" line_item_1.quantity = "2" line_item_1.unitPrice = "12.95" line_item_2 = apicontractsv1.lineItemType() line_item_2.itemId = "67890" line_item_2.name = "second" line_item_2.description = "Here's the second line item" line_item_2.quantity = "3" line_item_2.unitPrice = "7.95" # build the array of line items line_items = apicontractsv1.ArrayOfLineItem() line_items.lineItem.append(line_item_1) line_items.lineItem.append(line_item_2) # Create a transactionRequestType object and add the previous objects to it. transactionrequest = apicontractsv1.transactionRequestType() transactionrequest.transactionType = "authCaptureTransaction" transactionrequest.amount = amount transactionrequest.payment = payment transactionrequest.order = order transactionrequest.billTo = customerAddress transactionrequest.customer = customerData transactionrequest.transactionSettings = settings transactionrequest.lineItems = line_items # Assemble the complete transaction request createtransactionrequest = apicontractsv1.createTransactionRequest() createtransactionrequest.merchantAuthentication = merchantAuth createtransactionrequest.refId = "MerchantID-0001" createtransactionrequest.transactionRequest = transactionrequest # Create the controller createtransactioncontroller = createTransactionController( createtransactionrequest) createtransactioncontroller.execute() response = createtransactioncontroller.getresponse() if response is not None: # Check to see if the API request was successfully received and acted upon if response.messages.resultCode == "Ok": # Since the API request was successful, look for a transaction response # and parse it to display the results of authorizing the card if hasattr(response.transactionResponse, 'messages') is True: print( 'Successfully created transaction with Transaction ID: %s' % response.transactionResponse.transId) print('Transaction Response Code: %s' % response.transactionResponse.responseCode) print('Message Code: %s' % response.transactionResponse.messages.message[0].code) print('Description: %s' % response.transactionResponse. messages.message[0].description) else: print('Failed Transaction.') if hasattr(response.transactionResponse, 'errors') is True: print('Error Code: %s' % str(response.transactionResponse. errors.error[0].errorCode)) print( 'Error message: %s' % response.transactionResponse.errors.error[0].errorText) # Or, print errors if the API request wasn't successful else: print('Failed Transaction.') if hasattr(response, 'transactionResponse') is True and hasattr( response.transactionResponse, 'errors') is True: print('Error Code: %s' % str( response.transactionResponse.errors.error[0].errorCode)) print('Error message: %s' % response.transactionResponse.errors.error[0].errorText) else: print('Error Code: %s' % response.messages.message[0]['code'].text) print('Error message: %s' % response.messages.message[0]['text'].text) else: print('Null Response.') return response
def __PyxbDeserialization(self, lastElement = None): loggingfilename = utility.helper.getproperty(constants.propertiesloggingfilename) logginglevel = utility.helper.getproperty(constants.propertiesexecutionlogginglevel) deserializedObject = None deserializedBadObject = None if (None == loggingfilename): loggingfilename = constants.defaultLogFileName if (None == logginglevel): logginglevel = constants.defaultLoggingLevel logging.basicConfig(filename=loggingfilename, level=logginglevel, format=constants.defaultlogformat) merchantAuth = apicontractsv1.merchantAuthenticationType() merchantAuth.name = "unknown" merchantAuth.transactionKey = "anon" creditCard = apicontractsv1.creditCardType() creditCard.cardNumber = "4111111111111111" creditCard.expirationDate = "2020-12" payment = apicontractsv1.paymentType() payment.creditCard = creditCard transactionrequest = apicontractsv1.transactionRequestType() transactionrequest.transactionType = "authCaptureTransaction" transactionrequest.amount = Decimal( 6.99) transactionrequest.payment = payment createtransactionrequest = apicontractsv1.createTransactionRequest() createtransactionrequest.merchantAuthentication = merchantAuth createtransactionrequest.transactionRequest = transactionrequest createtransactionrequest.refId = "MerchantID-0001" logging.debug( "Request: %s " % datetime.datetime.now()) logging.debug( " : %s " % createtransactionrequest ) try: xmlRequest = createtransactionrequest.toxml(encoding=constants.xml_encoding, element_name='createTransactionRequest') xmlRequest = xmlRequest.replace(constants.nsNamespace1, '') xmlRequest = xmlRequest.replace(constants.nsNamespace2, '') ##print ("xmlRequest %s " %xmlRequest) logging.debug( "Xml Request: %s" % xmlRequest) except Exception as ex: logging.debug( "Xml Exception: %s" % ex) badXmlElement = None if (lastElement == None): try: deserializedObject = apicontractsv1.CreateFromDocument(xmlRequest) self.assertIsNotNone(deserializedObject, "Null deserializedObject ") if type(createtransactionrequest) == type(deserializedObject): ##print (" for good xml objects are equal") logging.debug( "createtransactionrequest object is equal to deserializedObject") else: ##print ("for good xml some error: objects are NOT equal" ) logging.debug( "createtransactionrequest object is NOT equal to deserializedObject") deseriaziedObjectXmlRequest = deserializedObject.toxml(encoding=constants.xml_encoding, element_name='deserializedObject') deseriaziedObjectXmlRequest = deseriaziedObjectXmlRequest.replace(constants.nsNamespace1, '') deseriaziedObjectXmlRequest = deseriaziedObjectXmlRequest.replace(constants.nsNamespace2, '') logging.debug( "Good Dom Request: %s " % deseriaziedObjectXmlRequest ) ##print ( "Good De-serialized XML: %s \n" % deseriaziedObjectXmlRequest ) except Exception as ex: logging.error( 'Create Document Exception: %s, %s', type(ex), ex.args ) else: if (lastElement == False): try: splitString = "<amount>" lines = xmlRequest.split( splitString) badXmlElement = "<badElement>BadElement</badElement>" badXmlRequest = lines[0] + badXmlElement + splitString + lines[1] logging.debug( "Bad XmlRequest: %s" % badXmlRequest) ##print ("ElementInMidXML Request: %s \n" %badXmlRequest) except Exception as ex: ##print ("ElementInMidXML can not be inserted: %s, %s",type(ex), ex.args) logging.debug( "ElementInMidXML can not be inserted: %s, %s" ,type(ex), ex.args) if (lastElement == True): try: splitStringAtLast = "</payment>" lines = xmlRequest.split( splitStringAtLast) badXmlElementAtLast = "<badElementAtLast>BadElementAtLast</badElementAtLast>" badXmlRequest = lines[0] + badXmlElementAtLast + splitStringAtLast + lines[1] logging.debug( "Bad XmlRequest at Last: %s" % badXmlRequest) ##print ("ElementAtLastXML Request: %s \n" %badXmlRequest) except Exception as ex: ##print ("ElementAtLastXML can not be inserted: %s, %s",type(ex), ex.args) logging.debug("ElementAtLastXML can not be inserted: %s, %s",type(ex), ex.args) try: deserializedBadObject = apicontractsv1.CreateFromDocument(badXmlRequest) self.assertIsNotNone(deserializedBadObject, "Null deserializedObject ") badDomXml = deserializedBadObject.toxml(encoding=constants.xml_encoding, element_name='deserializedBadObject') badDomXml = badDomXml.replace(constants.nsNamespace1, '') badDomXml = badDomXml.replace(constants.nsNamespace2, '') logging.debug( "Bad Dom Request: %s " % badDomXml ) ##print ("Bad Dom De-serialized: %s \n" %badDomXml) except Exception as ex: logging.error( 'Create Document Exception: %s, %s', type(ex), ex.args )