Skip to content

Commit

Permalink
Merge pull request #665 from mollie/release/2.29.0
Browse files Browse the repository at this point in the history
Release/2.29.0
  • Loading branch information
Marvin-Magmodules authored Jul 25, 2023
2 parents 81f6b20 + db6ee3c commit 5104662
Show file tree
Hide file tree
Showing 53 changed files with 650 additions and 8,357 deletions.
5 changes: 4 additions & 1 deletion Block/Info/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Magento\Sales\Api\Data\OrderInterface;
use Mollie\Payment\Helper\General as MollieHelper;
use Mollie\Payment\Model\Methods\Billie;
use Mollie\Payment\Model\Methods\Klarna;
use Mollie\Payment\Model\Methods\Klarnapaylater;
use Mollie\Payment\Model\Methods\Klarnapaynow;
use Mollie\Payment\Model\Methods\Klarnasliceit;
Expand Down Expand Up @@ -166,7 +167,9 @@ public function isBuyNowPayLaterMethod(): bool
{
try {
$code = $this->getInfo()->getMethod();
if (in_array($code, [Billie::CODE, Klarnapaylater::CODE, Klarnasliceit::CODE, Klarnapaynow::CODE])) {
$methods = [Billie::CODE, Klarna::CODE, Klarnapaylater::CODE, Klarnasliceit::CODE, Klarnapaynow::CODE];

if (in_array($code, $methods)) {
return true;
}
} catch (\Exception $e) {
Expand Down
1 change: 1 addition & 0 deletions Helper/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ public function getAllActiveMethods($storeId)
'mollie_methods_ideal',
'mollie_methods_in3',
'mollie_methods_kbc',
'mollie_methods_klarna',
'mollie_methods_klarnapaylater',
'mollie_methods_klarnapaynow',
'mollie_methods_klarnasliceit',
Expand Down
3 changes: 2 additions & 1 deletion Model/Client/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,8 @@ public function createOrderRefund(Order\Creditmemo $creditmemo, Order $order)
}

$methodCode = $this->mollieHelper->getMethodCode($order);
if (!$order->hasShipments() && (in_array($methodCode, ['klarnapaylater', 'klarnasliceit', 'klarnapaynow']))) {
$methods = ['klarna', 'klarnapaylater', 'klarnasliceit', 'klarnapaynow'];
if (!$order->hasShipments() && (in_array($methodCode, $methods))) {
$msg = __('Order can only be refunded after Klarna has been captured (after shipment)');
throw new LocalizedException($msg);
}
Expand Down
24 changes: 24 additions & 0 deletions Model/Methods/Klarna.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Copyright © 2018 Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Model\Methods;

use Mollie\Payment\Model\Mollie;

/**
* Class Klarna
*
* @package Mollie\Payment\Model\Methods
*/
class Klarna extends Mollie
{
/**
* Payment method code
*
* @var string
*/
const CODE = 'mollie_methods_klarna';
}
2 changes: 1 addition & 1 deletion Model/Methods/Klarnapaylater.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Mollie\Payment\Model\Mollie;

/**
* Class Klarna
* Class Klarnapaylater
*
* @package Mollie\Payment\Model\Methods
*/
Expand Down
2 changes: 1 addition & 1 deletion Model/Methods/Klarnapaynow.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Mollie\Payment\Model\Mollie;

/**
* Class Klarna
* Class Klarnapaynow
*
* @package Mollie\Payment\Model\Methods
*/
Expand Down
2 changes: 1 addition & 1 deletion Model/Methods/Klarnasliceit.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Mollie\Payment\Model\Mollie;

/**
* Class KlarnaSlice
* Class Klarnasliceit
*
* @package Mollie\Payment\Model\Methods
*/
Expand Down
3 changes: 2 additions & 1 deletion Model/Mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ private function startTransactionUsingTheOrdersApi(Order $order, MollieApiClient
}

$methodCode = $this->mollieHelper->getMethodCode($order);
if (in_array($methodCode, ['billie', 'klarnapaylater', 'klarnapaynow', 'klarnasliceit', 'voucher', 'in3'])) {
$methods = ['billie', 'klarna', 'klarnapaylater', 'klarnapaynow', 'klarnasliceit', 'voucher', 'in3'];
if (in_array($methodCode, $methods)) {
throw new LocalizedException(__($exception->getMessage()));
}

Expand Down
1 change: 1 addition & 0 deletions Model/MollieConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class MollieConfigProvider implements ConfigProviderInterface
'mollie_methods_ideal',
'mollie_methods_in3',
'mollie_methods_kbc',
'mollie_methods_klarna',
'mollie_methods_klarnapaylater',
'mollie_methods_klarnapaynow',
'mollie_methods_klarnasliceit',
Expand Down
14 changes: 5 additions & 9 deletions Observer/SalesOrderShipmentSaveBefore/CreateMollieShipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
use Magento\Framework\Event\Observer;
use Mollie\Payment\Model\Client\Orders;
use Mollie\Payment\Model\Client\Payments\CapturePayment;
use Mollie\Payment\Model\Mollie as MollieModel;
use Mollie\Payment\Helper\General as MollieHelper;

/**
* Class SalesOrderShipmentSaveBefore
Expand All @@ -21,26 +19,24 @@
class CreateMollieShipment implements ObserverInterface
{
/**
* @var MollieHelper
* @var \Mollie\Payment\Config
*/
private $mollieHelper;

private $config;
/**
* @var Orders
*/
private $ordersApi;

/**
* @var CapturePayment
*/
private $capturePayment;

public function __construct(
MollieHelper $mollieHelper,
\Mollie\Payment\Config $config,
Orders $ordersApi,
CapturePayment $capturePayment
) {
$this->mollieHelper = $mollieHelper;
$this->config = $config;
$this->ordersApi = $ordersApi;
$this->capturePayment = $capturePayment;
}
Expand All @@ -64,7 +60,7 @@ public function execute(Observer $observer)
$this->ordersApi->createShipment($shipment, $order);
}

if (!$useOrdersApi) {
if (!$useOrdersApi && $this->config->useManualCapture((int)$order->getStoreId())) {
$this->capturePayment->execute($shipment, $order);
}
}
Expand Down
2 changes: 2 additions & 0 deletions Plugin/Sales/AddPaymentFeeToOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ private function addMolliePaymentFeeTo(OrderInterface $entity)
$extensionAttributes = $this->getExtensionAttributes($entity);
$extensionAttributes->setMolliePaymentFee($entity->getData('mollie_payment_fee'));
$extensionAttributes->setMolliePaymentFeeTax($entity->getData('mollie_payment_fee_tax'));
$extensionAttributes->setBaseMolliePaymentFee($entity->getData('base_mollie_payment_fee'));
$extensionAttributes->setBaseMolliePaymentFeeTax($entity->getData('base_mollie_payment_fee_tax'));
$entity->setExtensionAttributes($extensionAttributes);
}

Expand Down
12 changes: 11 additions & 1 deletion Service/Mollie/FormatExceptionMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@ class FormatExceptionMessages
'The webhook URL is invalid because it is unreachable from Mollie\'s point of view' => 'The webhook URL is invalid because it is unreachable from Mollie\'s point of view. View this article for more information: https://github.com/mollie/magento2/wiki/Webhook-Communication-between-your-Magento-webshop-and-Mollie',
];

public function __construct(
array $allowedErrorMessages = []
) {
$this->allowedErrorMessages = array_merge($this->allowedErrorMessages, $allowedErrorMessages);
}

public function execute(\Exception $exception, MethodInterface $methodInstance = null): string
{
// Make sure this can be picked up by bin/magento i18n:collect-phrases
// __('The billing country is not supported for this payment method.')
// __('A billing organization name is required for this payment method.')

foreach ($this->allowedErrorMessages as $message) {
if (stripos($exception->getMessage(), $message) !== false) {
return $message;
return __($message);
}
}

Expand Down
1 change: 1 addition & 0 deletions Service/Mollie/Order/CreateInvoiceOnShipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function execute(OrderInterface $order): bool
$methodCode = $order->getPayment()->getMethod();
if (in_array($methodCode, [
'mollie_methods_billie',
'mollie_methods_klarna',
'mollie_methods_klarnapaylater',
'mollie_methods_klarnapaynow',
'mollie_methods_klarnasliceit',
Expand Down
1 change: 1 addition & 0 deletions Service/Mollie/PaymentMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function __construct(
'mollie_methods_giropay',
'mollie_methods_giftcard',
'mollie_methods_kbc',
'mollie_methods_klarna',
'mollie_methods_klarnapaylater',
'mollie_methods_klarnapaynow',
'mollie_methods_klarnasliceit',
Expand Down
141 changes: 97 additions & 44 deletions Test/End-2-end/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ module.exports = defineConfig({
},
e2e: {
experimentalWebKitSupport: true,
setupNodeEvents(on, config) {
async setupNodeEvents(on, config) {
require('./cypress/plugins/index.js')(on, config);
require('./cypress/plugins/disable-successful-videos.js')(on, config);

return new Promise((resolve, reject) => {
var https = require('follow-redirects').https;
var fs = require('fs');
// Retrieve available method
await new Promise((resolve, reject) => {
var https = require('follow-redirects').https;

const baseUrl = config.baseUrl;
const urlObj = new URL(baseUrl);
const hostname = urlObj.hostname;
const baseUrl = config.baseUrl;
const urlObj = new URL(baseUrl);
const hostname = urlObj.hostname;

const query = `
const query = `
query {
molliePaymentMethods(input:{amount:100, currency:"EUR"}) {
methods {
Expand All @@ -36,53 +37,105 @@ module.exports = defineConfig({
}
`;

var options = {
'method': 'GET',
'hostname': hostname,
'path': '/graphql?query=' + encodeURIComponent(query),
'headers': {
'Content-Type': 'application/json',
// 'Cookie': 'XDEBUG_SESSION=PHPSTORM'
},
'maxRedirects': 20
};
var options = {
'method': 'GET',
'hostname': hostname,
'path': '/graphql?query=' + encodeURIComponent(query),
'headers': {
'Content-Type': 'application/json',
// 'Cookie': 'XDEBUG_SESSION=PHPSTORM'
},
'maxRedirects': 20
};

var req = https.request(options, function (res) {
var chunks = [];
console.log('Requesting Mollie payment methods from "' + baseUrl + '". One moment please...');
var req = https.request(options, function (res) {
var chunks = [];

res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("data", function (chunk) {
chunks.push(chunk);
});

res.on("end", function (chunk) {
const body = Buffer.concat(chunks);
res.on("end", function (chunk) {
const body = Buffer.concat(chunks);

console.info('Received body', body.toString());
const methods = JSON.parse(body.toString()).data.molliePaymentMethods.methods.map(data => {
return data.code
})

const methods = JSON.parse(body.toString()).data.molliePaymentMethods.methods.map(data => {
return data.code
})
config.env.mollie_available_methods = methods;

config.env.mollie_available_methods = methods;
console.log('Available Mollie payment methods: ', methods);

console.log('Available Mollie payment methods: ', methods);
resolve(config);
});

resolve(config);
});
res.on("error", function (error) {
console.error('Error while fetching Mollie Payment methods', error);
reject(error);
});
});

res.on("error", function (error) {
console.error('Error while fetching Mollie Payment methods', error);
reject(error);
});
});

var postData = JSON.stringify({
query: '',
variables: {}
});
req.end();
});

req.end();
// retrieve admin token
await new Promise((resolve, reject) => {
const baseUrl = config.baseUrl;
const urlObj = new URL(baseUrl);
const hostname = urlObj.hostname;

const username = 'exampleuser';
const password = 'examplepassword123';

var options = {
'method': 'POST',
'hostname': hostname,
'path': '/rest/all/V1/integration/admin/token',
'headers': {
'accept': 'application/json',
'Content-Type': 'application/json',
// 'Cookie': 'XDEBUG_SESSION=PHPSTORM'
},
'body': JSON.stringify({
'username': username,
'password': password,
}),
};

console.log('Requesting admin token from "' + baseUrl + '". One moment please...');
var https = require('follow-redirects').https;
var req = https.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});

res.on("end", function (chunk) {
const body = Buffer.concat(chunks);

if (res.statusCode !== 200) {
console.error('Received invalid status code', res.statusCode, body.toString());
reject(body.toString());
}

console.log('Received admin token', body.toString(), res.statusCode);
config.env.admin_token = JSON.parse(body.toString());

resolve(config);
});

res.on("error", function (error) {
console.error('Error while fetching Mollie Payment methods', error);
reject(error);
});
});

req.write(options.body);
req.end();
});

return config;
},
},
});
Loading

0 comments on commit 5104662

Please sign in to comment.