├── .gitignore ├── .travis.yml ├── Logging.md ├── README.md ├── Validation ├── ExpectedResults │ ├── csharp_expected_results.json │ ├── java_expected_results.json │ ├── json_expected_results.json │ ├── node_expected_results.json │ ├── php_expected_results.json │ ├── python_expected_results.json │ └── ruby_expected_results.json ├── json_to_prettified_html.py ├── response_code_validator.py └── sample_code_log_processor.py ├── __init__.py ├── data ├── Configuration.py ├── MLEConfiguration.py ├── MerchantBoardingConfiguration.py └── __init__.py ├── lib └── sampleapiclient │ ├── __init__.py │ ├── connection │ ├── Connection.py │ ├── Headers.py │ ├── HttpConnection.py │ ├── JwtUrlConnection.py │ └── __init__.py │ ├── controller │ ├── ApiController.py │ └── __init__.py │ ├── masking │ ├── Masking.py │ └── __init__.py │ ├── model │ ├── AggregatorInformation.py │ ├── AmountDetails.py │ ├── BillTo.py │ ├── Card.py │ ├── ClientReferenceInformation.py │ ├── OrderInformation.py │ ├── PaymentInformation.py │ ├── Payments.py │ ├── ProcessingInformation.py │ ├── SubMerchant.py │ └── __init__.py │ ├── service │ ├── PaymentRequestService.py │ └── __init__.py │ ├── setup.py │ └── test │ ├── __init__.py │ └── test_ApiController.py ├── license.txt ├── resources ├── NetworkTokenCert.pem ├── __init__.py ├── request.json ├── testrest.p12 ├── testrest_cpctv.p12 └── trr_report.json ├── sampleCodeIgnoreList.txt ├── sample_code_runner.sh ├── samples ├── AccountUpdater │ ├── amex-registration-customer-token-batch.py │ ├── amex-registration-instrument-identifier-token-batch.py │ ├── list-batches.py │ ├── one-off-visa-mastercard-customer-token-batch.py │ ├── one-off-visa-mastercard-instrument-identifier-token-batch.py │ ├── retrieve-batch-report.py │ └── retrieve-batch-status.py ├── AzureIntermediateTesting │ └── IntermediateHostTesting.py ├── BinLookup │ ├── bin-lookup-with-card.py │ ├── bin-lookup-with-healthcare-card.py │ ├── bin-lookup-with-network-token.py │ ├── bin-lookup-with-tms-customer-id.py │ ├── bin-lookup-with-tms-instrument-identifier.py │ ├── bin-lookup-with-tms-jti-transient-token.py │ ├── bin-lookup-with-tms-jwt-transient-token.py │ └── bin-lookup-with-tms-payment-instrument.py ├── FlexMicroform │ ├── generate-capture-context-accept-card.py │ └── generate-capture-context-accept-check.py ├── Invoicing │ ├── InvoiceSettings │ │ ├── get-invoice-settings.py │ │ └── updateinvoicesettings.py │ └── Invoices │ │ ├── cancel-invoice.py │ │ ├── create-and-send-invoice-immediately.py │ │ ├── create-draft-invoice.py │ │ ├── create-invoice-and-assign-it-specific-invoice-number.py │ │ ├── create-invoice-without-sending-it.py │ │ ├── get-invoice-details.py │ │ ├── get-list-of-invoices.py │ │ ├── send-invoice.py │ │ └── update-invoice.py ├── MLEFeature │ ├── PaymentsWithMLE.py │ ├── PaymentsWithMLEControlFromMAPConfig.py │ └── PaymentsWithMLEControlFromMapConfigOnly.py ├── MerchantBoarding │ ├── create_registration.py │ ├── merchant-boarding-amex-direct.py │ ├── merchant-boarding-barclays.py │ ├── merchant-boarding-bin-lookup.py │ ├── merchant-boarding-cup.py │ ├── merchant-boarding-eftpos.py │ ├── merchant-boarding-fdi-global.py │ ├── merchant-boarding-gpx.py │ ├── merchant-boarding-smart-fdc.py │ ├── merchant-boarding-tsys.py │ └── merchant-boarding-vpc.py ├── PayerAuthentication │ ├── authentication-with-new-account.py │ ├── authentication-with-no-redirect.py │ ├── enroll-with-customerid-as-payment-information.py │ ├── enroll-with-pending-authentication.py │ ├── enroll-with-transient-token.py │ ├── enroll-with-travel-information.py │ ├── pending-authentication-with-unknown-path.py │ ├── setup-completion-with-card-number.py │ ├── setup-completion-with-flex-transient-token.py │ ├── setup-completion-with-fluid-data-value-and-payment-solution.py │ ├── setup-completion-with-secure-storage-token.py │ ├── setup-completion-with-tms-token.py │ ├── setup-completion-with-tokenized-card.py │ └── validate-authentication-results.py ├── Payments │ ├── Capture │ │ ├── capture-of-authorization-that-used-swiped-track-data.py │ │ ├── capture-payment-service-fee.py │ │ ├── capture-payment.py │ │ └── restaurant-capture-with-gratuity.py │ ├── Credit │ │ ├── credit-using-bluefin-pci-p2pe-for-card-present-enabled-acquirer.py │ │ ├── credit-using-bluefin-pci-p2pe-with-visa-platform-connect.py │ │ ├── credit-with-customer-payment-instrument-and-shipping-address-token-id.py │ │ ├── credit-with-customer-token-id.py │ │ ├── credit-with-instrument-identifier-token-id.py │ │ ├── credit.py │ │ ├── ebt-merchandise-return-credit-voucher-from-snap.py │ │ ├── electronic-check-standalone-credits.py │ │ ├── pin-debit-credit-using-emv-technology-with-contactless-read-with-visa-platform-connect.py │ │ ├── pin-debit-credit-using-swiped-track-data-with-visa-platform-connect.py │ │ └── service-fees-credit.py │ ├── Payments │ │ ├── american-express-direct-emv-with-contact-read.py │ │ ├── authorization-capture-for-timeout-void-flow.py │ │ ├── authorization-for-incremental-authorization-flow.py │ │ ├── authorization-for-timeout-reversal-flow.py │ │ ├── authorization-skip-decisionmanager-for-single-transaction.py │ │ ├── authorization-using-bluefin-pci-p2pe-for-card-present-enabled-acquirer.py │ │ ├── authorization-using-bluefin-pci-p2pe-with-visa-platform-connect.py │ │ ├── authorization-using-swiped-track-data.py │ │ ├── authorization-with-capturesale.py │ │ ├── authorization-with-customer-payment-instrument-and-shipping-address-token-id.py │ │ ├── authorization-with-customer-token-creation.py │ │ ├── authorization-with-customer-token-default-payment-instrument-and-shipping-address-creation.py │ │ ├── authorization-with-customer-token-id.py │ │ ├── authorization-with-decision-manager-buyer-information.py │ │ ├── authorization-with-decision-manager-custom-setup.py │ │ ├── authorization-with-decision-manager-device-information.py │ │ ├── authorization-with-decision-manager-merchant-defined-information.py │ │ ├── authorization-with-decision-manager-shipping-information.py │ │ ├── authorization-with-decision-manager-travel-information.py │ │ ├── authorization-with-decision-manager.py │ │ ├── authorization-with-dmaccept-pa-enroll.py │ │ ├── authorization-with-dmreject-pa-enroll.py │ │ ├── authorization-with-dmreview-pa-enroll.py │ │ ├── authorization-with-instrument-identifier-token-creation.py │ │ ├── authorization-with-instrument-identifier-token-id.py │ │ ├── authorization-with-legacy-token.py │ │ ├── authorization-with-pa-enroll-authentication-needed.py │ │ ├── authorization-with-payer-auth-validation.py │ │ ├── authorization-with-tms-token-bypassing-network-token.py │ │ ├── cit-initiating-instalment-subscription-uk.py │ │ ├── cit-initiating-recurring-subscription.py │ │ ├── cit-placing-credential-on-file.py │ │ ├── digital-payment-googlepay.py │ │ ├── digital-payments-applepay.py │ │ ├── ebt-electronic-voucher-purchase-from-snap-account-with-visa-platform-connect.py │ │ ├── ebt-purchase-from-cash-benefits-account-with-cashback.py │ │ ├── ebt-purchase-from-snap-account-with-visa-platform-connect.py │ │ ├── electronic-check-debits-with-legacy-token.py │ │ ├── electronic-check-debits.py │ │ ├── incremental-authorization.py │ │ ├── level-ii-data.py │ │ ├── level-iii-data.py │ │ ├── mit-industry-practice-delayed-charge-ri-visa.py │ │ ├── mit-industry-practice-resubmission.py │ │ ├── mit-instalment.py │ │ ├── mit-recurring.py │ │ ├── mit-unscheduled-credential-on-file.py │ │ ├── partial-authorization.py │ │ ├── payment-network-tokenization.py │ │ ├── payment-with-flex-token.py │ │ ├── payment-with-flex-tokencreate-permanent-tms-token.py │ │ ├── pin-debit-purchase-using-emv-technology-with-contactless-read-with-visa-platform-connect.py │ │ ├── pin-debit-purchase-using-swiped-track-data-with-visa-platform-connect.py │ │ ├── restaurant-authorization.py │ │ ├── sale-using-emv-technology-with-contact-read-one-for-card-present-enabled-acquirer.py │ │ ├── sale-using-emv-technology-with-contact-read-two-for-card-present-enabled-acquirer.py │ │ ├── sale-using-emv-technology-with-contact-read-with-visa-platform-connect.py │ │ ├── sale-using-emv-technology-with-contactless-read-for-card-present-enabled-acquirer.py │ │ ├── sale-using-emv-technology-with-contactless-read-with-visa-platform-connect.py │ │ ├── sale-using-emv-technology-with-contactless.py │ │ ├── sale-using-keyed-data-for-card-present-enabled-acquirer.py │ │ ├── sale-using-keyed-data-with-balance-inquiry.py │ │ ├── sale-using-keyed-data-with-visa-platform-connect.py │ │ ├── sale-using-swiped-track-data-for-card-present-enabled-acquirer.py │ │ ├── sale-using-swiped-track-data-with-visa-platform-connect.py │ │ ├── service-fees-with-credit-card-transaction.py │ │ ├── simple-authorizationinternet.py │ │ ├── swiped.py │ │ └── zero-dollar-authorization.py │ ├── Refund │ │ ├── electronic-check-followon-refund.py │ │ ├── refund-capture.py │ │ └── refund-payment.py │ ├── Reversal │ │ ├── process-authorization-reversal.py │ │ ├── service-fees-authorization-reversal.py │ │ └── timeout-reversal.py │ └── Void │ │ ├── ebt-reversal-of-purchase-from-snap-account.py │ │ ├── pin-debit-purchase-reversal-void.py │ │ ├── timeout-void.py │ │ ├── void-capture.py │ │ ├── void-credit.py │ │ ├── void-payment.py │ │ └── void-refund.py ├── Payouts │ ├── payout-card-not-token.py │ └── payout-token.py ├── RecurringBillingSubscriptions │ ├── Plans │ │ ├── activate-plan.py │ │ ├── create-plan.py │ │ ├── deactivate-plan.py │ │ ├── delete-plan.py │ │ ├── get-list-of-plans.py │ │ ├── get-plan-code.py │ │ ├── get-plan.py │ │ └── update-plan.py │ └── Subscriptions │ │ ├── activate-subscription.py │ │ ├── cancel-subscription.py │ │ ├── create-subscription.py │ │ ├── get-list-of-subscriptions.py │ │ ├── get-subscription-code.py │ │ ├── get-subscription.py │ │ ├── suspend-subscription.py │ │ └── update-subscription.py ├── Reporting │ ├── ChargebackDetails │ │ └── get-chargeback-details.py │ ├── ChargebackSummaries │ │ └── get-chargeback-summaries.py │ ├── ConversionDetails │ │ └── get-conversion-detail-transactions.py │ ├── InterchangeClearingLevelDetails │ │ └── interchange-clearing-level-data-for-account-or-merchant.py │ ├── NetFundings │ │ └── get-netfunding-information-for-account-or-merchant.py │ ├── NotificationOfChanges │ │ └── get-notification-of-changes.py │ ├── PaymentBatchSummaries │ │ └── get-payment-batch-summary-data.py │ ├── PurchaseAndRefundDetails │ │ └── get-purchase-and-refund-details.py │ ├── ReportDefinitions │ │ ├── get-report-definition.py │ │ └── get-reporting-resource-information.py │ ├── ReportDownloads │ │ └── download-report.py │ ├── ReportSubscriptions │ │ ├── create-classicstandard-report-subscription.py │ │ ├── create-report-subscription.py │ │ ├── delete-subscription-of-report-name-by-organization.py │ │ ├── get-all-subscriptions.py │ │ └── get-subscription-for-report-name.py │ ├── Reports │ │ ├── create-adhoc-report.py │ │ ├── get-report-based-on-report-id.py │ │ └── retrieve-available-reports.py │ ├── RetrievalDetails │ │ └── get-retrieval-details.py │ └── RetrievalSummaries │ │ └── get-retrieval-summaries.py ├── RiskManagement │ ├── DecisionManager │ │ ├── add-data-to-list.py │ │ ├── add-duplicate-information.py │ │ ├── basic-dm-transaction.py │ │ ├── dm-with-buyer-information.py │ │ ├── dm-with-decisionprofilereject-response.py │ │ ├── dm-with-device-information.py │ │ ├── dm-with-merchant-defined-information.py │ │ ├── dm-with-scoreexceedsthreshold-response.py │ │ ├── dm-with-shipping-information.py │ │ ├── dm-with-travel-information.py │ │ ├── mark-as-suspect.py │ │ └── remove-from-history.py │ └── Verification │ │ ├── address-match-not-found.py │ │ ├── apartment-number-missing-or-not-found.py │ │ ├── canadian-billing-details.py │ │ ├── compliance-status-completed.py │ │ ├── customer-match-denied-parties-list.py │ │ ├── export-compliance-information-provided.py │ │ ├── multiple-line-items.py │ │ ├── multiple-sanction-lists.py │ │ ├── no-company-name.py │ │ ├── shipping-details-not-us-or-canada.py │ │ └── verbose-request-with-all-fields.py ├── SecureFileShare │ ├── download-file-with-file-identifier.py │ └── get-list-of-files.py ├── TokenManagement │ ├── Customer │ │ ├── create-customer.py │ │ ├── delete-customer.py │ │ ├── retrieve-customer.py │ │ ├── update-customer.py │ │ ├── update-customers-default-payment-instrument.py │ │ └── update-customers-default-shipping-address.py │ ├── CustomerPaymentInstrument │ │ ├── create-customer-default-payment-instrument-card.py │ │ ├── create-customer-nondefault-payment-instrument-card.py │ │ ├── create-customer-payment-instrument-bank-account.py │ │ ├── create-customer-payment-instrument-pinless-debit.py │ │ ├── delete-customer-payment-instrument.py │ │ ├── list-payment-instruments-for-customer.py │ │ └── retrieve-customer-payment-instrument.py │ ├── CustomerShippingAddress │ │ ├── create-customer-default-shipping-address.py │ │ ├── create-customer-nondefault-shipping-address.py │ │ ├── delete-customer-shipping-address.py │ │ ├── list-shipping-addresses-for-customer.py │ │ └── retrieve-customer-shipping-address.py │ ├── InstrumentIdentifier │ │ ├── create-instrument-identifier-bank-account.py │ │ ├── create-instrument-identifier-card-enroll-for-network-token.py │ │ ├── create-instrument-identifier-card.py │ │ ├── delete-instrument-identifier.py │ │ ├── enroll-instrument-identifier-for-network-tokenization.py │ │ ├── list-payment-instruments-for-instrument-identifier.py │ │ ├── retrieve-instrument-identifier.py │ │ └── update-instrument-identifier-previoustransactionid.py │ └── PaymentInstrument │ │ ├── create-payment-instrument-bank-account.py │ │ ├── create-payment-instrument-card.py │ │ ├── create-payment-instrument-pinless-debit.py │ │ ├── delete-payment-instrument.py │ │ ├── retrieve-payment-instrument.py │ │ └── update-payment-instrument.py ├── TransactionBatches │ ├── get-individual-batch-file.py │ ├── get-list-of-batch-files.py │ └── get-transaction-details-for-given-batch-id.py ├── TransactionDetails │ └── retrieve-transaction.py ├── TransactionSearch │ ├── create-search-request.py │ └── get-search-results.py ├── UnifiedCheckout │ ├── generate-capture-context-for-click-to-pay-dropin-ui.py │ ├── generate-unified-checkout-passing-billing-shipping.py │ └── generate-unified-checkout.py ├── UserManagement │ └── UserManagement │ │ └── get-user-information-deprecated.py ├── ValueAddedService │ ├── basic-tax-calculation-request.py │ ├── committed-tax-call-request.py │ ├── committed-tax-refund-call-request.py │ ├── tax-refund-request.py │ └── void-committed-tax-call.py ├── Webhooks │ ├── CreateNewWebhooks │ │ ├── create-alternative-payments-notification-webhook.py │ │ ├── create-decision-manager-webhook.py │ │ ├── create-fraud-management-webhook.py │ │ ├── create-invoicing-webhook.py │ │ ├── create-outage-and-key-expiration-notification-webhook.py │ │ ├── create-recurring-billing-webhook.py │ │ ├── create-secure-acceptance-webhook.py │ │ ├── create-terminal-management-webhook.py │ │ ├── create-token-management-webhook.py │ │ ├── create-webhook-symmetric-key.py │ │ ├── create-webhook-using-oauth-with-client-credentials.py │ │ ├── create-webhook-using-oauth-with-jwt.py │ │ ├── find-products-you-can-subscribe-to.py │ │ └── store-oauth-credentials.py │ └── ManageWebhooks │ │ ├── create-asymmetric-key.py │ │ ├── delete-webhook-subscription.py │ │ ├── get-details-on-all-created-webhooks.py │ │ ├── get-details-on-single-webhook.py │ │ ├── replay-failed-transactions-by-set-start-and-end-time.py │ │ ├── replay-failed-transactions-in-last-hours.py │ │ ├── replay-specific-list-of-transactions.py │ │ └── update-webhook.py ├── __init__.py ├── authentication │ ├── Resources │ │ ├── __init__.py │ │ ├── cybs.json │ │ ├── request.json │ │ ├── testrest.p12 │ │ └── trr_report.json │ ├── __init__.py │ ├── data │ │ ├── Configuration.py │ │ ├── RequestData.py │ │ └── __init__.py │ └── sample_code │ │ ├── DeleteMethod.py │ │ ├── Delete_Generate_Headers.py │ │ ├── GetMethod.py │ │ ├── GetObjectMethod.py │ │ ├── Get_Generate_Headers.py │ │ ├── PostMethod.py │ │ ├── PostObjectMethod.py │ │ ├── Post_Generate_Headers.py │ │ ├── PutMethod.py │ │ ├── Put_Generate_Headers.py │ │ ├── StandAloneHttpSignature.py │ │ ├── StandAloneJWT.py │ │ ├── StandAloneMetaKey.py │ │ ├── StandAloneOAuth.py │ │ └── __init__.py └── networkToken │ ├── NetworkToken.py │ ├── create_instrument_identifier_card_enroll_for_network_token.py │ └── payment_credentials_from_network_token.py └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib64/ 18 | parts/ 19 | sdist/ 20 | var/ 21 | wheels/ 22 | *.egg-info/ 23 | .installed.cfg 24 | *.egg 25 | MANIFEST 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *.cover 46 | .hypothesis/ 47 | .pytest_cache/ 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | local_settings.py 56 | db.sqlite3 57 | 58 | # Flask stuff: 59 | instance/ 60 | .webassets-cache 61 | 62 | # Scrapy stuff: 63 | .scrapy 64 | 65 | # Sphinx documentation 66 | docs/_build/ 67 | 68 | # PyBuilder 69 | target/ 70 | 71 | # Jupyter Notebook 72 | .ipynb_checkpoints 73 | 74 | # pyenv 75 | .python-version 76 | 77 | # celery beat schedule file 78 | celerybeat-schedule 79 | 80 | # SageMath parsed files 81 | *.sage.py 82 | 83 | # Environments 84 | .env 85 | .venv 86 | env/ 87 | venv/ 88 | ENV/ 89 | env.bak/ 90 | venv.bak/ 91 | 92 | # Spyder project settings 93 | .spyderproject 94 | .spyproject 95 | 96 | # Rope project settings 97 | .ropeproject 98 | 99 | # mkdocs documentation 100 | /site 101 | 102 | # mypy 103 | .mypy_cache/ 104 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | sudo: false 3 | 4 | python: 5 | - "2.7" 6 | - "3.4" 7 | - "3.5" 8 | - "3.6" 9 | - "pypy" 10 | - "pypy3" 11 | 12 | env: 13 | - PYTHONWARNINGS="ignore:Unverified HTTPS request" 14 | 15 | matrix: 16 | fast_finish: true 17 | include: 18 | - python: 3.7 19 | dist: xenial 20 | sudo: true 21 | - python: 3.8 22 | dist: xenial 23 | sudo: true 24 | allow_failures: 25 | - python: "pypy" 26 | - python: "pypy3" 27 | # pypy will just crash due to an incompatibility with lxml. 28 | # Newer versions of pypy seem to crash also, so we probably have to fix with a newer version of lxml 29 | - python: "2.7" 30 | - python: "3.4" 31 | - python: "3.5" 32 | 33 | install: 34 | - pip install cybersource-rest-client-python 35 | - pip install -e . 36 | 37 | script: 38 | - bash sample_code_runner.sh 39 | - cat output.log 40 | -------------------------------------------------------------------------------- /Logging.md: -------------------------------------------------------------------------------- 1 | [![Generic badge](https://img.shields.io/badge/LOGGING-NEW-GREEN.svg)](https://shields.io/) 2 | 3 | # Logging in CyberSource REST Client SDK (Python) 4 | 5 | Since v0.0.31, a new logging framework has been introduced in the SDK. This new logging framework makes use of Python's native logging, and standardizes the logging so that it can be integrated with the logging in the client application. 6 | 7 | ## Python's native logging Configuration 8 | 9 | In order to leverage the new logging framework, the following configuration settings may be added to the merchant configuration as part of **`LogConfiguration`**: 10 | 11 | * enableLog 12 | * log_directory 13 | * log_file_name 14 | * log_format 15 | * log_date_format 16 | * log_max_size 17 | * log_level 18 | * enable_masking 19 | 20 | In our [sample Configuration.py](https://github.com/CyberSource/cybersource-rest-samples-python/blob/master/data/Configuration.py) file, the following lines have been added to support this new framework: 21 | 22 | ```python 23 | self.enable_log = True 24 | self.log_file_name = "cybs" 25 | self.log_maximum_size = 10487560 26 | self.log_directory = os.path.join(os.getcwd(), "Logs") 27 | self.log_level = "Debug" 28 | self.enable_masking = False 29 | self.log_format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" 30 | self.log_date_format = "%Y-%m-%d %H:%M:%S" 31 | ... 32 | log_config = LogConfiguration() 33 | log_config.set_enable_log(self.enable_log) 34 | log_config.set_log_directory(self.log_directory) 35 | log_config.set_log_file_name(self.log_file_name) 36 | log_config.set_log_maximum_size(self.log_maximum_size) 37 | log_config.set_log_level(self.log_level) 38 | log_config.set_enable_masking(self.enable_masking) 39 | log_config.set_log_format(self.log_format) 40 | log_config.set_log_date_format(self.log_date_format) 41 | configuration_dictionary["log_config"] = log_config 42 | ``` 43 | 44 | ### Important Notes 45 | 46 | The variable `enableMasking` needs to be set to `true` if sensitive data in the request/response should be hidden/masked. 47 | 48 | Sensitive data fields are listed below: 49 | 50 | * Card Security Code 51 | * Card Number 52 | * Any field with `number` in the name 53 | * Card Expiration Month 54 | * Card Expiration Year 55 | * Account 56 | * Routing Number 57 | * Email 58 | * First Name & Last Name 59 | * Phone Number 60 | * Type 61 | * Token 62 | * Signature 63 | -------------------------------------------------------------------------------- /Validation/sample_code_log_processor.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | IMPORTS 4 | """ 5 | 6 | import argparse 7 | import re 8 | import json 9 | 10 | """ 11 | ARGUMENT PARSER 12 | """ 13 | 14 | def parse_arguments(): 15 | parser = argparse.ArgumentParser(description="Processes the log file from Sample Code Testing") 16 | parser.add_argument("--log", "-l", help="Log file for the current testing run of Sample Codes") 17 | parser.add_argument("--output", "-o", help="JSON file to store the actual results from the current testing run") 18 | 19 | args = parser.parse_args() 20 | log_path = args.log 21 | output_file = args.output 22 | return log_path, output_file 23 | 24 | """ 25 | LOG FILE PROCESSOR 26 | """ 27 | 28 | def process_log_file(filepath): 29 | with open(filepath, "r", encoding = "utf-8") as file: 30 | contents = file.read() 31 | matches = re.findall(r"(\[Sample Code Testing\]) (\[([A-Za-z0-9\-_]+)\]) ([0-9]{3})", contents) 32 | 33 | return matches 34 | 35 | """ 36 | ADD TO JSON OBJECT 37 | """ 38 | 39 | def add_to_json_object(json_obj, key, value): 40 | json_obj[key] = value 41 | return json_obj 42 | 43 | """ 44 | DUMP JSON TO FILE 45 | """ 46 | 47 | def dump_json_to_file(filepath, src): 48 | with open(filepath, "w") as file: 49 | json.dump(src, file, ensure_ascii=False, indent=4) 50 | 51 | """ 52 | MAIN FUNCTION 53 | """ 54 | 55 | def main(): 56 | current_log_file, output_json_file = parse_arguments() 57 | log_statements = process_log_file(current_log_file) 58 | 59 | code_map = {} 60 | for statement in log_statements: 61 | if statement[2] not in ("Configuration"): 62 | code_map = add_to_json_object(code_map, statement[2], statement[3]) 63 | 64 | dump_json_to_file(output_json_file, code_map) 65 | 66 | if __name__ == "__main__": 67 | main() -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyberSource/cybersource-rest-samples-python/8763756c9294a3d78f3c95bb67372cb89b8e4d52/__init__.py -------------------------------------------------------------------------------- /data/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyberSource/cybersource-rest-samples-python/8763756c9294a3d78f3c95bb67372cb89b8e4d52/data/__init__.py -------------------------------------------------------------------------------- /lib/sampleapiclient/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyberSource/cybersource-rest-samples-python/8763756c9294a3d78f3c95bb67372cb89b8e4d52/lib/sampleapiclient/__init__.py -------------------------------------------------------------------------------- /lib/sampleapiclient/connection/Connection.py: -------------------------------------------------------------------------------- 1 | from abc import ABCMeta, abstractmethod 2 | 3 | 4 | class Connection: 5 | __metaclass__ = ABCMeta 6 | 7 | @abstractmethod 8 | def open_connection(self, mconfig, header, proxies): 9 | pass 10 | 11 | @abstractmethod 12 | def set_proxy_connection(self): 13 | pass 14 | -------------------------------------------------------------------------------- /lib/sampleapiclient/connection/Headers.py: -------------------------------------------------------------------------------- 1 | from abc import ABCMeta, abstractmethod 2 | 3 | 4 | class Headers: 5 | __metaclass__ = ABCMeta 6 | 7 | @abstractmethod 8 | def set_header_data(self): 9 | pass 10 | 11 | @abstractmethod 12 | def set_digest(self): 13 | pass 14 | 15 | @abstractmethod 16 | def set_signature(self, date_time, logger): 17 | pass 18 | 19 | @abstractmethod 20 | def set_user_agent(self): 21 | pass 22 | 23 | @abstractmethod 24 | def set_json_application(self): 25 | pass 26 | -------------------------------------------------------------------------------- /lib/sampleapiclient/connection/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyberSource/cybersource-rest-samples-python/8763756c9294a3d78f3c95bb67372cb89b8e4d52/lib/sampleapiclient/connection/__init__.py -------------------------------------------------------------------------------- /lib/sampleapiclient/controller/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyberSource/cybersource-rest-samples-python/8763756c9294a3d78f3c95bb67372cb89b8e4d52/lib/sampleapiclient/controller/__init__.py -------------------------------------------------------------------------------- /lib/sampleapiclient/masking/Masking.py: -------------------------------------------------------------------------------- 1 | import json 2 | from authenticationsdk.util.GlobalLabelParameters import * 3 | 4 | 5 | # This method reads the items to be masked and accordingly masks the response from the server 6 | def masking(r): 7 | try: 8 | j = json.loads(r) 9 | 10 | maskdata = json.dumps( 11 | remove_key(j, "expirationMonth", "expirationYear", "email", "firstName", "lastName", "phoneNumber", 12 | "number", "securityCode", "type")) 13 | 14 | return maskdata 15 | except ValueError as e: 16 | return r 17 | 18 | 19 | # This function replaces the value of the items to be masked to "XXXXX" 20 | def remove_key(obj, *keys): 21 | if type(obj) is dict: 22 | for k, v in list(obj.items()): 23 | if k not in keys: 24 | obj[k] = remove_key(v, *keys) 25 | obj[k] = v 26 | else: 27 | obj[k] = GlobalLabelParameters.MASKING_VALUE 28 | 29 | return obj 30 | -------------------------------------------------------------------------------- /lib/sampleapiclient/masking/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyberSource/cybersource-rest-samples-python/8763756c9294a3d78f3c95bb67372cb89b8e4d52/lib/sampleapiclient/masking/__init__.py -------------------------------------------------------------------------------- /lib/sampleapiclient/model/AggregatorInformation.py: -------------------------------------------------------------------------------- 1 | class AggregatorInformation: 2 | def __init__(self): 3 | self.subMerchant = None 4 | self.name = None 5 | self.aggregatorID = None 6 | 7 | def set_submerchant(self, value): 8 | self.subMerchant = value 9 | 10 | def set_name(self, value): 11 | self.name = value 12 | 13 | def set_aggregator_id(self, value): 14 | self.aggregatorID = value 15 | -------------------------------------------------------------------------------- /lib/sampleapiclient/model/AmountDetails.py: -------------------------------------------------------------------------------- 1 | class AmountDetails: 2 | def __init__(self): 3 | self.totalAmount = None 4 | self.currency = None 5 | 6 | def set_total_amount(self, value): 7 | self.totalAmount = value 8 | 9 | def set_currency(self, value): 10 | self.currency = value 11 | -------------------------------------------------------------------------------- /lib/sampleapiclient/model/BillTo.py: -------------------------------------------------------------------------------- 1 | class BillTo: 2 | def __init__(self): 3 | self.country = None 4 | self.lastName = None 5 | self.address2 = None 6 | self.address1 = None 7 | self.postalCode = None 8 | self.locality = None 9 | self.administrativeArea = None 10 | self.firstName = None 11 | self.phoneNumber = None 12 | self.district = None 13 | self.buildingNumber = None 14 | self.company = None 15 | self.email = None 16 | 17 | def set_country(self, value): 18 | self.country = value 19 | 20 | def set_last_name(self, value): 21 | self.lastName = value 22 | 23 | def set_address2(self, value): 24 | self.address2 = value 25 | 26 | def set_address1(self, value): 27 | self.address1 = value 28 | 29 | def set_postal_code(self, value): 30 | self.postalCode = value 31 | 32 | def set_locality(self, value): 33 | self.locality = value 34 | 35 | def set_administrative_area(self, value): 36 | self.administrativeArea = value 37 | 38 | def set_first_name(self, value): 39 | self.firstName = value 40 | 41 | def set_phone_number(self, value): 42 | self.phoneNumber = value 43 | 44 | def set_district(self, value): 45 | self.district = value 46 | 47 | def set_building_number(self, value): 48 | self.buildingNumber = value 49 | 50 | def set_company(self, value): 51 | self.company = value 52 | 53 | def set_email(self, value): 54 | self.email = value 55 | -------------------------------------------------------------------------------- /lib/sampleapiclient/model/Card.py: -------------------------------------------------------------------------------- 1 | class Card: 2 | def __init__(self): 3 | self.expirationYear = None 4 | self.number = None 5 | self.securityCode = None 6 | self.expirationMonth = None 7 | self.type = None 8 | 9 | def set_espiration_year(self, value): 10 | self.expirationYear = value 11 | 12 | def set_number(self, value): 13 | self.number = value 14 | 15 | def set_security_code(self, value): 16 | self.securityCode = value 17 | 18 | def set_expiration_month(self, value): 19 | self.expirationMonth = value 20 | 21 | def set_type(self, value): 22 | self.type = value 23 | -------------------------------------------------------------------------------- /lib/sampleapiclient/model/ClientReferenceInformation.py: -------------------------------------------------------------------------------- 1 | class ClientReferenceInformation: 2 | def __init__(self): 3 | self.code = None 4 | 5 | def set_code(self, value): 6 | self.code = value 7 | -------------------------------------------------------------------------------- /lib/sampleapiclient/model/OrderInformation.py: -------------------------------------------------------------------------------- 1 | class OrderInformation: 2 | def __init__(self): 3 | self.billTo = None 4 | self.amountDetails = None 5 | 6 | def set_bill_to(self, value): 7 | self.billTo = value 8 | 9 | def set_amount_details(self, value): 10 | self.amountDetails = value 11 | 12 | 13 | -------------------------------------------------------------------------------- /lib/sampleapiclient/model/PaymentInformation.py: -------------------------------------------------------------------------------- 1 | class PaymentInformation: 2 | def __init__(self): 3 | self.card = None 4 | 5 | def set_card(self, value): 6 | self.card = value 7 | -------------------------------------------------------------------------------- /lib/sampleapiclient/model/Payments.py: -------------------------------------------------------------------------------- 1 | class Payments: 2 | def __init__(self): 3 | self.clientReferenceInformation = None 4 | 5 | self.processingInformation = None 6 | self.aggregatorInformation = None 7 | self.orderInformation = None 8 | self.paymentInformation = None 9 | 10 | def set_client_reference_information(self, value): 11 | self.clientReferenceInformation = value 12 | 13 | def set_processing_information(self, value): 14 | self.processingInformation = value 15 | 16 | def set_aggregator_information(self, value): 17 | self.aggregatorInformation = value 18 | 19 | def set_order_information(self, value): 20 | self.orderInformation = value 21 | 22 | def set_payment_information(self, value): 23 | self.paymentInformation = value 24 | -------------------------------------------------------------------------------- /lib/sampleapiclient/model/ProcessingInformation.py: -------------------------------------------------------------------------------- 1 | class ProcessingInformation: 2 | def __init__(self): 3 | self.commerceIndicator = None 4 | 5 | def set_commerce_indicator(self, value): 6 | self.commerceIndicator = value 7 | -------------------------------------------------------------------------------- /lib/sampleapiclient/model/SubMerchant.py: -------------------------------------------------------------------------------- 1 | class SubMerchant: 2 | def __init__(self): 3 | self.cardAcceptorID = None 4 | self.country = None 5 | self.phoneNumber = None 6 | self.address1 = None 7 | self.postalCode = None 8 | self.locality = None 9 | self.name = None 10 | self.administrativeArea = None 11 | self.region = None 12 | self.email = None 13 | 14 | def set_card_acceptor_id(self, value): 15 | self.cardAcceptorID = value 16 | 17 | def set_country(self, value): 18 | self.country = value 19 | 20 | def set_phone_number(self, value): 21 | self.phoneNumber = value 22 | 23 | def set_address1(self, value): 24 | self.address1 = value 25 | 26 | def set_postal_code(self, value): 27 | self.postalCode = value 28 | 29 | def set_locality(self, value): 30 | self.locality = value 31 | 32 | def set_name(self, value): 33 | self.name = value 34 | 35 | def set_administrative_area(self, value): 36 | self.administrativeArea = value 37 | 38 | def set_region(self, value): 39 | self.region = value 40 | 41 | def set_email(self, value): 42 | self.email = value 43 | -------------------------------------------------------------------------------- /lib/sampleapiclient/model/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyberSource/cybersource-rest-samples-python/8763756c9294a3d78f3c95bb67372cb89b8e4d52/lib/sampleapiclient/model/__init__.py -------------------------------------------------------------------------------- /lib/sampleapiclient/service/PaymentRequestService.py: -------------------------------------------------------------------------------- 1 | from lib.sampleapiclient.connection.HttpConnection import * 2 | from lib.sampleapiclient.connection.JwtUrlConnection import * 3 | from authenticationsdk.core.ExceptionHandling import * 4 | 5 | 6 | # Here the call is made to respective connection class (HTTPConnection or JWTConnection) 7 | # depending on the Authentication type 8 | 9 | class PaymentRequestService: 10 | def __init__(self): 11 | self.get_merchant_config = None 12 | 13 | # merchantConfig : This object contains all the details present in the cybs.properties. 14 | # requestType : Method which is under process or execution (Get or Post). 15 | # getID : The Get unique ID. 16 | 17 | def payment_request_service(self, mconfig): 18 | 19 | self.process_payment_request(mconfig) 20 | 21 | # merchantConfig : This object contains all the details present in the cybs.properties. 22 | # requestType : Method which is under process or execution (Get or Post). 23 | # getID : The Get unique ID. 24 | 25 | # noinspection PyMethodMayBeStatic 26 | def process_payment_request(self, mconfig): 27 | 28 | authentication_type = mconfig.authentication_type 29 | # This method establishes Connection based on the Authorization Type 30 | if authentication_type.upper() == GlobalLabelParameters.HTTP.upper(): 31 | httpconnection = HttpConnection() 32 | httpconnection.http_connection(mconfig) 33 | elif authentication_type.upper() == GlobalLabelParameters.JWT.upper(): 34 | jwt_url_obj = JwtUrlConnection() 35 | jwt_url_obj.jwt_url_connection(mconfig) 36 | else: 37 | raise ApiException(1, GlobalLabelParameters.AUTH_ERROR) 38 | -------------------------------------------------------------------------------- /lib/sampleapiclient/service/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyberSource/cybersource-rest-samples-python/8763756c9294a3d78f3c95bb67372cb89b8e4d52/lib/sampleapiclient/service/__init__.py -------------------------------------------------------------------------------- /lib/sampleapiclient/setup.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from setuptools import setup, find_packages 3 | 4 | -------------------------------------------------------------------------------- /lib/sampleapiclient/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyberSource/cybersource-rest-samples-python/8763756c9294a3d78f3c95bb67372cb89b8e4d52/lib/sampleapiclient/test/__init__.py -------------------------------------------------------------------------------- /resources/NetworkTokenCert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC4aEj4mUxdBAea 3 | YVtGmuJ1e4+QNj80t/K5kYP2xKc576t5V08Z643O6T+kNYoFRRBADhs0yPfBM0rK 4 | p+f8y6EiMTI/IjlB99OS16CXgprQKYoFAV8xUvUntbkOkCpyn157l05XLgnnIP+P 5 | Y1Y7/vlcq/ODpZPj6l4kKyeQwx3OQ8fQ1zsSPJ0SYhKu+M+oVGGH2ybEUaIBirWC 6 | v3XA/x32lz6AIyRF+IDqthBTTurWtwiYBWm6xJuTw8zZT+etm8bSNbRFnTNIkEtt 7 | DglA5qCeKQWKM6vgFO9+cnUaV7egT9rbS/DyxJXGP3yfJbWwaaWs5xRZHrlJUioB 8 | XSN/jOzVAgMBAAECggEAB++xCEXss+oa+6lp+LlsupqlPJMhGD88aoEZOVMQUV1/ 9 | tzqrNFXfZgLC0unc9UoaH2+b+yMVCpMPCna8dLQ8zJBqda4e4bhtOhoelravu/q1 10 | rm53LtO/qkRXYQmSUhmKwu3pmLXqBjD03rJrQSzBhZv+4HENUtdA0vSqgL/s9fYB 11 | BQHnq1wYPSHGonMdQCOBh2JeLqoJVnrU3tdrfu9gppS0a/olKN5s5+5jO4tf3wWH 12 | DeDUDwIN7+vw/pzYOzTTJOs/hWIbxzr4wxYhG2RRBbKwyrbBRwS7GMSQfPA+BuYW 13 | ZF9fPUP7L8SMwME/cIQ4ZKQVyun+5QDQvDSWxG7hIQKBgQDwSvIyRjuTlVP9zkWR 14 | ihyYW6I5BQivnd5kjEHFWYoH/XXwEJTk/lB8hFVJx02S0iBxxQW+3AUF52ejKWVq 15 | 7AI6khhooBcc0iImh0Dm2qy912N0SLn29lfz8Lgb47lvCOvvgUUZqZDuugYPhCaU 16 | zbRBEaXXXzZq64JvI0GNDjM2hQKBgQDEdidphv/ZItWOhsaaRBav56jVsRscXcIR 17 | Xe+Fnz5NTDE8OJeJwCNLkmrV5GZTlHVc1aQ6eUOPgOUiJhr4MNN4CIf+fDbhpw6d 18 | m8sHfGEmKt18Ei7fXaSlvICNz5SHkZ3M52nDfKUcp8W+2zB8iIUdXokhHJk4/drT 19 | sI9nsoF2EQKBgAGmYhdaSBpxUgxSGEQxkJSzPF/r2u1pxhcmp2T1gm8fnGmzk3In 20 | FOJl/jfteGjjrHlbgviWhipONnX2WM3tJO7GBgjh4IbAIp/lGdr78We0TOiFf1Fk 21 | y6HPK1R1sdZDV2tjldfhRC9/c38zxxgKeYxg1KSv8K23REQDF/Yh/NQJAoGBAMLq 22 | Ks4S5zGJ0vEWHGKfXRbmsuZYUXqCNvG+Dc63oDtWdZ620voTC7GFscNGWJNhvlL9 23 | j3OILhRpIGwR/D3zS0tSw4IjwNt+QAz0raleqJAShS38aE6p/JmGfNC1ezpJqZLK 24 | oW8W8kWM2q8xjlhvpgnuagTU99vIWFwgVxbdzn3RAoGBANmfExNfl/WhPby8BRCU 25 | OAt39sWZbm5j6USdUcnENs7XQ6vRLLFbPn1oUJiw8YSFn0QSmZXAHYPmLBoSKo9N 26 | xXrEdoDF22Exktb9/Htq/Iw0V+2xmKss7OCYOZS8erNPQ9BgqMmQC7faoEgDiGOS 27 | MMtHbJvYmrSvZgBF1E3snHE+ 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /resources/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyberSource/cybersource-rest-samples-python/8763756c9294a3d78f3c95bb67372cb89b8e4d52/resources/__init__.py -------------------------------------------------------------------------------- /resources/request.json: -------------------------------------------------------------------------------- 1 | { 2 | "clientReferenceInformation": { 3 | "code": "TC50171_3" 4 | }, 5 | "processingInformation": { 6 | "commerceIndicator": "internet" 7 | }, 8 | "aggregatorInformation": { 9 | "subMerchant": { 10 | "cardAcceptorID": "1234567890", 11 | "country": "US", 12 | "phoneNumber": "650-432-0000", 13 | "address1": "900 Metro Center", 14 | "postalCode": "94404-2775", 15 | "locality": "Foster City", 16 | "name": "Visa Inc", 17 | "administrativeArea": "CA", 18 | "region": "PEN", 19 | "email": "test@cybs.com" 20 | }, 21 | "name": "V-Internatio", 22 | "aggregatorID": "123456789" 23 | }, 24 | "orderInformation": { 25 | "billTo": { 26 | "country": "US", 27 | "lastName": "VDP", 28 | "address2": "Address 2", 29 | "address1": "201 S. Division St.", 30 | "postalCode": "48104-2201", 31 | "locality": "Ann Arbor", 32 | "administrativeArea": "MI", 33 | "firstName": "RTS", 34 | "phoneNumber": "999999999", 35 | "district": "MI", 36 | "buildingNumber": "123", 37 | "company": "Visa", 38 | "email": "test@cybs.com" 39 | }, 40 | "amountDetails": { 41 | "totalAmount": "102.21", 42 | "currency": "USD" 43 | } 44 | }, 45 | "paymentInformation": { 46 | "card": { 47 | "expirationYear": "2031", 48 | "number": "5555555555554444", 49 | "securityCode": "123", 50 | "expirationMonth": "12", 51 | "type": "002" 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /resources/testrest.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyberSource/cybersource-rest-samples-python/8763756c9294a3d78f3c95bb67372cb89b8e4d52/resources/testrest.p12 -------------------------------------------------------------------------------- /resources/testrest_cpctv.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyberSource/cybersource-rest-samples-python/8763756c9294a3d78f3c95bb67372cb89b8e4d52/resources/testrest_cpctv.p12 -------------------------------------------------------------------------------- /resources/trr_report.json: -------------------------------------------------------------------------------- 1 | { 2 | "startDay":"23", 3 | "timeZone":"America/Chicago", 4 | "reportDefinitionName":"TransactionRequestClass", 5 | "startTime":"1100", 6 | "reportFrequency":"DAILY", 7 | "ReportName":"TRRReport", 8 | "reportFormat":"csv", 9 | "orgId":"testrest", 10 | "reportType":"detail", 11 | "reportFields": ["Request.RequestID","Request.TransactionDate","Request.MerchantReferenceNumber","Request.MerchantID"] 12 | } -------------------------------------------------------------------------------- /sampleCodeIgnoreList.txt: -------------------------------------------------------------------------------- 1 | .*__init__.py 2 | .*/data/.* 3 | .*Flex_Security_Exception.py 4 | .*/Webhooks/.* 5 | .*/authentication/.* 6 | .*/MerchantBoarding/.* 7 | .*updateinvoicesettings.py 8 | -------------------------------------------------------------------------------- /sample_code_runner.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | FILECOUNT=0 3 | SAMPLECOUNT=1 4 | find samples -print | grep -i -e "\.py$" > list.txt 5 | 6 | echo > output.log 7 | 8 | set -e 9 | while IFS="" read -r p || [ -n "$p" ] 10 | do 11 | if [[ "$p" =~ $(echo ^\($(sed 's/[[:blank:]]//g' sampleCodeIgnoreList.txt | paste -sd '|' /dev/stdin)\)$) ]]; then 12 | printf '\n\n#### SKIPPED - %s ####\n' "$p" 13 | printf '\n\n#### SKIPPED - %s ####\n' "$p" >> output.log 14 | else 15 | printf '\n\n**** RUNNING - %s ****\n' "$p" 16 | printf '\n\n%s **** RUNNING - %s ****\n' "$SAMPLECOUNT" "$p" >> output.log 17 | python "$p" >> output.log 18 | printf '\n\n**** END RUNNING - %s ****\n' "$p" >> output.log 19 | SAMPLECOUNT=$((SAMPLECOUNT+1)) 20 | fi 21 | 22 | FILECOUNT=$((FILECOUNT+1)) 23 | 24 | done < list.txt 25 | printf '\n\n**** %s Sample Codes ran successfully ****\n' "$SAMPLECOUNT" 26 | printf '\n\n**** %s Sample Codes ran successfully ****\n' "$FILECOUNT" >> output.log 27 | rm -f list.txt -------------------------------------------------------------------------------- /samples/AccountUpdater/amex-registration-customer-token-batch.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | import json 4 | from importlib.machinery import SourceFileLoader 5 | from pathlib import Path 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | elif isinstance(value, list): 18 | for item in value: 19 | del_none(item) 20 | return d 21 | 22 | def amex_registration_customer_token_batch(): 23 | type = "amexRegistration" 24 | 25 | includedTokens = [] 26 | includedTokens1 = Accountupdaterv1batchesIncludedTokens( 27 | id = "C06977C0EDC0E985E053AF598E0A3326" 28 | ) 29 | 30 | includedTokens.append(includedTokens1.__dict__) 31 | 32 | includedTokens2 = Accountupdaterv1batchesIncludedTokens( 33 | id = "C069A534044F6140E053AF598E0AD492" 34 | ) 35 | 36 | includedTokens.append(includedTokens2.__dict__) 37 | 38 | included = Accountupdaterv1batchesIncluded( 39 | tokens = includedTokens 40 | ) 41 | 42 | merchantReference = "TC50171_3" 43 | notificationEmail = "test@cybs.com" 44 | requestObj = Body( 45 | type = type, 46 | included = included.__dict__, 47 | merchant_reference = merchantReference, 48 | notification_email = notificationEmail 49 | ) 50 | 51 | 52 | requestObj = del_none(requestObj.__dict__) 53 | requestObj = json.dumps(requestObj) 54 | 55 | try: 56 | config_obj = configuration.Configuration() 57 | client_config = config_obj.get_configuration() 58 | api_instance = BatchesApi(client_config) 59 | return_data, status, body = api_instance.post_batch(requestObj) 60 | 61 | print("\nAPI RESPONSE CODE : ", status) 62 | print("\nAPI RESPONSE BODY : ", body) 63 | 64 | write_log_audit(status) 65 | 66 | return return_data 67 | except Exception as e: 68 | write_log_audit(e.status) 69 | print("\nException when calling BatchesApi->post_batch: %s\n" % e) 70 | 71 | def write_log_audit(status): 72 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 73 | 74 | if __name__ == "__main__": 75 | amex_registration_customer_token_batch() 76 | -------------------------------------------------------------------------------- /samples/AccountUpdater/amex-registration-instrument-identifier-token-batch.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | import json 4 | from importlib.machinery import SourceFileLoader 5 | from pathlib import Path 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def amex_registration_instrument_identifier_token_batch(): 20 | type = "amexRegistration" 21 | 22 | includedTokens = [] 23 | includedTokens1 = Accountupdaterv1batchesIncludedTokens( 24 | id = "7030000000000260224", 25 | expiration_month = "12", 26 | expiration_year = "2020" 27 | ) 28 | 29 | includedTokens.append(includedTokens1.__dict__) 30 | 31 | includedTokens2 = Accountupdaterv1batchesIncludedTokens( 32 | id = "7030000000000231118", 33 | expiration_month = "12", 34 | expiration_year = "2020" 35 | ) 36 | 37 | includedTokens.append(includedTokens2.__dict__) 38 | 39 | included = Accountupdaterv1batchesIncluded( 40 | tokens = includedTokens 41 | ) 42 | 43 | merchantReference = "TC50171_3" 44 | notificationEmail = "test@cybs.com" 45 | requestObj = Body( 46 | type = type, 47 | included = included.__dict__, 48 | merchant_reference = merchantReference, 49 | notification_email = notificationEmail 50 | ) 51 | 52 | 53 | requestObj = del_none(requestObj.__dict__) 54 | requestObj = json.dumps(requestObj) 55 | 56 | try: 57 | config_obj = configuration.Configuration() 58 | client_config = config_obj.get_configuration() 59 | api_instance = BatchesApi(client_config) 60 | return_data, status, body = api_instance.post_batch(requestObj) 61 | 62 | print("\nAPI RESPONSE CODE : ", status) 63 | print("\nAPI RESPONSE BODY : ", body) 64 | 65 | write_log_audit(status) 66 | 67 | return return_data 68 | except Exception as e: 69 | write_log_audit(e.status) 70 | print("\nException when calling BatchesApi->post_batch: %s\n" % e) 71 | 72 | def write_log_audit(status): 73 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 74 | 75 | if __name__ == "__main__": 76 | amex_registration_instrument_identifier_token_batch() 77 | -------------------------------------------------------------------------------- /samples/AccountUpdater/list-batches.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | import json 4 | from importlib.machinery import SourceFileLoader 5 | from pathlib import Path 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def list_batches(): 20 | 21 | try: 22 | config_obj = configuration.Configuration() 23 | client_config = config_obj.get_configuration() 24 | api_instance = BatchesApi(client_config) 25 | offset = 0 26 | limit = 10 27 | from_date = '20230101T123000Z' 28 | to_date = '20231001T123000Z' 29 | return_data, status, body = api_instance.get_batches_list(offset = offset, limit = limit, from_date = from_date, to_date = to_date) 30 | 31 | print("\nAPI RESPONSE CODE : ", status) 32 | print("\nAPI RESPONSE BODY : ", body) 33 | 34 | write_log_audit(status) 35 | 36 | return return_data 37 | except Exception as e: 38 | write_log_audit(e.status) 39 | print("\nException when calling BatchesApi->get_batches_list: %s\n" % e) 40 | 41 | def write_log_audit(status): 42 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 43 | 44 | if __name__ == "__main__": 45 | list_batches() 46 | -------------------------------------------------------------------------------- /samples/AccountUpdater/one-off-visa-mastercard-customer-token-batch.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | import json 4 | from importlib.machinery import SourceFileLoader 5 | from pathlib import Path 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | elif isinstance(value, list): 18 | for item in value: 19 | del_none(item) 20 | return d 21 | 22 | def one_off_visa_mastercard_customer_token_batch(): 23 | type = "oneOff" 24 | 25 | includedTokens = [] 26 | includedTokens1 = Accountupdaterv1batchesIncludedTokens( 27 | id = "C064DE56200B0DB0E053AF598E0A52AA" 28 | ) 29 | 30 | includedTokens.append(includedTokens1.__dict__) 31 | 32 | includedTokens2 = Accountupdaterv1batchesIncludedTokens( 33 | id = "C064DE56213D0DB0E053AF598E0A52AA" 34 | ) 35 | 36 | includedTokens.append(includedTokens2.__dict__) 37 | 38 | included = Accountupdaterv1batchesIncluded( 39 | tokens = includedTokens 40 | ) 41 | 42 | merchantReference = "TC50171_3" 43 | notificationEmail = "test@cybs.com" 44 | requestObj = Body( 45 | type = type, 46 | included = included.__dict__, 47 | merchant_reference = merchantReference, 48 | notification_email = notificationEmail 49 | ) 50 | 51 | 52 | requestObj = del_none(requestObj.__dict__) 53 | requestObj = json.dumps(requestObj) 54 | 55 | 56 | try: 57 | config_obj = configuration.Configuration() 58 | client_config = config_obj.get_configuration() 59 | api_instance = BatchesApi(client_config) 60 | return_data, status, body = api_instance.post_batch(requestObj) 61 | 62 | print("\nAPI RESPONSE CODE : ", status) 63 | print("\nAPI RESPONSE BODY : ", body) 64 | 65 | write_log_audit(status) 66 | 67 | return return_data 68 | except Exception as e: 69 | write_log_audit(e.status) 70 | print("\nException when calling BatchesApi->post_batch: %s\n" % e) 71 | 72 | def write_log_audit(status): 73 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 74 | 75 | if __name__ == "__main__": 76 | one_off_visa_mastercard_customer_token_batch() 77 | -------------------------------------------------------------------------------- /samples/AccountUpdater/one-off-visa-mastercard-instrument-identifier-token-batch.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | import json 4 | from importlib.machinery import SourceFileLoader 5 | from pathlib import Path 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def one_off_visa_mastercard_instrument_identifier_token_batch(): 20 | type = "oneOff" 21 | 22 | includedTokens = [] 23 | includedTokens1 = Accountupdaterv1batchesIncludedTokens( 24 | id = "7030000000000116236", 25 | expiration_month = "12", 26 | expiration_year = "2020" 27 | ) 28 | 29 | includedTokens.append(includedTokens1.__dict__) 30 | 31 | includedTokens2 = Accountupdaterv1batchesIncludedTokens( 32 | id = "7030000000000178855", 33 | expiration_month = "12", 34 | expiration_year = "2020" 35 | ) 36 | 37 | includedTokens.append(includedTokens2.__dict__) 38 | 39 | included = Accountupdaterv1batchesIncluded( 40 | tokens = includedTokens 41 | ) 42 | 43 | merchantReference = "TC50171_3" 44 | notificationEmail = "test@cybs.com" 45 | requestObj = Body( 46 | type = type, 47 | included = included.__dict__, 48 | merchant_reference = merchantReference, 49 | notification_email = notificationEmail 50 | ) 51 | 52 | 53 | requestObj = del_none(requestObj.__dict__) 54 | requestObj = json.dumps(requestObj) 55 | 56 | 57 | try: 58 | config_obj = configuration.Configuration() 59 | client_config = config_obj.get_configuration() 60 | api_instance = BatchesApi(client_config) 61 | return_data, status, body = api_instance.post_batch(requestObj) 62 | 63 | print("\nAPI RESPONSE CODE : ", status) 64 | print("\nAPI RESPONSE BODY : ", body) 65 | 66 | write_log_audit(status) 67 | 68 | return return_data 69 | except Exception as e: 70 | write_log_audit(e.status) 71 | print("\nException when calling BatchesApi->post_batch: %s\n" % e) 72 | 73 | def write_log_audit(status): 74 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 75 | 76 | if __name__ == "__main__": 77 | one_off_visa_mastercard_instrument_identifier_token_batch() 78 | -------------------------------------------------------------------------------- /samples/AccountUpdater/retrieve-batch-report.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | import json 4 | from importlib.machinery import SourceFileLoader 5 | from pathlib import Path 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | elif isinstance(value, list): 18 | for item in value: 19 | del_none(item) 20 | return d 21 | 22 | def retrieve_batch_report(): 23 | 24 | try: 25 | batch_id = '16188390061150001062041064' 26 | config_obj = configuration.Configuration() 27 | client_config = config_obj.get_configuration() 28 | api_instance = BatchesApi(client_config) 29 | return_data, status, body = api_instance.get_batch_report(batch_id) 30 | 31 | print("\nAPI RESPONSE CODE : ", status) 32 | print("\nAPI RESPONSE BODY : ", body) 33 | 34 | write_log_audit(status) 35 | 36 | return return_data 37 | except Exception as e: 38 | write_log_audit(e.status) 39 | print("\nException when calling BatchesApi->get_batch_report: %s\n" % e) 40 | 41 | def write_log_audit(status): 42 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 43 | 44 | if __name__ == "__main__": 45 | retrieve_batch_report() 46 | -------------------------------------------------------------------------------- /samples/AccountUpdater/retrieve-batch-status.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | import json 4 | from importlib.machinery import SourceFileLoader 5 | from pathlib import Path 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def retrieve_batch_status(): 20 | 21 | try: 22 | batch_id = '16188390061150001062041064' 23 | config_obj = configuration.Configuration() 24 | client_config = config_obj.get_configuration() 25 | api_instance = BatchesApi(client_config) 26 | return_data, status, body = api_instance.get_batch_status(batch_id) 27 | 28 | print("\nAPI RESPONSE CODE : ", status) 29 | print("\nAPI RESPONSE BODY : ", body) 30 | 31 | write_log_audit(status) 32 | 33 | return return_data 34 | except Exception as e: 35 | write_log_audit(e.status) 36 | print("\nException when calling BatchesApi->get_batch_status: %s\n" % e) 37 | 38 | def write_log_audit(status): 39 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 40 | 41 | if __name__ == "__main__": 42 | retrieve_batch_status() 43 | -------------------------------------------------------------------------------- /samples/BinLookup/bin-lookup-with-card.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | import json 4 | from importlib.machinery import SourceFileLoader 5 | from pathlib import Path 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | elif isinstance(value, list): 18 | for item in value: 19 | del_none(item) 20 | return d 21 | 22 | def bin_lookup_with_card(): 23 | clientReferenceInformation = Binv1binlookupClientReferenceInformation( 24 | ) 25 | 26 | paymentInformationCardNumber = "4111111111111111" 27 | paymentInformationCard = Binv1binlookupPaymentInformationCard( 28 | number = paymentInformationCardNumber 29 | ) 30 | 31 | paymentInformation = Binv1binlookupPaymentInformation( 32 | card = paymentInformationCard.__dict__ 33 | ) 34 | 35 | requestObj = CreateBinLookupRequest( 36 | client_reference_information = clientReferenceInformation.__dict__, 37 | payment_information = paymentInformation.__dict__ 38 | ) 39 | 40 | 41 | requestObj = del_none(requestObj.__dict__) 42 | requestObj = json.dumps(requestObj) 43 | 44 | 45 | try: 46 | config_obj = configuration.Configuration() 47 | client_config = config_obj.get_configuration() 48 | api_instance = BinLookupApi(client_config) 49 | return_data, status, body = api_instance.get_account_info(requestObj) 50 | 51 | print("\nAPI RESPONSE CODE : ", status) 52 | print("\nAPI RESPONSE BODY : ", body) 53 | 54 | write_log_audit(status) 55 | 56 | return return_data 57 | except Exception as e: 58 | write_log_audit(e.status) 59 | print("\nException when calling BinLookupApi->get_account_info: %s\n" % e) 60 | 61 | def write_log_audit(status): 62 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 63 | 64 | if __name__ == "__main__": 65 | bin_lookup_with_card() -------------------------------------------------------------------------------- /samples/BinLookup/bin-lookup-with-healthcare-card.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | import json 4 | from importlib.machinery import SourceFileLoader 5 | from pathlib import Path 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | elif isinstance(value, list): 18 | for item in value: 19 | del_none(item) 20 | return d 21 | 22 | def bin_lookup_with_healthcare_card(): 23 | paymentInformationCardNumber = "4288900100000" 24 | paymentInformationCard = Binv1binlookupPaymentInformationCard( 25 | number = paymentInformationCardNumber 26 | ) 27 | 28 | paymentInformation = Binv1binlookupPaymentInformation( 29 | card = paymentInformationCard.__dict__ 30 | ) 31 | 32 | requestObj = CreateBinLookupRequest( 33 | payment_information = paymentInformation.__dict__ 34 | ) 35 | 36 | 37 | requestObj = del_none(requestObj.__dict__) 38 | requestObj = json.dumps(requestObj) 39 | 40 | 41 | try: 42 | config_obj = configuration.Configuration() 43 | client_config = config_obj.get_configuration() 44 | api_instance = BinLookupApi(client_config) 45 | return_data, status, body = api_instance.get_account_info(requestObj) 46 | 47 | print("\nAPI RESPONSE CODE : ", status) 48 | print("\nAPI RESPONSE BODY : ", body) 49 | 50 | write_log_audit(status) 51 | 52 | return return_data 53 | except Exception as e: 54 | write_log_audit(e.status) 55 | print("\nException when calling BinLookupApi->get_account_info: %s\n" % e) 56 | 57 | def write_log_audit(status): 58 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 59 | 60 | if __name__ == "__main__": 61 | bin_lookup_with_healthcare_card() -------------------------------------------------------------------------------- /samples/BinLookup/bin-lookup-with-network-token.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | import json 4 | from importlib.machinery import SourceFileLoader 5 | from pathlib import Path 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | elif isinstance(value, list): 18 | for item in value: 19 | del_none(item) 20 | return d 21 | 22 | def bin_lookup_with_network_token(): 23 | paymentInformationCardNumber = "4895370016313691" 24 | paymentInformationCard = Binv1binlookupPaymentInformationCard( 25 | number = paymentInformationCardNumber 26 | ) 27 | 28 | paymentInformation = Binv1binlookupPaymentInformation( 29 | card = paymentInformationCard.__dict__ 30 | ) 31 | 32 | requestObj = CreateBinLookupRequest( 33 | payment_information = paymentInformation.__dict__ 34 | ) 35 | 36 | 37 | requestObj = del_none(requestObj.__dict__) 38 | requestObj = json.dumps(requestObj) 39 | 40 | 41 | try: 42 | config_obj = configuration.Configuration() 43 | client_config = config_obj.get_configuration() 44 | api_instance = BinLookupApi(client_config) 45 | return_data, status, body = api_instance.get_account_info(requestObj) 46 | 47 | print("\nAPI RESPONSE CODE : ", status) 48 | print("\nAPI RESPONSE BODY : ", body) 49 | 50 | write_log_audit(status) 51 | 52 | return return_data 53 | except Exception as e: 54 | write_log_audit(e.status) 55 | print("\nException when calling BinLookupApi->get_account_info: %s\n" % e) 56 | 57 | def write_log_audit(status): 58 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 59 | 60 | if __name__ == "__main__": 61 | bin_lookup_with_network_token() -------------------------------------------------------------------------------- /samples/BinLookup/bin-lookup-with-tms-customer-id.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | import json 4 | from importlib.machinery import SourceFileLoader 5 | from pathlib import Path 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | elif isinstance(value, list): 18 | for item in value: 19 | del_none(item) 20 | return d 21 | 22 | def bin_lookup_with_tms_customer_id(): 23 | paymentInformationCustomerId = "E5426CFDE77F7390E053A2598D0A925D" 24 | paymentInformationCustomer = GetAllSubscriptionsResponsePaymentInformationCustomer( 25 | id = paymentInformationCustomerId 26 | ) 27 | 28 | paymentInformation = Binv1binlookupPaymentInformation( 29 | customer = paymentInformationCustomer.__dict__ 30 | ) 31 | 32 | requestObj = CreateBinLookupRequest( 33 | payment_information = paymentInformation.__dict__ 34 | ) 35 | 36 | 37 | requestObj = del_none(requestObj.__dict__) 38 | requestObj = json.dumps(requestObj) 39 | 40 | 41 | try: 42 | config_obj = configuration.Configuration() 43 | client_config = config_obj.get_configuration() 44 | api_instance = BinLookupApi(client_config) 45 | return_data, status, body = api_instance.get_account_info(requestObj) 46 | 47 | print("\nAPI RESPONSE CODE : ", status) 48 | print("\nAPI RESPONSE BODY : ", body) 49 | 50 | write_log_audit(status) 51 | 52 | return return_data 53 | except Exception as e: 54 | write_log_audit(e.status) 55 | print("\nException when calling BinLookupApi->get_account_info: %s\n" % e) 56 | 57 | def write_log_audit(status): 58 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 59 | 60 | if __name__ == "__main__": 61 | bin_lookup_with_tms_customer_id() -------------------------------------------------------------------------------- /samples/BinLookup/bin-lookup-with-tms-instrument-identifier.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | import json 4 | from importlib.machinery import SourceFileLoader 5 | from pathlib import Path 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | elif isinstance(value, list): 18 | for item in value: 19 | del_none(item) 20 | return d 21 | 22 | def bin_lookup_with_tms_instrument_identifier(): 23 | paymentInformationInstrumentIdentifierId = "7010000000016241111" 24 | paymentInformationInstrumentIdentifier = Ptsv2paymentsPaymentInformationInstrumentIdentifier( 25 | id = paymentInformationInstrumentIdentifierId 26 | ) 27 | 28 | paymentInformation = Binv1binlookupPaymentInformation( 29 | instrument_identifier = paymentInformationInstrumentIdentifier.__dict__ 30 | ) 31 | 32 | requestObj = CreateBinLookupRequest( 33 | payment_information = paymentInformation.__dict__ 34 | ) 35 | 36 | 37 | requestObj = del_none(requestObj.__dict__) 38 | requestObj = json.dumps(requestObj) 39 | 40 | 41 | try: 42 | config_obj = configuration.Configuration() 43 | client_config = config_obj.get_configuration() 44 | api_instance = BinLookupApi(client_config) 45 | return_data, status, body = api_instance.get_account_info(requestObj) 46 | 47 | print("\nAPI RESPONSE CODE : ", status) 48 | print("\nAPI RESPONSE BODY : ", body) 49 | 50 | write_log_audit(status) 51 | 52 | return return_data 53 | except Exception as e: 54 | write_log_audit(e.status) 55 | print("\nException when calling BinLookupApi->get_account_info: %s\n" % e) 56 | 57 | def write_log_audit(status): 58 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 59 | 60 | if __name__ == "__main__": 61 | bin_lookup_with_tms_instrument_identifier() -------------------------------------------------------------------------------- /samples/BinLookup/bin-lookup-with-tms-jti-transient-token.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | import json 4 | from importlib.machinery import SourceFileLoader 5 | from pathlib import Path 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | elif isinstance(value, list): 18 | for item in value: 19 | del_none(item) 20 | return d 21 | 22 | def bin_lookup_with_tms_jti_transient_token(): 23 | tokenInformationJti = "1E0WC1GO87JG1BDP0CQ8SCR1TTK86U9N98H3WH8IFM9MVEWTIYFI62F4941E7A92" 24 | tokenInformation = Binv1binlookupTokenInformation( 25 | jti = tokenInformationJti 26 | ) 27 | 28 | requestObj = CreateBinLookupRequest( 29 | token_information = tokenInformation.__dict__ 30 | ) 31 | 32 | 33 | requestObj = del_none(requestObj.__dict__) 34 | requestObj = json.dumps(requestObj) 35 | 36 | 37 | try: 38 | config_obj = configuration.Configuration() 39 | client_config = config_obj.get_configuration() 40 | api_instance = BinLookupApi(client_config) 41 | return_data, status, body = api_instance.get_account_info(requestObj) 42 | 43 | print("\nAPI RESPONSE CODE : ", status) 44 | print("\nAPI RESPONSE BODY : ", body) 45 | 46 | write_log_audit(status) 47 | 48 | return return_data 49 | except Exception as e: 50 | write_log_audit(e.status) 51 | print("\nException when calling BinLookupApi->get_account_info: %s\n" % e) 52 | 53 | def write_log_audit(status): 54 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 55 | 56 | if __name__ == "__main__": 57 | bin_lookup_with_tms_jti_transient_token() -------------------------------------------------------------------------------- /samples/BinLookup/bin-lookup-with-tms-payment-instrument.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | import json 4 | from importlib.machinery import SourceFileLoader 5 | from pathlib import Path 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | elif isinstance(value, list): 18 | for item in value: 19 | del_none(item) 20 | return d 21 | 22 | def bin_lookup_with_tms_payment_instrument(): 23 | paymentInformationPaymentInstrumentId = "E5427539180789D0E053A2598D0AF053" 24 | paymentInformationPaymentInstrument = Ptsv2paymentsPaymentInformationPaymentInstrument( 25 | id = paymentInformationPaymentInstrumentId 26 | ) 27 | 28 | paymentInformation = Binv1binlookupPaymentInformation( 29 | payment_instrument = paymentInformationPaymentInstrument.__dict__ 30 | ) 31 | 32 | requestObj = CreateBinLookupRequest( 33 | payment_information = paymentInformation.__dict__ 34 | ) 35 | 36 | 37 | requestObj = del_none(requestObj.__dict__) 38 | requestObj = json.dumps(requestObj) 39 | 40 | 41 | try: 42 | config_obj = configuration.Configuration() 43 | client_config = config_obj.get_configuration() 44 | api_instance = BinLookupApi(client_config) 45 | return_data, status, body = api_instance.get_account_info(requestObj) 46 | 47 | print("\nAPI RESPONSE CODE : ", status) 48 | print("\nAPI RESPONSE BODY : ", body) 49 | 50 | write_log_audit(status) 51 | 52 | return return_data 53 | except Exception as e: 54 | write_log_audit(e.status) 55 | print("\nException when calling BinLookupApi->get_account_info: %s\n" % e) 56 | 57 | def write_log_audit(status): 58 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 59 | 60 | if __name__ == "__main__": 61 | bin_lookup_with_tms_payment_instrument() -------------------------------------------------------------------------------- /samples/FlexMicroform/generate-capture-context-accept-check.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from CyberSource.rest import ApiException 3 | from CyberSource import GenerateCaptureContextRequest 4 | import os 5 | import json 6 | from importlib.machinery import SourceFileLoader 7 | from pathlib import Path 8 | 9 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 10 | configuration = SourceFileLoader("module.name", config_file).load_module() 11 | 12 | # To delete None values in Input Request Json body 13 | def del_none(d): 14 | for key, value in list(d.items()): 15 | if value is None: 16 | del d[key] 17 | elif isinstance(value, dict): 18 | del_none(value) 19 | return d 20 | 21 | def generate_capture_context_accept_check(): 22 | clientVersion = "v2" 23 | 24 | targetOrigins = [] 25 | targetOrigins.append("https://www.test.com") 26 | allowedPaymentTypes = [] 27 | allowedPaymentTypes.append("CHECK") 28 | requestObj = GenerateCaptureContextRequest( 29 | client_version = clientVersion, 30 | target_origins = targetOrigins, 31 | allowed_payment_types=allowedPaymentTypes 32 | ) 33 | 34 | 35 | requestObj = del_none(requestObj.__dict__) 36 | requestObj = json.dumps(requestObj) 37 | 38 | 39 | try: 40 | config_obj = configuration.Configuration() 41 | client_config = config_obj.get_configuration() 42 | api_instance = MicroformIntegrationApi(client_config) 43 | return_data, status, body = api_instance.generate_capture_context(requestObj) 44 | 45 | print("\nAPI RESPONSE CODE : ", status) 46 | print("\nAPI RESPONSE BODY : ", body) 47 | 48 | write_log_audit(status) 49 | 50 | return return_data 51 | except Exception as e: 52 | write_log_audit(e.status) 53 | print("\nException when calling MicroformIntegrationApi->generate_capture_context: %s\n" % e) 54 | 55 | def write_log_audit(status): 56 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 57 | 58 | if __name__ == "__main__": 59 | generate_capture_context_accept_check() -------------------------------------------------------------------------------- /samples/Invoicing/InvoiceSettings/get-invoice-settings.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def get_invoice_settings(): 20 | 21 | try: 22 | config_obj = configuration.Configuration() 23 | client_config = config_obj.get_configuration() 24 | api_instance = InvoiceSettingsApi(client_config) 25 | return_data, status, body = api_instance.get_invoice_settings() 26 | 27 | print("\nAPI RESPONSE CODE : ", status) 28 | print("\nAPI RESPONSE BODY : ", body) 29 | 30 | write_log_audit(status) 31 | return return_data 32 | except Exception as e: 33 | write_log_audit(e.status if hasattr(e, 'status') else 999) 34 | print("\nException when calling InvoiceSettingsApi->get_invoice_settings: %s\n" % e) 35 | 36 | def write_log_audit(status): 37 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 38 | 39 | if __name__ == "__main__": 40 | get_invoice_settings() 41 | -------------------------------------------------------------------------------- /samples/Invoicing/Invoices/cancel-invoice.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 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 | create_invoice_path = os.path.join(os.getcwd(), "samples", "Invoicing", "Invoices", "create-draft-invoice.py") 10 | create_invoice = SourceFileLoader("module.name", create_invoice_path).load_module() 11 | 12 | 13 | def cancel_invoice(): 14 | try: 15 | invoice_id = create_invoice.create_draft_invoice().id 16 | config_obj = configuration.Configuration() 17 | client_config = config_obj.get_configuration() 18 | api_instance = InvoicesApi(client_config) 19 | return_data, status, body = api_instance.perform_cancel_action(invoice_id) 20 | 21 | print("\nAPI RESPONSE CODE : ", status) 22 | print("\nAPI RESPONSE BODY : ", body) 23 | 24 | write_log_audit(status) 25 | return return_data 26 | except Exception as e: 27 | write_log_audit(e.status if hasattr(e, 'status') else 999) 28 | print("\nException when calling InvoicesApi->perform_cancel_action: %s\n" % e) 29 | 30 | 31 | def write_log_audit(status): 32 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 33 | 34 | 35 | if __name__ == "__main__": 36 | cancel_invoice() 37 | -------------------------------------------------------------------------------- /samples/Invoicing/Invoices/get-invoice-details.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | create_invoice_path = os.path.join(os.getcwd(), "samples", "Invoicing", "Invoices", "create-draft-invoice.py") 11 | create_invoice = SourceFileLoader("module.name", create_invoice_path).load_module() 12 | 13 | # To delete None values in Input Request Json body 14 | def del_none(d): 15 | for key, value in list(d.items()): 16 | if value is None: 17 | del d[key] 18 | elif isinstance(value, dict): 19 | del_none(value) 20 | return d 21 | 22 | def get_invoice_details(): 23 | try: 24 | id = create_invoice.create_draft_invoice().id 25 | config_obj = configuration.Configuration() 26 | client_config = config_obj.get_configuration() 27 | api_instance = InvoicesApi(client_config) 28 | return_data, status, body = api_instance.get_invoice(id) 29 | 30 | print("\nAPI RESPONSE CODE : ", status) 31 | print("\nAPI RESPONSE BODY : ", body) 32 | 33 | write_log_audit(status) 34 | return return_data 35 | except Exception as e: 36 | write_log_audit(e.status if hasattr(e, 'status') else 999) 37 | print("\nException when calling InvoicesApi->get_invoice: %s\n" % e) 38 | 39 | def write_log_audit(status): 40 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 41 | 42 | if __name__ == "__main__": 43 | get_invoice_details() 44 | -------------------------------------------------------------------------------- /samples/Invoicing/Invoices/get-list-of-invoices.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 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 | 10 | def get_list_of_invoices(): 11 | try: 12 | offset = 0 13 | limit = 10 14 | status = None 15 | 16 | config_obj = configuration.Configuration() 17 | client_config = config_obj.get_configuration() 18 | api_instance = InvoicesApi(client_config) 19 | return_data, status, body = api_instance.get_all_invoices(offset, limit, status=status) 20 | 21 | print("\nAPI RESPONSE CODE : ", status) 22 | print("\nAPI RESPONSE BODY : ", body) 23 | 24 | write_log_audit(status) 25 | return return_data 26 | except Exception as e: 27 | write_log_audit(e.status if hasattr(e, 'status') else 999) 28 | print("\nException when calling InvoicesApi->get_all_invoices: %s\n" % e) 29 | 30 | 31 | def write_log_audit(status): 32 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 33 | 34 | 35 | if __name__ == "__main__": 36 | get_list_of_invoices() 37 | -------------------------------------------------------------------------------- /samples/Invoicing/Invoices/send-invoice.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 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 | create_invoice_path = os.path.join(os.getcwd(), "samples", "Invoicing", "Invoices", "create-draft-invoice.py") 10 | create_invoice = SourceFileLoader("module.name", create_invoice_path).load_module() 11 | 12 | 13 | def send_invoice(): 14 | try: 15 | invoice_id = create_invoice.create_draft_invoice().id 16 | config_obj = configuration.Configuration() 17 | client_config = config_obj.get_configuration() 18 | api_instance = InvoicesApi(client_config) 19 | return_data, status, body = api_instance.perform_send_action(invoice_id) 20 | 21 | print("\nAPI RESPONSE CODE : ", status) 22 | print("\nAPI RESPONSE BODY : ", body) 23 | 24 | write_log_audit(status) 25 | return return_data 26 | except Exception as e: 27 | write_log_audit(e.status if hasattr(e, 'status') else 999) 28 | print("\nException when calling InvoicesApi->perform_send_action: %s\n" % e) 29 | 30 | 31 | def write_log_audit(status): 32 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 33 | 34 | 35 | if __name__ == "__main__": 36 | send_invoice() 37 | -------------------------------------------------------------------------------- /samples/PayerAuthentication/setup-completion-with-flex-transient-token.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def setup_completion_with_flex_transient_token(): 20 | clientReferenceInformationCode = "cybs_test" 21 | clientReferenceInformation = Riskv1authenticationsetupsClientReferenceInformation( 22 | code = clientReferenceInformationCode 23 | ) 24 | 25 | tokenInformationTransientToken = "1D5ZX4HMOV20FKEBE3IO240JWYJ0NJ90B4V9XQ6SCK4BDN0W96E65E2A39052056" 26 | tokenInformation = Riskv1authenticationsetupsTokenInformation( 27 | transient_token = tokenInformationTransientToken 28 | ) 29 | 30 | requestObj = PayerAuthSetupRequest( 31 | client_reference_information = clientReferenceInformation.__dict__, 32 | token_information = tokenInformation.__dict__ 33 | ) 34 | 35 | 36 | requestObj = del_none(requestObj.__dict__) 37 | requestObj = json.dumps(requestObj) 38 | 39 | 40 | try: 41 | config_obj = configuration.Configuration() 42 | client_config = config_obj.get_configuration() 43 | api_instance = PayerAuthenticationApi(client_config) 44 | return_data, status, body = api_instance.payer_auth_setup(requestObj) 45 | 46 | print("\nAPI RESPONSE CODE : ", status) 47 | print("\nAPI RESPONSE BODY : ", body) 48 | 49 | write_log_audit(status) 50 | return return_data 51 | except Exception as e: 52 | write_log_audit(e.status if hasattr(e, 'status') else 999) 53 | print("\nException when calling PayerAuthenticationApi->payer_auth_setup: %s\n" % e) 54 | 55 | def write_log_audit(status): 56 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 57 | 58 | if __name__ == "__main__": 59 | setup_completion_with_flex_transient_token() 60 | -------------------------------------------------------------------------------- /samples/PayerAuthentication/setup-completion-with-secure-storage-token.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def setup_completion_with_secure_storage_token(): 20 | clientReferenceInformationCode = "cybs_test" 21 | clientReferenceInformation = Riskv1authenticationsetupsClientReferenceInformation( 22 | code = clientReferenceInformationCode 23 | ) 24 | 25 | paymentInformationCustomerCustomerId = "5795045921830181636348" 26 | paymentInformationCustomer = Riskv1authenticationsetupsPaymentInformationCustomer( 27 | customer_id = paymentInformationCustomerCustomerId 28 | ) 29 | 30 | paymentInformation = Riskv1authenticationsetupsPaymentInformation( 31 | customer = paymentInformationCustomer.__dict__ 32 | ) 33 | 34 | requestObj = PayerAuthSetupRequest( 35 | client_reference_information = clientReferenceInformation.__dict__, 36 | payment_information = paymentInformation.__dict__ 37 | ) 38 | 39 | 40 | requestObj = del_none(requestObj.__dict__) 41 | requestObj = json.dumps(requestObj) 42 | 43 | 44 | try: 45 | config_obj = configuration.Configuration() 46 | client_config = config_obj.get_configuration() 47 | api_instance = PayerAuthenticationApi(client_config) 48 | return_data, status, body = api_instance.payer_auth_setup(requestObj) 49 | 50 | print("\nAPI RESPONSE CODE : ", status) 51 | print("\nAPI RESPONSE BODY : ", body) 52 | 53 | write_log_audit(status) 54 | return return_data 55 | except Exception as e: 56 | write_log_audit(e.status if hasattr(e, 'status') else 999) 57 | print("\nException when calling PayerAuthenticationApi->payer_auth_setup: %s\n" % e) 58 | 59 | def write_log_audit(status): 60 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 61 | 62 | if __name__ == "__main__": 63 | setup_completion_with_secure_storage_token() 64 | -------------------------------------------------------------------------------- /samples/PayerAuthentication/setup-completion-with-tms-token.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def setup_completion_with_tms_token(): 20 | clientReferenceInformationCode = "cybs_test" 21 | clientReferenceInformation = Riskv1authenticationsetupsClientReferenceInformation( 22 | code = clientReferenceInformationCode 23 | ) 24 | 25 | paymentInformationCustomerCustomerId = "AB695DA801DD1BB6E05341588E0A3BDC" 26 | paymentInformationCustomer = Riskv1authenticationsetupsPaymentInformationCustomer( 27 | customer_id = paymentInformationCustomerCustomerId 28 | ) 29 | 30 | paymentInformation = Riskv1authenticationsetupsPaymentInformation( 31 | customer = paymentInformationCustomer.__dict__ 32 | ) 33 | 34 | requestObj = PayerAuthSetupRequest( 35 | client_reference_information = clientReferenceInformation.__dict__, 36 | payment_information = paymentInformation.__dict__ 37 | ) 38 | 39 | 40 | requestObj = del_none(requestObj.__dict__) 41 | requestObj = json.dumps(requestObj) 42 | 43 | 44 | try: 45 | config_obj = configuration.Configuration() 46 | client_config = config_obj.get_configuration() 47 | api_instance = PayerAuthenticationApi(client_config) 48 | return_data, status, body = api_instance.payer_auth_setup(requestObj) 49 | 50 | print("\nAPI RESPONSE CODE : ", status) 51 | print("\nAPI RESPONSE BODY : ", body) 52 | 53 | write_log_audit(status) 54 | return return_data 55 | except Exception as e: 56 | write_log_audit(e.status if hasattr(e, 'status') else 999) 57 | print("\nException when calling PayerAuthenticationApi->payer_auth_setup: %s\n" % e) 58 | 59 | def write_log_audit(status): 60 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 61 | 62 | if __name__ == "__main__": 63 | setup_completion_with_tms_token() 64 | -------------------------------------------------------------------------------- /samples/Payments/Void/timeout-void.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | authorization_path = os.path.join(os.getcwd(), "samples", "Payments", "Payments", "authorization-capture-for-timeout-void-flow.py") 11 | authorization = SourceFileLoader("module.name", authorization_path).load_module() 12 | 13 | # To delete None values in Input Request Json body 14 | def del_none(d): 15 | for key, value in list(d.items()): 16 | if value is None: 17 | del d[key] 18 | elif isinstance(value, dict): 19 | del_none(value) 20 | return d 21 | 22 | def timeout_void(): 23 | # id = authorization.authorization_capture_for_timeout_void_flow().id 24 | timeoutVoidTransactionId = authorization.timeoutVoidTransactionId 25 | 26 | clientReferenceInformationCode = "TC50171_3" 27 | clientReferenceInformationTransactionId = timeoutVoidTransactionId 28 | clientReferenceInformation = Ptsv2paymentsClientReferenceInformation( 29 | code = clientReferenceInformationCode, 30 | transaction_id = clientReferenceInformationTransactionId 31 | ) 32 | 33 | requestObj = MitVoidRequest( 34 | client_reference_information = clientReferenceInformation.__dict__ 35 | ) 36 | 37 | 38 | requestObj = del_none(requestObj.__dict__) 39 | requestObj = json.dumps(requestObj) 40 | 41 | 42 | try: 43 | config_obj = configuration.Configuration() 44 | client_config = config_obj.get_configuration() 45 | api_instance = VoidApi(client_config) 46 | return_data, status, body = api_instance.mit_void(requestObj) 47 | 48 | print("\nAPI RESPONSE CODE : ", status) 49 | print("\nAPI RESPONSE BODY : ", body) 50 | 51 | write_log_audit(status) 52 | return return_data 53 | except Exception as e: 54 | write_log_audit(e.status if hasattr(e, 'status') else 999) 55 | print("\nException when calling VoidApi->mit_void: %s\n" % e) 56 | 57 | def write_log_audit(status): 58 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 59 | 60 | if __name__ == "__main__": 61 | timeout_void() 62 | -------------------------------------------------------------------------------- /samples/Payments/Void/void-capture.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | capture_payment_path = os.path.join(os.getcwd(), "samples", "Payments", "Capture", "capture-payment.py") 11 | capture_payment = SourceFileLoader("module.name", capture_payment_path).load_module() 12 | 13 | # To delete None values in Input Request Json body 14 | def del_none(d): 15 | for key, value in list(d.items()): 16 | if value is None: 17 | del d[key] 18 | elif isinstance(value, dict): 19 | del_none(value) 20 | return d 21 | 22 | def void_capture(): 23 | 24 | 25 | clientReferenceInformationCode = "test_void" 26 | clientReferenceInformation = Ptsv2paymentsidreversalsClientReferenceInformation( 27 | code = clientReferenceInformationCode 28 | ) 29 | 30 | requestObj = VoidCaptureRequest( 31 | client_reference_information = clientReferenceInformation.__dict__ 32 | ) 33 | 34 | 35 | requestObj = del_none(requestObj.__dict__) 36 | requestObj = json.dumps(requestObj) 37 | 38 | 39 | try: 40 | api_capture_response = capture_payment.capture_payment() 41 | id = api_capture_response.id 42 | config_obj = configuration.Configuration() 43 | client_config = config_obj.get_configuration() 44 | api_instance = VoidApi(client_config) 45 | return_data, status, body = api_instance.void_capture(requestObj, id) 46 | 47 | print("\nAPI RESPONSE CODE : ", status) 48 | print("\nAPI RESPONSE BODY : ", body) 49 | 50 | write_log_audit(status) 51 | return return_data 52 | except Exception as e: 53 | write_log_audit(e.status if hasattr(e, 'status') else 999) 54 | print("\nException when calling VoidApi->void_capture: %s\n" % e) 55 | 56 | def write_log_audit(status): 57 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 58 | 59 | if __name__ == "__main__": 60 | void_capture() 61 | -------------------------------------------------------------------------------- /samples/Payments/Void/void-credit.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | credit_payment_path = os.path.join(os.getcwd(), "samples", "Payments", "Credit", "credit.py") 11 | credit_payment = SourceFileLoader("module.name", credit_payment_path).load_module() 12 | 13 | # To delete None values in Input Request Json body 14 | def del_none(d): 15 | for key, value in list(d.items()): 16 | if value is None: 17 | del d[key] 18 | elif isinstance(value, dict): 19 | del_none(value) 20 | return d 21 | 22 | def void_credit(): 23 | 24 | 25 | clientReferenceInformationCode = "test_void" 26 | clientReferenceInformation = Ptsv2paymentsidreversalsClientReferenceInformation( 27 | code = clientReferenceInformationCode 28 | ) 29 | 30 | requestObj = VoidCreditRequest( 31 | client_reference_information = clientReferenceInformation.__dict__ 32 | ) 33 | 34 | 35 | requestObj = del_none(requestObj.__dict__) 36 | requestObj = json.dumps(requestObj) 37 | 38 | 39 | try: 40 | api_credit_response = credit_payment.credit() 41 | id = api_credit_response.id 42 | config_obj = configuration.Configuration() 43 | client_config = config_obj.get_configuration() 44 | api_instance = VoidApi(client_config) 45 | return_data, status, body = api_instance.void_credit(requestObj, id) 46 | 47 | print("\nAPI RESPONSE CODE : ", status) 48 | print("\nAPI RESPONSE BODY : ", body) 49 | 50 | write_log_audit(status) 51 | return return_data 52 | except Exception as e: 53 | write_log_audit(e.status if hasattr(e, 'status') else 999) 54 | print("\nException when calling VoidApi->void_credit: %s\n" % e) 55 | 56 | def write_log_audit(status): 57 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 58 | 59 | if __name__ == "__main__": 60 | void_credit() 61 | -------------------------------------------------------------------------------- /samples/Payments/Void/void-payment.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | process_payment_path = os.path.join(os.getcwd(), "samples", "Payments", "Payments", "simple-authorizationinternet.py") 11 | process_payment = SourceFileLoader("module.name", process_payment_path).load_module() 12 | 13 | # To delete None values in Input Request Json body 14 | def del_none(d): 15 | for key, value in list(d.items()): 16 | if value is None: 17 | del d[key] 18 | elif isinstance(value, dict): 19 | del_none(value) 20 | return d 21 | 22 | def void_payment(): 23 | 24 | 25 | clientReferenceInformationCode = "test_void" 26 | clientReferenceInformation = Ptsv2paymentsidreversalsClientReferenceInformation( 27 | code = clientReferenceInformationCode 28 | ) 29 | 30 | requestObj = VoidPaymentRequest( 31 | client_reference_information = clientReferenceInformation.__dict__ 32 | ) 33 | 34 | 35 | requestObj = del_none(requestObj.__dict__) 36 | requestObj = json.dumps(requestObj) 37 | 38 | 39 | try: 40 | api_payment_response = process_payment.simple_authorizationinternet(False) 41 | id = api_payment_response.id 42 | config_obj = configuration.Configuration() 43 | client_config = config_obj.get_configuration() 44 | api_instance = VoidApi(client_config) 45 | return_data, status, body = api_instance.void_payment(requestObj, id) 46 | 47 | print("\nAPI RESPONSE CODE : ", status) 48 | print("\nAPI RESPONSE BODY : ", body) 49 | 50 | write_log_audit(status) 51 | return return_data 52 | except Exception as e: 53 | write_log_audit(e.status if hasattr(e, 'status') else 999) 54 | print("\nException when calling VoidApi->void_payment: %s\n" % e) 55 | 56 | def write_log_audit(status): 57 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 58 | 59 | if __name__ == "__main__": 60 | void_payment() 61 | -------------------------------------------------------------------------------- /samples/Payments/Void/void-refund.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | refund_payment_path = os.path.join(os.getcwd(), "samples", "Payments", "Refund", "refund-payment.py") 11 | refund_payment = SourceFileLoader("module.name", refund_payment_path).load_module() 12 | 13 | # To delete None values in Input Request Json body 14 | def del_none(d): 15 | for key, value in list(d.items()): 16 | if value is None: 17 | del d[key] 18 | elif isinstance(value, dict): 19 | del_none(value) 20 | return d 21 | 22 | def void_refund(): 23 | 24 | 25 | clientReferenceInformationCode = "test_void" 26 | clientReferenceInformation = Ptsv2paymentsidreversalsClientReferenceInformation( 27 | code = clientReferenceInformationCode 28 | ) 29 | 30 | requestObj = VoidRefundRequest( 31 | client_reference_information = clientReferenceInformation.__dict__ 32 | ) 33 | 34 | 35 | requestObj = del_none(requestObj.__dict__) 36 | requestObj = json.dumps(requestObj) 37 | 38 | 39 | try: 40 | api_refund_response = refund_payment.refund_payment() 41 | id = api_refund_response.id 42 | config_obj = configuration.Configuration() 43 | client_config = config_obj.get_configuration() 44 | api_instance = VoidApi(client_config) 45 | return_data, status, body = api_instance.void_refund(requestObj, id) 46 | 47 | print("\nAPI RESPONSE CODE : ", status) 48 | print("\nAPI RESPONSE BODY : ", body) 49 | 50 | write_log_audit(status) 51 | return return_data 52 | except Exception as e: 53 | write_log_audit(e.status if hasattr(e, 'status') else 999) 54 | print("\nException when calling VoidApi->void_refund: %s\n" % e) 55 | 56 | def write_log_audit(status): 57 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 58 | 59 | if __name__ == "__main__": 60 | void_refund() 61 | -------------------------------------------------------------------------------- /samples/RecurringBillingSubscriptions/Plans/activate-plan.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | from importlib.machinery import SourceFileLoader 4 | from pathlib import Path 5 | 6 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 7 | configuration = SourceFileLoader("module.name", config_file).load_module() 8 | 9 | create_plan_path = os.path.join(os.getcwd(), "samples", "RecurringBillingSubscriptions", "Plans", "create-plan.py") 10 | create_new_plan = SourceFileLoader("module.name", create_plan_path).load_module() 11 | 12 | 13 | def activate_plan(): 14 | try: 15 | create_plan_response = create_new_plan.create_plan() 16 | plan_id = create_plan_response.id 17 | config_obj = configuration.Configuration() 18 | client_config = config_obj.get_configuration() 19 | api_instance = PlansApi(client_config) 20 | return_data, status, body = api_instance.activate_plan(plan_id) 21 | 22 | print("\nAPI RESPONSE CODE : ", status) 23 | print("\nAPI RESPONSE BODY : ", body) 24 | 25 | write_log_audit(status) 26 | 27 | return return_data 28 | except Exception as e: 29 | write_log_audit(e.status if hasattr(e, 'status') else 999) 30 | print("\nException when calling PlansApi->activate_plan: %s\n" % e) 31 | 32 | 33 | def write_log_audit(status): 34 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 35 | 36 | 37 | if __name__ == "__main__": 38 | activate_plan() 39 | -------------------------------------------------------------------------------- /samples/RecurringBillingSubscriptions/Plans/deactivate-plan.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | from importlib.machinery import SourceFileLoader 4 | from pathlib import Path 5 | 6 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 7 | configuration = SourceFileLoader("module.name", config_file).load_module() 8 | 9 | activate_plan_path = os.path.join(os.getcwd(), "samples", "RecurringBillingSubscriptions", "Plans", "activate-plan.py") 10 | activate_plan = SourceFileLoader("module.name", activate_plan_path).load_module() 11 | 12 | 13 | def deactivate_plan(): 14 | try: 15 | activate_plan_response = activate_plan.activate_plan() 16 | plan_id = activate_plan_response.id 17 | config_obj = configuration.Configuration() 18 | client_config = config_obj.get_configuration() 19 | api_instance = PlansApi(client_config) 20 | return_data, status, body = api_instance.deactivate_plan(plan_id) 21 | 22 | print("\nAPI RESPONSE CODE : ", status) 23 | print("\nAPI RESPONSE BODY : ", body) 24 | 25 | write_log_audit(status) 26 | 27 | return return_data 28 | except Exception as e: 29 | write_log_audit(e.status if hasattr(e, 'status') else 999) 30 | print("\nException when calling PlansApi->deactivate_plan: %s\n" % e) 31 | 32 | 33 | def write_log_audit(status): 34 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 35 | 36 | 37 | if __name__ == "__main__": 38 | deactivate_plan() 39 | -------------------------------------------------------------------------------- /samples/RecurringBillingSubscriptions/Plans/delete-plan.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | import json 4 | from importlib.machinery import SourceFileLoader 5 | from pathlib import Path 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | create_plan_path = os.path.join(os.getcwd(), "samples", "RecurringBillingSubscriptions", "Plans", "create-plan.py") 11 | create_plan = SourceFileLoader("module.name", create_plan_path).load_module() 12 | 13 | # To delete None values in Input Request Json body 14 | def del_none(d): 15 | for key, value in list(d.items()): 16 | if value is None: 17 | del d[key] 18 | elif isinstance(value, dict): 19 | del_none(value) 20 | return d 21 | 22 | def delete_plan(): 23 | 24 | try: 25 | create_plan_response = create_plan.create_plan() 26 | id = create_plan_response.id 27 | config_obj = configuration.Configuration() 28 | client_config = config_obj.get_configuration() 29 | api_instance = PlansApi(client_config) 30 | return_data, status, body = api_instance.delete_plan(id) 31 | 32 | print("\nAPI RESPONSE CODE : ", status) 33 | print("\nAPI RESPONSE BODY : ", body) 34 | 35 | write_log_audit(status) 36 | 37 | return return_data 38 | except Exception as e: 39 | write_log_audit(e.status) 40 | print("\nException when calling PlansApi->delete_plan: %s\n" % e) 41 | 42 | def write_log_audit(status): 43 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 44 | 45 | if __name__ == "__main__": 46 | delete_plan() -------------------------------------------------------------------------------- /samples/RecurringBillingSubscriptions/Plans/get-list-of-plans.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | from importlib.machinery import SourceFileLoader 4 | from pathlib import Path 5 | 6 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 7 | configuration = SourceFileLoader("module.name", config_file).load_module() 8 | 9 | 10 | def get_list_of_plans(): 11 | try: 12 | offset = 0 13 | limit = 10 14 | code = None 15 | status = None 16 | name = None 17 | 18 | config_obj = configuration.Configuration() 19 | client_config = config_obj.get_configuration() 20 | api_instance = PlansApi(client_config) 21 | return_data, status, body = api_instance.get_plans(offset=offset, limit=limit) 22 | 23 | print("\nAPI RESPONSE CODE : ", status) 24 | print("\nAPI RESPONSE BODY : ", body) 25 | 26 | write_log_audit(status) 27 | 28 | return return_data 29 | except Exception as e: 30 | write_log_audit(e.status) 31 | print("\nException when calling PlansApi->get_list_of_plans: %s\n" % e) 32 | 33 | 34 | def write_log_audit(status): 35 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 36 | 37 | 38 | if __name__ == "__main__": 39 | get_list_of_plans() 40 | -------------------------------------------------------------------------------- /samples/RecurringBillingSubscriptions/Plans/get-plan-code.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | from importlib.machinery import SourceFileLoader 4 | from pathlib import Path 5 | 6 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 7 | configuration = SourceFileLoader("module.name", config_file).load_module() 8 | 9 | 10 | def get_plan_code(): 11 | try: 12 | config_obj = configuration.Configuration() 13 | client_config = config_obj.get_configuration() 14 | api_instance = PlansApi(client_config) 15 | return_data, status, body = api_instance.get_plan_code() 16 | 17 | print("\nAPI RESPONSE CODE : ", status) 18 | print("\nAPI RESPONSE BODY : ", body) 19 | 20 | write_log_audit(status) 21 | 22 | return return_data 23 | except Exception as e: 24 | write_log_audit(e.status) 25 | print("\nException when calling PlansApi->get_plan_code: %s\n" % e) 26 | 27 | 28 | def write_log_audit(status): 29 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 30 | 31 | 32 | if __name__ == "__main__": 33 | get_plan_code() 34 | -------------------------------------------------------------------------------- /samples/RecurringBillingSubscriptions/Plans/get-plan.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | import json 4 | from importlib.machinery import SourceFileLoader 5 | from pathlib import Path 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | create_plan_path = os.path.join(os.getcwd(), "samples", "RecurringBillingSubscriptions", "Plans", "create-plan.py") 11 | create_plan = SourceFileLoader("module.name", create_plan_path).load_module() 12 | 13 | # To delete None values in Input Request Json body 14 | def del_none(d): 15 | for key, value in list(d.items()): 16 | if value is None: 17 | del d[key] 18 | elif isinstance(value, dict): 19 | del_none(value) 20 | return d 21 | 22 | def get_plan(): 23 | 24 | try: 25 | create_plan_response = create_plan.create_plan() 26 | plan_id = create_plan_response.id 27 | config_obj = configuration.Configuration() 28 | client_config = config_obj.get_configuration() 29 | api_instance = PlansApi(client_config) 30 | return_data, status, body = api_instance.get_plan(plan_id) 31 | 32 | print("\nAPI RESPONSE CODE : ", status) 33 | print("\nAPI RESPONSE BODY : ", body) 34 | 35 | write_log_audit(status) 36 | 37 | return return_data 38 | except Exception as e: 39 | write_log_audit(e.status if hasattr(e, 'status') else 999) 40 | print("\nException when calling PlansApi->get_plan: %s\n" % e) 41 | 42 | def write_log_audit(status): 43 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 44 | 45 | if __name__ == "__main__": 46 | get_plan() -------------------------------------------------------------------------------- /samples/RecurringBillingSubscriptions/Subscriptions/activate-subscription.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | from importlib.machinery import SourceFileLoader 4 | from pathlib import Path 5 | 6 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 7 | configuration = SourceFileLoader("module.name", config_file).load_module() 8 | 9 | cancel_subscription_path = os.path.join(os.getcwd(), "samples", "RecurringBillingSubscriptions", "Subscriptions", "cancel-subscription.py") 10 | cancel_subscription_module = SourceFileLoader("module.name", cancel_subscription_path).load_module() 11 | 12 | 13 | def activate_subscription(): 14 | try: 15 | cancelled_subscription_id = cancel_subscription_module.cancel_subscription().id 16 | config_obj = configuration.Configuration() 17 | client_config = config_obj.get_configuration() 18 | api_instance = SubscriptionsApi(client_config) 19 | return_data, status, body = api_instance.activate_subscription(cancelled_subscription_id) 20 | 21 | print("\nAPI RESPONSE CODE : ", status) 22 | print("\nAPI RESPONSE BODY : ", body) 23 | 24 | write_log_audit(status) 25 | 26 | return return_data 27 | except Exception as e: 28 | write_log_audit(e.status if hasattr(e, 'status') else 999) 29 | print("\nException when calling SubscriptionsApi->activate_subscription: %s\n" % e) 30 | 31 | def write_log_audit(status): 32 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 33 | 34 | if __name__ == "__main__": 35 | activate_subscription() 36 | -------------------------------------------------------------------------------- /samples/RecurringBillingSubscriptions/Subscriptions/cancel-subscription.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | from importlib.machinery import SourceFileLoader 4 | from pathlib import Path 5 | 6 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 7 | configuration = SourceFileLoader("module.name", config_file).load_module() 8 | 9 | create_subscription_path = os.path.join(os.getcwd(), "samples", "RecurringBillingSubscriptions", "Subscriptions", "create-subscription.py") 10 | create_subscription_module = SourceFileLoader("module.name", create_subscription_path).load_module() 11 | 12 | 13 | def cancel_subscription(): 14 | try: 15 | created_subscription_id = create_subscription_module.create_subscription().id 16 | config_obj = configuration.Configuration() 17 | client_config = config_obj.get_configuration() 18 | api_instance = SubscriptionsApi(client_config) 19 | return_data, status, body = api_instance.cancel_subscription(created_subscription_id) 20 | 21 | print("\nAPI RESPONSE CODE : ", status) 22 | print("\nAPI RESPONSE BODY : ", body) 23 | 24 | write_log_audit(status) 25 | 26 | return return_data 27 | except Exception as e: 28 | write_log_audit(e.status if hasattr(e, 'status') else 999) 29 | print("\nException when calling SubscriptionsApi->cancel_subscription: %s\n" % e) 30 | 31 | def write_log_audit(status): 32 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 33 | 34 | if __name__ == "__main__": 35 | cancel_subscription() 36 | -------------------------------------------------------------------------------- /samples/RecurringBillingSubscriptions/Subscriptions/get-list-of-subscriptions.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | from importlib.machinery import SourceFileLoader 4 | from pathlib import Path 5 | 6 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 7 | configuration = SourceFileLoader("module.name", config_file).load_module() 8 | 9 | def get_list_of_subscriptions(): 10 | offset = 0 11 | limit = 10 12 | code = None 13 | status = None 14 | 15 | try: 16 | config_obj = configuration.Configuration() 17 | client_config = config_obj.get_configuration() 18 | api_instance = SubscriptionsApi(client_config) 19 | return_data, status, body = api_instance.get_all_subscriptions(offset=offset, limit=limit) 20 | 21 | print("\nAPI RESPONSE CODE : ", status) 22 | print("\nAPI RESPONSE BODY : ", body) 23 | 24 | write_log_audit(status) 25 | 26 | return return_data 27 | except Exception as e: 28 | write_log_audit(e.status if hasattr(e, 'status') else 999) 29 | print("\nException when calling SubscriptionsApi->get_all_subscriptions: %s\n" % e) 30 | 31 | def write_log_audit(status): 32 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 33 | 34 | if __name__ == "__main__": 35 | get_list_of_subscriptions() 36 | -------------------------------------------------------------------------------- /samples/RecurringBillingSubscriptions/Subscriptions/get-subscription-code.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | from importlib.machinery import SourceFileLoader 4 | from pathlib import Path 5 | 6 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 7 | configuration = SourceFileLoader("module.name", config_file).load_module() 8 | 9 | 10 | def get_subscription_code(): 11 | try: 12 | config_obj = configuration.Configuration() 13 | client_config = config_obj.get_configuration() 14 | api_instance = SubscriptionsApi(client_config) 15 | return_data, status, body = api_instance.get_subscription_code() 16 | 17 | print("\nAPI RESPONSE CODE : ", status) 18 | print("\nAPI RESPONSE BODY : ", body) 19 | 20 | write_log_audit(status) 21 | 22 | return return_data 23 | except Exception as e: 24 | write_log_audit(e.status if hasattr(e, 'status') else 999) 25 | print("\nException when calling SubscriptionsApi->get_subscription_code: %s\n" % e) 26 | 27 | def write_log_audit(status): 28 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 29 | 30 | if __name__ == "__main__": 31 | get_subscription_code() 32 | -------------------------------------------------------------------------------- /samples/RecurringBillingSubscriptions/Subscriptions/get-subscription.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | import json 4 | from importlib.machinery import SourceFileLoader 5 | from pathlib import Path 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | create_subscription_path = os.path.join(os.getcwd(), "samples", "RecurringBillingSubscriptions", "Subscriptions", "create-subscription.py") 11 | create_subscription = SourceFileLoader("module.name", create_subscription_path).load_module() 12 | 13 | # To delete None values in Input Request Json body 14 | def del_none(d): 15 | for key, value in list(d.items()): 16 | if value is None: 17 | del d[key] 18 | elif isinstance(value, dict): 19 | del_none(value) 20 | return d 21 | 22 | def get_subscription(): 23 | 24 | try: 25 | # create_subscription_response = create_subscription.create_subscription() 26 | # The following `id` field is hardcoded because the above call will not allow duplicate requests. 27 | id = "6971805775636334604953" # create_subscription_response.id 28 | config_obj = configuration.Configuration() 29 | client_config = config_obj.get_configuration() 30 | api_instance = SubscriptionsApi(client_config) 31 | return_data, status, body = api_instance.get_subscription(id) 32 | 33 | print("\nAPI RESPONSE CODE : ", status) 34 | print("\nAPI RESPONSE BODY : ", body) 35 | 36 | write_log_audit(status) 37 | 38 | return return_data 39 | except Exception as e: 40 | write_log_audit(e.status) 41 | print("\nException when calling SubscriptionsApi->get_subscription: %s\n" % e) 42 | 43 | def write_log_audit(status): 44 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 45 | 46 | if __name__ == "__main__": 47 | get_subscription() -------------------------------------------------------------------------------- /samples/RecurringBillingSubscriptions/Subscriptions/suspend-subscription.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | from importlib.machinery import SourceFileLoader 4 | from pathlib import Path 5 | 6 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 7 | configuration = SourceFileLoader("module.name", config_file).load_module() 8 | 9 | create_subscription_path = os.path.join(os.getcwd(), "samples", "RecurringBillingSubscriptions", "Subscriptions", "create-subscription.py") 10 | create_subscription_module = SourceFileLoader("module.name", create_subscription_path).load_module() 11 | 12 | 13 | def suspend_subscription(): 14 | try: 15 | created_subscription_id = create_subscription_module.create_subscription().id 16 | config_obj = configuration.Configuration() 17 | client_config = config_obj.get_configuration() 18 | api_instance = SubscriptionsApi(client_config) 19 | return_data, status, body = api_instance.suspend_subscription(created_subscription_id) 20 | 21 | print("\nAPI RESPONSE CODE : ", status) 22 | print("\nAPI RESPONSE BODY : ", body) 23 | 24 | write_log_audit(status) 25 | 26 | return return_data 27 | except Exception as e: 28 | write_log_audit(e.status if hasattr(e, 'status') else 999) 29 | print("\nException when calling SubscriptionsApi->suspend_subscription: %s\n" % e) 30 | 31 | def write_log_audit(status): 32 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 33 | 34 | if __name__ == "__main__": 35 | suspend_subscription() 36 | -------------------------------------------------------------------------------- /samples/Reporting/ChargebackDetails/get-chargeback-details.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def get_chargeback_details(): 20 | # QUERY PARAMETERS 21 | organization_id = "testrest" 22 | start_time = "2024-08-01T00:00:00Z" 23 | end_time = "2024-09-01T23:59:59Z" 24 | 25 | try: 26 | config_obj = configuration.Configuration() 27 | client_config = config_obj.get_configuration() 28 | api_instance = ChargebackDetailsApi(client_config) 29 | return_data, status, body = api_instance.get_chargeback_details(start_time, end_time, organization_id = organization_id) 30 | 31 | print("\nAPI RESPONSE CODE : ", status) 32 | print("\nAPI RESPONSE BODY : ", body) 33 | 34 | write_log_audit(status) 35 | return return_data 36 | except Exception as e: 37 | write_log_audit(e.status if hasattr(e, 'status') else 999) 38 | print("\nException when calling ChargebackDetailsApi->get_chargeback_details: %s\n" % e) 39 | 40 | def write_log_audit(status): 41 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 42 | 43 | if __name__ == "__main__": 44 | get_chargeback_details() -------------------------------------------------------------------------------- /samples/Reporting/ChargebackSummaries/get-chargeback-summaries.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def get_chargeback_summaries(): 20 | # QUERY PARAMETERS 21 | organization_id = "testrest" 22 | start_time = "2024-08-01T00:00:00Z" 23 | end_time = "2024-09-01T23:59:59Z" 24 | 25 | try: 26 | config_obj = configuration.Configuration() 27 | client_config = config_obj.get_configuration() 28 | api_instance = ChargebackSummariesApi(client_config) 29 | return_data, status, body = api_instance.get_chargeback_summaries(start_time, end_time, organization_id = organization_id) 30 | 31 | print("\nAPI RESPONSE CODE : ", status) 32 | print("\nAPI RESPONSE BODY : ", body) 33 | 34 | write_log_audit(status) 35 | return return_data 36 | except Exception as e: 37 | write_log_audit(e.status if hasattr(e, 'status') else 999) 38 | print("\nException when calling ChargebackSummariesApi->get_chargeback_summaries: %s\n" % e) 39 | 40 | def write_log_audit(status): 41 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 42 | 43 | if __name__ == "__main__": 44 | get_chargeback_summaries() -------------------------------------------------------------------------------- /samples/Reporting/ConversionDetails/get-conversion-detail-transactions.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def get_conversion_detail_transactions(): 20 | startTime = "2024-10-21T00:00:00Z" 21 | endTime = "2024-10-21T23:00:00Z" 22 | organizationId = "testrest" 23 | 24 | try: 25 | config_obj = configuration.Configuration() 26 | client_config = config_obj.get_configuration() 27 | api_instance = ConversionDetailsApi(client_config) 28 | return_data, status, body = api_instance.get_conversion_detail(startTime, endTime, organization_id=organizationId) 29 | 30 | print("\nAPI RESPONSE CODE : ", status) 31 | print("\nAPI RESPONSE BODY : ", body) 32 | 33 | write_log_audit(status) 34 | return return_data 35 | except Exception as e: 36 | write_log_audit(e.status if hasattr(e, 'status') else 999) 37 | print("\nException when calling ConversionDetailsApi->get_conversion_detail: %s\n" % e) 38 | 39 | def write_log_audit(status): 40 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 41 | 42 | if __name__ == "__main__": 43 | get_conversion_detail_transactions() 44 | -------------------------------------------------------------------------------- /samples/Reporting/InterchangeClearingLevelDetails/interchange-clearing-level-data-for-account-or-merchant.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def interchange_clearing_level_data_for_account_or_merchant(): 20 | # QUERY PARAMETERS 21 | organization_id = "testrest" 22 | start_time = "2024-08-01T00:00:00Z" 23 | end_time = "2024-09-01T23:59:59Z" 24 | 25 | try: 26 | config_obj = configuration.Configuration() 27 | client_config = config_obj.get_configuration() 28 | api_instance = InterchangeClearingLevelDetailsApi(client_config) 29 | return_data, status, body = api_instance.get_interchange_clearing_level_details(start_time, end_time, organization_id = organization_id) 30 | 31 | print("\nAPI RESPONSE CODE : ", status) 32 | print("\nAPI RESPONSE BODY : ", body) 33 | 34 | write_log_audit(status) 35 | return return_data 36 | except Exception as e: 37 | write_log_audit(e.status if hasattr(e, 'status') else 999) 38 | print("\nException when calling InterchangeClearingLevelDetailsApi->get_interchange_clearing_level_details: %s\n" % e) 39 | 40 | def write_log_audit(status): 41 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 42 | 43 | if __name__ == "__main__": 44 | interchange_clearing_level_data_for_account_or_merchant() -------------------------------------------------------------------------------- /samples/Reporting/NetFundings/get-netfunding-information-for-account-or-merchant.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def get_netfunding_information_for_account_or_merchant(): 20 | startTime = "2024-01-01T00:00:00Z" 21 | endTime = "2024-01-02T23:59:59Z" 22 | organizationId = "testrest" 23 | 24 | try: 25 | config_obj = configuration.Configuration() 26 | client_config = config_obj.get_configuration() 27 | api_instance = NetFundingsApi(client_config) 28 | return_data, status, body = api_instance.get_net_funding_details(startTime, endTime, organization_id=organizationId) 29 | 30 | print("\nAPI RESPONSE CODE : ", status) 31 | print("\nAPI RESPONSE BODY : ", body) 32 | 33 | write_log_audit(status) 34 | return return_data 35 | except Exception as e: 36 | write_log_audit(e.status if hasattr(e, 'status') else 999) 37 | print("\nException when calling NetFundingsApi->get_net_funding_details: %s\n" % e) 38 | 39 | def write_log_audit(status): 40 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 41 | 42 | if __name__ == "__main__": 43 | get_netfunding_information_for_account_or_merchant() 44 | -------------------------------------------------------------------------------- /samples/Reporting/NotificationOfChanges/get-notification-of-changes.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def get_notification_of_changes(): 20 | startTime = "2024-10-01T12:00:00Z" 21 | endTime = "2024-10-10T12:00:00Z" 22 | 23 | try: 24 | config_obj = configuration.Configuration() 25 | client_config = config_obj.get_configuration() 26 | api_instance = NotificationOfChangesApi(client_config) 27 | return_data, status, body = api_instance.get_notification_of_change_report(startTime, endTime) 28 | 29 | print("\nAPI RESPONSE CODE : ", status) 30 | print("\nAPI RESPONSE BODY : ", body) 31 | 32 | write_log_audit(status) 33 | return return_data 34 | except Exception as e: 35 | write_log_audit(e.status if hasattr(e, 'status') else 999) 36 | print("\nException when calling NotificationOfChangesApi->get_notification_of_change_report: %s\n" % e) 37 | 38 | def write_log_audit(status): 39 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 40 | 41 | if __name__ == "__main__": 42 | get_notification_of_changes() 43 | -------------------------------------------------------------------------------- /samples/Reporting/PaymentBatchSummaries/get-payment-batch-summary-data.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def get_payment_batch_summary_data(): 20 | startTime = "2024-09-01T12:00:00Z" 21 | endTime = "2024-09-30T12:00:00Z" 22 | organizationId = "testrest" 23 | 24 | try: 25 | config_obj = configuration.Configuration() 26 | client_config = config_obj.get_configuration() 27 | api_instance = PaymentBatchSummariesApi(client_config) 28 | return_data, status, body = api_instance.get_payment_batch_summary(startTime, endTime, organization_id=organizationId) 29 | 30 | print("\nAPI RESPONSE CODE : ", status) 31 | print("\nAPI RESPONSE BODY : ", body) 32 | 33 | write_log_audit(status) 34 | return return_data 35 | except Exception as e: 36 | write_log_audit(e.status if hasattr(e, 'status') else 999) 37 | print("\nException when calling PaymentBatchSummariesApi->get_payment_batch_summary: %s\n" % e) 38 | 39 | def write_log_audit(status): 40 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 41 | 42 | if __name__ == "__main__": 43 | get_payment_batch_summary_data() 44 | -------------------------------------------------------------------------------- /samples/Reporting/PurchaseAndRefundDetails/get-purchase-and-refund-details.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def get_purchase_and_refund_details(): 20 | startTime = "2024-10-01T12:00:00Z" 21 | endTime = "2024-10-30T12:00:00Z" 22 | organizationId = "testrest" 23 | paymentSubtype = "VI" 24 | viewBy = "requestDate" 25 | groupName = "groupName" 26 | offset = 20 27 | limit = 2000 28 | 29 | try: 30 | config_obj = configuration.Configuration() 31 | client_config = config_obj.get_configuration() 32 | api_instance = PurchaseAndRefundDetailsApi(client_config) 33 | return_data, status, body = api_instance.get_purchase_and_refund_details(startTime, endTime, organization_id=organizationId, payment_subtype=paymentSubtype, view_by=viewBy, group_name=groupName, offset=offset, limit=limit) 34 | 35 | print("\nAPI RESPONSE CODE : ", status) 36 | print("\nAPI RESPONSE BODY : ", body) 37 | 38 | write_log_audit(status) 39 | return return_data 40 | except Exception as e: 41 | write_log_audit(e.status if hasattr(e, 'status') else 999) 42 | print("\nException when calling PurchaseAndRefundDetailsApi->get_purchase_and_refund_details: %s\n" % e) 43 | 44 | def write_log_audit(status): 45 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 46 | 47 | if __name__ == "__main__": 48 | get_purchase_and_refund_details() 49 | -------------------------------------------------------------------------------- /samples/Reporting/ReportDefinitions/get-report-definition.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def get_report_definition(): 20 | organizationId = "testrest" 21 | 22 | try: 23 | reportDefinitionName = "AcquirerExceptionDetailClass" 24 | 25 | config_obj = configuration.Configuration() 26 | client_config = config_obj.get_configuration() 27 | api_instance = ReportDefinitionsApi(client_config) 28 | return_data, status, body = api_instance.get_resource_info_by_report_definition(reportDefinitionName, organization_id=organizationId) 29 | 30 | print("\nAPI RESPONSE CODE : ", status) 31 | print("\nAPI RESPONSE BODY : ", body) 32 | 33 | write_log_audit(status) 34 | return return_data 35 | except Exception as e: 36 | write_log_audit(e.status if hasattr(e, 'status') else 999) 37 | print("\nException when calling ReportDefinitionsApi->get_resource_info_by_report_definition: %s\n" % e) 38 | 39 | def write_log_audit(status): 40 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 41 | 42 | if __name__ == "__main__": 43 | get_report_definition() 44 | -------------------------------------------------------------------------------- /samples/Reporting/ReportDefinitions/get-reporting-resource-information.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def get_reporting_resource_information(): 20 | organizationId = "testrest" 21 | 22 | try: 23 | config_obj = configuration.Configuration() 24 | client_config = config_obj.get_configuration() 25 | api_instance = ReportDefinitionsApi(client_config) 26 | return_data, status, body = api_instance.get_resource_v2_info(organization_id=organizationId) 27 | 28 | print("\nAPI RESPONSE CODE : ", status) 29 | print("\nAPI RESPONSE BODY : ", body) 30 | 31 | write_log_audit(status) 32 | return return_data 33 | except Exception as e: 34 | write_log_audit(e.status if hasattr(e, 'status') else 999) 35 | print("\nException when calling ReportDefinitionsApi->get_resource_v2_info: %s\n" % e) 36 | 37 | def write_log_audit(status): 38 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 39 | 40 | if __name__ == "__main__": 41 | get_reporting_resource_information() 42 | -------------------------------------------------------------------------------- /samples/Reporting/ReportDownloads/download-report.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | 12 | 13 | def del_none(d): 14 | for key, value in list(d.items()): 15 | if value is None: 16 | del d[key] 17 | elif isinstance(value, dict): 18 | del_none(value) 19 | return d 20 | 21 | 22 | def download_report(): 23 | organizationId = "testrest" 24 | reportDate = "2021-02-01" 25 | reportName = "magic" 26 | 27 | try: 28 | config_obj = configuration.Configuration() 29 | client_config = config_obj.get_configuration() 30 | api_instance = ReportDownloadsApi(client_config) 31 | api_instance.api_client.download_file_path = os.path.join(os.getcwd(), "resources", "download_report.csv") 32 | status, headers = api_instance.download_report(reportDate, reportName, organization_id=organizationId) 33 | 34 | print("Download Status : ", status) 35 | print("Response Headers : ", headers) 36 | 37 | print("Response downloaded at the location : " + api_instance.api_client.download_file_path) 38 | write_log_audit(status) 39 | except Exception as e: 40 | write_log_audit(e.status if hasattr(e, 'status') else 999) 41 | print("\nException when calling ReportDownloadsApi->download_report: %s\n" % e) 42 | 43 | def write_log_audit(status): 44 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 45 | 46 | if __name__ == "__main__": 47 | download_report() 48 | -------------------------------------------------------------------------------- /samples/Reporting/ReportSubscriptions/create-classicstandard-report-subscription.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def create_classicstandard_report_subscription(): 20 | reportDefinitionName = "TransactionRequestClass" 21 | subscriptionType = "CLASSIC" 22 | requestObj = PredefinedSubscriptionRequestBean( 23 | report_definition_name = reportDefinitionName, 24 | subscription_type = subscriptionType 25 | ) 26 | 27 | 28 | requestObj = del_none(requestObj.__dict__) 29 | requestObj = json.dumps(requestObj) 30 | 31 | 32 | try: 33 | config_obj = configuration.Configuration() 34 | client_config = config_obj.get_configuration() 35 | api_instance = ReportSubscriptionsApi(client_config) 36 | return_data, status, body = api_instance.create_standard_or_classic_subscription(requestObj) 37 | 38 | print("\nAPI RESPONSE CODE : ", status) 39 | print("\nAPI RESPONSE BODY : ", body) 40 | 41 | write_log_audit(status) 42 | return return_data 43 | except Exception as e: 44 | write_log_audit(e.status if hasattr(e, 'status') else 999) 45 | print("\nException when calling ReportSubscriptionsApi->create_standard_or_classic_subscription: %s\n" % e) 46 | 47 | def write_log_audit(status): 48 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 49 | 50 | if __name__ == "__main__": 51 | create_classicstandard_report_subscription() 52 | -------------------------------------------------------------------------------- /samples/Reporting/ReportSubscriptions/create-report-subscription.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def create_report_subscription(): 20 | reportDefinitionName = "TransactionRequestClass" 21 | 22 | reportFields = [] 23 | reportFields.append("Request.RequestID") 24 | reportFields.append("Request.TransactionDate") 25 | reportFields.append("Request.MerchantID") 26 | reportMimeType = "application/xml" 27 | reportFrequency = "WEEKLY" 28 | reportName = "testrest_subcription_v1" 29 | timezone = "GMT" 30 | startTime = "0900" 31 | startDay = 1 32 | requestObj = CreateReportSubscriptionRequest( 33 | report_definition_name = reportDefinitionName, 34 | report_fields = reportFields, 35 | report_mime_type = reportMimeType, 36 | report_frequency = reportFrequency, 37 | report_name = reportName, 38 | timezone = timezone, 39 | start_time = startTime, 40 | start_day = startDay 41 | ) 42 | 43 | 44 | requestObj = del_none(requestObj.__dict__) 45 | requestObj = json.dumps(requestObj) 46 | 47 | 48 | try: 49 | config_obj = configuration.Configuration() 50 | client_config = config_obj.get_configuration() 51 | api_instance = ReportSubscriptionsApi(client_config) 52 | return_data, status, body = api_instance.create_subscription(requestObj) 53 | 54 | print("\nAPI RESPONSE CODE : ", status) 55 | print("\nAPI RESPONSE BODY : ", body) 56 | 57 | write_log_audit(status) 58 | return return_data 59 | except Exception as e: 60 | write_log_audit(e.status if hasattr(e, 'status') else 999) 61 | print("\nException when calling ReportSubscriptionsApi->create_subscription: %s\n" % e) 62 | 63 | def write_log_audit(status): 64 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 65 | 66 | if __name__ == "__main__": 67 | create_report_subscription() 68 | -------------------------------------------------------------------------------- /samples/Reporting/ReportSubscriptions/delete-subscription-of-report-name-by-organization.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def delete_subscription_of_report_name_by_organization(): 20 | reportName = "testrest_v2" 21 | 22 | try: 23 | config_obj = configuration.Configuration() 24 | client_config = config_obj.get_configuration() 25 | api_instance = ReportSubscriptionsApi(client_config) 26 | return_data, status, body = api_instance.delete_subscription(reportName) 27 | 28 | print("\nAPI RESPONSE CODE : ", status) 29 | print("\nAPI RESPONSE BODY : ", body) 30 | 31 | write_log_audit(status) 32 | return return_data 33 | except Exception as e: 34 | write_log_audit(e.status if hasattr(e, 'status') else 999) 35 | print("\nException when calling ReportSubscriptionsApi->delete_subscription: %s\n" % e) 36 | 37 | def write_log_audit(status): 38 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 39 | 40 | if __name__ == "__main__": 41 | delete_subscription_of_report_name_by_organization() 42 | -------------------------------------------------------------------------------- /samples/Reporting/ReportSubscriptions/get-all-subscriptions.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def get_all_subscriptions(): 20 | 21 | try: 22 | config_obj = configuration.Configuration() 23 | client_config = config_obj.get_configuration() 24 | api_instance = ReportSubscriptionsApi(client_config) 25 | return_data, status, body = api_instance.get_all_subscriptions() 26 | 27 | print("\nAPI RESPONSE CODE : ", status) 28 | print("\nAPI RESPONSE BODY : ", body) 29 | 30 | write_log_audit(status) 31 | return return_data 32 | except Exception as e: 33 | write_log_audit(e.status if hasattr(e, 'status') else 999) 34 | print("\nException when calling ReportSubscriptionsApi->get_all_subscriptions: %s\n" % e) 35 | 36 | def write_log_audit(status): 37 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 38 | 39 | if __name__ == "__main__": 40 | get_all_subscriptions() 41 | -------------------------------------------------------------------------------- /samples/Reporting/ReportSubscriptions/get-subscription-for-report-name.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def get_subscription_for_report_name(): 20 | reportName = "testv2_subscription" 21 | 22 | try: 23 | config_obj = configuration.Configuration() 24 | client_config = config_obj.get_configuration() 25 | api_instance = ReportSubscriptionsApi(client_config) 26 | return_data, status, body = api_instance.get_subscription(reportName) 27 | 28 | print("\nAPI RESPONSE CODE : ", status) 29 | print("\nAPI RESPONSE BODY : ", body) 30 | 31 | write_log_audit(status) 32 | return return_data 33 | except Exception as e: 34 | write_log_audit(e.status if hasattr(e, 'status') else 999) 35 | print("\nException when calling ReportSubscriptionsApi->get_subscription: %s\n" % e) 36 | 37 | def write_log_audit(status): 38 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 39 | 40 | if __name__ == "__main__": 41 | get_subscription_for_report_name() 42 | -------------------------------------------------------------------------------- /samples/Reporting/Reports/get-report-based-on-report-id.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def get_report_based_on_report_id(): 20 | organizationId = "testrest" 21 | 22 | try: 23 | reportId = "79642c43-2368-0cd5-e053-a2588e0a7b3c" 24 | config_obj = configuration.Configuration() 25 | client_config = config_obj.get_configuration() 26 | api_instance = ReportsApi(client_config) 27 | return_data, status, body = api_instance.get_report_by_report_id(reportId, organization_id=organizationId) 28 | 29 | print("\nAPI RESPONSE CODE : ", status) 30 | print("\nAPI RESPONSE BODY : ", body) 31 | 32 | write_log_audit(status) 33 | return return_data 34 | except Exception as e: 35 | write_log_audit(e.status if hasattr(e, 'status') else 999) 36 | print("\nException when calling ReportsApi->get_report_by_report_id: %s\n" % e) 37 | 38 | def write_log_audit(status): 39 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 40 | 41 | if __name__ == "__main__": 42 | get_report_based_on_report_id() 43 | -------------------------------------------------------------------------------- /samples/Reporting/Reports/retrieve-available-reports.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def retrieve_available_reports(): 20 | startTime = "2024-04-01T00:00:00Z" 21 | endTime = "2024-04-03T23:59:59Z" 22 | timeQueryType = "executedTime" 23 | reportMimeType = "application/xml" 24 | 25 | try: 26 | config_obj = configuration.Configuration() 27 | client_config = config_obj.get_configuration() 28 | api_instance = ReportsApi(client_config) 29 | return_data, status, body = api_instance.search_reports(startTime, endTime, timeQueryType, report_mime_type=reportMimeType) 30 | 31 | print("\nAPI RESPONSE CODE : ", status) 32 | print("\nAPI RESPONSE BODY : ", body) 33 | 34 | write_log_audit(status) 35 | return return_data 36 | except Exception as e: 37 | write_log_audit(e.status if hasattr(e, 'status') else 999) 38 | print("\nException when calling ReportsApi->search_reports: %s\n" % e) 39 | 40 | def write_log_audit(status): 41 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 42 | 43 | if __name__ == "__main__": 44 | retrieve_available_reports() 45 | -------------------------------------------------------------------------------- /samples/Reporting/RetrievalDetails/get-retrieval-details.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def get_retrieval_details(): 20 | # QUERY PARAMETERS 21 | organization_id = "testrest" 22 | start_time = "2024-08-01T00:00:00Z" 23 | end_time = "2024-09-01T23:59:59Z" 24 | 25 | try: 26 | config_obj = configuration.Configuration() 27 | client_config = config_obj.get_configuration() 28 | api_instance = RetrievalDetailsApi(client_config) 29 | return_data, status, body = api_instance.get_retrieval_details(start_time, end_time, organization_id = organization_id) 30 | 31 | print("\nAPI RESPONSE CODE : ", status) 32 | print("\nAPI RESPONSE BODY : ", body) 33 | 34 | write_log_audit(status) 35 | return return_data 36 | except Exception as e: 37 | write_log_audit(e.status if hasattr(e, 'status') else 999) 38 | print("\nException when calling RetrievalDetailsApi->get_retrieval_details: %s\n" % e) 39 | 40 | def write_log_audit(status): 41 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 42 | 43 | if __name__ == "__main__": 44 | get_retrieval_details() -------------------------------------------------------------------------------- /samples/Reporting/RetrievalSummaries/get-retrieval-summaries.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def get_retrieval_summaries(): 20 | # QUERY PARAMETERS 21 | organization_id = "testrest" 22 | start_time = "2024-08-01T00:00:00Z" 23 | end_time = "2024-09-01T23:59:59Z" 24 | 25 | try: 26 | config_obj = configuration.Configuration() 27 | client_config = config_obj.get_configuration() 28 | api_instance = RetrievalSummariesApi(client_config) 29 | return_data, status, body = api_instance.get_retrieval_summary(start_time, end_time, organization_id = organization_id) 30 | 31 | print("\nAPI RESPONSE CODE : ", status) 32 | print("\nAPI RESPONSE BODY : ", body) 33 | 34 | write_log_audit(status) 35 | return return_data 36 | except Exception as e: 37 | write_log_audit(e.status if hasattr(e, 'status') else 999) 38 | print("\nException when calling RetrievalSummariesApi->get_retrieval_summary: %s\n" % e) 39 | 40 | def write_log_audit(status): 41 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 42 | 43 | if __name__ == "__main__": 44 | get_retrieval_summaries() -------------------------------------------------------------------------------- /samples/RiskManagement/DecisionManager/remove-from-history.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def remove_from_history(id): 20 | riskInformationMarkingDetailsNotes = "Adding this transaction as suspect" 21 | riskInformationMarkingDetailsReason = "suspected" 22 | riskInformationMarkingDetailsAction = "hide" 23 | riskInformationMarkingDetails = Riskv1decisionsidmarkingRiskInformationMarkingDetails( 24 | notes = riskInformationMarkingDetailsNotes, 25 | reason = riskInformationMarkingDetailsReason, 26 | action = riskInformationMarkingDetailsAction 27 | ) 28 | 29 | riskInformation = Riskv1decisionsidmarkingRiskInformation( 30 | marking_details = riskInformationMarkingDetails.__dict__ 31 | ) 32 | 33 | requestObj = FraudMarkingActionRequest( 34 | risk_information = riskInformation.__dict__ 35 | ) 36 | 37 | 38 | requestObj = del_none(requestObj.__dict__) 39 | requestObj = json.dumps(requestObj) 40 | 41 | 42 | try: 43 | config_obj = configuration.Configuration() 44 | client_config = config_obj.get_configuration() 45 | api_instance = DecisionManagerApi(client_config) 46 | return_data, status, body = api_instance.fraud_update(id, requestObj) 47 | 48 | print("\nAPI RESPONSE CODE : ", status) 49 | print("\nAPI RESPONSE BODY : ", body) 50 | 51 | write_log_audit(status) 52 | return return_data 53 | except Exception as e: 54 | write_log_audit(e.status if hasattr(e, 'status') else 999) 55 | print("\nException when calling DecisionManagerApi->fraud_update: %s\n" % e) 56 | 57 | def write_log_audit(status): 58 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 59 | 60 | if __name__ == "__main__": 61 | id = "5825489395116729903003" 62 | 63 | remove_from_history(id) 64 | -------------------------------------------------------------------------------- /samples/SecureFileShare/download-file-with-file-identifier.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def download_file_with_file_identifier(): 20 | organizationId = "testrest" 21 | fileId = "Q2hhcmdlYmFja0FuZFJldHJpZXZhbFJlcG9ydC1hYWVkMWEwMS03OGNhLTU1YzgtZTA1My1hMjU4OGUwYWNhZWEuY3N2LTIwMjAtMDctMzA=" 22 | 23 | try: 24 | config_obj = configuration.Configuration() 25 | client_config = config_obj.get_configuration() 26 | api_instance = SecureFileShareApi(client_config) 27 | api_instance.api_client.download_file_path = os.path.join(os.getcwd(), "resources", "download_report.csv") 28 | status, headers = api_instance.get_file(fileId, organization_id=organizationId) 29 | 30 | print("Download Status : ", status) 31 | print("Response Headers : ", headers) 32 | 33 | print("Response downloaded at the location : " + api_instance.api_client.download_file_path) 34 | write_log_audit(status) 35 | except Exception as e: 36 | write_log_audit(e.status if hasattr(e, 'status') else 999) 37 | print("\nException when calling SecureFileShareApi->get_file: %s\n" % e) 38 | 39 | def write_log_audit(status): 40 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 41 | 42 | if __name__ == "__main__": 43 | download_file_with_file_identifier() 44 | -------------------------------------------------------------------------------- /samples/SecureFileShare/get-list-of-files.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def get_list_of_files(): 20 | startDate = "2024-07-20" 21 | endDate = "2024-07-30" 22 | organizationId = "testrest" 23 | name = None 24 | 25 | try: 26 | config_obj = configuration.Configuration() 27 | client_config = config_obj.get_configuration() 28 | api_instance = SecureFileShareApi(client_config) 29 | return_data, status, body = api_instance.get_file_detail(startDate, endDate, organization_id=organizationId) 30 | 31 | print("\nAPI RESPONSE CODE : ", status) 32 | print("\nAPI RESPONSE BODY : ", body) 33 | 34 | write_log_audit(status) 35 | return return_data 36 | except Exception as e: 37 | write_log_audit(e.status if hasattr(e, 'status') else 999) 38 | print("\nException when calling SecureFileShareApi->get_file_detail: %s\n" % e) 39 | 40 | def write_log_audit(status): 41 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 42 | 43 | if __name__ == "__main__": 44 | get_list_of_files() 45 | -------------------------------------------------------------------------------- /samples/TokenManagement/Customer/create-customer.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def create_customer(): 20 | buyerInformationMerchantCustomerID = "Your customer identifier" 21 | buyerInformationEmail = "test@cybs.com" 22 | buyerInformation = Tmsv2customersBuyerInformation( 23 | merchant_customer_id = buyerInformationMerchantCustomerID, 24 | email = buyerInformationEmail 25 | ) 26 | 27 | clientReferenceInformationCode = "TC50171_3" 28 | clientReferenceInformation = Tmsv2customersClientReferenceInformation( 29 | code = clientReferenceInformationCode 30 | ) 31 | 32 | 33 | merchantDefinedInformation = [] 34 | merchantDefinedInformation1 = Tmsv2customersMerchantDefinedInformation( 35 | name = "data1", 36 | value = "Your customer data" 37 | ) 38 | 39 | merchantDefinedInformation.append(merchantDefinedInformation1.__dict__) 40 | 41 | requestObj = PostCustomerRequest( 42 | buyer_information = buyerInformation.__dict__, 43 | client_reference_information = clientReferenceInformation.__dict__, 44 | merchant_defined_information = merchantDefinedInformation 45 | ) 46 | 47 | 48 | requestObj = del_none(requestObj.__dict__) 49 | requestObj = json.dumps(requestObj) 50 | 51 | 52 | try: 53 | config_obj = configuration.Configuration() 54 | client_config = config_obj.get_configuration() 55 | api_instance = CustomerApi(client_config) 56 | return_data, status, body = api_instance.post_customer(requestObj) 57 | 58 | print("\nAPI RESPONSE CODE : ", status) 59 | print("\nAPI RESPONSE BODY : ", body) 60 | 61 | write_log_audit(status) 62 | return return_data 63 | except Exception as e: 64 | write_log_audit(e.status if hasattr(e, 'status') else 999) 65 | print("\nException when calling CustomerApi->post_customer: %s\n" % e) 66 | 67 | def write_log_audit(status): 68 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 69 | 70 | if __name__ == "__main__": 71 | create_customer() 72 | -------------------------------------------------------------------------------- /samples/TokenManagement/Customer/delete-customer.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | create_customer_path = os.path.join(os.getcwd(), "samples", "TokenManagement", "Customer", "create-customer.py") 8 | create_customer = SourceFileLoader("module.name", create_customer_path).load_module() 9 | 10 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 11 | configuration = SourceFileLoader("module.name", config_file).load_module() 12 | 13 | # To delete None values in Input Request Json body 14 | def del_none(d): 15 | for key, value in list(d.items()): 16 | if value is None: 17 | del d[key] 18 | elif isinstance(value, dict): 19 | del_none(value) 20 | return d 21 | 22 | def delete_customer(): 23 | 24 | try: 25 | api_response = create_customer.create_customer() 26 | customerTokenId = api_response.id 27 | config_obj = configuration.Configuration() 28 | client_config = config_obj.get_configuration() 29 | api_instance = CustomerApi(client_config) 30 | return_data, status, body = api_instance.delete_customer(customerTokenId) 31 | 32 | print("\nAPI RESPONSE CODE : ", status) 33 | print("\nAPI RESPONSE BODY : ", body) 34 | 35 | write_log_audit(status) 36 | return return_data 37 | except Exception as e: 38 | write_log_audit(e.status if hasattr(e, 'status') else 999) 39 | print("\nException when calling CustomerApi->delete_customer: %s\n" % e) 40 | 41 | def write_log_audit(status): 42 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 43 | 44 | if __name__ == "__main__": 45 | delete_customer() 46 | -------------------------------------------------------------------------------- /samples/TokenManagement/Customer/retrieve-customer.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def retrieve_customer(): 20 | customerTokenId = "AB695DA801DD1BB6E05341588E0A3BDC" 21 | 22 | try: 23 | config_obj = configuration.Configuration() 24 | client_config = config_obj.get_configuration() 25 | api_instance = CustomerApi(client_config) 26 | return_data, status, body = api_instance.get_customer(customerTokenId) 27 | 28 | print("\nAPI RESPONSE CODE : ", status) 29 | print("\nAPI RESPONSE BODY : ", body) 30 | 31 | write_log_audit(status) 32 | return return_data 33 | except Exception as e: 34 | write_log_audit(e.status if hasattr(e, 'status') else 999) 35 | print("\nException when calling CustomerApi->get_customer: %s\n" % e) 36 | 37 | def write_log_audit(status): 38 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 39 | 40 | if __name__ == "__main__": 41 | retrieve_customer() 42 | -------------------------------------------------------------------------------- /samples/TokenManagement/Customer/update-customers-default-payment-instrument.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def update_customers_default_payment_instrument(): 20 | customerTokenId = "AB695DA801DD1BB6E05341588E0A3BDC" 21 | 22 | defaultPaymentInstrumentId = "AB6A54B982A6FCB6E05341588E0A3935" 23 | defaultPaymentInstrument = Tmsv2customersDefaultPaymentInstrument( 24 | id = defaultPaymentInstrumentId 25 | ) 26 | 27 | requestObj = PatchCustomerRequest( 28 | default_payment_instrument = defaultPaymentInstrument.__dict__ 29 | ) 30 | 31 | 32 | requestObj = del_none(requestObj.__dict__) 33 | requestObj = json.dumps(requestObj) 34 | 35 | 36 | try: 37 | config_obj = configuration.Configuration() 38 | client_config = config_obj.get_configuration() 39 | api_instance = CustomerApi(client_config) 40 | return_data, status, body = api_instance.patch_customer(customerTokenId, requestObj) 41 | 42 | print("\nAPI RESPONSE CODE : ", status) 43 | print("\nAPI RESPONSE BODY : ", body) 44 | 45 | write_log_audit(status) 46 | return return_data 47 | except Exception as e: 48 | write_log_audit(e.status if hasattr(e, 'status') else 999) 49 | print("\nException when calling CustomerApi->patch_customer: %s\n" % e) 50 | 51 | def write_log_audit(status): 52 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 53 | 54 | if __name__ == "__main__": 55 | update_customers_default_payment_instrument() 56 | -------------------------------------------------------------------------------- /samples/TokenManagement/Customer/update-customers-default-shipping-address.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def update_customers_default_shipping_address(): 20 | customerTokenId = "AB695DA801DD1BB6E05341588E0A3BDC" 21 | 22 | defaultShippingAddressId = "AB6A54B97C00FCB6E05341588E0A3935" 23 | defaultShippingAddress = Tmsv2customersDefaultShippingAddress( 24 | id = defaultShippingAddressId 25 | ) 26 | 27 | requestObj = PatchCustomerRequest( 28 | default_shipping_address = defaultShippingAddress.__dict__ 29 | ) 30 | 31 | 32 | requestObj = del_none(requestObj.__dict__) 33 | requestObj = json.dumps(requestObj) 34 | 35 | 36 | try: 37 | config_obj = configuration.Configuration() 38 | client_config = config_obj.get_configuration() 39 | api_instance = CustomerApi(client_config) 40 | return_data, status, body = api_instance.patch_customer(customerTokenId, requestObj) 41 | 42 | print("\nAPI RESPONSE CODE : ", status) 43 | print("\nAPI RESPONSE BODY : ", body) 44 | 45 | write_log_audit(status) 46 | return return_data 47 | except Exception as e: 48 | write_log_audit(e.status if hasattr(e, 'status') else 999) 49 | print("\nException when calling CustomerApi->patch_customer: %s\n" % e) 50 | 51 | def write_log_audit(status): 52 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 53 | 54 | if __name__ == "__main__": 55 | update_customers_default_shipping_address() 56 | -------------------------------------------------------------------------------- /samples/TokenManagement/CustomerPaymentInstrument/delete-customer-payment-instrument.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | create_customer_payment_instrument_path = os.path.join(os.getcwd(), "samples", "TokenManagement", "CustomerPaymentInstrument", "create-customer-nondefault-payment-instrument-card.py") 8 | create_customer_payment_instrument = SourceFileLoader("module.name", create_customer_payment_instrument_path).load_module() 9 | 10 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 11 | configuration = SourceFileLoader("module.name", config_file).load_module() 12 | 13 | # To delete None values in Input Request Json body 14 | def del_none(d): 15 | for key, value in list(d.items()): 16 | if value is None: 17 | del d[key] 18 | elif isinstance(value, dict): 19 | del_none(value) 20 | return d 21 | 22 | def delete_customer_payment_instrument(): 23 | customerTokenId = "AB695DA801DD1BB6E05341588E0A3BDC" 24 | 25 | 26 | try: 27 | api_response = create_customer_payment_instrument.create_customer_nondefault_payment_instrument_card() 28 | paymentInstrumentTokenId = api_response.id 29 | config_obj = configuration.Configuration() 30 | client_config = config_obj.get_configuration() 31 | api_instance = CustomerPaymentInstrumentApi(client_config) 32 | return_data, status, body = api_instance.delete_customer_payment_instrument(customerTokenId, paymentInstrumentTokenId) 33 | 34 | print("\nAPI RESPONSE CODE : ", status) 35 | print("\nAPI RESPONSE BODY : ", body) 36 | 37 | write_log_audit(status) 38 | return return_data 39 | except Exception as e: 40 | write_log_audit(e.status if hasattr(e, 'status') else 999) 41 | print("\nException when calling CustomerPaymentInstrumentApi->delete_customer_payment_instrument: %s\n" % e) 42 | 43 | def write_log_audit(status): 44 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 45 | 46 | if __name__ == "__main__": 47 | delete_customer_payment_instrument() 48 | -------------------------------------------------------------------------------- /samples/TokenManagement/CustomerPaymentInstrument/list-payment-instruments-for-customer.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def list_payment_instruments_for_customer(): 20 | customerTokenId = "AB695DA801DD1BB6E05341588E0A3BDC" 21 | 22 | try: 23 | config_obj = configuration.Configuration() 24 | client_config = config_obj.get_configuration() 25 | api_instance = CustomerPaymentInstrumentApi(client_config) 26 | return_data, status, body = api_instance.get_customer_payment_instruments_list(customerTokenId) 27 | 28 | print("\nAPI RESPONSE CODE : ", status) 29 | print("\nAPI RESPONSE BODY : ", body) 30 | 31 | write_log_audit(status) 32 | return return_data 33 | except Exception as e: 34 | write_log_audit(e.status if hasattr(e, 'status') else 999) 35 | print("\nException when calling CustomerPaymentInstrumentApi->get_customer_payment_instruments_list: %s\n" % e) 36 | 37 | def write_log_audit(status): 38 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 39 | 40 | if __name__ == "__main__": 41 | list_payment_instruments_for_customer() 42 | -------------------------------------------------------------------------------- /samples/TokenManagement/CustomerPaymentInstrument/retrieve-customer-payment-instrument.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def retrieve_customer_payment_instrument(): 20 | customerTokenId = "AB695DA801DD1BB6E05341588E0A3BDC" 21 | paymentInstrumentTokenId = "AB6A54B982A6FCB6E05341588E0A3935" 22 | 23 | try: 24 | config_obj = configuration.Configuration() 25 | client_config = config_obj.get_configuration() 26 | api_instance = CustomerPaymentInstrumentApi(client_config) 27 | return_data, status, body = api_instance.get_customer_payment_instrument(customerTokenId, paymentInstrumentTokenId) 28 | 29 | print("\nAPI RESPONSE CODE : ", status) 30 | print("\nAPI RESPONSE BODY : ", body) 31 | 32 | write_log_audit(status) 33 | return return_data 34 | except Exception as e: 35 | write_log_audit(e.status if hasattr(e, 'status') else 999) 36 | print("\nException when calling CustomerPaymentInstrumentApi->get_customer_payment_instrument: %s\n" % e) 37 | 38 | def write_log_audit(status): 39 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 40 | 41 | if __name__ == "__main__": 42 | retrieve_customer_payment_instrument() 43 | -------------------------------------------------------------------------------- /samples/TokenManagement/CustomerShippingAddress/delete-customer-shipping-address.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | create_customer_shipping_address_path = os.path.join(os.getcwd(), "samples", "TokenManagement", "CustomerShippingAddress", "create-customer-nondefault-shipping-address.py") 8 | create_customer_shipping_address = SourceFileLoader("module.name", create_customer_shipping_address_path).load_module() 9 | 10 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 11 | configuration = SourceFileLoader("module.name", config_file).load_module() 12 | 13 | # To delete None values in Input Request Json body 14 | def del_none(d): 15 | for key, value in list(d.items()): 16 | if value is None: 17 | del d[key] 18 | elif isinstance(value, dict): 19 | del_none(value) 20 | return d 21 | 22 | def delete_customer_shipping_address(): 23 | customerTokenId = "AB695DA801DD1BB6E05341588E0A3BDC" 24 | 25 | try: 26 | api_response = create_customer_shipping_address.create_customer_nondefault_shipping_address() 27 | shippingAddressTokenId = api_response.id 28 | config_obj = configuration.Configuration() 29 | client_config = config_obj.get_configuration() 30 | api_instance = CustomerShippingAddressApi(client_config) 31 | return_data, status, body = api_instance.delete_customer_shipping_address(customerTokenId, shippingAddressTokenId) 32 | 33 | print("\nAPI RESPONSE CODE : ", status) 34 | print("\nAPI RESPONSE BODY : ", body) 35 | 36 | write_log_audit(status) 37 | return return_data 38 | except Exception as e: 39 | write_log_audit(e.status if hasattr(e, 'status') else 999) 40 | print("\nException when calling CustomerShippingAddressApi->delete_customer_shipping_address: %s\n" % e) 41 | 42 | def write_log_audit(status): 43 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 44 | 45 | if __name__ == "__main__": 46 | delete_customer_shipping_address() 47 | -------------------------------------------------------------------------------- /samples/TokenManagement/CustomerShippingAddress/list-shipping-addresses-for-customer.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def list_shipping_addresses_for_customer(): 20 | customerTokenId = "AB695DA801DD1BB6E05341588E0A3BDC" 21 | 22 | try: 23 | config_obj = configuration.Configuration() 24 | client_config = config_obj.get_configuration() 25 | api_instance = CustomerShippingAddressApi(client_config) 26 | return_data, status, body = api_instance.get_customer_shipping_addresses_list(customerTokenId) 27 | 28 | print("\nAPI RESPONSE CODE : ", status) 29 | print("\nAPI RESPONSE BODY : ", body) 30 | 31 | write_log_audit(status) 32 | return return_data 33 | except Exception as e: 34 | write_log_audit(e.status if hasattr(e, 'status') else 999) 35 | print("\nException when calling CustomerShippingAddressApi->get_customer_shipping_addresses_list: %s\n" % e) 36 | 37 | def write_log_audit(status): 38 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 39 | 40 | if __name__ == "__main__": 41 | list_shipping_addresses_for_customer() 42 | -------------------------------------------------------------------------------- /samples/TokenManagement/CustomerShippingAddress/retrieve-customer-shipping-address.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def retrieve_customer_shipping_address(): 20 | customerTokenId = "AB695DA801DD1BB6E05341588E0A3BDC" 21 | shippingAddressTokenId = "AB6A54B97C00FCB6E05341588E0A3935" 22 | 23 | try: 24 | config_obj = configuration.Configuration() 25 | client_config = config_obj.get_configuration() 26 | api_instance = CustomerShippingAddressApi(client_config) 27 | return_data, status, body = api_instance.get_customer_shipping_address(customerTokenId, shippingAddressTokenId) 28 | 29 | print("\nAPI RESPONSE CODE : ", status) 30 | print("\nAPI RESPONSE BODY : ", body) 31 | 32 | write_log_audit(status) 33 | return return_data 34 | except Exception as e: 35 | write_log_audit(e.status if hasattr(e, 'status') else 999) 36 | print("\nException when calling CustomerShippingAddressApi->get_customer_shipping_address: %s\n" % e) 37 | 38 | def write_log_audit(status): 39 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 40 | 41 | if __name__ == "__main__": 42 | retrieve_customer_shipping_address() 43 | -------------------------------------------------------------------------------- /samples/TokenManagement/InstrumentIdentifier/create-instrument-identifier-bank-account.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def create_instrument_identifier_bank_account(): 20 | profileid = "93B32398-AD51-4CC2-A682-EA3E93614EB1" 21 | bankAccountNumber = "4100" 22 | bankAccountRoutingNumber = "071923284" 23 | bankAccount = TmsEmbeddedInstrumentIdentifierBankAccount( 24 | number = bankAccountNumber, 25 | routing_number = bankAccountRoutingNumber 26 | ) 27 | 28 | requestObj = PostInstrumentIdentifierRequest( 29 | bank_account = bankAccount.__dict__ 30 | ) 31 | 32 | 33 | requestObj = del_none(requestObj.__dict__) 34 | requestObj = json.dumps(requestObj) 35 | 36 | 37 | try: 38 | config_obj = configuration.Configuration() 39 | client_config = config_obj.get_configuration() 40 | api_instance = InstrumentIdentifierApi(client_config) 41 | return_data, status, body = api_instance.post_instrument_identifier(requestObj, profile_id=profileid) 42 | 43 | print("\nAPI RESPONSE CODE : ", status) 44 | print("\nAPI RESPONSE BODY : ", body) 45 | 46 | write_log_audit(status) 47 | return return_data 48 | except Exception as e: 49 | write_log_audit(e.status if hasattr(e, 'status') else 999) 50 | print("\nException when calling InstrumentIdentifierApi->post_instrument_identifier: %s\n" % e) 51 | 52 | def write_log_audit(status): 53 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 54 | 55 | if __name__ == "__main__": 56 | create_instrument_identifier_bank_account() 57 | -------------------------------------------------------------------------------- /samples/TokenManagement/InstrumentIdentifier/create-instrument-identifier-card.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def create_instrument_identifier_card(): 20 | profileid = "93B32398-AD51-4CC2-A682-EA3E93614EB1" 21 | 22 | cardNumber = "4111111111111111" 23 | card = TmsEmbeddedInstrumentIdentifierCard( 24 | number = cardNumber 25 | ) 26 | 27 | requestObj = PostInstrumentIdentifierRequest( 28 | card = card.__dict__ 29 | ) 30 | 31 | 32 | requestObj = del_none(requestObj.__dict__) 33 | requestObj = json.dumps(requestObj) 34 | 35 | 36 | try: 37 | config_obj = configuration.Configuration() 38 | client_config = config_obj.get_configuration() 39 | api_instance = InstrumentIdentifierApi(client_config) 40 | return_data, status, body = api_instance.post_instrument_identifier(requestObj, profile_id=profileid) 41 | 42 | print("\nAPI RESPONSE CODE : ", status) 43 | print("\nAPI RESPONSE BODY : ", body) 44 | 45 | write_log_audit(status) 46 | return return_data 47 | except Exception as e: 48 | write_log_audit(e.status if hasattr(e, 'status') else 999) 49 | print("\nException when calling InstrumentIdentifierApi->post_instrument_identifier: %s\n" % e) 50 | 51 | def write_log_audit(status): 52 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 53 | 54 | if __name__ == "__main__": 55 | create_instrument_identifier_card() 56 | -------------------------------------------------------------------------------- /samples/TokenManagement/InstrumentIdentifier/delete-instrument-identifier.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | tms_file_path = os.path.join(os.getcwd(), "samples", "TokenManagement", "InstrumentIdentifier", "create-instrument-identifier-card.py") 11 | create_instrument_identifier = SourceFileLoader("module.name", tms_file_path).load_module() 12 | 13 | # To delete None values in Input Request Json body 14 | def del_none(d): 15 | for key, value in list(d.items()): 16 | if value is None: 17 | del d[key] 18 | elif isinstance(value, dict): 19 | del_none(value) 20 | return d 21 | 22 | def delete_instrument_identifier(): 23 | profileid = "93B32398-AD51-4CC2-A682-EA3E93614EB1" 24 | 25 | 26 | try: 27 | api_response = create_instrument_identifier.create_instrument_identifier_card() 28 | instrumentIdentifierTokenId = api_response.id 29 | config_obj = configuration.Configuration() 30 | client_config = config_obj.get_configuration() 31 | api_instance = InstrumentIdentifierApi(client_config) 32 | return_data, status, body = api_instance.delete_instrument_identifier(instrumentIdentifierTokenId, profile_id=profileid) 33 | 34 | print("\nAPI RESPONSE CODE : ", status) 35 | print("\nAPI RESPONSE BODY : ", body) 36 | 37 | write_log_audit(status) 38 | return return_data 39 | except Exception as e: 40 | write_log_audit(e.status if hasattr(e, 'status') else 999) 41 | print("\nException when calling InstrumentIdentifierApi->delete_instrument_identifier: %s\n" % e) 42 | 43 | def write_log_audit(status): 44 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 45 | 46 | if __name__ == "__main__": 47 | delete_instrument_identifier() 48 | -------------------------------------------------------------------------------- /samples/TokenManagement/InstrumentIdentifier/list-payment-instruments-for-instrument-identifier.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def list_payment_instruments_for_instrument_identifier(): 20 | profileid = "93B32398-AD51-4CC2-A682-EA3E93614EB1" 21 | instrumentIdentifierTokenId = "7010000000016241111" 22 | 23 | try: 24 | config_obj = configuration.Configuration() 25 | client_config = config_obj.get_configuration() 26 | api_instance = InstrumentIdentifierApi(client_config) 27 | return_data, status, body = api_instance.get_instrument_identifier_payment_instruments_list(instrumentIdentifierTokenId, profile_id=profileid) 28 | 29 | print("\nAPI RESPONSE CODE : ", status) 30 | print("\nAPI RESPONSE BODY : ", body) 31 | 32 | write_log_audit(status) 33 | return return_data 34 | except Exception as e: 35 | write_log_audit(e.status if hasattr(e, 'status') else 999) 36 | print("\nException when calling InstrumentIdentifierApi->get_instrument_identifier_payment_instruments_list: %s\n" % e) 37 | 38 | def write_log_audit(status): 39 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 40 | 41 | if __name__ == "__main__": 42 | list_payment_instruments_for_instrument_identifier() 43 | -------------------------------------------------------------------------------- /samples/TokenManagement/InstrumentIdentifier/retrieve-instrument-identifier.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | tms_file_path = os.path.join(os.getcwd(), "samples", "TokenManagement", "InstrumentIdentifier", "create-instrument-identifier-card.py") 11 | create_instrument_identifier = SourceFileLoader("module.name", tms_file_path).load_module() 12 | 13 | # To delete None values in Input Request Json body 14 | def del_none(d): 15 | for key, value in list(d.items()): 16 | if value is None: 17 | del d[key] 18 | elif isinstance(value, dict): 19 | del_none(value) 20 | return d 21 | 22 | def retrieve_instrument_identifier(): 23 | profileid = "93B32398-AD51-4CC2-A682-EA3E93614EB1" 24 | 25 | 26 | 27 | try: 28 | api_response = create_instrument_identifier.create_instrument_identifier_card() 29 | instrumentIdentifierTokenId = api_response.id 30 | config_obj = configuration.Configuration() 31 | client_config = config_obj.get_configuration() 32 | api_instance = InstrumentIdentifierApi(client_config) 33 | return_data, status, body = api_instance.get_instrument_identifier(instrumentIdentifierTokenId, profile_id=profileid) 34 | 35 | print("\nAPI RESPONSE CODE : ", status) 36 | print("\nAPI RESPONSE BODY : ", body) 37 | 38 | write_log_audit(status) 39 | return return_data 40 | except Exception as e: 41 | write_log_audit(e.status if hasattr(e, 'status') else 999) 42 | print("\nException when calling InstrumentIdentifierApi->get_instrument_identifier: %s\n" % e) 43 | 44 | def write_log_audit(status): 45 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 46 | 47 | if __name__ == "__main__": 48 | retrieve_instrument_identifier() 49 | -------------------------------------------------------------------------------- /samples/TokenManagement/PaymentInstrument/delete-payment-instrument.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | import time 6 | from importlib.machinery import SourceFileLoader 7 | 8 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 9 | configuration = SourceFileLoader("module.name", config_file).load_module() 10 | 11 | tms_file_path = os.path.join(os.getcwd(), "samples", "TokenManagement", "PaymentInstrument", "create-payment-instrument-card.py") 12 | create_payment_instrument = SourceFileLoader("module.name", tms_file_path).load_module() 13 | 14 | # To delete None values in Input Request Json body 15 | def del_none(d): 16 | for key, value in list(d.items()): 17 | if value is None: 18 | del d[key] 19 | elif isinstance(value, dict): 20 | del_none(value) 21 | return d 22 | 23 | def delete_payment_instrument(): 24 | profileid = "93B32398-AD51-4CC2-A682-EA3E93614EB1" 25 | 26 | 27 | try: 28 | api_response = create_payment_instrument.create_payment_instrument_card() 29 | paymentInstrumentTokenId = api_response.id 30 | 31 | time.sleep(15) 32 | config_obj = configuration.Configuration() 33 | client_config = config_obj.get_configuration() 34 | api_instance = PaymentInstrumentApi(client_config) 35 | return_data, status, body = api_instance.delete_payment_instrument(paymentInstrumentTokenId, profile_id=profileid) 36 | 37 | print("\nAPI RESPONSE CODE : ", status) 38 | print("\nAPI RESPONSE BODY : ", body) 39 | 40 | write_log_audit(status) 41 | return return_data 42 | except Exception as e: 43 | write_log_audit(e.status if hasattr(e, 'status') else 999) 44 | print("\nException when calling PaymentInstrumentApi->delete_payment_instrument: %s\n" % e) 45 | 46 | def write_log_audit(status): 47 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 48 | 49 | if __name__ == "__main__": 50 | delete_payment_instrument() 51 | -------------------------------------------------------------------------------- /samples/TokenManagement/PaymentInstrument/retrieve-payment-instrument.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | import time 6 | from importlib.machinery import SourceFileLoader 7 | 8 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 9 | configuration = SourceFileLoader("module.name", config_file).load_module() 10 | 11 | tms_file_path = os.path.join(os.getcwd(), "samples", "TokenManagement", "PaymentInstrument", "create-payment-instrument-card.py") 12 | create_payment_instrument = SourceFileLoader("module.name", tms_file_path).load_module() 13 | 14 | # To delete None values in Input Request Json body 15 | def del_none(d): 16 | for key, value in list(d.items()): 17 | if value is None: 18 | del d[key] 19 | elif isinstance(value, dict): 20 | del_none(value) 21 | return d 22 | 23 | def retrieve_payment_instrument(): 24 | profileid = "93B32398-AD51-4CC2-A682-EA3E93614EB1" 25 | paymentInstrumentTokenId = "888454C31FB6150CE05340588D0AA9BE" 26 | 27 | time.sleep(10) 28 | 29 | try: 30 | config_obj = configuration.Configuration() 31 | client_config = config_obj.get_configuration() 32 | api_instance = PaymentInstrumentApi(client_config) 33 | return_data, status, body = api_instance.get_payment_instrument(paymentInstrumentTokenId, profile_id=profileid) 34 | 35 | print("\nAPI RESPONSE CODE : ", status) 36 | print("\nAPI RESPONSE BODY : ", body) 37 | 38 | write_log_audit(status) 39 | return return_data 40 | except Exception as e: 41 | write_log_audit(e.status if hasattr(e, 'status') else 999) 42 | print("\nException when calling PaymentInstrumentApi->get_payment_instrument: %s\n" % e) 43 | 44 | def write_log_audit(status): 45 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 46 | 47 | if __name__ == "__main__": 48 | retrieve_payment_instrument() 49 | -------------------------------------------------------------------------------- /samples/TransactionBatches/get-individual-batch-file.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def get_individual_batch_file(): 20 | id = "Owcyk6pl" 21 | 22 | try: 23 | config_obj = configuration.Configuration() 24 | client_config = config_obj.get_configuration() 25 | api_instance = TransactionBatchesApi(client_config) 26 | return_data, status, body = api_instance.get_transaction_batch_id(id) 27 | 28 | print("\nAPI RESPONSE CODE : ", status) 29 | print("\nAPI RESPONSE BODY : ", body) 30 | 31 | write_log_audit(status) 32 | return return_data 33 | except Exception as e: 34 | write_log_audit(e.status if hasattr(e, 'status') else 999) 35 | print("\nException when calling TransactionBatchesApi->get_transaction_batch_id: %s\n" % e) 36 | 37 | def write_log_audit(status): 38 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 39 | 40 | if __name__ == "__main__": 41 | get_individual_batch_file() 42 | -------------------------------------------------------------------------------- /samples/TransactionBatches/get-list-of-batch-files.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def get_list_of_batch_files(): 20 | startTime = "2020-02-22T01:47:57.000Z" 21 | endTime = "2020-02-22T22:47:57.000Z" 22 | 23 | try: 24 | config_obj = configuration.Configuration() 25 | client_config = config_obj.get_configuration() 26 | api_instance = TransactionBatchesApi(client_config) 27 | return_data, status, body = api_instance.get_transaction_batches(startTime, endTime) 28 | 29 | print("\nAPI RESPONSE CODE : ", status) 30 | print("\nAPI RESPONSE BODY : ", body) 31 | 32 | write_log_audit(status) 33 | return return_data 34 | except Exception as e: 35 | write_log_audit(e.status if hasattr(e, 'status') else 999) 36 | print("\nException when calling TransactionBatchesApi->get_transaction_batches: %s\n" % e) 37 | 38 | def write_log_audit(status): 39 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 40 | 41 | if __name__ == "__main__": 42 | get_list_of_batch_files() 43 | -------------------------------------------------------------------------------- /samples/TransactionBatches/get-transaction-details-for-given-batch-id.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def get_transaction_details_for_given_batch_id(): 20 | id = "12345" 21 | uploadDate = "2019-08-30" 22 | status = "Rejected" 23 | 24 | try: 25 | config_obj = configuration.Configuration() 26 | client_config = config_obj.get_configuration() 27 | api_instance = TransactionBatchesApi(client_config) 28 | api_instance.api_client.download_file_path = os.path.join(os.getcwd(), "resources", "download_report.csv") 29 | status, headers = api_instance.get_transaction_batch_details(id, upload_date=uploadDate, status=status) 30 | 31 | print("Download Status : ", status) 32 | print("Response Headers : ", headers) 33 | 34 | print("Response downloaded at the location : " + api_instance.api_client.download_file_path) 35 | write_log_audit(status) 36 | except Exception as e: 37 | write_log_audit(e.status if hasattr(e, 'status') else 999) 38 | print("\nException when calling TransactionBatchesApi->get_transaction_batch_details: %s\n" % e) 39 | 40 | def write_log_audit(status): 41 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 42 | 43 | if __name__ == "__main__": 44 | get_transaction_details_for_given_batch_id() 45 | -------------------------------------------------------------------------------- /samples/TransactionDetails/retrieve-transaction.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | import time 6 | from importlib.machinery import SourceFileLoader 7 | 8 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 9 | configuration = SourceFileLoader("module.name", config_file).load_module() 10 | 11 | process_payment_path = os.path.join(os.getcwd(), "samples", "Payments", "Payments", "simple-authorizationinternet.py") 12 | process_payment = SourceFileLoader("module.name", process_payment_path).load_module() 13 | 14 | # To delete None values in Input Request Json body 15 | def del_none(d): 16 | for key, value in list(d.items()): 17 | if value is None: 18 | del d[key] 19 | elif isinstance(value, dict): 20 | del_none(value) 21 | return d 22 | 23 | def retrieve_transaction(): 24 | 25 | 26 | try: 27 | api_payment_response = process_payment.simple_authorizationinternet(False) 28 | id = api_payment_response.id 29 | 30 | time.sleep(15) 31 | config_obj = configuration.Configuration() 32 | client_config = config_obj.get_configuration() 33 | api_instance = TransactionDetailsApi(client_config) 34 | return_data, status, body = api_instance.get_transaction(id) 35 | 36 | print("\nAPI RESPONSE CODE : ", status) 37 | print("\nAPI RESPONSE BODY : ", body) 38 | 39 | write_log_audit(status) 40 | return return_data 41 | except Exception as e: 42 | write_log_audit(e.status if hasattr(e, 'status') else 999) 43 | print("\nException when calling TransactionDetailsApi->get_transaction: %s\n" % e) 44 | 45 | def write_log_audit(status): 46 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 47 | 48 | if __name__ == "__main__": 49 | retrieve_transaction() 50 | -------------------------------------------------------------------------------- /samples/TransactionSearch/create-search-request.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def create_search_request(): 20 | save = False 21 | name = "MRN" 22 | timezone = "America/Chicago" 23 | query = "clientReferenceInformation.code:TC50171_3 AND submitTimeUtc:[NOW/DAY-7DAYS TO NOW/DAY+1DAY}" 24 | offset = 0 25 | limit = 100 26 | sort = "id:asc,submitTimeUtc:asc" 27 | requestObj = CreateSearchRequest( 28 | save = save, 29 | name = name, 30 | timezone = timezone, 31 | query = query, 32 | offset = offset, 33 | limit = limit, 34 | sort = sort 35 | ) 36 | 37 | 38 | requestObj = del_none(requestObj.__dict__) 39 | requestObj = json.dumps(requestObj) 40 | 41 | 42 | try: 43 | config_obj = configuration.Configuration() 44 | client_config = config_obj.get_configuration() 45 | api_instance = SearchTransactionsApi(client_config) 46 | return_data, status, body = api_instance.create_search(requestObj) 47 | 48 | print("\nAPI RESPONSE CODE : ", status) 49 | print("\nAPI RESPONSE BODY : ", body) 50 | 51 | write_log_audit(status) 52 | return return_data 53 | except Exception as e: 54 | write_log_audit(e.status if hasattr(e, 'status') else 999) 55 | print("\nException when calling SearchTransactionsApi->create_search: %s\n" % e) 56 | 57 | def write_log_audit(status): 58 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 59 | 60 | if __name__ == "__main__": 61 | create_search_request() 62 | -------------------------------------------------------------------------------- /samples/TransactionSearch/get-search-results.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | search_path = os.path.join(os.getcwd(), "samples", "TransactionSearch", "create-search-request.py") 11 | create_search = SourceFileLoader("module.name", search_path).load_module() 12 | 13 | # To delete None values in Input Request Json body 14 | def del_none(d): 15 | for key, value in list(d.items()): 16 | if value is None: 17 | del d[key] 18 | elif isinstance(value, dict): 19 | del_none(value) 20 | return d 21 | 22 | def get_search_results(): 23 | api_search_response = create_search.create_search_request() 24 | searchId = api_search_response.search_id 25 | 26 | try: 27 | config_obj = configuration.Configuration() 28 | client_config = config_obj.get_configuration() 29 | api_instance = SearchTransactionsApi(client_config) 30 | return_data, status, body = api_instance.get_search(searchId) 31 | 32 | print("\nAPI RESPONSE CODE : ", status) 33 | print("\nAPI RESPONSE BODY : ", body) 34 | 35 | write_log_audit(status) 36 | return return_data 37 | except Exception as e: 38 | write_log_audit(e.status if hasattr(e, 'status') else 999) 39 | print("\nException when calling SearchTransactionsApi->get_search: %s\n" % e) 40 | 41 | def write_log_audit(status): 42 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 43 | 44 | if __name__ == "__main__": 45 | get_search_results() 46 | -------------------------------------------------------------------------------- /samples/UserManagement/UserManagement/get-user-information-deprecated.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | def get_user_information_deprecated(): 20 | organizationId = "testrest" 21 | permissionId = "CustomerProfileViewPermission" 22 | 23 | try: 24 | config_obj = configuration.Configuration() 25 | client_config = config_obj.get_configuration() 26 | api_instance = UserManagementApi(client_config) 27 | return_data, status, body = api_instance.get_users(organization_id=organizationId, permission_id=permissionId) 28 | 29 | print("\nAPI RESPONSE CODE : ", status) 30 | print("\nAPI RESPONSE BODY : ", body) 31 | 32 | write_log_audit(status) 33 | return return_data 34 | except Exception as e: 35 | write_log_audit(e.status if hasattr(e, 'status') else 999) 36 | print("\nException when calling UserManagementApi->get_users: %s\n" % e) 37 | 38 | def write_log_audit(status): 39 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 40 | 41 | if __name__ == "__main__": 42 | get_user_information_deprecated() 43 | -------------------------------------------------------------------------------- /samples/ValueAddedService/void-committed-tax-call.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | from pathlib import Path 3 | import os 4 | import json 5 | from importlib.machinery import SourceFileLoader 6 | 7 | committed_tax_call_request_path = os.path.join(os.getcwd(), "samples", "ValueAddedService", "committed-tax-call-request.py") 8 | committed_tax_call_request = SourceFileLoader("module.name", committed_tax_call_request_path).load_module() 9 | 10 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 11 | configuration = SourceFileLoader("module.name", config_file).load_module() 12 | 13 | # To delete None values in Input Request Json body 14 | def del_none(d): 15 | for key, value in list(d.items()): 16 | if value is None: 17 | del d[key] 18 | elif isinstance(value, dict): 19 | del_none(value) 20 | return d 21 | 22 | def void_committed_tax_call(): 23 | 24 | 25 | clientReferenceInformationCode = "TAX_TC001" 26 | clientReferenceInformation = Vasv2taxidClientReferenceInformation( 27 | code = clientReferenceInformationCode 28 | ) 29 | 30 | requestObj = VoidTaxRequest( 31 | client_reference_information = clientReferenceInformation.__dict__ 32 | ) 33 | 34 | 35 | requestObj = del_none(requestObj.__dict__) 36 | requestObj = json.dumps(requestObj) 37 | 38 | 39 | try: 40 | api_payment_response = committed_tax_call_request.committed_tax_call_request() 41 | id = api_payment_response.id 42 | config_obj = configuration.Configuration() 43 | client_config = config_obj.get_configuration() 44 | api_instance = TaxesApi(client_config) 45 | return_data, status, body = api_instance.void_tax(requestObj, id) 46 | 47 | print("\nAPI RESPONSE CODE : ", status) 48 | print("\nAPI RESPONSE BODY : ", body) 49 | 50 | write_log_audit(status) 51 | return return_data 52 | except Exception as e: 53 | write_log_audit(e.status if hasattr(e, 'status') else 999) 54 | print("\nException when calling TaxesApi->void_tax: %s\n" % e) 55 | 56 | def write_log_audit(status): 57 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 58 | 59 | if __name__ == "__main__": 60 | void_committed_tax_call() 61 | -------------------------------------------------------------------------------- /samples/Webhooks/CreateNewWebhooks/find-products-you-can-subscribe-to.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | import json 4 | from importlib.machinery import SourceFileLoader 5 | from pathlib import Path 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | if isinstance(d, str): 13 | return d 14 | for key, value in list(d.items()): 15 | if value is None: 16 | del d[key] 17 | elif isinstance(value, dict): 18 | del_none(value) 19 | elif isinstance(value, list): 20 | for item in value: 21 | del_none(item) 22 | return d 23 | 24 | def find_products_you_can_subscribe_to(organization_id): 25 | 26 | try: 27 | config_obj = configuration.Configuration() 28 | client_config = config_obj.get_configuration() 29 | api_instance = CreateNewWebhooksApi(client_config) 30 | return_data, status, body = api_instance.find_products_to_subscribe(organization_id) 31 | 32 | print("\nAPI RESPONSE CODE : ", status) 33 | print("\nAPI RESPONSE BODY : ", body) 34 | 35 | write_log_audit(status) 36 | 37 | return return_data 38 | except Exception as e: 39 | write_log_audit(e.status) 40 | print("\nException when calling CreateNewWebhooksApi->find_products_to_subscribe: %s\n" % e) 41 | 42 | def write_log_audit(status): 43 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 44 | 45 | if __name__ == "__main__": 46 | find_products_you_can_subscribe_to(organization_id) -------------------------------------------------------------------------------- /samples/Webhooks/ManageWebhooks/delete-webhook-subscription.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | import json 4 | from importlib.machinery import SourceFileLoader 5 | from pathlib import Path 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | if isinstance(d, str): 13 | return d 14 | for key, value in list(d.items()): 15 | if value is None: 16 | del d[key] 17 | elif isinstance(value, dict): 18 | del_none(value) 19 | elif isinstance(value, list): 20 | for item in value: 21 | del_none(item) 22 | return d 23 | 24 | def delete_webhook_subscription(webhook_id): 25 | 26 | try: 27 | config_obj = configuration.Configuration() 28 | client_config = config_obj.get_configuration() 29 | api_instance = ManageWebhooksApi(client_config) 30 | return_data, status, body = api_instance.delete_webhook_subscription(webhook_id) 31 | 32 | print("\nAPI RESPONSE CODE : ", status) 33 | print("\nAPI RESPONSE BODY : ", body) 34 | 35 | write_log_audit(status) 36 | 37 | return return_data 38 | except Exception as e: 39 | write_log_audit(e.status) 40 | print("\nException when calling ManageWebhooksApi->delete_webhook_subscription: %s\n" % e) 41 | 42 | def write_log_audit(status): 43 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 44 | 45 | if __name__ == "__main__": 46 | delete_webhook_subscription(webhook_id) -------------------------------------------------------------------------------- /samples/Webhooks/ManageWebhooks/get-details-on-all-created-webhooks.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | import json 4 | from importlib.machinery import SourceFileLoader 5 | from pathlib import Path 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | if isinstance(d, str): 13 | return d 14 | for key, value in list(d.items()): 15 | if value is None: 16 | del d[key] 17 | elif isinstance(value, dict): 18 | del_none(value) 19 | elif isinstance(value, list): 20 | for item in value: 21 | del_none(item) 22 | return d 23 | 24 | def get_details_on_all_created_webhooks(): 25 | // QUERY PARAMETERS 26 | organization_id = "testrest" 27 | product_id = "testProductId" 28 | event_type = "testEventType" 29 | 30 | try: 31 | config_obj = configuration.Configuration() 32 | client_config = config_obj.get_configuration() 33 | api_instance = ManageWebhooksApi(client_config) 34 | return_data, status, body = api_instance.get_webhook_subscriptions_by_org(organization_id, product_id, event_type) 35 | 36 | print("\nAPI RESPONSE CODE : ", status) 37 | print("\nAPI RESPONSE BODY : ", body) 38 | 39 | write_log_audit(status) 40 | 41 | return return_data 42 | except Exception as e: 43 | write_log_audit(e.status) 44 | print("\nException when calling ManageWebhooksApi->get_webhook_subscriptions_by_org: %s\n" % e) 45 | 46 | def write_log_audit(status): 47 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 48 | 49 | if __name__ == "__main__": 50 | get_details_on_all_created_webhooks() -------------------------------------------------------------------------------- /samples/Webhooks/ManageWebhooks/get-details-on-single-webhook.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | import json 4 | from importlib.machinery import SourceFileLoader 5 | from pathlib import Path 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | if isinstance(d, str): 13 | return d 14 | for key, value in list(d.items()): 15 | if value is None: 16 | del d[key] 17 | elif isinstance(value, dict): 18 | del_none(value) 19 | elif isinstance(value, list): 20 | for item in value: 21 | del_none(item) 22 | return d 23 | 24 | def get_details_on_single_webhook(webhook_id): 25 | 26 | try: 27 | config_obj = configuration.Configuration() 28 | client_config = config_obj.get_configuration() 29 | api_instance = ManageWebhooksApi(client_config) 30 | return_data, status, body = api_instance.get_webhook_subscription_by_id(webhook_id) 31 | 32 | print("\nAPI RESPONSE CODE : ", status) 33 | print("\nAPI RESPONSE BODY : ", body) 34 | 35 | write_log_audit(status) 36 | 37 | return return_data 38 | except Exception as e: 39 | write_log_audit(e.status) 40 | print("\nException when calling ManageWebhooksApi->get_webhook_subscription_by_id: %s\n" % e) 41 | 42 | def write_log_audit(status): 43 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 44 | 45 | if __name__ == "__main__": 46 | get_details_on_single_webhook(webhook_id) -------------------------------------------------------------------------------- /samples/Webhooks/ManageWebhooks/replay-failed-transactions-by-set-start-and-end-time.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | import json 4 | from importlib.machinery import SourceFileLoader 5 | from pathlib import Path 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | if isinstance(d, str): 13 | return d 14 | for key, value in list(d.items()): 15 | if value is None: 16 | del d[key] 17 | elif isinstance(value, dict): 18 | del_none(value) 19 | elif isinstance(value, list): 20 | for item in value: 21 | del_none(item) 22 | return d 23 | 24 | def replay_failed_transactions_by_set_start_and_end_time(webhook_id): 25 | byDeliveryStatusStatus = "FAILED" 26 | byDeliveryStatusStartTime = "2021-01-01T15:05:52.284+05:30" 27 | byDeliveryStatusEndTime = "2021-01-02T03:05:52.284+05:30" 28 | byDeliveryStatusProductId = "tokenManagement" 29 | byDeliveryStatusEventType = "tms.token.created" 30 | byDeliveryStatus = Nrtfv1webhookswebhookIdreplaysByDeliveryStatus( 31 | status = byDeliveryStatusStatus, 32 | start_time = byDeliveryStatusStartTime, 33 | end_time = byDeliveryStatusEndTime, 34 | product_id = byDeliveryStatusProductId, 35 | event_type = byDeliveryStatusEventType 36 | ) 37 | 38 | requestObj = ReplayWebhooksRequest( 39 | by_delivery_status = byDeliveryStatus.__dict__ 40 | ) 41 | 42 | 43 | requestObj = del_none(requestObj.__dict__) 44 | requestObj = json.dumps(requestObj) 45 | 46 | 47 | try: 48 | config_obj = configuration.Configuration() 49 | client_config = config_obj.get_configuration() 50 | api_instance = ManageWebhooksApi(client_config) 51 | return_data, status, body = api_instance.replay_previous_webhooks(webhook_id, requestObj) 52 | 53 | print("\nAPI RESPONSE CODE : ", status) 54 | print("\nAPI RESPONSE BODY : ", body) 55 | 56 | write_log_audit(status) 57 | 58 | return return_data 59 | except Exception as e: 60 | write_log_audit(e.status) 61 | print("\nException when calling ManageWebhooksApi->replay_previous_webhooks: %s\n" % e) 62 | 63 | def write_log_audit(status): 64 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 65 | 66 | if __name__ == "__main__": 67 | replay_failed_transactions_by_set_start_and_end_time(webhook_id) -------------------------------------------------------------------------------- /samples/Webhooks/ManageWebhooks/replay-failed-transactions-in-last-hours.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | import json 4 | from importlib.machinery import SourceFileLoader 5 | from pathlib import Path 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | if isinstance(d, str): 13 | return d 14 | for key, value in list(d.items()): 15 | if value is None: 16 | del d[key] 17 | elif isinstance(value, dict): 18 | del_none(value) 19 | elif isinstance(value, list): 20 | for item in value: 21 | del_none(item) 22 | return d 23 | 24 | def replay_failed_transactions_in_last_hours(webhook_id): 25 | byDeliveryStatusStatus = "FAILED" 26 | byDeliveryStatusHoursBack = 24 27 | byDeliveryStatusProductId = "tokenManagement" 28 | byDeliveryStatusEventType = "tms.token.created" 29 | byDeliveryStatus = Nrtfv1webhookswebhookIdreplaysByDeliveryStatus( 30 | status = byDeliveryStatusStatus, 31 | hours_back = byDeliveryStatusHoursBack, 32 | product_id = byDeliveryStatusProductId, 33 | event_type = byDeliveryStatusEventType 34 | ) 35 | 36 | requestObj = ReplayWebhooksRequest( 37 | by_delivery_status = byDeliveryStatus.__dict__ 38 | ) 39 | 40 | 41 | requestObj = del_none(requestObj.__dict__) 42 | requestObj = json.dumps(requestObj) 43 | 44 | 45 | try: 46 | config_obj = configuration.Configuration() 47 | client_config = config_obj.get_configuration() 48 | api_instance = ManageWebhooksApi(client_config) 49 | return_data, status, body = api_instance.replay_previous_webhooks(webhook_id, requestObj) 50 | 51 | print("\nAPI RESPONSE CODE : ", status) 52 | print("\nAPI RESPONSE BODY : ", body) 53 | 54 | write_log_audit(status) 55 | 56 | return return_data 57 | except Exception as e: 58 | write_log_audit(e.status) 59 | print("\nException when calling ManageWebhooksApi->replay_previous_webhooks: %s\n" % e) 60 | 61 | def write_log_audit(status): 62 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 63 | 64 | if __name__ == "__main__": 65 | replay_failed_transactions_in_last_hours(webhook_id) -------------------------------------------------------------------------------- /samples/Webhooks/ManageWebhooks/replay-specific-list-of-transactions.py: -------------------------------------------------------------------------------- 1 | from CyberSource import * 2 | import os 3 | import json 4 | from importlib.machinery import SourceFileLoader 5 | from pathlib import Path 6 | 7 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 8 | configuration = SourceFileLoader("module.name", config_file).load_module() 9 | 10 | # To delete None values in Input Request Json body 11 | def del_none(d): 12 | if isinstance(d, str): 13 | return d 14 | for key, value in list(d.items()): 15 | if value is None: 16 | del d[key] 17 | elif isinstance(value, dict): 18 | del_none(value) 19 | elif isinstance(value, list): 20 | for item in value: 21 | del_none(item) 22 | return d 23 | 24 | def replay_specific_list_of_transactions(webhook_id): 25 | 26 | byTransactionTraceIdentifiers = [] 27 | byTransactionTraceIdentifiers.append("1f1d0bf4-9299-418d-99d8-faa3313829f1") 28 | byTransactionTraceIdentifiers.append("d19fb205-20e5-43a2-867e-bd0f574b771e") 29 | byTransactionTraceIdentifiers.append("2f2461a3-457c-40e9-867f-aced89662bbb") 30 | byTransactionTraceIdentifiers.append("e23ddc19-93d5-4f1f-8482-d7cafbb3ed9b") 31 | byTransactionTraceIdentifiers.append("eb9fc4a9-b31f-48d5-81a9-b1d773fd76d8") 32 | requestObj = ReplayWebhooksRequest( 33 | by_transaction_trace_identifiers = byTransactionTraceIdentifiers 34 | ) 35 | 36 | 37 | requestObj = del_none(requestObj.__dict__) 38 | requestObj = json.dumps(requestObj) 39 | 40 | 41 | try: 42 | config_obj = configuration.Configuration() 43 | client_config = config_obj.get_configuration() 44 | api_instance = ManageWebhooksApi(client_config) 45 | return_data, status, body = api_instance.replay_previous_webhooks(webhook_id, requestObj) 46 | 47 | print("\nAPI RESPONSE CODE : ", status) 48 | print("\nAPI RESPONSE BODY : ", body) 49 | 50 | write_log_audit(status) 51 | 52 | return return_data 53 | except Exception as e: 54 | write_log_audit(e.status) 55 | print("\nException when calling ManageWebhooksApi->replay_previous_webhooks: %s\n" % e) 56 | 57 | def write_log_audit(status): 58 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 59 | 60 | if __name__ == "__main__": 61 | replay_specific_list_of_transactions(webhook_id) -------------------------------------------------------------------------------- /samples/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyberSource/cybersource-rest-samples-python/8763756c9294a3d78f3c95bb67372cb89b8e4d52/samples/__init__.py -------------------------------------------------------------------------------- /samples/authentication/Resources/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyberSource/cybersource-rest-samples-python/8763756c9294a3d78f3c95bb67372cb89b8e4d52/samples/authentication/Resources/__init__.py -------------------------------------------------------------------------------- /samples/authentication/Resources/cybs.json: -------------------------------------------------------------------------------- 1 | { 2 | "authentication_type":"jwt", 3 | "merchantid": "testrest", 4 | "run_environment": "apitest.cybersource.com", 5 | "key_alias": "testrest", 6 | "key_password": "testrest", 7 | "key_file_name": "testrest", 8 | "keys_directory": "samples/authentication/Resources/", 9 | "merchant_keyid": "08c94330-f618-42a3-b09d-e1e43be5efda", 10 | "merchant_secretkey": "yBJxy6LjM2TmcPGu+GaJrHtkke25fPpUX+UY6/L/1tE=", 11 | "proxy_address": "userproxy.visa.com", 12 | "proxy_port": "" 13 | } 14 | 15 | -------------------------------------------------------------------------------- /samples/authentication/Resources/request.json: -------------------------------------------------------------------------------- 1 | { 2 | "clientReferenceInformation": { 3 | "code": "TC50171_3" 4 | }, 5 | "processingInformation": { 6 | "commerceIndicator": "internet" 7 | }, 8 | "aggregatorInformation": { 9 | "subMerchant": { 10 | "cardAcceptorID": "1234567890", 11 | "country": "US", 12 | "phoneNumber": "650-432-0000", 13 | "address1": "900 Metro Center", 14 | "postalCode": "94404-2775", 15 | "locality": "Foster City", 16 | "name": "Visa Inc", 17 | "administrativeArea": "CA", 18 | "region": "PEN", 19 | "email": "test@cybs.com" 20 | }, 21 | "name": "V-Internatio", 22 | "aggregatorID": "123456789" 23 | }, 24 | "orderInformation": { 25 | "billTo": { 26 | "country": "US", 27 | "lastName": "VDP", 28 | "address2": "Address 2", 29 | "address1": "201 S. Division St.", 30 | "postalCode": "48104-2201", 31 | "locality": "Ann Arbor", 32 | "administrativeArea": "MI", 33 | "firstName": "RTS", 34 | "phoneNumber": "999999999", 35 | "district": "MI", 36 | "buildingNumber": "123", 37 | "company": "Visa", 38 | "email": "test@cybs.com" 39 | }, 40 | "amountDetails": { 41 | "totalAmount": "102.21", 42 | "currency": "USD" 43 | } 44 | }, 45 | "paymentInformation": { 46 | "card": { 47 | "expirationYear": "2031", 48 | "number": "5555555555554444", 49 | "securityCode": "123", 50 | "expirationMonth": "12", 51 | "type": "002" 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /samples/authentication/Resources/testrest.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyberSource/cybersource-rest-samples-python/8763756c9294a3d78f3c95bb67372cb89b8e4d52/samples/authentication/Resources/testrest.p12 -------------------------------------------------------------------------------- /samples/authentication/Resources/trr_report.json: -------------------------------------------------------------------------------- 1 | { 2 | "startDay":"23", 3 | "timeZone":"America/Chicago", 4 | "reportDefinitionName":"TransactionRequestClass", 5 | "startTime":"1100", 6 | "reportFrequency":"DAILY", 7 | "ReportName":"TRRReport", 8 | "reportFormat":"csv", 9 | "orgId":"testrest", 10 | "reportType":"detail", 11 | "reportFields": ["Request.RequestID","Request.TransactionDate","Request.MerchantReferenceNumber","Request.MerchantID"] 12 | } -------------------------------------------------------------------------------- /samples/authentication/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyberSource/cybersource-rest-samples-python/8763756c9294a3d78f3c95bb67372cb89b8e4d52/samples/authentication/__init__.py -------------------------------------------------------------------------------- /samples/authentication/data/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyberSource/cybersource-rest-samples-python/8763756c9294a3d78f3c95bb67372cb89b8e4d52/samples/authentication/data/__init__.py -------------------------------------------------------------------------------- /samples/authentication/sample_code/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CyberSource/cybersource-rest-samples-python/8763756c9294a3d78f3c95bb67372cb89b8e4d52/samples/authentication/sample_code/__init__.py -------------------------------------------------------------------------------- /samples/networkToken/NetworkToken.py: -------------------------------------------------------------------------------- 1 | import os 2 | from importlib.machinery import SourceFileLoader 3 | from jwcrypto import jwk 4 | 5 | from CyberSource.utilities.JWEResponse.JWEUtility import JWEUtility 6 | from authenticationsdk.core.MerchantConfiguration import MerchantConfiguration 7 | 8 | from create_instrument_identifier_card_enroll_for_network_token import \ 9 | create_instrument_identifier_card_enroll_for_network_token 10 | from payment_credentials_from_network_token import payment_credentials_from_network_token 11 | 12 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 13 | configuration = SourceFileLoader("module.name", config_file).load_module() 14 | 15 | def del_none(d): 16 | for key, value in list(d.items()): 17 | if value is None: 18 | del d[key] 19 | elif isinstance(value, dict): 20 | del_none(value) 21 | return d 22 | 23 | def get_private_key_from_pem_file(pem_file_path): 24 | with open(pem_file_path, 'r') as pem_file: 25 | cert = pem_file.read() 26 | private_key = jwk.JWK.from_pem(cert.encode('utf-8')) 27 | return private_key 28 | 29 | def network_token(): 30 | config_obj = configuration.Configuration() 31 | client_config = config_obj.get_configuration() 32 | merchant_config = MerchantConfiguration() 33 | merchant_config.set_merchantconfig(client_config) 34 | try: 35 | #Step-I 36 | instrument_identifier_for_network_token = create_instrument_identifier_card_enroll_for_network_token() 37 | token_id = instrument_identifier_for_network_token.id 38 | 39 | #Step-II 40 | encoded_response = payment_credentials_from_network_token(token_id) 41 | 42 | #Step-III 43 | 44 | # The following method JWEUtility.decrypt_jwe_response(encoded_response, merchant_config) has been deprecated. 45 | # decoded_response = JWEUtility.decrypt_jwe_response(encoded_response, merchant_config) 46 | 47 | # Using the new method JWEUtility.decrypt_jwe_response_using_private_key(private_key, encoded_response) instead 48 | private_key = get_private_key_from_pem_file(merchant_config.get_jwePEMFileDirectory()) 49 | decoded_response = JWEUtility.decrypt_jwe_response_using_private_key(private_key, encoded_response) 50 | 51 | print("Decoded Response") 52 | print(decoded_response) 53 | 54 | except Exception as e: 55 | print("\nException when running the sample code of networkToken: %s\n" % e) 56 | 57 | if __name__ == "__main__": 58 | network_token() 59 | -------------------------------------------------------------------------------- /samples/networkToken/create_instrument_identifier_card_enroll_for_network_token.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | from importlib.machinery import SourceFileLoader 4 | from pathlib import Path 5 | 6 | from CyberSource import TmsEmbeddedInstrumentIdentifierCard, \ 7 | PostInstrumentIdentifierRequest, InstrumentIdentifierApi 8 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 9 | configuration = SourceFileLoader("module.name", config_file).load_module() 10 | 11 | def del_none(d): 12 | for key, value in list(d.items()): 13 | if value is None: 14 | del d[key] 15 | elif isinstance(value, dict): 16 | del_none(value) 17 | return d 18 | 19 | 20 | def create_instrument_identifier_card_enroll_for_network_token(): 21 | profileid = "93B32398-AD51-4CC2-A682-EA3E93614EB1" 22 | type = "enrollable card" 23 | cardNumber = "5204245750003216" 24 | cardExpirationMonth = "12" 25 | cardExpirationYear = "2025" 26 | card = TmsEmbeddedInstrumentIdentifierCard( 27 | number=cardNumber, 28 | expiration_month=cardExpirationMonth, 29 | expiration_year=cardExpirationYear 30 | ) 31 | 32 | requestObj = PostInstrumentIdentifierRequest( 33 | type=type, 34 | card=card.__dict__ 35 | ) 36 | 37 | requestObj = del_none(requestObj.__dict__) 38 | requestObj = json.dumps(requestObj) 39 | 40 | try: 41 | config_obj = configuration.Configuration() 42 | client_config = config_obj.get_configuration() 43 | api_instance = InstrumentIdentifierApi(client_config) 44 | return_data, status, body = api_instance.post_instrument_identifier(requestObj, profile_id=profileid) 45 | 46 | print("\nAPI RESPONSE CODE : ", status) 47 | print("\nAPI RESPONSE BODY : ", body) 48 | 49 | write_log_audit(status) 50 | return return_data 51 | except Exception as e: 52 | write_log_audit(e.status if hasattr(e, 'status') else 999) 53 | print("\nException when calling InstrumentIdentifierApi->post_instrument_identifier: %s\n" % e) 54 | 55 | 56 | def write_log_audit(status): 57 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 58 | 59 | 60 | if __name__ == "__main__": 61 | print(os.getcwd()) 62 | create_instrument_identifier_card_enroll_for_network_token() 63 | -------------------------------------------------------------------------------- /samples/networkToken/payment_credentials_from_network_token.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | from importlib.machinery import SourceFileLoader 4 | from pathlib import Path 5 | 6 | from CyberSource import * 7 | from create_instrument_identifier_card_enroll_for_network_token import create_instrument_identifier_card_enroll_for_network_token 8 | 9 | config_file = os.path.join(os.getcwd(), "data", "Configuration.py") 10 | configuration = SourceFileLoader("module.name", config_file).load_module() 11 | 12 | 13 | def del_none(d): 14 | for key, value in list(d.items()): 15 | if value is None: 16 | del d[key] 17 | elif isinstance(value, dict): 18 | del_none(value) 19 | return d 20 | 21 | 22 | def payment_credentials_from_network_token(token_id=None): 23 | profile_id = "93B32398-AD51-4CC2-A682-EA3E93614EB1" 24 | if token_id is None: 25 | token_id = create_instrument_identifier_card_enroll_for_network_token().id 26 | 27 | try: 28 | config_obj = configuration.Configuration() 29 | client_config = config_obj.get_configuration() 30 | api_instance = TokenApi(client_config) 31 | post_payment_credentials_request = PostPaymentCredentialsRequest() 32 | post_payment_credentials_request = del_none(post_payment_credentials_request.__dict__) 33 | post_payment_credentials_request = json.dumps(post_payment_credentials_request) 34 | return_data, status, body = api_instance.post_token_payment_credentials(token_id, post_payment_credentials_request, profile_id=profile_id) 35 | print("\nAPI RESPONSE CODE : ", status) 36 | print("\nAPI RESPONSE BODY : ", body) 37 | 38 | write_log_audit(status) 39 | return return_data 40 | except Exception as e: 41 | write_log_audit(e.status if hasattr(e, 'status') else 999) 42 | print("\nException when calling TokenAPI->payment-credentials API: %s\n" % e) 43 | 44 | 45 | def write_log_audit(status): 46 | print(f"[Sample Code Testing] [{Path(__file__).stem}] {status}") 47 | 48 | 49 | if __name__ == "__main__": 50 | payment_credentials_from_network_token() 51 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from setuptools import setup, find_packages 3 | 4 | setup(name='samples', version='1.0', packages=find_packages()) 5 | --------------------------------------------------------------------------------