Package: checkout-sdk
Checkout.com Python SDKGetting started# Requires Python > 3.6
pip install checkout-sdk==<version>Version 3.0.0 is here!We improved the initialization of SDK making it easier to understand the available options.NowNASaccounts are the default instance for the SDK andABCstructure was moved to apreviousprefixes.If you have been using this SDK before, you may find the following important changes:Imports: if you used to importcheckout_sdk.payments.paymentsnow usecheckout_sdk.payments.payments_previousMarketplace module was moved to Accounts module, same for classes and references.In most cases, IDE can help you determine from where to import, but if you’re still having issues don't hesitate to open aticket.:rocket: Please check inGitHub releasesfor all the versions available.:book: Checkout our official documentation.Official Docs (Default)Official Docs (Previous):books: Check out our official API documentation guide, where you can also find more usage examples.API Reference (Default)API Reference (Previous)How to use the SDKThis SDK can be used with two different pair of API keys provided by Checkout. However, using different API keys imply
using specific API features. Please find in the table below the types of keys that can be used within this SDK.Account SystemPublic Key (example)Secret Key (example)Defaultpk_pkhpdtvabcf7hdgpwnbhw7r2uicsk_m73dzypy7cf3gf5d2xr4k7sxo4ePreviouspk_g650ff27-7c42-4ce1-ae90-5691a188ee7bsk_gk3517a8-3z01-45fq-b4bd-4282384b0a64Note: sandbox keys have asbox_ortest_identifier, for Default and Previous accounts respectively.If you don't have your own API keys, you can sign up for a test
accounthere.PLEASE NEVER SHARE OR PUBLISH YOUR CHECKOUT CREDENTIALS.DefaultDefault keys client instantiation can be done as follows:fromcheckout_sdk.checkout_sdkimportCheckoutSdkfromcheckout_sdk.environmentimportEnvironmentdefdefault():# public key is optional, only required for operations related with tokenscheckout_api=CheckoutSdk.builder().secret_key('secret_key').public_key('public_key').environment(Environment.sandbox()).build()payments_client=checkout_api.paymentspayments_client.refund_payment('payment_id')Default OAuthThe SDK supports client credentials OAuth, when initialized as follows:fromcheckout_sdk.checkout_sdkimportCheckoutSdkfromcheckout_sdk.environmentimportEnvironmentfromcheckout_sdk.oauth_scopesimportOAuthScopesdefoauth():checkout_api=CheckoutSdk.builder().oauth().client_credentials(client_id='client_id',client_secret='client_secret').environment(Environment.sandbox()).scopes([OAuthScopes.GATEWAY_PAYMENT_REFUNDS,OAuthScopes.FILES]).build()payments_client=checkout_api.paymentspayments_client.refund_payment('payment_id')PreviousIf your pair of keys matches the Previous type, this is how the SDK should be used:fromcheckout_sdk.checkout_sdkimportCheckoutSdkfromcheckout_sdk.environmentimportEnvironmentdefprevious():# public key is optional, only required for operations related with tokenscheckout_api=CheckoutSdk.builder().previous().secret_key('secret_key').public_key('public_key').environment(Environment.sandbox()).build()payments_client=checkout_api.paymentspayments_client.refund_payment('payment_id')LoggingCheckout SDK custom logger can be enabled and configured through Python's logging module:importlogginglogging.basicConfig()logging.getLogger('checkout').setLevel(logging.INFO)HttpClientCheckout SDK usesrequestslibrary to perform http operations, and you can provide your own custom http client implementingHttpClientBuilderInterfaceimportrequestsfromrequestsimportSessionimportcheckout_sdkfromcheckout_sdk.checkout_sdkimportCheckoutSdkfromcheckout_sdk.environmentimportEnvironmentfromcheckout_sdk.oauth_scopesimportOAuthScopesfromcheckout_sdk.http_client_interfaceimportHttpClientBuilderInterfaceclassCustomHttpClientBuilder(HttpClientBuilderInterface):defget_client(self)->Session:session=requests.Session()session.max_redirects=5returnsessiondefoauth():checkout_api=CheckoutSdk.builder().oauth().client_credentials(client_id='client_id',client_secret='client_secret').environment(Environment.sandbox()).http_client_builder(CustomHttpClientBuilder()).scopes([OAuthScopes.GATEWAY_PAYMENT_REFUNDS,OAuthScopes.FILES]).build()payments_client=checkout_api.paymentspayments_client.refund_payment('payment_id')Exception handlingAll the API responses that do not fall in the 2** status codes will cause aCheckoutApiException. The exception encapsulates
thehttp_metadataand a dictionary oferror_details, if available.try:checkout_api.customers.get("customer_id")exceptCheckoutApiExceptionaserr:http_status_code=err.http_metadata.status_codeerror_details=err.error_detailsBuilding from sourceOnce you checkout the code from GitHub, the project can be built usingpip:# install the latest version pip
python -m pip install --upgrade pip

# install project dependencies
pip install -r requirements-dev.txt

# run unit and integration tests
python -m pytestThe execution of integration tests require the following environment variables set in your system:For Default account systems:CHECKOUT_DEFAULT_PUBLIC_KEY&CHECKOUT_DEFAULT_SECRET_KEYFor OAuth account systems:CHECKOUT_DEFAULT_OAUTH_CLIENT_ID&CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRETFor Previous account systems:CHECKOUT_PREVIOUS_PUBLIC_KEY&CHECKOUT_PREVIOUS_SECRET_KEYCode of ConductPlease refer toCode of ConductLicensingMIT