Payment Methods API¶
API для работы со способами оплаты.
- class aioyookassa.core.api.payment_methods.PaymentMethodsAPI(client: BaseAPIClient)[source]¶
Bases:
BaseAPI[CreatePaymentMethodParams,PaymentMethod]YooKassa payment methods API client.
Provides methods for creating and retrieving payment methods.
Initialize base API client.
- Parameters:
client – Base API client instance.
- async create_payment_method(params: CreatePaymentMethodParams | dict | None = None, **kwargs: Any) PaymentMethod[source]¶
Create a new payment method in YooKassa.
- Parameters:
params (Union[CreatePaymentMethodParams, dict, None]) – Payment method parameters (CreatePaymentMethodParams or dict).
kwargs – Additional parameters (merged with params if params is None or dict).
- Returns:
PaymentMethod object.
- Return type:
- Seealso:
- Example:
>>> from aioyookassa.types.params import ( ... CreatePaymentMethodParams, ... PaymentMethodCardData, ... PaymentMethodHolder, ... PaymentMethodConfirmation ... ) >>> params = CreatePaymentMethodParams( ... type="bank_card", ... card=PaymentMethodCardData( ... number="5555555555554444", ... expiry_year="2025", ... expiry_month="12", ... cardholder="John Doe", ... csc="123" ... ), ... holder=PaymentMethodHolder(gateway_id="gateway_123"), ... confirmation=PaymentMethodConfirmation( ... type="redirect", ... return_url="https://example.com/return" ... ) ... ) >>> payment_method = await client.payment_methods.create_payment_method(params)
- async get_payment_method(payment_method_id: str) PaymentMethod[source]¶
Retrieve payment method information by ID.
- Parameters:
payment_method_id (str) – Payment method identifier.
- Returns:
PaymentMethod object.
- Return type:
- Seealso:
Методы¶
create_payment_method¶
Создание нового способа оплаты.
from aioyookassa.types.params import (
CreatePaymentMethodParams,
PaymentMethodCardData,
PaymentMethodHolder,
PaymentMethodConfirmation
)
params = CreatePaymentMethodParams(
type="bank_card",
card=PaymentMethodCardData(
number="5555555555554444",
expiry_year="2025",
expiry_month="12",
cardholder="John Doe",
csc="123"
),
holder=PaymentMethodHolder(
gateway_id="gateway_123",
client_ip="192.168.1.1"
),
confirmation=PaymentMethodConfirmation(
type="redirect",
return_url="https://example.com/return"
)
)
payment_method = await client.payment_methods.create_payment_method(params)
get_payment_method¶
Получение информации о конкретном способе оплаты.
payment_method = await client.payment_methods.get_payment_method("payment_method_id")