From d85465e111a2866b29562de6c3ac3ed2454adac2 Mon Sep 17 00:00:00 2001 From: alexdpunkt Date: Tue, 15 Dec 2020 20:05:35 +0100 Subject: [PATCH] Trim spaces from csv strings If payment methods are supplied with spaces, like `AMEX, BANCONTACT` those spaces end up in request data like ` BANCONTACT`, which causes problems. Refactored exploding of csv strings to `trimExplode()` --- Api.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Api.php b/Api.php index 063e9ea..78b9ece 100644 --- a/Api.php +++ b/Api.php @@ -296,14 +296,14 @@ protected function addOptionalInterfaceParams(string $interface, array $payload) $payload['ConfigSet'] = (string) $optionValue; break; case 'payment_methods': - $payload['PaymentMethods'] = explode(',', $optionValue); + $payload['PaymentMethods'] = $this->trimExplode($optionValue); break; case 'wallets': - $payload['Wallets'] = explode(',', $optionValue); + $payload['Wallets'] = $this->trimExplode($optionValue); break; case 'notification_merchant_email': $payload['Notification'] = $payload['Notification'] ?? []; - $payload['Notification']['MerchantEmails'] = explode(',', $optionValue); + $payload['Notification']['MerchantEmails'] = $this->trimExplode($optionValue); break; case 'notification_payer_email': $payload['Notification'] = $payload['Notification'] ?? []; @@ -329,4 +329,13 @@ protected function addOptionalInterfaceParams(string $interface, array $payload) return $payload; } + + /** + * @param string $data + * @param string $delimiter + * @return array + */ + protected function trimExplode(string $data, string $delimiter = ','): array { + return array_map('trim', explode($delimiter, $data)); + } }