Payments feature integration

Edit on GitHub
You are browsing a previous version of the document. The latest version is 202212.0.
The following feature integration guide expects the basic feature to be in place.
The current feature integration guide only adds the following functionalities:
  • Payment Back Office UI;
  • Payment method per store;
  • Payment data import.

Install Feature Core

Prerequisites

To start the feature integration, overview and install the necessary features:

Name Version
Spryker Core 202001.0

1) Install the required modules using Composer

Run the following command(s) to install the required modules:

composer require "spryker-feature/payments:^202001.0" "spryker/checkout-rest-api:^3.0.0" --update-with-dependencies
Verification
Make sure that the following modules have been installed:
ModuleExpected Directory
`PaymentDataImport``vendor/spryker/payment-data-import`
`PaymentGui``vendor/spryker/payment-gui`

2) Set up Database Schema and Transfer Objects

Run the following commands to apply database changes and generate entity and transfer changes:

console transfer:generate
console propel:install
console transfer:generate
Verification
Make sure that the following changes have been applied by checking your database:
Database EntityTypeEvent
`spy_payment_method`tablecreated
`spy_payment_provider`tablecreated
`spy_payment_method_store`tablecreated
Verification
Make sure that the following changes have been applied in transfer objects:
TransferTypeEventPath
`PaymentMethodTransfer`classcreated`src/Generated/Shared/Transfer/PaymentMethodTransfer`
`PaymentProviderTransfer`classcreated`src/Generated/Shared/Transfer/PaymentProviderTransfer`
`PaymentMethodResponseTransfer`classcreated`src/Generated/Shared/Transfer/PaymentMethodResponseTransfer`
`StoreTransfer`classcreated`src/Generated/Shared/Transfer/StoreTransfer`
`DataImporterConfigurationTransfer`classcreated`src/Generated/Shared/Transfer/DataImporterConfigurationTransfer`
`DataImporterReaderConfigurationTransfer`classcreated`src/Generated/Shared/Transfer/DataImporterReaderConfigurationTransfer`
`DataImporterReportTransfer`classcreated`src/Generated/Shared/Transfer/DataImporterReportTransfer`
`DataImporterReportMessageTransfer`classcreated`src/Generated/Shared/Transfer/DataImporterReportMessageTransfer`

3) Import Data

Import Payment Methods

Info
The following imported entities will be used as payment methods in Spryker OS.

Prepare your data according to your requirements using our demo data:

data/import/payment_method.csv

payment_method_key,payment_method_name,payment_provider_key,payment_provider_name,is_active
dummyPaymentInvoice,Invoice,dummyPayment,Dummy Payment,1
dummyPaymentCreditCard,Credit Card,dummyPayment,Dummy Payment,1
Column REQUIRED Data Type Data Example Data Explanation
payment_method_key mandatory string dummyPaymentInvoice Key of a payment method.
payment_method_name mandatory string Invoice Name of a payment method.
payment_provider_key mandatory string dummyPayment Key of a payment provider.
payment_provider_name mandatory string Dummy Payment Name of a payment provider.
is_active optional boolean 1 Indicates if this payment method is available.

data/import/payment_method_store.csv

payment_method_key,store
dummyPaymentInvoice,DE
dummyPaymentInvoice,AT
dummyPaymentInvoice,US
dummyPaymentCreditCard,DE
dummyPaymentCreditCard,AT
dummyPaymentCreditCard,US
Column REQUIRED Data Type Data Example Data Explanation
payment_method_key mandatory string dummyPaymentInvoice Key of the existing payment method.
store mandatory string DE Name of the existing store.

Register the following plugin data import plugins:

Plugin Specification Prerequisites Namespace
PaymentMethodDataImportPlugin Imports payment method data into the database. None \Spryker\Zed\PaymentDataImport\Communication\Plugin
PaymentMethodStoreDataImportPlugin Imports payment method store data into the database. None \Spryker\Zed\PaymentDataImport\Communication\Plugin

src/Pyz/Zed/DataImport/DataImportDependencyProvider.php

<?php
 
namespace Pyz\Zed\DataImport;
 
use Spryker\Zed\DataImport\DataImportDependencyProvider as SprykerDataImportDependencyProvider;
use Spryker\Zed\PaymentDataImport\Communication\Plugin\PaymentMethodDataImportPlugin;
use Spryker\Zed\PaymentDataImport\Communication\Plugin\PaymentMethodStoreDataImportPlugin;
 
