Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PISHPS-229: add bancomat pay #724

Merged
merged 9 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Components/ApplePayDirect/ApplePayDirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Shopware\Core\Checkout\Order\OrderEntity;
use Shopware\Core\Checkout\Payment\Cart\AsyncPaymentTransactionStruct;
use Shopware\Core\Framework\Validation\DataBag\DataBag;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
use Shopware\Core\System\SalesChannel\SalesChannelContext;

class ApplePayDirect
Expand Down Expand Up @@ -457,7 +458,7 @@ public function createPayment(OrderEntity $order, string $shopwareReturnUrl, str
# This is required for a smooth checkout with our already validated Apple Pay transaction.
$this->paymentHandler->setToken($paymentToken);

$paymentData = $this->molliePayments->startMolliePayment(ApplePayPayment::PAYMENT_METHOD_NAME, $asyncPaymentTransition, $context, $this->paymentHandler);
$paymentData = $this->molliePayments->startMolliePayment(ApplePayPayment::PAYMENT_METHOD_NAME, $asyncPaymentTransition, $context, $this->paymentHandler, new RequestDataBag());

# now also update the custom fields of our order
# we want to have the mollie metadata in the
Expand Down
16 changes: 15 additions & 1 deletion src/Facade/MolliePaymentDoPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Shopware\Core\Checkout\Order\Aggregate\OrderLineItem\OrderLineItemCollection;
use Shopware\Core\Checkout\Order\OrderEntity;
use Shopware\Core\Checkout\Payment\Cart\AsyncPaymentTransactionStruct;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Twig\Environment;
use Twig\Extension\CoreExtension;
Expand Down Expand Up @@ -135,10 +136,11 @@ public function __construct(OrderDataExtractor $extractor, MollieOrderBuilder $o
* @param AsyncPaymentTransactionStruct $transactionStruct
* @param SalesChannelContext $salesChannelContext
* @param PaymentHandler $paymentHandler
* @param RequestDataBag $dataBag
* @throws ApiException
* @return MolliePaymentPrepareData
*/
public function startMolliePayment(string $paymentMethod, AsyncPaymentTransactionStruct $transactionStruct, SalesChannelContext $salesChannelContext, PaymentHandler $paymentHandler): MolliePaymentPrepareData
public function startMolliePayment(string $paymentMethod, AsyncPaymentTransactionStruct $transactionStruct, SalesChannelContext $salesChannelContext, PaymentHandler $paymentHandler, RequestDataBag $dataBag): MolliePaymentPrepareData
{
$settings = $this->settingsService->getSettings($salesChannelContext->getSalesChannelId());

Expand Down Expand Up @@ -172,6 +174,16 @@ public function startMolliePayment(string $paymentMethod, AsyncPaymentTransactio
$mollieOrderId = $orderCustomFields->getMollieOrderId();


$bancomatPayPhoneNumber = $dataBag->get('mollieBancomatPayPhone');

if ($bancomatPayPhoneNumber !== null) {
BlackScorp marked this conversation as resolved.
Show resolved Hide resolved
## we need to pass the custom fields now, so we can use them in create order and display the number on failed orders
$orderCustomFields->setBancomatPayPhoneNumber($bancomatPayPhoneNumber);
$order->setCustomFields($orderCustomFields->toArray());
$this->updaterOrderCustomFields->updateOrder($order->getId(), $orderCustomFields, $salesChannelContext->getContext());
}


# now let's check if we have another payment attempt for an existing order.
# this is the case, if we already have a Mollie Order ID in our custom fields.
# in this case, we just add a new payment (transaction) to the existing order in Mollie.
Expand Down Expand Up @@ -211,6 +223,7 @@ public function startMolliePayment(string $paymentMethod, AsyncPaymentTransactio
# We just try to create the customer before we create the actual order.
$this->createCustomerAtMollie($order, $salesChannelContext);


# let's create our real Mollie order
# for this payment in Shopware.
$molliePaymentData = $this->createMollieOrder($order, $paymentMethod, $transactionStruct, $salesChannelContext, $paymentHandler);
Expand All @@ -232,6 +245,7 @@ public function startMolliePayment(string $paymentMethod, AsyncPaymentTransactio
$orderCustomFields->setSubscriptionData($subscriptionId, '');
}


/**
* @var OrderLineItemCollection $orderLineItems
*/
Expand Down
33 changes: 33 additions & 0 deletions src/Handler/Method/BancomatPayment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Kiener\MolliePayments\Handler\Method;

use Kiener\MolliePayments\Handler\PaymentHandler;
use Kiener\MolliePayments\Struct\Order\OrderAttributes;
use Mollie\Api\Types\PaymentMethod;
use Shopware\Core\Checkout\Customer\CustomerEntity;
use Shopware\Core\Checkout\Order\OrderEntity;
use Shopware\Core\System\SalesChannel\SalesChannelContext;

class BancomatPayment extends PaymentHandler
{
public const PAYMENT_METHOD_NAME = PaymentMethod::BANCOMATPAY;
public const PAYMENT_METHOD_DESCRIPTION = 'Bancomat Pay';

/** @var string */
protected $paymentMethod = self::PAYMENT_METHOD_NAME;

/**
* @param array<mixed> $orderData
* @param OrderEntity $orderEntity
* @param SalesChannelContext $salesChannelContext
* @param CustomerEntity $customer
* @return array<mixed>
*/
public function processPaymentMethodSpecificParameters(array $orderData, OrderEntity $orderEntity, SalesChannelContext $salesChannelContext, CustomerEntity $customer): array
{
$orderCustomFields = new OrderAttributes($orderEntity);
$orderData['billingAddress']['phone'] = $orderCustomFields->getBancomatPayPhoneNumber();
BlackScorp marked this conversation as resolved.
Show resolved Hide resolved
return $orderData;
}
}
3 changes: 2 additions & 1 deletion src/Handler/PaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public function pay(AsyncPaymentTransactionStruct $transaction, RequestDataBag $
$this->paymentMethod,
$transaction,
$salesChannelContext,
$this
$this,
$dataBag
);

$paymentUrl = $paymentData->getCheckoutURL();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Plugin from '@shopware-storefront-sdk/plugin-system/plugin.class';

export default class MollieBancomatPlugin extends Plugin {

init() {

const phoneField = document.getElementById('mollieBancomatPayPhone');
if (phoneField === null) {

return;
}

const inputFieldWrapper = document.querySelector('.mollie-bancomat-pay');

const errorMessageElement = document.querySelector('.mollie-bancomat-pay [data-form-validation-invalid-phone="true"]');

phoneField.addEventListener('focus',(e)=>{
inputFieldWrapper.classList.add('was-validated');
e.target.removeAttribute('invalid');
errorMessageElement.classList.add('d-none');
});


phoneField.addEventListener('blur', (e) => {
const form = e.target.form;
if(form.reportValidity() === false){
e.target.setAttribute('invalid',true);
errorMessageElement.classList.remove('d-none');
}
return form.reportValidity();

})

}
}
3 changes: 3 additions & 0 deletions src/Resources/app/storefront/src/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import MollieApplePayDirect from './mollie-payments/plugins/apple-pay-direct.plu
import MollieApplePayPaymentMethod from './mollie-payments/plugins/apple-pay-payment-method.plugin';
import MollieCreditCardMandateManage from './mollie-payments/plugins/creditcard-mandate-manage.plugin';
import MolliePosTerminalPlugin from './mollie-payments/plugins/pos-terminal.plugin';
import MollieBancomatPlugin from './mollie-payments/plugins/bancomat-plugin';


export default class MolliRegistration {
Expand Down Expand Up @@ -42,6 +43,8 @@ export default class MolliRegistration {
// POS Terminal
// -----------------------------------------------------------------------------
pluginManager.register('MolliePosTerminal', MolliePosTerminalPlugin, '[data-mollie-template-pos-terminal]');

pluginManager.register('MollieBancomatPlugin',MollieBancomatPlugin);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
margin-top: 15px;
}

.mollie-bancomat-pay{
margin-top:15px;
}

.mollie-pos-terminals {
margin-top: 15px;
}
Expand All @@ -27,6 +31,10 @@
}
}

.mollie-bancomat-pay{
margin-top:15px;
}

.mollie-pos-terminals {
margin-top: 15px;

Expand Down
7 changes: 7 additions & 0 deletions src/Resources/config/services/handlers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@
<tag name="shopware.payment.method.async"/>
</service>

<!-- Bancomat PaymentHandler -->
<service id="Kiener\MolliePayments\Handler\Method\BancomatPayment">
<argument type="service" id="mollie_payments.logger"/>
<argument type="service" id="service_container"/>
<tag name="shopware.payment.method.async"/>
</service>

<!-- KlanraOne PaymentHandler-->
<service id="Kiener\MolliePayments\Handler\Method\KlarnaOnePayment">
<argument type="service" id="mollie_payments.logger"/>
Expand Down
4 changes: 4 additions & 0 deletions src/Resources/snippet/de_DE/mollie-payments.de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
"deleteButton": "Löschen",
"deleteConfirmation": "Sind Sie sicher, dass Sie die Zahlart löschen möchten?",
"title": "Bestätigung zum Löschen"
},
"bancomatPay": {
"headLine": "Telefonnummer",
"phoneErrorMessage": "Die Telefonnummer ist erforderlich. Zum Beispiel +31208202070"
}
},
"messages": {
Expand Down
4 changes: 4 additions & 0 deletions src/Resources/snippet/en_GB/mollie-payments.en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
"deleteButton": "Delete",
"deleteConfirmation": "Are you sure you want to delete?",
"title": "Delete Confirmation"
},
"bancomatPay": {
"headLine": "Phone number",
"phoneErrorMessage": "Phone Number is required. For example +31208202070"
}
},
"messages": {
Expand Down
4 changes: 4 additions & 0 deletions src/Resources/snippet/nl_NL/mollie-payments.nl-NL.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
"deleteButton": "Verwijderen",
"deleteConfirmation": "Weet je zeker dat je dat wilt verwijderen?",
"title": "Bevestiging verwijderen"
},
"bancomatPay": {
"headLine": "Telefoonnummer",
"phoneErrorMessage": "Telefoonnummer is vereist. Bijvoorbeeld +31208202070"
}
},
"messages": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% if context.paymentMethod.translated.customFields.mollie_payment_method_name == 'bancomatpay' %}
<div class="mollie-bancomat-pay">

