Skip to content

Commit

Permalink
Merge branch 'feature/twint' into release-week-01
Browse files Browse the repository at this point in the history
  • Loading branch information
michielgerritsen committed Jan 10, 2024
2 parents 90c1304 + c5f09b3 commit b7adc44
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 68 deletions.
4 changes: 2 additions & 2 deletions GraphQL/Resolver/General/MolliePaymentMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
}

$storeId = $context->getExtensionAttributes()->getStore()->getId();
$apiMethods = $this->getMethods($amount, $currency, $storeId);
$apiMethods = $this->getMethods($amount, $currency, $storeId) ?? [];

$methods = [];
/** @var Method $method */
Expand All @@ -90,7 +90,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
];
}

public function getMethods(float $amount, ?string $currency, int $storeId): MethodCollection
public function getMethods(float $amount, ?string $currency, int $storeId): ?MethodCollection
{
$mollieApiClient = $this->mollieApiClient->loadByStore($storeId);

Expand Down
4 changes: 2 additions & 2 deletions Helper/Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getMethods($testKey = null, $liveKey = null)
try {
$availableMethods = [];
$mollieApi = $this->mollieModel->loadMollieApi($testKey);
$methods = $mollieApi->methods->allAvailable();
$methods = $mollieApi->methods->allAvailable() ?? [];

foreach ($methods as $apiMethod) {
$availableMethods[] = ucfirst($apiMethod->id);
Expand Down Expand Up @@ -87,7 +87,7 @@ public function getMethods($testKey = null, $liveKey = null)
try {
$availableMethods = [];
$mollieApi = $this->mollieModel->loadMollieApi($liveKey);
$methods = $mollieApi->methods->allAvailable();
$methods = $mollieApi->methods->allAvailable() ?? [];

foreach ($methods as $apiMethod) {
$availableMethods[] = ucfirst($apiMethod->id);
Expand Down
109 changes: 46 additions & 63 deletions Test/End-2-end/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,82 +18,65 @@ module.exports = defineConfig({
require('./cypress/plugins/disable-successful-videos.js')(on, config);

// Retrieve available method
await new Promise((methodsPromiseResolve, reject) => {
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 currencies = ['EUR', 'CHF'];
const query = `
query {
molliePaymentMethods(input:{amount:100, currency:null}) {
methods {
code
image
name
}
}
}
`;

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

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();
});
console.log('Requesting Mollie payment methods from "' + baseUrl + '". One moment please...');
var req = https.request(options, function (res) {
var chunks = [];

promises.push(promise);
});
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
})

Promise.all(promises).then((values) => {
const methods = [].concat(...values);
config.env.mollie_available_methods = [...new Set(methods)];
config.env.mollie_available_methods = methods;

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

methodsPromiseResolve();
resolve(config);
});

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

req.end();
});

// retrieve admin token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,14 @@ private function callEndpoint($methods): array
{
$this->loadFakeEncryptor()->addReturnValue('', 'test_dummyapikeythatisvalidandislongenough');

$methodCollection = new \Mollie\Api\Resources\MethodCollection(count($methods), null);
foreach ($methods as $method) {
$methodCollection[] = $method;
}

$methodsEndpointMock = $this->createMock(MethodEndpoint::class);
$methodsEndpointMock->method('allActive')->willReturn($methods);
$methodsEndpointMock->method('allActive')->willReturn($methodCollection);
$methodsEndpointMock->method('allAvailable')->willReturn($methodCollection);

$mollieApiMock = $this->createMock(MollieApiClient::class);
$mollieApiMock->methods = $methodsEndpointMock;
Expand Down

0 comments on commit b7adc44

Please sign in to comment.