class DataImportDependencyProvider extends SprykerDataImportDependencyProvider
{
    /**
     * @return array
     */
    protected function getDataImporterPlugins(): array
    {
        return [
            new PaymentMethodDataImportPlugin(),
            new PaymentMethodStoreDataImportPlugin(),
        ];
    }
}

Enable the behaviors by registering the console commands:

src/Pyz/Zed/Console/ConsoleDependencyProvider.php

<?php
 
namespace Pyz\Zed\Console;
 
use Spryker\Zed\Kernel\Container;
use Spryker\Zed\Console\ConsoleDependencyProvider as SprykerConsoleDependencyProvider;
use Spryker\Zed\DataImport\Communication\Console\DataImportConsole;
use Spryker\Zed\PaymentDataImport\PaymentDataImportConfig;
 
class ConsoleDependencyProvider extends SprykerConsoleDependencyProvider
{
    /**
     * @param \Spryker\Zed\Kernel\Container $container
     *
     * @return \Symfony\Component\Console\Command\Command[]
     */
    protected function getConsoleCommands(Container $container)
    {
        $commands = [
            new DataImportConsole(DataImportConsole::DEFAULT_NAME . ':' . PaymentDataImportConfig::IMPORT_TYPE_PAYMENT_METHOD),
            new DataImportConsole(DataImportConsole::DEFAULT_NAME . ':' . PaymentDataImportConfig::IMPORT_TYPE_PAYMENT_METHOD_STORE),
        ];
 
        return $commands;
    }
}

Run the following console command to import data:

console data:import:payment-method
console data:import:payment-method-store
Verification
Make sure that the configured data has been added to the `spy_payment_method`, `spy_payment_provider`, and `spy_payment_method_store` tables in the database.

4) Set up Behavior

Configure the data import to use your data on the project level.

src/Pyz/Zed/PaymentDataImport/PaymentDataImportConfig

<?php
 
namespace Pyz\Zed\PaymentDataImport;
 
use Generated\Shared\Transfer\DataImporterConfigurationTransfer;
use Spryker\Zed\PaymentDataImport\PaymentDataImportConfig as SprykerPaymentDataImportConfig;
 
class PaymentDataImportConfig extends SprykerPaymentDataImportConfig
{
    /**
     * @return \Generated\Shared\Transfer\DataImporterConfigurationTransfer
     */
    public function getPaymentMethodDataImporterConfiguration(): DataImporterConfigurationTransfer
    {
        return $this->buildImporterConfiguration('payment_method.csv', static::IMPORT_TYPE_PAYMENT_METHOD);
    }
 
    /**
     * @return \Generated\Shared\Transfer\DataImporterConfigurationTransfer
     */
    public function getPaymentMethodAtoreDataImporterConfiguration(): DataImporterConfigurationTransfer
    {
        return $this->buildImporterConfiguration('payment_method_store.csv', static::IMPORT_TYPE_PAYMENT_METHOD_STORE);
    }
}

Configure the Payment GUI module with money and store plugins.

Plugin Specification Prerequisites Namespace
StoreRelationToggleFormTypePlugin Represents a store relation toggle form based on stores registered in the system. None Spryker\Zed\Store\Communication\Plugin\Form

src/Pyz/Zed/PaymentGui/PaymentGuiDependencyProvider.php

<?php
 
namespace Pyz\Zed\PaymentGui;
 
use Spryker\Zed\Kernel\Communication\Form\FormTypeInterface;
use Spryker\Zed\Kernel\Container;
use Spryker\Zed\PaymentGui\PaymentGuiDependencyProvider as SprykerPaymentGuiDependencyProvider;
use Spryker\Zed\Store\Communication\Plugin\Form\StoreRelationToggleFormTypePlugin;
 
class PaymentGuiDependencyProvider extends SprykerPaymentGuiDependencyProvider
{
    /**
     * @return \Spryker\Zed\Kernel\Communication\Form\FormTypeInterface
     */
    protected function getStoreRelationFormTypePlugin(): FormTypeInterface
    {
        return new StoreRelationToggleFormTypePlugin();
    }
}
Verification
Make sure that:
  • You can see the list of payment methods in the **Back Office > Administration > Payment Management > Payment Methods** section.
  • You can see information about the payment method in the **Back Office > Administration > Payment Management > Payment Methods > View** section.
  • You can edit the payment method in the **Back Office > Administration > Payment Management > Payment Methods > Edit** section.

5) Additional cleanups:

The SalesPaymentMethodTypeInstallerPlugin plugin was removed, please use the PaymentDataImport module instead. The PaymentConfig::getSalesPaymentMethodTypes() config method was removed, please use the PaymentDataImport module instead.