Python client for Craftgate API
Project description
Craftgate Python Client
This repo contains the Python client for Craftgate API.
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.request_options import RequestOptions
from craftgate.adapter.payment_adapter import PaymentAdapter
options = RequestOptions(
api_key="<YOUR API KEY>",
secret_key="<YOUR SECRET KEY>",
base_url="https://sandbox-api.craftgate.io"
)
payment = PaymentAdapter(options)
Example: Credit Card Payment
import uuid
from decimal import Decimal
from craftgate.adapter.payment_adapter import PaymentAdapter
from craftgate.request_options import RequestOptions
from craftgate.model.currency import Currency
from craftgate.model.payment_group import PaymentGroup
from craftgate.model.payment_phase import PaymentPhase
from craftgate.request.create_payment_request import CreatePaymentRequest
from craftgate.request.dto.card import Card
from craftgate.request.dto.payment_item import 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"
)
payment = PaymentAdapter(options)
# 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.0.tar.gz.
File metadata
- Download URL: craftgate-1.0.0.tar.gz
- Upload date:
- Size: 75.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f82c0448d70be9a889b6265ed247fdc29e76455130af8611642d191a12ef91fa
|
|
| MD5 |
29356d644e495a25b3cc44f45a63a0f4
|
|
| BLAKE2b-256 |
04c51d87ccdd36760bdb20aa4fc104b78569c0997b84374c48e77b209c6b2ade
|
File details
Details for the file craftgate-1.0.0-py3-none-any.whl.
File metadata
- Download URL: craftgate-1.0.0-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.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51ef6f675c056cf364f906cbd242663af980444440f35ecf89761172fbe2feac
|
|
| MD5 |
db1be3f29dd06080be2f1fe49b07e294
|
|
| BLAKE2b-256 |
099bb40fcd83166c70cb742b25608687394da80d3833c82d47c3c7d04d05442a
|