Skip to main content

Python client for Craftgate API

Project description

Craftgate Python Client

Gitpod ready-to-code

This repo contains the Python client for Craftgate API.

PyPI package: https://pypi.org/project/craftgate/

Open in Gitpod

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

craftgate-1.0.2.tar.gz (76.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

craftgate-1.0.2-py3-none-any.whl (151.8 kB view details)

Uploaded Python 3

File details

Details for the file craftgate-1.0.2.tar.gz.

File metadata

  • Download URL: craftgate-1.0.2.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

Hashes for craftgate-1.0.2.tar.gz
Algorithm Hash digest
SHA256 6d1046d730efe67b8825bd240b52e0d5e1473d56420c17072c1d5e0ec95c36df
MD5 fb84fe5877124c6b15d01e9c28f960c8
BLAKE2b-256 3e47a9712bcfda148515f7c6d254063f0672b6a0359686034e90d3104dc6ba13

See more details on using hashes here.

File details

Details for the file craftgate-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: craftgate-1.0.2-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

Hashes for craftgate-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 13d5e33782217674699308a8794cc56670cd069dbb1dd0e89f5c6b17c802e412
MD5 0e988e6338b0a3bf6da845fefd64db88
BLAKE2b-256 7e66d1eb9d2de151290fd949904ad3c022af0efa2e7c6e77bbf54ffed9565102

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page