This directory contains the Python implementation of the Google Pay PSP client library. It currently covers 4 PSPs — Adyen, Checkout.com, Square, and Stripe. More PSPs will be added as official Python libraries or REST integrations are introduced.
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtpython -m unittest discover -s testsEvery PSP module exposes a pay(config, order) method. order requires a total, currency, and either a raw Google
Pay paymentResponse or an already-extracted paymentToken.
from psp_client import clients, PaymentValidationError
# PSP-specific configuration, in this case Stripe.
config = {
"secretKey": "sk_test_...",
}
# An order requires a total, currency, and client-side response from the Google Pay API.
order = {
"total": 100,
"currency": "USD",
"paymentResponse": payment_response, # raw response from the Google Pay API
}
try:
response = clients["stripe"].pay(config, order)
print(response) # PSP-specific response
except PaymentValidationError as err:
print(err.error) # validation message
except Exception as err:
print(err) # PSP-specific error- Add a new module to
psp_client/handlers/. It should export a singlepay(config, order)function that performs the charge and returns the PSP's response, raising on failure. - Register it in the
clientsdict inpsp_client/__init__.py. - The
orderpassed to your handler has already been validated and normalized bypsp_client/order.py— you can rely on:order["totalInt"]— the total amount in the smallest possible unit (e.g. cents for USD)order["totalFixed"]— the rounded total amount as a fixed-precision decimal stringorder["paymentToken"]— the Google Pay token, JSON-decoded into adictwhen possible (left as a raw string otherwise, e.g. for PSPs like Square whose token is a plain nonce)