Skip to content

DelegatedPayments

KristofersOzolinsMagebit edited this page Oct 14, 2025 · 1 revision

Delegated Payments

On this page

Overview

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.

Endpoint

  • Path: POST agentic_commerce/delegate_payment
  • Request: DelegatePaymentRequestInterface
  • Response: DelegatePaymentResponseInterface (id token, created ISO-8601, metadata)

Vault handlers

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>

Clone this wiki locally