Skip to content

Commit

Permalink
Feature: New payment method TWINT
Browse files Browse the repository at this point in the history
  • Loading branch information
michielgerritsen committed Jan 8, 2024
1 parent 4543d53 commit 3587541
Show file tree
Hide file tree
Showing 37 changed files with 503 additions and 49 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/end-2-end-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ jobs:
- name: Activate the extension
run: |
docker exec magento-project-community-edition php /data/merge-config.php
docker exec magento-project-community-edition ./retry "php bin/magento module:enable Mollie_Payment"
docker exec magento-project-community-edition ./retry "php bin/magento setup:upgrade"
docker exec magento-project-community-edition ./retry "php bin/magento setup:upgrade --no-interaction"
docker exec magento-project-community-edition /bin/bash /data/configure-mollie.sh
docker exec magento-project-community-edition ./retry "bin/magento config:set payment/mollie_general/use_webhooks custom_url"
docker exec magento-project-community-edition ./retry "bin/magento config:set payment/mollie_general/custom_webhook_url ${{ env.magento_url }}/mollie/checkout/webhook"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/templates/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
volumes:
- ../../../magento-logs:/data/var/log
- ./magento/configure-mollie.sh:/data/configure-mollie.sh
- ./magento/merge-config.php.stub:/data/merge-config.php
depends_on:
- ngrok

Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/templates/magento/configure-mollie.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ bin/magento config:set payment/mollie_methods_paymentlink/active 1 &
bin/magento config:set payment/mollie_methods_paysafecard/active 1 &
bin/magento config:set payment/mollie_methods_pointofsale/active 1 &
bin/magento config:set payment/mollie_methods_sofort/active 1 &
bin/magento config:set payment/mollie_methods_twint/active 1 &

# Enable Components
bin/magento config:set payment/mollie_methods_creditcard/use_components 1 &
Expand All @@ -38,6 +39,11 @@ bin/magento config:set payment/mollie_methods_ideal/add_qr 1 &

bin/magento config:set payment/mollie_general/use_webhooks disabled &

# Configure currency for the swiss store view
bin/magento config:set currency/options/allow EUR,CHF &
bin/magento config:set currency/options/default CHF --scope=ch &
bin/magento config:set payment/mollie_general/currency 0 --scope=ch &

wait

if grep -q Magento_TwoFactorAuth "app/etc/config.php"; then
Expand Down
81 changes: 81 additions & 0 deletions .github/workflows/templates/magento/merge-config.php.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

# Merge the config.php file generated by Magento with our own scopes to create multiple store views.

$magentoConfig = require('app/etc/config.php');
$magentoConfig['scopes'] = [
'websites' => [
'admin' => [
'website_id' => '0',
'code' => 'admin',
'name' => 'Admin',
'sort_order' => '0',
'default_group_id' => '0',
'is_default' => '0'
],
'base' => [
'website_id' => '1',
'code' => 'base',
'name' => 'Main Website',
'sort_order' => '0',
'default_group_id' => '1',
'is_default' => '1'
]
],
'groups' => [
[
'group_id' => '0',
'website_id' => '0',
'name' => 'Default',
'root_category_id' => '0',
'default_store_id' => '0',
'code' => 'default'
],
[
'group_id' => '1',
'website_id' => '1',
'name' => 'Main Website Store',
'root_category_id' => '2',
'default_store_id' => '1',
'code' => 'main_website_store'
]
],
'stores' => [
'admin' => [
'store_id' => '0',
'code' => 'admin',
'website_id' => '0',
'group_id' => '0',
'name' => 'Admin',
'sort_order' => '0',
'is_active' => '1'
],
'default' => [
'store_id' => '1',
'code' => 'default',
'website_id' => '1',
'group_id' => '1',
'name' => 'Default Store View',
'sort_order' => '0',
'is_active' => '1'
],
'ch' => [
'store_id' => '2',
'code' => 'ch',
'website_id' => '1',
'group_id' => '1',
'name' => 'Swiss',
'sort_order' => '0',
'is_active' => '1'
]
]
];

file_put_contents(
'app/etc/config.php',
'<?php return ' . var_export($magentoConfig, true) . ';' . PHP_EOL
);
1 change: 1 addition & 0 deletions Helper/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ public function getAllActiveMethods($storeId)
'mollie_methods_pointofsale',
'mollie_methods_przelewy24',
'mollie_methods_sofort',
'mollie_methods_twint',
];

