Skip to main content

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},
)

Release files for peachpayments-partner-pydantic 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for peachpayments-partner-pydantic 1.2.0
File Size Uploaded
peachpayments_partner_pydantic-1.2.0.tar.gz 11.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for peachpayments-partner-pydantic 1.2.0
File Interpreter ABI Platform
peachpayments_partner_pydantic-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 26.6 kB

Release files / peachpayments_partner_pydantic-1.2.0.tar.gz

Download URL peachpayments_partner_pydantic-1.2.0.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
82b6804de5bb2e1848f181610a3b68812bc66732a7e3abc00d3f13e41e7ece6e
BLAKE2b-256 checksum
How to use checksums
7a30639ab397d39239f9b7c2da159968828e6e36dc67074bb7e228153790645f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.9.17 Linux/5.4.0-1088-aws

Release files / peachpayments_partner_pydantic-1.2.0-py3-none-any.whl

Download URL peachpayments_partner_pydantic-1.2.0-py3-none-any.whl
Size 14.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9f6a815f13a375d73f0e3c102a4079b900c5182be5235915ab792f3c3021a090
BLAKE2b-256 checksum
How to use checksums
3450073e7c9a51a5919d003586bd24aaa2129ddb76a0a25eca155e4cb5bc7676
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.9.17 Linux/5.4.0-1088-aws

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.0

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page