|
| 1 | +from CyberSource import * |
| 2 | +import os |
| 3 | +import json |
| 4 | +from importlib.machinery import SourceFileLoader |
| 5 | + |
| 6 | +config_file = os.path.join(os.getcwd(), "data", "Configuration.py") |
| 7 | +configuration = SourceFileLoader("module.name", config_file).load_module() |
| 8 | + |
| 9 | +# To delete None values in Input Request Json body |
| 10 | +def del_none(d): |
| 11 | + for key, value in list(d.items()): |
| 12 | + if value is None: |
| 13 | + del d[key] |
| 14 | + elif isinstance(value, dict): |
| 15 | + del_none(value) |
| 16 | + return d |
| 17 | + |
| 18 | +def authorization_with_instrument_identifier_token_creation(): |
| 19 | + clientReferenceInformationCode = "TC50171_3" |
| 20 | + clientReferenceInformation = Ptsv2paymentsClientReferenceInformation( |
| 21 | + code = clientReferenceInformationCode |
| 22 | + ) |
| 23 | + |
| 24 | + |
| 25 | + processingInformationActionList = [] |
| 26 | + processingInformationActionList.append("TOKEN_CREATE") |
| 27 | + |
| 28 | + processingInformationActionTokenTypes = [] |
| 29 | + processingInformationActionTokenTypes.append("instrumentIdentifier") |
| 30 | + processingInformationCapture = False |
| 31 | + processingInformationCommerceIndicator = "internet" |
| 32 | + processingInformation = Ptsv2paymentsProcessingInformation( |
| 33 | + action_list = processingInformationActionList, |
| 34 | + action_token_types = processingInformationActionTokenTypes, |
| 35 | + capture = processingInformationCapture, |
| 36 | + commerce_indicator = processingInformationCommerceIndicator |
| 37 | + ) |
| 38 | + |
| 39 | + paymentInformationCardNumber = "4111111111111111" |
| 40 | + paymentInformationCardExpirationMonth = "12" |
| 41 | + paymentInformationCardExpirationYear = "2031" |
| 42 | + paymentInformationCardSecurityCode = "123" |
| 43 | + paymentInformationCard = Ptsv2paymentsPaymentInformationCard( |
| 44 | + number = paymentInformationCardNumber, |
| 45 | + expiration_month = paymentInformationCardExpirationMonth, |
| 46 | + expiration_year = paymentInformationCardExpirationYear, |
| 47 | + security_code = paymentInformationCardSecurityCode |
| 48 | + ) |
| 49 | + |
| 50 | + paymentInformation = Ptsv2paymentsPaymentInformation( |
| 51 | + card = paymentInformationCard.__dict__ |
| 52 | + ) |
| 53 | + |
| 54 | + orderInformationAmountDetailsTotalAmount = "102.21" |
| 55 | + orderInformationAmountDetailsCurrency = "USD" |
| 56 | + orderInformationAmountDetails = Ptsv2paymentsOrderInformationAmountDetails( |
| 57 | + total_amount = orderInformationAmountDetailsTotalAmount, |
| 58 | + currency = orderInformationAmountDetailsCurrency |
| 59 | + ) |
| 60 | + |
| 61 | + orderInformationBillToFirstName = "John" |
| 62 | + orderInformationBillToLastName = "Doe" |
| 63 | + orderInformationBillToAddress1 = "1 Market St" |
| 64 | + orderInformationBillToLocality = "san francisco" |
| 65 | + orderInformationBillToAdministrativeArea = "CA" |
| 66 | + orderInformationBillToPostalCode = "94105" |
| 67 | + orderInformationBillToCountry = "US" |
| 68 | + orderInformationBillToEmail = "[email protected]" |
| 69 | + orderInformationBillToPhoneNumber = "4158880000" |
| 70 | + orderInformationBillTo = Ptsv2paymentsOrderInformationBillTo( |
| 71 | + first_name = orderInformationBillToFirstName, |
| 72 | + last_name = orderInformationBillToLastName, |
| 73 | + address1 = orderInformationBillToAddress1, |
| 74 | + locality = orderInformationBillToLocality, |
| 75 | + administrative_area = orderInformationBillToAdministrativeArea, |
| 76 | + postal_code = orderInformationBillToPostalCode, |
| 77 | + country = orderInformationBillToCountry, |
| 78 | + email = orderInformationBillToEmail, |
| 79 | + phone_number = orderInformationBillToPhoneNumber |
| 80 | + ) |
| 81 | + |
| 82 | + orderInformationShipToFirstName = "John" |
| 83 | + orderInformationShipToLastName = "Doe" |
| 84 | + orderInformationShipToAddress1 = "1 Market St" |
| 85 | + orderInformationShipToLocality = "san francisco" |
| 86 | + orderInformationShipToAdministrativeArea = "CA" |
| 87 | + orderInformationShipToPostalCode = "94105" |
| 88 | + orderInformationShipToCountry = "US" |
| 89 | + orderInformationShipTo = Ptsv2paymentsOrderInformationShipTo( |
| 90 | + first_name = orderInformationShipToFirstName, |
| 91 | + last_name = orderInformationShipToLastName, |
| 92 | + address1 = orderInformationShipToAddress1, |
| 93 | + locality = orderInformationShipToLocality, |
| 94 | + administrative_area = orderInformationShipToAdministrativeArea, |
| 95 | + postal_code = orderInformationShipToPostalCode, |
| 96 | + country = orderInformationShipToCountry |
| 97 | + ) |
| 98 | + |
| 99 | + orderInformation = Ptsv2paymentsOrderInformation( |
| 100 | + amount_details = orderInformationAmountDetails.__dict__, |
| 101 | + bill_to = orderInformationBillTo.__dict__, |
| 102 | + ship_to = orderInformationShipTo.__dict__ |
| 103 | + ) |
| 104 | + |
| 105 | + requestObj = CreatePaymentRequest( |
| 106 | + client_reference_information = clientReferenceInformation.__dict__, |
| 107 | + processing_information = processingInformation.__dict__, |
| 108 | + payment_information = paymentInformation.__dict__, |
| 109 | + order_information = orderInformation.__dict__ |
| 110 | + ) |
| 111 | + |
| 112 | + |
| 113 | + requestObj = del_none(requestObj.__dict__) |
| 114 | + requestObj = json.dumps(requestObj) |
| 115 | + |
| 116 | + |
| 117 | + try: |
| 118 | + config_obj = configuration.Configuration() |
| 119 | + client_config = config_obj.get_configuration() |
| 120 | + api_instance = PaymentsApi(client_config) |
| 121 | + return_data, status, body = api_instance.create_payment(requestObj) |
| 122 | + |
| 123 | + print("\nAPI RESPONSE CODE : ", status) |
| 124 | + print("\nAPI RESPONSE BODY : ", body) |
| 125 | + |
| 126 | + return return_data |
| 127 | + except Exception as e: |
| 128 | + print("\nException when calling PaymentsApi->create_payment: %s\n" % e) |
| 129 | + |
| 130 | +if __name__ == "__main__": |
| 131 | + authorization_with_instrument_identifier_token_creation() |
0 commit comments