Implement prepayment in backend
Edit on GitHubTo integrate the prepayment method into the checkout, you need to provide implementations for these two plugins:
CheckoutPreCondition
PaymentSaveOrder
Perform the following steps:
- Add the following plugins in Zed, in the
Communication/Plugin/Checkout/
folder of the newly added module.
PrepaymentPreCheckPlugin
<?php
namespace Pyz\Zed\PaymentMethods\Communication\Plugin\Checkout;
use Generated\Shared\Transfer\CheckoutResponseTransfer;
use Generated\Shared\Transfer\QuoteTransfer;
use Spryker\Zed\Kernel\Communication\AbstractPlugin;
use Spryker\Zed\Payment\Dependency\Plugin\Checkout\CheckoutPreCheckPluginInterface;
class PrepaymentPreCheckPlugin extends AbstractPlugin implements CheckoutPreCheckPluginInterface
{
/**
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
* @param \Generated\Shared\Transfer\CheckoutResponseTransfer $checkoutResponseTransfer
*
* @return \Generated\Shared\Transfer\CheckoutResponseTransfer
*/
public function checkCondition(QuoteTransfer $quoteTransfer, CheckoutResponseTransfer $checkoutResponseTransfer)
{
return $checkoutResponseTransfer;
}
}
PrepaymentSaveOrderPlugin
<?php
namespace Pyz\Zed\PaymentMethods\Communication\Plugin\Checkout;
use Generated\Shared\Transfer\CheckoutResponseTransfer;
use Generated\Shared\Transfer\QuoteTransfer;
use Spryker\Zed\Kernel\Communication\AbstractPlugin;
use Spryker\Zed\Payment\Dependency\Plugin\Checkout\CheckoutSaveOrderPluginInterface;
class PrepaymentSaveOrderPlugin extends AbstractPlugin implements CheckoutSaveOrderPluginInterface
{
/**
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
* @param \Generated\Shared\Transfer\CheckoutResponseTransfer $checkoutResponseTransfer
*
* @return void
*/
public function saveOrder(QuoteTransfer $quoteTransfer, CheckoutResponseTransfer $checkoutResponseTransfer)
{
}
}
- Inject these plugins into the
Payment
module by creating thePaymentDependencyInjector
in theDependency/Injector
folder:
<?php
namespace Pyz\Zed\PaymentMethods\Dependency\Injector;
use Pyz\Zed\PaymentMethods\Communication\Plugin\Checkout\PrepaymentPreCheckPlugin;
use Pyz\Zed\PaymentMethods\Communication\Plugin\Checkout\PrepaymentSaveOrderPlugin;
use Spryker\Zed\Kernel\Container;
use Pyz\Shared\PaymentMethods\PaymentMethodsConstants;
use Spryker\Zed\Kernel\Dependency\Injector\AbstractDependencyInjector;
use Spryker\Zed\Payment\Dependency\Plugin\Checkout\CheckoutPluginCollection;
use Spryker\Zed\Payment\PaymentDependencyProvider;
class PaymentDependencyInjector extends AbstractDependencyInjector
{
/**
* @param \Spryker\Zed\Kernel\Container $container
*
* @return \Spryker\Zed\Kernel\Container
*/
public function injectBusinessLayerDependencies(Container $container)
{
$container = $this->injectPaymentPlugins($container);
return $container;
}
/**
* @param \Spryker\Zed\Kernel\Container $container
*
* @return \Spryker\Zed\Kernel\Container
*/
protected function injectPaymentPlugins(Container $container)
{
$container->extend(PaymentDependencyProvider::CHECKOUT_PLUGINS, function (CheckoutPluginCollection $pluginCollection) {
$pluginCollection->add(new PrepaymentPreCheckPlugin(), PaymentMethodsConstants::PROVIDER, PaymentDependencyProvider::CHECKOUT_PRE_CHECK_PLUGINS);
$pluginCollection->add(new PrepaymentSaveOrderPlugin(), PaymentMethodsConstants::PROVIDER, PaymentDependencyProvider::CHECKOUT_ORDER_SAVER_PLUGINS);
return $pluginCollection;
});
return $container;
}
}
- Link the prepayment state machine to process the orders submitted with the payment method we’re implementing.
Use the prepayment state machine that’s delivered with Demoshop.
In the SalesConfig
class, add this configuration:
/**
* @var array
*/
protected static $stateMachineMapper = [
//..
PaymentMethodsConstants::PAYMENT_PREPAYMENT_FORM_PROPERTY_PATH => OmsConfig::ORDER_PROCESS_PREPAYMENT_01,
];
Thank you!
For submitting the form