Skip to content

Commit

Permalink
Trim spaces from csv strings
Browse files Browse the repository at this point in the history
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()`
  • Loading branch information
alexdpunkt authored Dec 15, 2020
1 parent 9e9d192 commit d85465e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ?? [];
Expand All @@ -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));
}
}

0 comments on commit d85465e

Please sign in to comment.