PeachPayments Partner Pydantic library contains Pydantic schemas to help integrate PeachPayments with their partners.
Project description
PeachPayments Partner Pydantic Library
Overview
PeachPayments Partner Pydantic Library is a platform-agnostic Python package to help Payment Service Providers in integrating with PeachPayments. This library provides functionality to validate request and response data using Pydantic Python library.
Source Code: https://gitlab.com/peachpayments/peach-partner-pydantic/
Key terms
Term | Definition |
---|---|
Partner API | A service provided by Peach Payments to enable Payment Service Providers to become available on the Peach Platform |
Payment Service Provider | A payment service provider who integrates with the Partner API |
Outbound API call | API calls sent from Partner API to the Payment Service Provider |
Inbound API call | API calls sent from Payment Service Provider to Partner API |
Usage
Package requires Python 3.9+
Installation
# pip
$ pip3 install peachpayments-partner-pydantic
# poetry
$ poetry add peachpayments-partner-pydantic
Field validation
Scenario: Payment Service Provider written in FastAPI receives a debit request from PeachPayments.
# ... imports
from peachpayments_partner_pydantic.schemas import DebitRequest, DebitResponse
@router.post(
"/v1/debit",
response_model=schemas.DebitResponse,
)
def debit_request(
*, debit_in: schemas.DebitRequest
) -> Any:
# Store the transaction
transaction = Transaction.create_from_debit(debit_in)
# Validate the debit response
debit_response = DebitResponse(**transaction.to_debit_response_fields())
return debit_response.dict()
Translating exception to PeachPayments error response
Scenario: Payment Service Provider written in FastAPI receives a request with a validation error from PeachPayments.
1. Write validation exception handler
# app/exception_handlers.py
from fastapi import Request, status
from fastapi.exceptions import RequestValidationError
from fastapi.responses import JSONResponse
from peachpayments_partner_pydantic.exception_handlers import exception_to_response
async def validation_exception_handler(request: Request, exc: RequestValidationError) -> JSONResponse:
return JSONResponse(status_code=status.HTTP_400_BAD_REQUEST, content=exception_to_response(exc))
2. Connect it to the application
# app/main.py
from fastapi import FastAPI
from fastapi.exceptions import RequestValidationError
from app.exception_handlers import validation_exception_handler
application = FastAPI(
exception_handlers={RequestValidationError: validation_exception_handler},
)
Project details
Release history Release notifications | RSS feed
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
Hashes for peachpayments_partner_pydantic-0.2.9.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc8273e95f346198f6210690182aae9f15f11c84d7b7574108c96d5659a6a066 |
|
MD5 | 9e2ea25c101aa764463185dd142a8a5c |
|
BLAKE2b-256 | 448610dcb3cffcd65ee78f335b7aa83a2b6bc2144202818f878ca1502824be70 |
Hashes for peachpayments_partner_pydantic-0.2.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e690e177432ef2e209a8da57fc0533856f245a8f1af50c2e9bad2a4bdaf8430 |
|
MD5 | e322c7698aff7f4ddb9d1e79a3bb5105 |
|
BLAKE2b-256 | 0e9d5e1bbfa853aa14b286839f2e15a577db47ab0ccbe268c762c8fbbed93d31 |