Skip to main content

Plural P3P Buyer SDK — x402 Plural P3P client for AI agents (Python)

Project description

Pine Labs Online P3P Buyer SDK (Python)

Python SDK for Pine Labs Online P3P buyer clients. It mirrors @pine-labs-online/p3p-buyer-sdk, intercepts HTTP 402 Payment Required responses, creates customer-scoped P3P payment credentials, and retries paid requests.

Installation

pip install pinelabs-p3p-buyer-sdk

Import module: pinelabs_p3p_buyer. Requires Python 3.9 or newer.

Quick Start

from pinelabs_p3p_buyer import (
    BuyerRuntimeContext,
    P3PEnvironment,
    PaymentGateway,
    PaymentMethod,
    PluralBuyer,
    PluralBuyerConfig,
)

buyer = PluralBuyer.create(PluralBuyerConfig(
    env=P3PEnvironment.SANDBOX,
    paymentGateway=PaymentGateway.PineLabsOnline,
    selectedPaymentMethod=PaymentMethod.UpiSbmd,
))

response = buyer.get(
    "https://seller.example.com/api/premium",
    context=BuyerRuntimeContext(
        customerKey="customer-api-token",
        customerReference="9876543210",
        mobileNumber="9876543210",
    ),
)
print(response.json())
buyer.close()

Customer identity is runtime context, not static SDK config. This lets one buyer instance safely serve many customers.

402 Flow

  1. Your code calls buyer.get(url, context=...).
  2. The seller returns HTTP 402 with WWW-Authenticate: Payment <challenge>.
  3. The SDK decodes the challenge and validates paymentGateway == "PINE LABS ONLINE".
  4. The SDK calls POST /api/v1/customer/mpp/token with:
    • X-Customer-Key: <context.customerKey>
    • customer.mobile_number
    • challenge_id
    • payment_amount.value in minor units
  5. The SDK retries the seller with P3P-Credential: Payment <credential>.
  6. The seller captures the payment and may return Payment-Receipt.

Direct Token API

from pinelabs_p3p_buyer import Amount, CreateTokenOptions, PaymentMethod

token = buyer.methods.create_token(CreateTokenOptions(
    customerKey="customer-api-token",
    customerReference="9876543210",
    mobileNumber="9876543210",
    challengeId="ch_...",
    paymentAmount=Amount(value=50000, currency="INR"),
    paymentMethod=PaymentMethod.UpiSbmd,
))

The buyer SDK no longer creates mandates. Mandate/pre-authorization creation is handled by the seller SDK.

Supported Methods

  • PaymentMethod.UpiSbmd -> "SBMD" / UPI ReservePay
  • PaymentMethod.Crypto -> "CRYPTO"

Error Handling

from pinelabs_p3p_buyer import P3PChallengeError, P3PError, P3PNetworkError

try:
    response = buyer.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_mpp_client_sdk-0.1.3.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

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

pinelabs_online_mpp_client_sdk-0.1.3-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

Details for the file pinelabs_online_mpp_client_sdk-0.1.3.tar.gz.

File metadata

File hashes

Hashes for pinelabs_online_mpp_client_sdk-0.1.3.tar.gz
Algorithm Hash digest
SHA256 346b0b2aa9380673bfc433165d463e6e38c14765dc0283e16dd0cbc3b213aad5
MD5 173f9d062c407d860556e5d050551746
BLAKE2b-256 38fb5f9b01644d2335a07a46b8fd212025cd4842fb432bca6ee8bc7c151137b2

See more details on using hashes here.

File details

Details for the file pinelabs_online_mpp_client_sdk-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for pinelabs_online_mpp_client_sdk-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1a995acedf3b4c754f7869e481e63f86ef84fbb088dc500a7a72e3f80541cd80
MD5 bd55cc0309a721c1f4772df2d37cd8a0
BLAKE2b-256 b769beabc75fe04e758e53483b07c8812212d35d8a1d47be066cda67bc437e75

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