Integrating Heidelpay

Edit on GitHub
You are browsing a previous version of the document. The latest version is 202212.0.

To integrate Heidelpay, follow the steps below:

Back-end Integration

  1. Add sub form plugins and payment method handlers:
Pyz\Yves\CheckoutPage\CheckoutPageDependencyProvider
 protected function addSubFormPluginCollection(Container $container): Container
{
	$container[self::PAYMENT_SUB_FORMS] = function () {
		$subFormPluginCollection = new SubFormPluginCollection();
		...
		$subFormPluginCollection->add(new HeidelpaySofortSubFormPlugin());
		$subFormPluginCollection->add(new HeidelpayPaypalAuthorizeSubFormPlugin());
		$subFormPluginCollection->add(new HeidelpayPaypalDebitSubFormPlugin());
		$subFormPluginCollection->add(new HeidelpayIdealSubFormPlugin());
		$subFormPluginCollection->add(new HeidelpayCreditCardSecureSubFormPlugin());

		return $subFormPluginCollection;
	};

	return $container;
}

protected function addPaymentMethodHandlerPluginCollection(Container $container):
{
	$container[self::PAYMENT_METHOD_HANDLER] = function () {
		$stepHandlerPluginCollection = new StepHandlerPluginCollection();
		...
		$stepHandlerPluginCollection->add(new HeidelpayHandlerPlugin(), PaymentTransfer::HEIDELPAY_SOFORT);
		$stepHandlerPluginCollection->add(new HeidelpayHandlerPlugin(), PaymentTransfer::HEIDELPAY_PAYPAL_AUTHORIZE);
		$stepHandlerPluginCollection->add(new HeidelpayHandlerPlugin(), PaymentTransfer::HEIDELPAY_PAYPAL_DEBIT);
		$stepHandlerPluginCollection->add(new HeidelpayHandlerPlugin(), PaymentTransfer::HEIDELPAY_IDEAL);
		$stepHandlerPluginCollection->add(new HeidelpayCreditCardHandlerPlugin(), PaymentTransfer::HEIDELPAY_CREDIT_CARD_SECURE);

		return $stepHandlerPluginCollection;
	};

	return $container;
}

  1. Add controller provider:
\Pyz\Yves\ShopApplication\YvesBootstrap
```php

protected function getControllerProviderStack($isSsl) { return [ … new HeidelpayControllerProvider($isSsl), ];> }

<br>
</details>

3. Add checkout plugins:

 <details open>
<summary markdown='span'>\Pyz\Zed\Checkout\CheckoutDependencyProvider</summary>

```php
 protected function getCheckoutOrderSavers(Container $container)
{
	$plugins = [
		...
		new HeidelpaySaveOrderPlugin(),
	];

	return $plugins;
}

protected function getCheckoutPostHooks(Container $container)
{
	return [
		...
		new HeidelpayPostSavePlugin(),
	];
}

  1. Add OMS commands and conditions:
\Pyz\Zed\Oms\OmsDependencyProvider
public function provideBusinessLayerDependencies(Container $container)
{
	$container = parent::provideBusinessLayerDependencies($container);
	$container = $this->addCommandPlugins($container);
	$container = $this->addConditionPlugins($container);

	return $container;
}
protected function addConditionPlugins(Container $container): Container
{
	$container[self::CONDITION_PLUGINS] = function () {
		$conditionCollection = new ConditionCollection();
		$conditionCollection->add(new IsAuthorizationCompletedPlugin(), 'Heidelpay/IsAuthorizationCompleted');
		$conditionCollection->add(new IsDebitCompletedPlugin(), 'Heidelpay/IsDebitCompleted');
		$conditionCollection->add(new IsCaptureApprovedPlugin(), 'Heidelpay/IsCaptureApproved');

		return $conditionCollection;
	};

	return $container;
}

