checkout-sdk


Namecheckout-sdk JSON
Version 3.0.21 PyPI version JSON
download
home_pagehttps://github.com/checkout/checkout-sdk-python
SummaryCheckout.com Python SDK
upload_time2024-03-25 16:49:40
maintainerNone
docs_urlNone
authorCheckout.com
requires_pythonNone
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Checkout.com Python SDK

[![build-status](https://github.com/checkout/checkout-sdk-python/workflows/build-main/badge.svg)](https://github.com/checkout/checkout-sdk-python/actions/workflows/build-main.yml)
![CodeQL](https://github.com/checkout/checkout-sdk-python/workflows/CodeQL/badge.svg)

[![build-status](https://github.com/checkout/checkout-sdk-python/workflows/build-release/badge.svg)](https://github.com/checkout/checkout-sdk-python/actions/workflows/build-release.yml)
[![GitHub release](https://img.shields.io/github/release/checkout/checkout-sdk-python.svg)](https://GitHub.com/checkout/checkout-sdk-php/releases/)
[![PyPI - latest](https://img.shields.io/pypi/v/checkout-sdk?label=latest&logo=pypi)](https://pypi.org/project/checkout-sdk)

[![GitHub license](https://img.shields.io/github/license/checkout/checkout-sdk-python.svg)](https://github.com/checkout/checkout-sdk-python/blob/main/LICENSE.md)

## Getting started

```
# Requires Python > 3.6
pip install checkout-sdk==<version>
```

> **Version 3.0.0 is here!**
>  <br/><br/>
> We improved the initialization of SDK making it easier to understand the available options. <br/>
> Now `NAS` accounts are the default instance for the SDK and `ABC` structure was moved to a `previous` prefixes. <br/>
> If you have been using this SDK before, you may find the following important changes:
> * Imports: if you used to import `checkout_sdk.payments.payments` now use `checkout_sdk.payments.payments_previous`
> * Marketplace 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 a [ticket](https://github.com/checkout/checkout-sdk-python/issues/new/choose).


### :rocket: Please check in [GitHub releases](https://github.com/checkout/checkout-sdk-python/releases) for all the versions available.

### :book: Checkout our official documentation.

* [Official Docs (Default)](https://docs.checkout.com/)
* [Official Docs (Previous)](https://docs.checkout.com/previous)

### :books: Check out our official API documentation guide, where you can also find more usage examples.

* [API Reference (Default)](https://api-reference.checkout.com/)
* [API Reference (Previous)](https://api-reference.checkout.com/previous)

## How to use the SDK

This 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 System | Public Key (example)                    | Secret Key (example)                    |
|----------------|-----------------------------------------|-----------------------------------------|
| Default        | pk_pkhpdtvabcf7hdgpwnbhw7r2uic          | sk_m73dzypy7cf3gf5d2xr4k7sxo4e          |
| Previous       | pk_g650ff27-7c42-4ce1-ae90-5691a188ee7b | sk_gk3517a8-3z01-45fq-b4bd-4282384b0a64 |

Note: sandbox keys have a `sbox_` or `test_` identifier, for Default and Previous accounts respectively.

If you don't have your own API keys, you can sign up for a test
account [here](https://www.checkout.com/get-test-account).

**PLEASE NEVER SHARE OR PUBLISH YOUR CHECKOUT CREDENTIALS.**

### Default

Default keys client instantiation can be done as follows:

```python
from checkout_sdk.checkout_sdk import CheckoutSdk
from checkout_sdk.environment import Environment


def default():
    # public key is optional, only required for operations related with tokens
    checkout_api = CheckoutSdk
        .builder()
        .secret_key('secret_key')
        .public_key('public_key')
        .environment(Environment.sandbox())
        .build()

    payments_client = checkout_api.payments
    payments_client.refund_payment('payment_id')
```

### Default OAuth

The SDK supports client credentials OAuth, when initialized as follows:

```python
from checkout_sdk.checkout_sdk import CheckoutSdk
from checkout_sdk.environment import Environment
from checkout_sdk.oauth_scopes import OAuthScopes


def oauth():
    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.payments
    payments_client.refund_payment('payment_id')
```

### Previous

If your pair of keys matches the Previous type, this is how the SDK should be used:

```python
from checkout_sdk.checkout_sdk import CheckoutSdk
from checkout_sdk.environment import Environment

def previous():
    # public key is optional, only required for operations related with tokens
    checkout_api = CheckoutSdk
        .builder()
        .previous()
        .secret_key('secret_key')
        .public_key('public_key')
        .environment(Environment.sandbox())
        .build()

    payments_client = checkout_api.payments
    payments_client.refund_payment('payment_id')
```

## Logging

Checkout SDK custom logger can be enabled and configured through Python's logging module:

```python
import logging
logging.basicConfig()
logging.getLogger('checkout').setLevel(logging.INFO)
```

## HttpClient

Checkout SDK uses `requests` library to perform http operations, and you can provide your own custom http client implementing `HttpClientBuilderInterface`

```python
import requests
from requests import Session

import checkout_sdk
from checkout_sdk.checkout_sdk import CheckoutSdk
from checkout_sdk.environment import Environment
from checkout_sdk.oauth_scopes import OAuthScopes
from checkout_sdk.http_client_interface import HttpClientBuilderInterface


class CustomHttpClientBuilder(HttpClientBuilderInterface):

    def get_client(self) -> Session:
        session = requests.Session()
        session.max_redirects = 5
        return session


def oauth():
    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.payments
    payments_client.refund_payment('payment_id')
```

## Exception handling

All the API responses that do not fall in the 2** status codes will cause a `CheckoutApiException`. The exception encapsulates
the `http_metadata` and a dictionary of `error_details`, if available.

```python
try:
    checkout_api.customers.get("customer_id")
except CheckoutApiException as err:
    http_status_code = err.http_metadata.status_code
    error_details = err.error_details
```

## Building from source

Once you checkout the code from GitHub, the project can be built using `pip`:

```
# 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 pytest
```

The execution of integration tests require the following environment variables set in your system:

* For Default account systems: `CHECKOUT_DEFAULT_PUBLIC_KEY` & `CHECKOUT_DEFAULT_SECRET_KEY`
* For OAuth account systems: `CHECKOUT_DEFAULT_OAUTH_CLIENT_ID` & `CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRET`
* For Previous account systems: `CHECKOUT_PREVIOUS_PUBLIC_KEY` & `CHECKOUT_PREVIOUS_SECRET_KEY`

## Code of Conduct

Please refer to [Code of Conduct](CODE_OF_CONDUCT.md)

## Licensing

[MIT](LICENSE.md)



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/checkout/checkout-sdk-python",
    "name": "checkout-sdk",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Checkout.com",
    "author_email": "support@checkout.com",
    "download_url": "https://files.pythonhosted.org/packages/2a/dd/8be3ecd0faa48a13424d4823865d6ef9a380311a55a7358186f0015a5a11/checkout_sdk-3.0.21.tar.gz",
    "platform": null,
    "description": "# Checkout.com Python SDK\n\n[![build-status](https://github.com/checkout/checkout-sdk-python/workflows/build-main/badge.svg)](https://github.com/checkout/checkout-sdk-python/actions/workflows/build-main.yml)\n![CodeQL](https://github.com/checkout/checkout-sdk-python/workflows/CodeQL/badge.svg)\n\n[![build-status](https://github.com/checkout/checkout-sdk-python/workflows/build-release/badge.svg)](https://github.com/checkout/checkout-sdk-python/actions/workflows/build-release.yml)\n[![GitHub release](https://img.shields.io/github/release/checkout/checkout-sdk-python.svg)](https://GitHub.com/checkout/checkout-sdk-php/releases/)\n[![PyPI - latest](https://img.shields.io/pypi/v/checkout-sdk?label=latest&logo=pypi)](https://pypi.org/project/checkout-sdk)\n\n[![GitHub license](https://img.shields.io/github/license/checkout/checkout-sdk-python.svg)](https://github.com/checkout/checkout-sdk-python/blob/main/LICENSE.md)\n\n## Getting started\n\n```\n# Requires Python > 3.6\npip install checkout-sdk==<version>\n```\n\n> **Version 3.0.0 is here!**\n>  <br/><br/>\n> We improved the initialization of SDK making it easier to understand the available options. <br/>\n> Now `NAS` accounts are the default instance for the SDK and `ABC` structure was moved to a `previous` prefixes. <br/>\n> If you have been using this SDK before, you may find the following important changes:\n> * Imports: if you used to import `checkout_sdk.payments.payments` now use `checkout_sdk.payments.payments_previous`\n> * Marketplace module was moved to Accounts module, same for classes and references.\n> * In most cases, IDE can help you determine from where to import, but if you\u2019re still having issues don't hesitate to open a [ticket](https://github.com/checkout/checkout-sdk-python/issues/new/choose).\n\n\n### :rocket: Please check in [GitHub releases](https://github.com/checkout/checkout-sdk-python/releases) for all the versions available.\n\n### :book: Checkout our official documentation.\n\n* [Official Docs (Default)](https://docs.checkout.com/)\n* [Official Docs (Previous)](https://docs.checkout.com/previous)\n\n### :books: Check out our official API documentation guide, where you can also find more usage examples.\n\n* [API Reference (Default)](https://api-reference.checkout.com/)\n* [API Reference (Previous)](https://api-reference.checkout.com/previous)\n\n## How to use the SDK\n\nThis SDK can be used with two different pair of API keys provided by Checkout. However, using different API keys imply\nusing specific API features. Please find in the table below the types of keys that can be used within this SDK.\n\n| Account System | Public Key (example)                    | Secret Key (example)                    |\n|----------------|-----------------------------------------|-----------------------------------------|\n| Default        | pk_pkhpdtvabcf7hdgpwnbhw7r2uic          | sk_m73dzypy7cf3gf5d2xr4k7sxo4e          |\n| Previous       | pk_g650ff27-7c42-4ce1-ae90-5691a188ee7b | sk_gk3517a8-3z01-45fq-b4bd-4282384b0a64 |\n\nNote: sandbox keys have a `sbox_` or `test_` identifier, for Default and Previous accounts respectively.\n\nIf you don't have your own API keys, you can sign up for a test\naccount [here](https://www.checkout.com/get-test-account).\n\n**PLEASE NEVER SHARE OR PUBLISH YOUR CHECKOUT CREDENTIALS.**\n\n### Default\n\nDefault keys client instantiation can be done as follows:\n\n```python\nfrom checkout_sdk.checkout_sdk import CheckoutSdk\nfrom checkout_sdk.environment import Environment\n\n\ndef default():\n    # public key is optional, only required for operations related with tokens\n    checkout_api = CheckoutSdk\n        .builder()\n        .secret_key('secret_key')\n        .public_key('public_key')\n        .environment(Environment.sandbox())\n        .build()\n\n    payments_client = checkout_api.payments\n    payments_client.refund_payment('payment_id')\n```\n\n### Default OAuth\n\nThe SDK supports client credentials OAuth, when initialized as follows:\n\n```python\nfrom checkout_sdk.checkout_sdk import CheckoutSdk\nfrom checkout_sdk.environment import Environment\nfrom checkout_sdk.oauth_scopes import OAuthScopes\n\n\ndef oauth():\n    checkout_api = CheckoutSdk\n        .builder()\n        .oauth()\n        .client_credentials(client_id='client_id', client_secret='client_secret')\n        .environment(Environment.sandbox())\n        .scopes([OAuthScopes.GATEWAY_PAYMENT_REFUNDS, OAuthScopes.FILES])\n        .build()\n\n    payments_client = checkout_api.payments\n    payments_client.refund_payment('payment_id')\n```\n\n### Previous\n\nIf your pair of keys matches the Previous type, this is how the SDK should be used:\n\n```python\nfrom checkout_sdk.checkout_sdk import CheckoutSdk\nfrom checkout_sdk.environment import Environment\n\ndef previous():\n    # public key is optional, only required for operations related with tokens\n    checkout_api = CheckoutSdk\n        .builder()\n        .previous()\n        .secret_key('secret_key')\n        .public_key('public_key')\n        .environment(Environment.sandbox())\n        .build()\n\n    payments_client = checkout_api.payments\n    payments_client.refund_payment('payment_id')\n```\n\n## Logging\n\nCheckout SDK custom logger can be enabled and configured through Python's logging module:\n\n```python\nimport logging\nlogging.basicConfig()\nlogging.getLogger('checkout').setLevel(logging.INFO)\n```\n\n## HttpClient\n\nCheckout SDK uses `requests` library to perform http operations, and you can provide your own custom http client implementing `HttpClientBuilderInterface`\n\n```python\nimport requests\nfrom requests import Session\n\nimport checkout_sdk\nfrom checkout_sdk.checkout_sdk import CheckoutSdk\nfrom checkout_sdk.environment import Environment\nfrom checkout_sdk.oauth_scopes import OAuthScopes\nfrom checkout_sdk.http_client_interface import HttpClientBuilderInterface\n\n\nclass CustomHttpClientBuilder(HttpClientBuilderInterface):\n\n    def get_client(self) -> Session:\n        session = requests.Session()\n        session.max_redirects = 5\n        return session\n\n\ndef oauth():\n    checkout_api = CheckoutSdk\n        .builder()\n        .oauth()\n        .client_credentials(client_id='client_id', client_secret='client_secret')\n        .environment(Environment.sandbox())\n        .http_client_builder(CustomHttpClientBuilder())\n        .scopes([OAuthScopes.GATEWAY_PAYMENT_REFUNDS, OAuthScopes.FILES])\n        .build()\n\n    payments_client = checkout_api.payments\n    payments_client.refund_payment('payment_id')\n```\n\n## Exception handling\n\nAll the API responses that do not fall in the 2** status codes will cause a `CheckoutApiException`. The exception encapsulates\nthe `http_metadata` and a dictionary of `error_details`, if available.\n\n```python\ntry:\n    checkout_api.customers.get(\"customer_id\")\nexcept CheckoutApiException as err:\n    http_status_code = err.http_metadata.status_code\n    error_details = err.error_details\n```\n\n## Building from source\n\nOnce you checkout the code from GitHub, the project can be built using `pip`:\n\n```\n# install the latest version pip\npython -m pip install --upgrade pip\n\n# install project dependencies\npip install -r requirements-dev.txt\n\n# run unit and integration tests\npython -m pytest\n```\n\nThe execution of integration tests require the following environment variables set in your system:\n\n* For Default account systems: `CHECKOUT_DEFAULT_PUBLIC_KEY` & `CHECKOUT_DEFAULT_SECRET_KEY`\n* For OAuth account systems: `CHECKOUT_DEFAULT_OAUTH_CLIENT_ID` & `CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRET`\n* For Previous account systems: `CHECKOUT_PREVIOUS_PUBLIC_KEY` & `CHECKOUT_PREVIOUS_SECRET_KEY`\n\n## Code of Conduct\n\nPlease refer to [Code of Conduct](CODE_OF_CONDUCT.md)\n\n## Licensing\n\n[MIT](LICENSE.md)\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Checkout.com Python SDK",
    "version": "3.0.21",
    "project_urls": {
        "Homepage": "https://github.com/checkout/checkout-sdk-python"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c1db94cce0d10e6583e2b9151f34322f0523b56053c6ef99aa287a0551d2938e",
                "md5": "7d60a0d8bf2c7aa62d6a62d605bf0661",
                "sha256": "2bee0fc522b61c6034e4771b921cf2c2978cffc39d5b3e4efb5d36cccc2cf6b8"
            },
            "downloads": -1,
            "filename": "checkout_sdk-3.0.21-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7d60a0d8bf2c7aa62d6a62d605bf0661",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 76283,
            "upload_time": "2024-03-25T16:49:39",
            "upload_time_iso_8601": "2024-03-25T16:49:39.296653Z",
            "url": "https://files.pythonhosted.org/packages/c1/db/94cce0d10e6583e2b9151f34322f0523b56053c6ef99aa287a0551d2938e/checkout_sdk-3.0.21-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2add8be3ecd0faa48a13424d4823865d6ef9a380311a55a7358186f0015a5a11",
                "md5": "c10992d25a80c99232f0854451c3cc9b",
                "sha256": "bb7d8b6604d67c9db84041b999ad4fb01f0314d4ccd80769cc9c0a94ffdd0736"
            },
            "downloads": -1,
            "filename": "checkout_sdk-3.0.21.tar.gz",
            "has_sig": false,
            "md5_digest": "c10992d25a80c99232f0854451c3cc9b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 40584,
            "upload_time": "2024-03-25T16:49:40",
            "upload_time_iso_8601": "2024-03-25T16:49:40.576226Z",
            "url": "https://files.pythonhosted.org/packages/2a/dd/8be3ecd0faa48a13424d4823865d6ef9a380311a55a7358186f0015a5a11/checkout_sdk-3.0.21.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-25 16:49:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "checkout",
    "github_project": "checkout-sdk-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "checkout-sdk"
}
        
Elapsed time: 0.23050s