<label for="mollieBancomatPayPhone">{{ "molliePayments.components.bancomatPay.headLine"|trans|striptags }}:</label>
<input id="mollieBancomatPayPhone"
BlackScorp marked this conversation as resolved.
Show resolved Hide resolved
placeholder="+49123456789"
name="mollieBancomatPayPhone" form="confirmOrderForm" type="text" pattern="\+[1-9]\d{1,14}"
class="form-control"
value="{{ context.customer.activeBillingAddress.phoneNumber }}"
/>
<small class="form-text js-validation-message invalid-feedback d-none"
data-form-validation-invalid-phone="true" invalid="true">
{{ "molliePayments.components.bancomatPay.phoneErrorMessage"|trans|striptags }}
</small>

</div>
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@
{% sw_include '@MolliePayments/storefront/component/payment/component/ideal-fields.html.twig' %}
{% elseif payment.translated.customFields.mollie_payment_method_name == 'pointofsale' %}
{% sw_include '@MolliePayments/storefront/component/payment/component/pos-fields.html.twig' %}
{% elseif payment.translated.customFields.mollie_payment_method_name == 'bancomatpay' %}
{% sw_include '@MolliePayments/storefront/component/payment/component/bancomat-fields.html.twig' %}
{% endif %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@
{% sw_include '@MolliePayments/storefront/component/payment/component/ideal-fields.html.twig' %}
{% elseif payment.translated.customFields.mollie_payment_method_name == 'pointofsale' %}
{% sw_include '@MolliePayments/storefront/component/payment/component/pos-fields.html.twig' %}
{% elseif payment.translated.customFields.mollie_payment_method_name == 'bancomatpay' %}
{% sw_include '@MolliePayments/storefront/component/payment/component/bancomat-fields.html.twig' %}
{% endif %}
{% endblock %}
2 changes: 2 additions & 0 deletions src/Service/PaymentMethodService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Kiener\MolliePayments\Compatibility\VersionCompare;
use Kiener\MolliePayments\Handler\Method\ApplePayPayment;
use Kiener\MolliePayments\Handler\Method\BancomatPayment;
use Kiener\MolliePayments\Handler\Method\BanContactPayment;
use Kiener\MolliePayments\Handler\Method\BankTransferPayment;
use Kiener\MolliePayments\Handler\Method\BelfiusPayment;
Expand Down Expand Up @@ -441,6 +442,7 @@ public function getPaymentHandlers(): array
PosPayment::class,
TwintPayment::class,
BlikPayment::class,
BancomatPayment::class,
// IngHomePayPayment::class, // not allowed anymore
// DirectDebitPayment::class, // only allowed when updating subsriptions, aka => not allowed anymore
];
Expand Down
27 changes: 27 additions & 0 deletions src/Struct/Order/OrderAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ class OrderAttributes
*/
private $bankBic;

