Skip to main content

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

  1. Your code calls client.get(url, context=...).
  2. The server returns HTTP 402 with WWW-Authenticate: Payment <challenge>.
  3. The SDK decodes the challenge and validates amount, expiry, and accepted payment methods.
  4. The SDK creates a token:
    • default mode: POST /mpp/v1/token with Authorization: Bearer <token>
    • customer-key mode: POST /api/v1/customer/mpp/token with X-Customer-Key
    • customer.merchant_customer_reference and/or customer.mobile_number
    • challenge_id
    • payment_amount.value in minor units
  5. The SDK retries the server with P3P-Credential: Payment <credential>.
  6. 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 ReservePay
  • PaymentMethod.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

pinelabs_online_p3p_client_sdk-0.1.4.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file pinelabs_online_p3p_client_sdk-0.1.4.tar.gz.

File metadata

File hashes

Hashes for pinelabs_online_p3p_client_sdk-0.1.4.tar.gz
Algorithm Hash digest
SHA256 a8f0f7b1b5577a2a231001df6f1abc2f0fcbef36709f546f60181fb0e0682dac
MD5 df23c39798a68c6e2c974c19b49279ca
BLAKE2b-256 166b8c9e9d8c40f9aff8e0e30e929972f685f637b411e0d0a2a6f02bbec25917

See more details on using hashes here.

File details

Details for the file pinelabs_online_p3p_client_sdk-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for pinelabs_online_p3p_client_sdk-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f218a131413f6a864ca356bfa75f6ec48714a76254c61c645ce03f01cf3499a9
MD5 fec33377fee843662be4e690ece1ea42
BLAKE2b-256 6c7dedd5c41d74f570df1cca86b40ff9635433ecdfb92649b23fd792fe5458f0

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