Authorization request fails because in some cases payment method becomes hash map instead of array
Closed this issue · 0 comments
plewandowski commented
The problem
Payment cannot be initialized due API validation error.
Request
{
"RequestHeader": {
"SpecVersion": "1.33",
"CustomerId": "11111111",
"RequestId": "2b794e1d-d6eb-4c33-ae1a-31b97a5500dc",
"RetryIndicator": 0
},
"TerminalId": "111111111",
"Payment": {
"Amount": {
"Value": 12400,
"CurrencyCode": "CHF"
},
"OrderId": "000000039",
"Description": "Payment for order #000000039"
},
"PaymentMethods": {
"1": "DINERS",
"3": "PAYCONIQ",
"4": "MAESTRO",
"5": "MASTERCARD",
"6": "PAYPAL",
"7": "TWINT",
"8": "VISA"
},
"Notification": {
"PayerEmail": "piotr.lewandowski@madcoders.pl"
},
"ReturnUrl": {
"Url": "https://xxxxxxxxxxxxxxxxxxx/de_CH/order/after-pay?payum_token=r7wYLU0S_DTmz2lNA3azpplzaHNSkEcAS-bP_dMCb0o"
}
}
Response:
{
"ResponseHeader": {
"SpecVersion": "1.33",
"RequestId": "2b794e1d-d6eb-4c33-ae1a-31b97a5500dc"
},
"Behavior": "DO_NOT_RETRY",
"ErrorName": "VALIDATION_FAILED",
"ErrorMessage": "Request validation failed",
"ErrorDetail": [
"PaymentMethods.1: The field is invalid."
]
}
Looking at error detail and documentation (https://saferpay.github.io/jsonapi/#ChapterPaymentPage) we know that PaymentMethod should contain array of strings, thus it should look like:
"PaymentMethods": [
"DINERS",
"PAYCONIQ",
"MAESTRO",
"MASTERCARD",
"PAYPAL",
"TWINT",
"VISA"
]
I guess problem is related to this code:
How to fix?
For example:
/** @var array<string, string> $allowedPaymentMethods */
$allowedPaymentMethods = $gatewayConfig->getConfig()['allowed_payment_methods'];
replace with:
/** @var string[] $allowedPaymentMethods */
$allowedPaymentMethods = array_values($gatewayConfig->getConfig()['allowed_payment_methods']);