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

Release #775

Merged
merged 12 commits into from
May 16, 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
6 changes: 6 additions & 0 deletions .github/workflows/templates/magento/configure-mollie.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#
# Copyright Magmodules.eu. All rights reserved.
# See COPYING.txt for license details.
#

if [ -z "$MOLLIE_API_KEY_TEST" ]; then
echo "Variable \$MOLLIE_API_KEY_TEST is not set"
exit 1
Expand All @@ -23,6 +28,7 @@ bin/magento config:set payment/mollie_methods_paypal/active 1 &
bin/magento config:set payment/mollie_methods_przelewy24/active 1 &
bin/magento config:set payment/mollie_methods_alma/active 1 &
bin/magento config:set payment/mollie_methods_bancontact/active 1 &
bin/magento config:set payment/mollie_methods_bancomatpay/active 1 &
bin/magento config:set payment/mollie_methods_belfius/active 1 &
bin/magento config:set payment/mollie_methods_eps/active 1 &
bin/magento config:set payment/mollie_methods_giropay/active 1 &
Expand Down
11 changes: 10 additions & 1 deletion Config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/**
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/
Expand Down Expand Up @@ -59,6 +59,7 @@ class Config
const PAYMENT_CREDITCARD_USE_COMPONENTS = 'payment/mollie_methods_creditcard/use_components';
const PAYMENT_CREDITCARD_ENABLE_CUSTOMERS_API = 'payment/mollie_methods_creditcard/enable_customers_api';
const PAYMENT_BANKTRANSFER_STATUS_PENDING = 'payment/mollie_methods_banktransfer/order_status_pending';
const PAYMENT_METHOD_API_METHOD = 'payment/mollie_methods_%s/method';
const PAYMENT_METHOD_ISSUER_LIST_TYPE = 'payment/mollie_methods_%s/issuer_list_type';
const PAYMENT_METHOD_PAYMENT_ACTIVE = 'payment/mollie_methods_%s/active';
const PAYMENT_METHOD_PAYMENT_DESCRIPTION = 'payment/mollie_methods_%s/payment_description';
Expand Down Expand Up @@ -781,6 +782,14 @@ public function encryptPaymentDetails($storeId = null): bool
return $this->isSetFlag(static::GENERAL_ENCRYPT_PAYMENT_DETAILS, $storeId);
}

public function getApiMethod(string $method, int $storeId = null): string
{
return (string)$this->getPath(
$this->addMethodToPath(static::PAYMENT_METHOD_API_METHOD, $method),
$storeId
);
}

/**
* @param string $method
* @param null|int|string $storeId
Expand Down
8 changes: 7 additions & 1 deletion Controller/ApplePay/PlaceOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ public function execute()

$cart->setCustomerEmail($this->getRequest()->getParam('shippingAddress')['emailAddress']);

$shippingAddress->setShippingMethod($this->getRequest()->getParam('shippingMethod')['identifier']);
$shippingAddress->setShippingMethod(
str_replace(
'__SPLIT__',
'_',
$this->getRequest()->getParam('shippingMethod')['identifier']
)
);

$cart->setPaymentMethod('mollie_methods_applepay');
$cart->setCustomerIsGuest(true);
Expand Down
4 changes: 3 additions & 1 deletion Controller/ApplePay/ShippingMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ public function execute()
return $response->setData([
'shipping_methods' => array_map(function ($method) {
return [
'identifier' => $method->getCarrierCode() . '_' . $method->getMethodCode(),
// Magento uses an _ (underscore) to separate the carrier and method, but those can have an
// underscore as well. So separate by a different divider to prevent errors.
'identifier' => $method->getCarrierCode() . '__SPLIT__' . $method->getMethodCode(),
'label' => $method->getMethodTitle() . ' - ' . $method->getCarrierTitle(),
'amount' => number_format($method->getPriceInclTax() ?: 0.0, 2, '.', ''),
'detail' => '',
Expand Down
3 changes: 2 additions & 1 deletion Helper/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ public function getMethodCode($order): string
*/
public function getApiMethod(OrderInterface $order)
{
$method = $order->getPayment()->getMethodInstance()->getCode();
$method = $order->getPayment()->getMethod();
$method = str_replace('_vault', '', $method);
$methodXpath = str_replace('%method%', $method, self::XML_PATH_API_METHOD);
return $this->getStoreConfig($methodXpath, $order->getStoreId());
Expand Down Expand Up @@ -621,6 +621,7 @@ public function getAllActiveMethods($storeId)
$methodCodes = [
'mollie_methods_applepay',
'mollie_methods_alma',
'mollie_methods_bancomatpay',
'mollie_methods_bancontact',
'mollie_methods_banktransfer',
'mollie_methods_belfius',
Expand Down
23 changes: 16 additions & 7 deletions Model/Client/Orders.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2018 Magmodules.eu. All rights reserved.
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

Expand Down Expand Up @@ -35,6 +35,7 @@
use Mollie\Payment\Service\Mollie\Order\Transaction\Expires;
use Mollie\Payment\Service\Order\BuildTransaction;
use Mollie\Payment\Service\Order\Invoice\ShouldEmailInvoice;
use Mollie\Payment\Service\Order\Lines\Order as OrderOrderLines;
use Mollie\Payment\Service\Order\Lines\StoreCredit;
use Mollie\Payment\Service\Order\MethodCode;
use Mollie\Payment\Service\Order\OrderCommentHistory;
Expand All @@ -61,6 +62,10 @@ class Orders extends AbstractModel
* @var OrderLines
*/
private $orderLines;
/**
* @var OrderOrderLines
*/
private $orderOrderLines;
/**
* @var OrderRepository
*/
Expand Down Expand Up @@ -113,6 +118,7 @@ class Orders extends AbstractModel
* @var Transaction
*/
private $transaction;

/**
* @var BuildTransaction
*/
Expand Down Expand Up @@ -147,7 +153,6 @@ class Orders extends AbstractModel
* @var LinkTransactionToOrder
*/
private $linkTransactionToOrder;

/**
* @var ShouldEmailInvoice
*/
Expand All @@ -159,6 +164,7 @@ class Orders extends AbstractModel

public function __construct(
OrderLines $orderLines,
OrderOrderLines $orderOrderLines,
InvoiceSender $invoiceSender,
OrderRepository $orderRepository,
CheckoutSession $checkoutSession,
Expand All @@ -184,6 +190,7 @@ public function __construct(
MethodCode $methodCode
) {
$this->orderLines = $orderLines;
$this->orderOrderLines = $orderOrderLines;
$this->invoiceSender = $invoiceSender;
$this->orderRepository = $orderRepository;
$this->checkoutSession = $checkoutSession;
Expand Down Expand Up @@ -224,8 +231,10 @@ public function startTransaction(OrderInterface $order, $mollieApi)
$additionalData = $order->getPayment()->getAdditionalInformation();

$transactionId = $order->getMollieTransactionId();
if (!empty($transactionId)) {
return $this->getCheckoutUrl($mollieApi, $order);
if (!empty($transactionId) &&
$checkoutUrl = $this->getCheckoutUrl($mollieApi, $order)
) {
return $checkoutUrl;
}

$paymentToken = $this->paymentTokenForOrder->execute($order);
Expand All @@ -236,7 +245,7 @@ public function startTransaction(OrderInterface $order, $mollieApi)
'orderNumber' => $order->getIncrementId(),
'billingAddress' => $this->getAddressLine($order->getBillingAddress()),
'consumerDateOfBirth' => null,
'lines' => $this->orderLines->getOrderLines($order),
'lines' => $this->orderOrderLines->get($order),
'redirectUrl' => $this->transaction->getRedirectUrl($order, $paymentToken),
'webhookUrl' => $this->transaction->getWebhookUrl([$order]),
'locale' => $this->mollieHelper->getLocaleCode($storeId, self::CHECKOUT_TYPE),
Expand Down Expand Up @@ -308,7 +317,7 @@ public function getAddressLine($address)
*
* @throws LocalizedException
*/
public function processResponse(Order $order, $mollieOrder)
public function processResponse(OrderInterface $order, MollieOrder $mollieOrder): void
{
$eventData = [
'order' => $order,
Expand Down
24 changes: 19 additions & 5 deletions Model/Client/Payments.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2018 Magmodules.eu. All rights reserved.
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

Expand Down Expand Up @@ -202,9 +202,11 @@ public function startTransaction(OrderInterface $order, $mollieApi)
$orderId = $order->getEntityId();

$transactionId = $order->getMollieTransactionId();
if (!empty($transactionId) && substr($transactionId, 0, 4) != 'ord_') {
$payment = $mollieApi->payments->get($transactionId);
return $payment->getCheckoutUrl();
if (!empty($transactionId) &&
substr($transactionId, 0, 4) != 'ord_' &&
$checkoutUrl = $this->getCheckoutUrl($mollieApi, $transactionId)
) {
return $checkoutUrl;
}

$paymentToken = $this->paymentTokenForOrder->execute($order);
Expand Down Expand Up @@ -537,4 +539,16 @@ public function checkCheckoutSession(Order $order, $paymentToken, $paymentData,
}
}
}

/**
* @param MollieApiClient $mollieApi
* @param $transactionId
* @return string|null
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function getCheckoutUrl(MollieApiClient $mollieApi, $transactionId): ?string
{
$payment = $mollieApi->payments->get($transactionId);
return $payment->getCheckoutUrl();
}
}
24 changes: 24 additions & 0 deletions Model/Methods/Bancomatpay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Model\Methods;

use Mollie\Payment\Model\Mollie;

/**
* Class Bancomatpay
*
* @package Mollie\Payment\Model\Methods
*/
class Bancomatpay extends Mollie
{
/**
* Payment method code
*
* @var string
*/
const CODE = 'mollie_methods_bancomatpay';
}
3 changes: 3 additions & 0 deletions Model/Methods/Paymentlink.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace Mollie\Payment\Model\Methods;

use Magento\Sales\Model\Order;
use Mollie\Payment\Model\Mollie;
use Magento\Framework\DataObject;

Expand Down Expand Up @@ -39,6 +40,8 @@ public function initialize($paymentAction, $stateObject)
$order = $payment->getOrder();
$order->setCanSendNewEmailFlag(false);

$stateObject->setState(Order::STATE_PENDING_PAYMENT);

if ($status = $this->config->statusNewPaymentLink($order->getStoreId())) {
$stateObject->setStatus($status);
}
Expand Down
7 changes: 5 additions & 2 deletions Model/Methods/Reorder.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2018 Magmodules.eu. All rights reserved.
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

Expand All @@ -27,6 +27,7 @@
use Mollie\Payment\Model\Client\Orders\ProcessTransaction;
use Mollie\Payment\Model\Client\Payments as PaymentsApi;
use Mollie\Payment\Model\Mollie;
use Mollie\Payment\Service\Mollie\GetApiMethod;
use Mollie\Payment\Service\OrderLockService;
use Mollie\Payment\Service\Mollie\MollieApiClient;
use Mollie\Payment\Service\Mollie\Timeout;
Expand Down Expand Up @@ -70,6 +71,7 @@ public function __construct(
OrderLockService $orderLockService,
MollieApiClient $mollieApiClient,
TransactionToOrderRepositoryInterface $transactionToOrderRepository,
GetApiMethod $getApiMethod,
RequestInterface $request,
$formBlockType,
$infoBlockType,
Expand Down Expand Up @@ -97,6 +99,7 @@ public function __construct(
$orderLockService,
$mollieApiClient,
$transactionToOrderRepository,
$getApiMethod,
$formBlockType,
$infoBlockType,
$commandPool,
Expand Down
5 changes: 4 additions & 1 deletion Model/Methods/Voucher.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/**
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/
Expand Down Expand Up @@ -27,6 +27,7 @@
use Mollie\Payment\Model\Client\Orders\ProcessTransaction;
use Mollie\Payment\Model\Client\Payments as PaymentsApi;
use Mollie\Payment\Model\Mollie;
use Mollie\Payment\Service\Mollie\GetApiMethod;
use Mollie\Payment\Service\OrderLockService;
use Mollie\Payment\Service\Mollie\MollieApiClient;
use Mollie\Payment\Service\Mollie\Timeout;
Expand Down Expand Up @@ -66,6 +67,7 @@ public function __construct(
OrderLockService $orderLockService,
MollieApiClient $mollieApiClient,
TransactionToOrderRepositoryInterface $transactionToOrderRepository,
GetApiMethod $getApiMethod,
$formBlockType,
$infoBlockType,
QuoteHasMealVoucherProducts $quoteHasMealVoucherProducts,
Expand Down Expand Up @@ -93,6 +95,7 @@ public function __construct(
$orderLockService,
$mollieApiClient,
$transactionToOrderRepository,
$getApiMethod,
$formBlockType,
$infoBlockType,
$commandPool,
Expand Down
13 changes: 10 additions & 3 deletions Model/Mollie.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2018 Magmodules.eu. All rights reserved.
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

Expand Down Expand Up @@ -34,6 +34,7 @@
use Mollie\Payment\Model\Client\Orders\ProcessTransaction;
use Mollie\Payment\Model\Client\Payments as PaymentsApi;
use Mollie\Payment\Model\Client\ProcessTransactionResponse;
use Mollie\Payment\Service\Mollie\GetApiMethod;
use Mollie\Payment\Service\OrderLockService;
use Mollie\Payment\Service\Mollie\Timeout;
use Mollie\Payment\Service\Mollie\Wrapper\MollieApiClientFallbackWrapper;
Expand Down Expand Up @@ -115,6 +116,10 @@ class Mollie extends Adapter
* @var TransactionToOrderRepositoryInterface
*/
private $transactionToOrderRepository;
/**
* @var GetApiMethod
*/
private $getApiMethod;

public function __construct(
ManagerInterface $eventManager,
Expand All @@ -135,6 +140,7 @@ public function __construct(
OrderLockService $orderLockService,
\Mollie\Payment\Service\Mollie\MollieApiClient $mollieApiClient,
TransactionToOrderRepositoryInterface $transactionToOrderRepository,
GetApiMethod $getApiMethod,
$formBlockType,
$infoBlockType,
CommandPoolInterface $commandPool = null,
Expand Down Expand Up @@ -171,6 +177,7 @@ public function __construct(
$this->orderLockService = $orderLockService;
$this->mollieApiClient = $mollieApiClient;
$this->transactionToOrderRepository = $transactionToOrderRepository;
$this->getApiMethod = $getApiMethod;
}

public function getCode()
Expand Down Expand Up @@ -258,7 +265,7 @@ public function startTransaction(Order $order)

return $this->orderLockService->execute($order, function (OrderInterface $order) use ($apiKey) {
$mollieApi = $this->loadMollieApi($apiKey);
$method = $this->mollieHelper->getApiMethod($order);
$method = $this->getApiMethod->execute($order);

// When clicking the back button from the hosted payment we need a way to verify if the order was paid or not.
// If this is not the case, we restore the quote. This flag is used to determine if it was paid or not.
Expand Down
1 change: 1 addition & 0 deletions Model/MollieConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class MollieConfigProvider implements ConfigProviderInterface
private $methodCodes = [
'mollie_methods_applepay',
'mollie_methods_alma',
'mollie_methods_bancomatpay',
'mollie_methods_bancontact',
'mollie_methods_banktransfer',
'mollie_methods_belfius',
Expand Down
Loading
Loading