foreach ($methodCodes as $methodCode) {
Expand Down
24 changes: 24 additions & 0 deletions Model/Methods/Twint.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 TWINT
*
* @package Mollie\Payment\Model\Methods
*/
class Twint extends Mollie
{
/**
* Payment method code
*
* @var string
*/
const CODE = 'mollie_methods_twint';
}
1 change: 1 addition & 0 deletions Model/MollieConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class MollieConfigProvider implements ConfigProviderInterface
'mollie_methods_pointofsale',
'mollie_methods_przelewy24',
'mollie_methods_sofort',
'mollie_methods_twint',
'mollie_methods_voucher',
];
/**
Expand Down
1 change: 1 addition & 0 deletions Plugin/Quote/Api/LimitMethodsForRecurringPayments.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class LimitMethodsForRecurringPayments
'mollie_methods_mybank',
'mollie_methods_paypal',
'mollie_methods_sofort',
'mollie_methods_twint',
];

/**
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Mollie requires no minimum costs, no fixed contracts, no hidden costs. At Mollie
- Przelewy24
- SEPA Direct Debit
- SOFORT Banking
- TWINT

## Additional modules

Expand Down
1 change: 1 addition & 0 deletions Service/Mollie/PaymentMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function __construct(
'mollie_methods_pointofsale',
'mollie_methods_przelewy24',
'mollie_methods_sofort',
'mollie_methods_twint',
'mollie_methods_voucher',
];

Expand Down
2 changes: 1 addition & 1 deletion Service/Order/OrderAmount.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function getByTransactionId(string $transactionId): array
$currencies = [];
$orders = $this->getOrders($transactionId);
foreach ($orders->getItems() as $order) {
if ($this->config->useBaseCurrency()) {
if ($this->config->useBaseCurrency($order->getStoreId())) {
$currencies[] = $order->getBaseCurrencyCode();
$amount += $order->getBaseGrandTotal();
} else {
Expand Down
107 changes: 62 additions & 45 deletions Test/End-2-end/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,65 +18,82 @@ module.exports = defineConfig({
require('./cypress/plugins/disable-successful-videos.js')(on, config);

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

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

const query = `
query {
molliePaymentMethods(input:{amount:100, currency:"EUR"}) {
methods {
code
image
name
}
}
}
`;

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

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

res.on("data", function (chunk) {
chunks.push(chunk);
currencies.forEach(currency => {
const query = `
query {
molliePaymentMethods(input:{amount:100, currency:"${currency}"}) {
methods {
code
image
name
}
}
}
`;

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

console.log(`Requesting Mollie payment methods from "${baseUrl}" for ${currency}. One moment please...`);
const promise = new Promise((resolve, reject) => {
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);

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

console.log(`Available Mollie payment methods for ${currency}: `, methods);

resolve(methods);
});

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

req.end();
});

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

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

config.env.mollie_available_methods = methods;
promises.push(promise);
});

console.log('Available Mollie payment methods: ', methods);
Promise.all(promises).then((values) => {
const methods = [].concat(...values);
config.env.mollie_available_methods = [...new Set(methods)];

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

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

req.end();
});

// retrieve admin token
Expand Down
15 changes: 15 additions & 0 deletions Test/End-2-end/cypress/fixtures/swiss-shipping-address.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"type": {
"username": "johnsmith@mollie.com",
"firstname": "John",
"lastname": "Smith",
"street[0]": "Bahnhofstrasse 10",
"city": "Zurich",
"postcode": "8001",
"telephone": "0441234567"
},
"select": {
"country_id": "CH",
"region_id": "Zürich"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,18 @@ export default class VisitCheckoutPaymentCompositeAction {

checkoutShippingPage.fillShippingAddressUsingFixture(fixture);
}

changeStoreViewTo(name) {
cy.visit('/');

cy.get('.greet.welcome').should('be.visible');

cy.get('.switcher-trigger').then(($el) => {
if ($el.text().includes('Default Store View')) {
cy.get('#switcher-language-trigger .view-default').click();

cy.get('.switcher-dropdown').contains(name).click();
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class CheckoutPaymentPage {
placeOrder() {
cy.intercept('mollie/checkout/redirect/paymentToken/*').as('mollieRedirect');

cy.intercept('POST', 'rest/default/V1/guest-carts/*/payment-information').as('placeOrderAction');
cy.intercept('POST', 'rest/*/V1/guest-carts/*/payment-information').as('placeOrderAction');

this.pressPlaceOrderButton();

Expand Down
1 change: 1 addition & 0 deletions Test/Integration/Etc/Config/MethodsConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function methods(): array
['mollie_methods_pointofsale'],
['mollie_methods_przelewy24'],
['mollie_methods_sofort'],
['mollie_methods_twint'],
];
}

Expand Down
1 change: 1 addition & 0 deletions Test/Integration/Helper/GeneralTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public function getMethodCodeDataProvider()
'pointofsale' => ['mollie_methods_pointofsale', 'pointofsale'],
'przelewy24' => ['mollie_methods_przelewy24', 'przelewy24'],
'sofort' => ['mollie_methods_sofort', 'sofort'],
'twint' => ['mollie_methods_twint', 'twint'],
];
}

Expand Down
12 changes: 12 additions & 0 deletions Test/Integration/Model/Methods/TwintTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Mollie\Payment\Test\Integration\Model\Methods;

use Mollie\Payment\Model\Methods\Twint;

class TwintTest extends AbstractMethodTest
{
protected $instance = Twint::class;

protected $code = 'twint';
}
Loading

0 comments on commit 3587541

Please sign in to comment.