Skip to main content

Ginger Python bindings

Build Status MIT License

Requirements

  • Python 3.6 or later
  • requests 2.20 or later

Installation

You can install the Python bindings from PyPI:

pip install ginger-sdk

You can also use the Python bindings without using the Python Package Index by placing the ginger_sdk directory somewhere in your PYTHONPATH.

Getting started

First create a new API client with your API key and API endpoint:

from ginger_sdk import Ginger

client = Ginger.create_client('https://api.example.com', 'your-api-key')

Initiating a payment

You can start a new payment by creating a new order:

order = client.create_order(
    {
        'merchant_order_id': 'my-custom-order-id-12345',
        'currency': 'EUR',
        'amount': 2500,  # Amount in cents
        'description': 'Purchase order 12345',
        'return_url': 'https://www.example.com',
        'transactions': [
            {
                'payment_method': 'credit-card',
            }
        ]
    }
)

Once you've created your order, a transaction is created and associated with it. You will need to redirect the user to the transaction's payment URL, which you can retrieve as follows:

payment_url = order['order_url']

It is also recommended that you store the order's ID somewhere, so you can retrieve information about it later:

order_id = order['id']

There is a lot more data related to an order. Please refer to the API documentation provided by your PSP to learn more about the various payment methods and options.

Getting an order

If you want to retrieve an existing order, use the get_order method on the client:

order = client.get_order(order_id)

This will return an associative array with all order information.

Updating an order

Some fields are not read-only and you are able to update them after order has been created. You can do this using the update_order method on the client:

order = client.get_order(order_id)
order['description'] = 'New Order Description'
updated_order = client.update_order(order)

Initiating a refund

You can refund an existing order by using the refund_order method on the client:

refund_order = client.refund_order(order_id, {'amount': 123, 'description': 'My refund'})

Capturing an order

You can initiate a capture of an order's transaction by using the capture_order_transaction method:

client.capture_order_transaction(order_id, transaction_id)

Getting the iDEAL issuers

When you create an order with the iDEAL payment method, you need to provide an issuer ID. The issuer ID is an identifier of the bank the user has selected. You can retrieve all possible issuers by using the get_ideal_issuers method:

issuers = client.get_ideal_issuers()

You can then use this information to present a list to the user of possible banks to choose from.

Custom requests

You can send any request that the API accepts using the send method. E.g. instead of using the create_order method you could also use the following:

result = client.send(
    'POST',      # Request method
    '/orders/',  # API path
    order_data   # Data to send with the request; optional
)

The $result variable would then contain the decoded JSON returned by the API.

Using a different CA bundle

If you need to use a different CA bundle than the one that comes with your system, you can install the Certifi package from PyPI.

pip install certifi

The certificates supplied by Certifi will be automatically used.

Custom HTTP client

This library ships with its own minimal HTTP client for compatibility reasons. If you would like to use a different HTTP client, you can do so by extending the ginger_sdk.http_client.HttpClient abstract base class and then constructing your own client:

from ginger_sdk.api_client import ApiClient

my_http_client = MyHttpClient()
client = ApiClient(my_http_client)

Make sure your HTTP client prefixes the endpoint URL and API version to all requests, and uses HTTP basic auth to authenticate with the API using your API key.

API documentation

For the complete API documentation please prefer to the resources provided by your PSP.

Release files for ginger-sdk 2.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ginger-sdk 2.1.3
File Size Uploaded
ginger-sdk-2.1.3.tar.gz 5.2 kB Details

Release files / ginger-sdk-2.1.3.tar.gz

Download URL ginger-sdk-2.1.3.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b04daaba52005d50cc9a7232a920f2b45a3a6b768cc36ea36cb86009fed47ab6
BLAKE2b-256 checksum
How to use checksums
033ebf7626283e7f9654296e8c66d46696287bd8928a999d479be8d2374c891b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.7

Release history Release notifications | RSS feed

This release

2.1.3 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page