Pine Labs Online P3P Client SDK — x402 Pine Labs Online P3P client for AI agents (Python)
Project description
Pine Labs Online P3P Client SDK (Python)
Python SDK for Pine Labs Online P3P client integrations. It mirrors
@pine-labs-online/p3p-client-sdk, intercepts HTTP 402 Payment Required
responses, creates customer-scoped P3P payment credentials, and retries paid
requests.
Installation
pip install pinelabs-p3p-client-sdk
Import module: pinelabs_p3p_client. Requires Python 3.9 or newer.
Quick Start
from pinelabs_p3p_client import (
ClientRuntimeContext,
P3PEnvironment,
PaymentMethod,
PineLabsOnlineClient,
PineLabsOnlineClientConfig,
)
client = PineLabsOnlineClient.create(PineLabsOnlineClientConfig(
env=P3PEnvironment.SANDBOX,
selectedPaymentMethod=PaymentMethod.UPI_RESERVE_PAY,
clientId="client-client-id",
clientSecret="client-client-secret",
))
response = client.get(
"https://server.example.com/api/premium",
context=ClientRuntimeContext(
customerReference="9876543210",
mobileNumber="9876543210",
),
)
print(response.json())
client.close()
Customer identity is runtime context, not static SDK config. This lets one client instance safely serve many customers.
By default, the SDK uses client-credentials customer auth: it exchanges
clientId and clientSecret through POST /api/auth/v1/token, then calls
POST /mpp/v1/token.
For customer API-token flows, explicitly set
customerAuthMode=P3PCustomerAuthMode.CustomerKey and pass customerKey plus
mobileNumber in ClientRuntimeContext.
402 Flow
- Your code calls
client.get(url, context=...). - The server returns
HTTP 402withWWW-Authenticate: Payment <challenge>. - The SDK decodes the challenge and validates amount, expiry, and accepted payment methods.
- The SDK creates a token:
- default mode:
POST /mpp/v1/tokenwithAuthorization: Bearer <token> - customer-key mode:
POST /api/v1/customer/mpp/tokenwithX-Customer-Key customer.merchant_customer_referenceand/orcustomer.mobile_numberchallenge_idpayment_amount.valuein minor units
- default mode:
- The SDK retries the server with
P3P-Credential: Payment <credential>. - The server captures the payment and may return
Payment-Receipt.
Direct Token API
from pinelabs_p3p_client import Amount, CreateTokenOptions, PaymentMethod
token = client.methods.create_token(CreateTokenOptions(
customerReference="9876543210",
mobileNumber="9876543210",
challengeId="ch_...",
paymentAmount=Amount(value=50000, currency="INR"),
paymentMethod=PaymentMethod.UPI_RESERVE_PAY,
))
The client SDK no longer creates mandates. Mandate/pre-authorization creation is handled by the server SDK.
Customer-key mode remains available:
from pinelabs_p3p_client import P3PCustomerAuthMode
customer_key_client = PineLabsOnlineClient.create(PineLabsOnlineClientConfig(
env=P3PEnvironment.SANDBOX,
selectedPaymentMethod=PaymentMethod.UPI_RESERVE_PAY,
customerAuthMode=P3PCustomerAuthMode.CustomerKey,
))
Supported Methods
PaymentMethod.UPI_RESERVE_PAY->"SBMD"/ UPI ReservePayPaymentMethod.Crypto->"CRYPTO"
Error Handling
from pinelabs_p3p_client import P3PChallengeError, P3PError, P3PNetworkError
try:
response = client.get(url, context=runtime_context)
except P3PChallengeError as err:
...
except P3PNetworkError as err:
...
except P3PError as err:
print(err.code, err.http_status, err.details)
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
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 pinelabs_online_p3p_client_sdk-0.1.3.tar.gz.
File metadata
- Download URL: pinelabs_online_p3p_client_sdk-0.1.3.tar.gz
- Upload date:
- Size: 21.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
823df809db0c136e250f71f11e93caa70fd90e8370c3cb6adf375fa74c86bf79
|
|
| MD5 |
8c67e9278209e2a4d7126f0080a07b23
|
|
| BLAKE2b-256 |
22660386f156e3a78c989514625833292c6fd5f194c441d02a0e5e4e0b2d3b47
|
File details
Details for the file pinelabs_online_p3p_client_sdk-0.1.3-py3-none-any.whl.
File metadata
- Download URL: pinelabs_online_p3p_client_sdk-0.1.3-py3-none-any.whl
- Upload date:
- Size: 25.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80fc61c10372ac42f40db43bcf009918dec23227e7670edff517c315f15b7245
|
|
| MD5 |
0d636069bf3b1e1a5c9dc376f8cafbdc
|
|
| BLAKE2b-256 |
fd56305636c86951b0e5f00dd3f358f220b099e11081e17506645c8235ef602e
|