| description | Use PHP API to manage payments in Commerce. You can create, update and delete payments. |
|---|---|
| edition | commerce |
To get payments and manage them, use the Ibexa\Contracts\Payment\PaymentServiceInterface interface.
By default, UUID is used to generate payment identifiers.
You can change that by providing a custom payment identifier in Ibexa\Contracts\Payment\Payment\PaymentCreateStruct or Ibexa\Contracts\Payment\Payment\PaymentUpdateStruct.
To access a single payment by using its numerical ID, use the PaymentServiceInterface::getPayment method:
[[= include_code('code_samples/api/commerce/src/Command/PaymentCommand.php', 45, 48, remove_indent=True) =]]To access a single payment by using its string identifier, use the PaymentServiceInterface::getPaymentByIdentifier method:
[[= include_code('code_samples/api/commerce/src/Command/PaymentCommand.php', 51, 52, remove_indent=True) =]]To fetch multiple payments, use the PaymentServiceInterface::findPayments method.
It follows the same search query pattern as other APIs:
[[= include_code('code_samples/api/commerce/src/Command/PaymentCommand.php', 60, 75, remove_indent=True) =]]To create a payment, use the PaymentServiceInterface::createPayment method and provide it with the Ibexa\Contracts\Payment\Payment\PaymentCreateStruct object that takes the following arguments: method, order and amount.
[[= include_code('code_samples/api/commerce/src/Command/PaymentCommand.php', 78, 91, remove_indent=True) =]]You can update payment information after the payment is created.
You could do it to support a scenario when, for example, an online payment failed, has been processed by using other means, and its status has to be updated in the system.
The Ibexa\Contracts\Payment\Payment\PaymentUpdateStruct object takes the following arguments: transition, identifier, and context.
To update payment information, use the PaymentServiceInterface::updatePayment method:
[[= include_code('code_samples/api/commerce/src/Command/PaymentCommand.php', 94, 99, remove_indent=True) =]]To delete a payment from the system, use the PaymentServiceInterface::deletePayment method:
[[= include_code('code_samples/api/commerce/src/Command/PaymentCommand.php', 102, 102, remove_indent=True) =]]