Changeset View
Changeset View
Standalone View
Standalone View
src/app/Providers/Payment/Mollie.php
Show First 20 Lines • Show All 541 Lines • ▼ Show 20 Lines | protected static function paymentMethod($object, $default = ''): string | ||||
return $default; | return $default; | ||||
} | } | ||||
/** | /** | ||||
* List supported payment methods. | * List supported payment methods. | ||||
* | * | ||||
* @param string $type The payment type for which we require a method (oneoff/recurring). | * @param string $type The payment type for which we require a method (oneoff/recurring). | ||||
* @param string $currency Currency code | |||||
* | * | ||||
* @return array Array of array with available payment methods: | * @return array Array of array with available payment methods: | ||||
* - id: id of the method | * - id: id of the method | ||||
* - name: User readable name of the payment method | * - name: User readable name of the payment method | ||||
* - minimumAmount: Minimum amount to be charged in cents | * - minimumAmount: Minimum amount to be charged in cents | ||||
* - currency: Currency used for the method | * - currency: Currency used for the method | ||||
* - exchangeRate: The projected exchange rate (actual rate is determined during payment) | * - exchangeRate: The projected exchange rate (actual rate is determined during payment) | ||||
* - icon: An icon (icon name) representing the method | * - icon: An icon (icon name) representing the method | ||||
*/ | */ | ||||
public function providerPaymentMethods($type): array | public function providerPaymentMethods(string $type, string $currency): array | ||||
{ | { | ||||
$providerMethods = array_merge( | // Prefer methods in the system currency | ||||
// Fallback to EUR methods (later provider methods will override earlier ones) | $providerMethods = (array) mollie()->methods()->allActive( | ||||
(array) mollie()->methods()->allActive( | |||||
[ | [ | ||||
'sequenceType' => $type, | 'sequenceType' => $type, | ||||
'amount' => [ | 'amount' => [ | ||||
'value' => '1.00', | 'value' => '1.00', | ||||
'currency' => 'EUR' | 'currency' => $currency | ||||
] | ] | ||||
] | ] | ||||
), | ); | ||||
// Prefer CHF methods | |||||
(array) mollie()->methods()->allActive( | // Get EUR methods (e.g. bank transfers are in EUR only) | ||||
if ($currency != 'EUR') { | |||||
$eurMethods = (array) mollie()->methods()->allActive( | |||||
[ | [ | ||||
'sequenceType' => $type, | 'sequenceType' => $type, | ||||
'amount' => [ | 'amount' => [ | ||||
'value' => '1.00', | 'value' => '1.00', | ||||
'currency' => 'CHF' | 'currency' => 'EUR' | ||||
] | ] | ||||
] | ] | ||||
) | |||||
); | ); | ||||
// Later provider methods will override earlier ones | |||||
$providerMethods = array_merge($eurMethods, $providerMethods); | |||||
mollekopf: Can array_merge handle a non-existing $eurMethods in the $currency == 'EUR' case? Otherwise set… | |||||
Done Inline ActionsI don't get the question. If $currency == 'EUR' array_merge is not executed, because the first request to mollie will return them. machniak: I don't get the question. If $currency == 'EUR' array_merge is not executed, because the first… | |||||
} | |||||
$availableMethods = []; | $availableMethods = []; | ||||
foreach ($providerMethods as $method) { | foreach ($providerMethods as $method) { | ||||
$availableMethods[$method->id] = [ | $availableMethods[$method->id] = [ | ||||
'id' => $method->id, | 'id' => $method->id, | ||||
'name' => $method->description, | 'name' => $method->description, | ||||
'minimumAmount' => round(floatval($method->minimumAmount->value) * 100), // Converted to cents | 'minimumAmount' => round(floatval($method->minimumAmount->value) * 100), // Converted to cents | ||||
'currency' => $method->minimumAmount->currency, | 'currency' => $method->minimumAmount->currency, | ||||
'exchangeRate' => \App\Utils::exchangeRate('CHF', $method->minimumAmount->currency) | 'exchangeRate' => \App\Utils::exchangeRate($currency, $method->minimumAmount->currency) | ||||
]; | ]; | ||||
} | } | ||||
return $availableMethods; | return $availableMethods; | ||||
} | } | ||||
/** | /** | ||||
* Get a payment. | * Get a payment. | ||||
Show All 21 Lines |
Can array_merge handle a non-existing $eurMethods in the $currency == 'EUR' case? Otherwise set to []