Retrieve and use payment details from third-party PSPs

Edit on GitHub

This document describes how to retrieve and use payment details from third-party payment service providers (PSPs).

Configure payment details to be retrieved

  1. Install the required modules using Composer:
composer require spryker/sales-payment-detail
  1. In config/Shared/config_default.php, add or update the shared configs:
//...

use Generated\Shared\Transfer\PaymentCreatedTransfer;

$config[MessageBrokerConstants::MESSAGE_TO_CHANNEL_MAP] = [
    //...
    PaymentCreatedTransfer::class => 'payment-events',
];

$config[MessageBrokerConstants::CHANNEL_TO_RECEIVER_TRANSPORT_MAP] = [
    //...
    'payment-events' => MessageBrokerAwsConfig::HTTP_CHANNEL_TRANSPORT,
];

  1. In src/Pyz/Zed/MessageBroker/MessageBrokerDependencyProvider.php, add or update the config of the message broker dependency provider:

namespace Pyz\Zed\MessageBroker;

use Spryker\Zed\MessageBroker\MessageBrokerDependencyProvider as SprykerMessageBrokerDependencyProvider;
use Spryker\Zed\SalesPaymentDetail\Communication\Plugin\MessageBroker\PaymentCreatedMessageHandlerPlugin;

class MessageBrokerDependencyProvider extends SprykerMessageBrokerDependencyProvider
{
    /**
     * @return array<\Spryker\Zed\MessageBrokerExtension\Dependency\Plugin\MessageHandlerPluginInterface>
     */
    public function getMessageHandlerPlugins(): array
    {
        return [
            //...

            # This plugin is handling the `PaymentCreated` messages sent from any Payment App that supports this feature.
            new PaymentCreatedMessageHandlerPlugin(),
        ];
    }
}

  1. In src/Pyz/Zed/MessageBroker/MessageBrokerConfig.php, add or update the config of the message broker channels:
namespace Pyz\Zed\MessageBroker;

use Spryker\Zed\MessageBroker\MessageBrokerConfig as SprykerMessageBrokerConfig;

class MessageBrokerConfig extends SprykerMessageBrokerConfig
{
    /**
     * @return array<string>
     */
    public function getDefaultWorkerChannels(): array
    {
        return [
            //...
            'payment-events',
        ];
    }

    //...
}

Using payment details from third-party PSPs

When a third-party PSP supports this feature, your shop receives asynchronous messages about each payment when it’s created.

To use the data of the spy_sales_payment_detail table, you need to combine the data from the table with the entity you are fetching from the database to which this payment detail is related.

When the payment is used in the normal order process, the payment detail can be combined by using spy_sales_order.order_reference and spy_sales_payment_detail.entity_reference.