/**
* @var string
*/
private $bancomatPayPhoneNumber;

/**
* @param OrderEntity $order
*/
Expand All @@ -128,6 +133,7 @@ public function __construct(OrderEntity $order)
$this->bankAccount = $this->getCustomFieldValue($order, 'bankAccount');
$this->bankBic = $this->getCustomFieldValue($order, 'bankBic');
$this->timezone = $this->getCustomFieldValue($order, 'timezone');
$this->bancomatPayPhoneNumber = $this->getCustomFieldValue($order, 'bancomatPayPhoneNumber');
}

/**
Expand Down Expand Up @@ -444,6 +450,24 @@ public function setBankTransferDetails(?stdClass $details)
}
}

/**
* @return string
*/
public function getBancomatPayPhoneNumber(): string
{
return $this->bancomatPayPhoneNumber;
}

/**
* @param string $bancomatPayPhoneNumber
* @return void
*/
public function setBancomatPayPhoneNumber(string $bancomatPayPhoneNumber): void
{
$this->bancomatPayPhoneNumber = $bancomatPayPhoneNumber;
}


/**
* @return array<string,mixed>
*/
Expand Down Expand Up @@ -528,6 +552,9 @@ public function toArray(): array
$mollieData['bankBic'] = $this->bankBic;
}

if ($this->bancomatPayPhoneNumber !== '') {
$mollieData['bancomatPayPhoneNumber'] = $this->bancomatPayPhoneNumber;
}
return [
'mollie_payments' => $mollieData,
];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import Devices from "Services/utils/Devices";
import Session from "Services/utils/Session"
// ------------------------------------------------------
import PaymentAction from "Actions/storefront/checkout/PaymentAction";
import DummyBasketScenario from "Scenarios/DummyBasketScenario";
// ------------------------------------------------------


const devices = new Devices();
const session = new Session();

const paymentAction = new PaymentAction();
const scenarioDummyBasket = new DummyBasketScenario(1);

const device = devices.getFirstDevice();


describe('Bancomat Pay', () => {

context(devices.getDescription(device), () => {

before(function () {
devices.setDevice(device);
})

beforeEach(() => {
session.resetBrowserSession();
devices.setDevice(device);
});

it('C2775016: Bancomat Pay is existing in checkout', () => {

scenarioDummyBasket.execute();

paymentAction.switchPaymentMethod('Bancomat Pay');
})

})

})

Loading
Loading