Python client for Craftgate API
Project description
Craftgate Python Client
This repo contains the Python client for Craftgate API.
PyPI package: https://pypi.org/project/craftgate/
Requirements
- Python 3.6+
Installation
pip install craftgate
Usage
To access the Craftgate API you'll first need to obtain API credentials (API key & secret key). If you don't already have a Craftgate account, you can sign up at https://craftgate.io.
By default the client connects to production https://api.craftgate.io. For testing, use the sandbox URL
https://sandbox-api.craftgate.io.
from craftgate import Craftgate, RequestOptions
options = RequestOptions(
api_key="<YOUR API KEY>",
secret_key="<YOUR SECRET KEY>",
base_url="https://sandbox-api.craftgate.io"
)
payment = Craftgate(options).payment()
Example: Credit Card Payment
import uuid
from decimal import Decimal
from craftgate import Craftgate, RequestOptions
from craftgate.model import Currency, PaymentGroup, PaymentPhase
from craftgate.request import CreatePaymentRequest
from craftgate.request.dto import Card, PaymentItem
# Configure client (use sandbox for testing)
options = RequestOptions(
api_key="<YOUR API KEY>",
secret_key="<YOUR SECRET KEY>",
base_url="https://sandbox-api.craftgate.io"
)
craftgate = Craftgate(options)
payment = craftgate.payment()
# Build basket
items = []
for name, price in [("item 1", "30"), ("item 2", "50"), ("item 3", "20")]:
pi = PaymentItem()
pi.name = name
pi.external_id = str(uuid.uuid4())
pi.price = Decimal(price)
items.append(pi)
# Card info (sandbox test card)
card = Card()
card.card_holder_name = "Haluk Demir"
card.card_number = "5258640000000001"
card.expire_year = "2044"
card.expire_month = "07"
card.cvc = "000"
# Payment request
req = CreatePaymentRequest()
req.price = Decimal("100")
req.paid_price = Decimal("100")
req.wallet_price = Decimal("0")
req.installment = 1
req.currency = Currency.TRY
req.conversation_id = "456d1297-908e-4bd6-a13b-4be31a6e47d5"
req.payment_group = PaymentGroup.LISTING_OR_SUBSCRIPTION
req.payment_phase = PaymentPhase.AUTH
req.card = card
req.items = items
resp = payment.create_payment(req)
print(f"Create Payment Result: {resp}")
Examples
A variety of end-to-end samples (3DS, Checkout, APM, refunds, stored cards, marketplace, pre/post-auth) live under the
tests/ folder.
Run a single test:
python -m unittest tests/test_payment_sample.py::PaymentSample::test_create_payment
Contributions
For all contributions to this client please see the contribution guide at CONTRIBUTING.md.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file craftgate-1.0.1.tar.gz.
File metadata
- Download URL: craftgate-1.0.1.tar.gz
- Upload date:
- Size: 76.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ccc47371c4dd19b02e223eba044cbe8e2332b89ccc439abae71a5f99be78bf23
|
|
| MD5 |
ad6605861cfd11454b82539e632da1c0
|
|
| BLAKE2b-256 |
b4682f9d2784bb7632d326d9ce081bb0fbd74582b7c4efb05b7fc020c921709d
|
File details
Details for the file craftgate-1.0.1-py3-none-any.whl.
File metadata
- Download URL: craftgate-1.0.1-py3-none-any.whl
- Upload date:
- Size: 151.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fa9bffc83d1c6209a53fa5ca6cf723a4a2fd8d45d8cd3b6891909323e61237e
|
|
| MD5 |
53a2a5c004de2edd2478395e56745a57
|
|
| BLAKE2b-256 |
7491e3ae15f547652e7f0895374863fd0d9d4ae1da70a33b07c264382b3df355
|