Client¶
Client ¶
Main entry point for the merchants SDK.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
Provider | str
|
A :class: |
required |
auth
|
AuthStrategy | None
|
Optional :class: |
None
|
transport
|
Transport | None
|
Optional custom :class: |
None
|
base_url
|
str
|
Optional base URL used by :meth: |
''
|
Example::
from merchants import Client
from merchants.providers.stripe import StripeProvider
client = Client(provider=StripeProvider(api_key="sk_test_…"))
result = client.payments.create_checkout(
amount="19.99",
currency="USD",
success_url="https://example.com/success",
cancel_url="https://example.com/cancel",
)
Source code in merchants/client.py
Functions¶
request ¶
request(
method: str,
path: str,
*,
json: Any = None,
params: dict[str, str] | None = None,
headers: dict[str, str] | None = None,
timeout: float = 30.0,
) -> HttpResponse
Low-level HTTP escape hatch for provider-specific calls.
Applies configured auth if present and uses the configured transport.
Raises:
| Type | Description |
|---|---|
|
class: |
Source code in merchants/client.py
PaymentsResource ¶
Resource object exposed as client.payments.
Provides hosted-checkout creation and payment status retrieval.
Source code in merchants/client.py
Functions¶
create_checkout ¶
create_checkout(
amount: Decimal | int | float | str,
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 |
|---|---|---|---|
amount
|
Decimal | int | float | str
|
Payment amount; converted to :class: |
required |
currency
|
str
|
ISO-4217 currency code (e.g. |
required |
success_url
|
str
|
URL to redirect to after successful payment. |
required |
cancel_url
|
str
|
URL to redirect to when the user cancels. |
required |
metadata
|
dict[str, Any] | None
|
Optional key-value pairs passed to the provider. |
None
|
**kwargs
|
Any
|
Provider-specific keyword arguments (e.g. |
{}
|
Returns:
| Type | Description |
|---|---|
CheckoutSession
|
class: |
CheckoutSession
|
|
Raises:
| Type | Description |
|---|---|
|
class: |
Source code in merchants/client.py
get ¶
Retrieve and normalise the status of a payment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payment_id
|
str
|
Provider-specific payment / session identifier. |
required |
Returns:
| Type | Description |
|---|---|
PaymentStatus
|
class: |