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.1.8.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1bfcbda4238d5c4cd66df1bfc62ee24ab2f5583dc1c2e680c7c0f46f9d4cab2 |
|
MD5 | afb35b102d0a546bafceffe1b2fd909b |
|
BLAKE2b-256 | 1ed8f284d10f0d9102ebfc195d4cec3458de0a89474879de5d38e7031701eebd |
Hashes for peachpayments_partner_pydantic-0.1.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 631a32ecdd2c6d150aa425f027d8066026739004d388c90645ee0d9fdc183979 |
|
MD5 | 6d5b29a1c2f83e0c16e8387233205cac |
|
BLAKE2b-256 | 2d099fc60781b58e60fac8706c4717236db6a0ebbc5c548710b76a17a20f044f |