Skip to main content

YouCanPay SDK

A Python SDK for integrating with the YouCan Pay payment gateway.

Installation

pip install youcanpay-sdk

Usage

from youcanpay import YouCanPay

# Initialize the client
client = YouCanPay(
    private_key="pri_your_private_key",
    public_key="pub_your_public_key",
    sandbox=True  # Set to False for production
)

# Create a payment token
try:
    token = client.create_payment_token(
        order_id="order_123",
        amount=1000,  # 10.00 MAD (in cents)
        currency="MAD",
        customer_ip="123.123.123.123",
        success_url="https://yourdomain.com/success",
        error_url="https://yourdomain.com/error",
        customer_info={
            "name": "John Doe",
            "email": "john@example.com",
            "phone": "+212600000000"
        },
        metadata={
            "description": "Test payment"
        }
    )
    print(f"Payment token: {token['id']}")
    print(f"Redirect URL: {token['redirect_url']}")
except YouCanPayError as e:
    print(f"Error: {e}")

# Get transaction details
try:
    transaction = client.get_transaction("transaction_id")
    print(f"Transaction status: {transaction['status']}")
except YouCanPayError as e:
    print(f"Error: {e}")

# Refund a transaction
try:
    refund = client.refund_transaction("transaction_id", amount=500)  # Partial refund of 5.00 MAD
    print(f"Refund status: {refund['status']}")
except YouCanPayError as e:
    print(f"Error: {e}")

Features

  • Create payment tokens
  • Get transaction details
  • Process refunds
  • Support for sandbox and production environments
  • Type hints for better IDE support

Requirements

  • Python 3.6+
  • requests>=2.25.1

License

MIT License

Metadata

Release files for youcanpay-sdk 0.1.0

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

Source distribution (sdist)

Source distribution for youcanpay-sdk 0.1.0
File Size Uploaded
youcanpay_sdk-0.1.0.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for youcanpay-sdk 0.1.0
File Interpreter ABI Platform
youcanpay_sdk-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.7 kB

Release files / youcanpay_sdk-0.1.0.tar.gz

Download URL youcanpay_sdk-0.1.0.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b891fba9a6fea2f83c4880a80c1b97dbc4928452ff2987ad6fb89daedd764e7f
BLAKE2b-256 checksum
How to use checksums
28dd08729468a5bc7b21a018c17d0138d14799cf46dd280a45bf6d49501d30f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.6

Release files / youcanpay_sdk-0.1.0-py3-none-any.whl

Download URL youcanpay_sdk-0.1.0-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
779b2a54d2b34b51a4d488ecdb106224d052c4009f1f5f3b6692f04ab2b0aa70
BLAKE2b-256 checksum
How to use checksums
6231d5d94621a1ae8a0b66f974144d5c4fcce748e5b382c4f61f30c1c22ea940
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.6

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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