Providers¶
Base Class and Registry¶
Provider ¶
Bases: ABC
Abstract base class for payment provider integrations.
Source code in merchants/providers/__init__.py
Functions¶
get_info ¶
Return a :class:ProviderInfo populated from this provider's class attributes.
Source code in merchants/providers/__init__.py
create_checkout
abstractmethod
¶
create_checkout(
amount: Decimal,
currency: str,
success_url: str,
cancel_url: str,
metadata: dict[str, Any] | None = None,
**kwargs: Any,
) -> CheckoutSession
Create a hosted-checkout session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kwargs
|
Any
|
Provider-specific keyword arguments (e.g. |
{}
|
Returns:
| Type | Description |
|---|---|
CheckoutSession
|
class: |
Raises:
| Type | Description |
|---|---|
|
class: |
Source code in merchants/providers/__init__.py
get_payment
abstractmethod
¶
Retrieve and normalise the status of a payment.
Returns:
| Type | Description |
|---|---|
PaymentStatus
|
class: |
PaymentStatus
|
class: |
Source code in merchants/providers/__init__.py
parse_webhook
abstractmethod
¶
Parse and normalise a raw webhook payload.
Returns:
| Type | Description |
|---|---|
WebhookEvent
|
class: |
UserError ¶
Bases: Exception
Raised when a provider returns a user-level / validation error.
Source code in merchants/providers/__init__.py
register_provider ¶
get_provider ¶
Return a provider by string key or pass through a Provider instance.
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Source code in merchants/providers/__init__.py
list_providers ¶
normalise_state ¶
Map a provider-specific status string to a :class:~merchants.models.PaymentState.
Built-in Providers¶
StripeProvider ¶
Bases: Provider
Stripe-like provider stub.
Demonstrates:
- Converting amounts to/from minor units (cents).
- Authorization: Bearer <key> auth header.
- Stripe-style status strings in state normalisation.
.. note::
This is a stub - it does not call the real Stripe API.
Replace base_url and inject a real transport to connect to Stripe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str
|
Stripe secret key ( |
required |
base_url
|
str
|
Override for testing; defaults to |
'https://api.stripe.com'
|
transport
|
Transport | None
|
Optional custom transport. |
None
|
Source code in merchants/providers/stripe.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
PayPalProvider ¶
Bases: Provider
PayPal-like provider stub.
Demonstrates:
- Sending amounts as decimal strings (e.g. "19.99").
- Authorization: Bearer <token> auth header.
- PayPal-style status strings in state normalisation.
.. note::
This is a stub - it does not call the real PayPal API.
Replace base_url and inject a real transport to connect to PayPal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_token
|
str
|
OAuth access token. |
required |
base_url
|
str
|
Override for testing; defaults to |
'https://api-m.paypal.com'
|
transport
|
Transport | None
|
Optional custom transport. |
None
|
Source code in merchants/providers/paypal.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
GenericProvider ¶
Bases: Provider
A minimal HTTP provider that POST/GET against configurable endpoints.
This is useful for custom or in-house payment gateways that follow a simple REST interface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkout_url
|
str
|
Endpoint to |
required |
payment_url_template
|
str
|
URL template with |
required |
transport
|
Transport | None
|
Optional custom :class: |
None
|
Source code in merchants/providers/generic.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
DummyProvider ¶
Bases: Provider
Local development / testing provider.
Returns plausible random data without hitting any real API. Useful for rapid iteration and unit-testing application code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
Fake base URL included in the redirect URL
(default: |
'https://dummy-pay.example.com'
|
always_state
|
PaymentState | None
|
If set, every :meth: |
None
|