-
Notifications
You must be signed in to change notification settings - Fork 6
DelegatedPayments
Delegated payments allow an agent to send payment method details once, receive a vault token, and use that token to complete checkout. Storage and order placement are extensible via handlers.
- Path:
POST agentic_commerce/delegate_payment - Request:
DelegatePaymentRequestInterface - Response:
DelegatePaymentResponseInterface(idtoken,createdISO-8601,metadata)
By default, this module does not store any payment data as the implementation logic will be different depending on what PSP is used by the merchant. To enable delegated payments, it's required to implement a
class that implements Magebit\AgenticCommerce\Api\PaymentMethodVaultHandlerInterface and handles the storage of the
payment method data. Payment Method Vault handler will receive DelegatePaymentRequestInterface object and must return a vault token.
An example for an imaginary FooBar payment service provider:
<?php
namespace My\Module\AgenticCommerce\Model;
use Magebit\AgenticCommerce\Api\PaymentMethodVaultHandlerInterface;
use Magebit\AgenticCommerce\Api\Data\Request\DelegatePaymentRequestInterface;
class FooBarPaymentVaultHandler implements DelegatePaymentRequestInterface
{
/**
* @param DelegatePaymentRequestInterface $request
* @return bool
*/
public function canStore(DelegatePaymentRequestInterface $request): bool
{
return $request->getPaymentMethod()->getType() === 'card';
}
/**
* @param DelegatePaymentRequestInterface $request
* @return string
*/
public function handle(DelegatePaymentRequestInterface $request): string
{
$fooBarVaultToken = $this->fooBarPaymentsApi->createPaymentMethod([
'type' => 'card',
'number' => $request->getPaymentMethod()->getNumber(),
'expMonth' => $request->getPaymentMethod()->getExpMonth(),
'expYear' => $request->getPaymentMethod()->getExpYear(),
'cvc' => $request->getPaymentMethod()->getCvc(),
]);
return $fooBarVaultToken->id;
}
}Vault handler class must be registered in di.xml:
<type name="Magebit\AgenticCommerce\Service\DelegatePaymentService">
<arguments>
<argument name="paymentMethodVaultHandlers" xsi:type="array">
<item name="foo_bar" xsi:type="object">My\Module\AgenticCommerce\Model\FooBarPaymentVaultHandler</item>
</argument>
</arguments>
</type>