protected function addCommandPlugins(Container $container): Container
{
	$container[self::COMMAND_PLUGINS] = function () {
		$commandCollection = new CommandCollection();
		$commandCollection->add(new SendOrderConfirmationPlugin(), 'Oms/SendOrderConfirmation');
		$commandCollection->add(new SendOrderShippedPlugin(), 'Oms/SendOrderShipped');
		$commandCollection->add(new AuthorizePlugin(), 'Heidelpay/Authorize');
		$commandCollection->add(new DebitPlugin(), 'Heidelpay/Debit');
		$commandCollection->add(new CapturePlugin(), 'Heidelpay/Capture');

		return $commandCollection;
	};

	return $container;
}

Front-end Integration

To make Heidelpay module work with your project, it’s necessary to extend the frontend part:

tsconfig.json
"include": [
"./vendor/spryker/spryker-shop/**/*",
"./vendor/spryker-eco/**/*",
"./src/Pyz/Yves/**/*"
],

frontend/settings.js
```bash

// eco folders eco: { // all modules modules: ‘./vendor/spryker-eco’ }, … componentEntryPoints: { // absolute dirs in which look for dirs: [ … path.join(context, paths.eco.modules), … ],

<br>
</details>

<details open>
<summary markdown='span'>src/Pyz/Yves/CheckoutPage/Theme/default/views/payment/payment.twig</summary>

   ```twig
...

{% block content %}
{% embed molecule('form') with {
class: 'box',
data: {
form: data.forms.payment,
options: {
attr: {
id: 'payment-form'
}
},
submit: {
enable: true,
text: 'checkout.step.summary' | trans
},
cancel: {
enable: true,
url: data.backUrl,
text: 'general.back.button' | trans
}
}
} only %}
{% block fieldset %}
{% for name, choices in data.form.paymentSelection.vars.choices %}
{% set paymentProviderIndex = loop.index %}
<h5>{{ ('checkout.payment.provider.' ~ name) | trans }}</h5>
<ul class="list spacing-y">
{% for key, choice in choices %}
<li class="list__item spacing-y clear">
{% embed molecule('form') with {
data: {
form: data.form[data.form.paymentSelection[key].vars.value],
enableStart: false,
enableEnd: false
},
embed: {
index: loop.index ~ '-' ~ paymentProviderIndex,
toggler: data.form.paymentSelection[key]
}
} only %}
{% block fieldset %}
{% for name, choices in data.form.paymentSelection.vars.choices %}
{% set paymentProviderIndex = (loop.index0) %}
<h5>{{ ('checkout.payment.provider.' ~ name) | trans }}</h5>
<ul class="list spacing-y">
{% if choices is iterable %}
{% for key, choice in choices %}
<li class="list__item spacing-y clear">
{% include molecule('payment-method', 'CheckoutPage') with {
data: {
form: data.form[data.form.paymentSelection[key].vars.value],
index: loop.index ~ '-' ~ paymentProviderIndex,
toggler: data.form.paymentSelection[key],
}
} only %}
</li>
{% endfor %}
{% else %}
<li class="list__item spacing-y clear">
{% include molecule('payment-method', 'CheckoutPage') with {
data: {
form: data.form[data.form.paymentSelection[paymentProviderIndex].vars.value],
index: loop.index ~ '-' ~ paymentProviderIndex,
toggler: data.form.paymentSelection[paymentProviderIndex],
parentFormId: data.options.attr.id
}
} only %}
</li>
{% endif %}
</ul>
{% endfor %}
{% endblock %}
{% endembed %}
</li>
{% endfor %}
</ul>
{% endfor %}
{% endblock %}
{% endembed %}
{% endblock %}

src/Pyz/Yves/Twig/TwigConfig.php
protected function addCoreTemplatePaths(array $paths)
{
...
$paths[] = APPLICATION_VENDOR_DIR . '/spryker-eco/%1$s/src/SprykerEco/Yves/%1$s/Theme/' . $themeName;

return $paths;
}