Endpoint did not accept the request. (Code: 422)
ayafaheem opened this issue · 16 comments
Hello dear ,
I'm having an issue in the checkout-sdk-php when payments using apple pay
after pay using apple pay and Create a Apple Pay token then Create new payment method this error appear to me .
Checkout\Library\Exceptions\CheckoutHttpException: The endpoint did not accept the request. (Code: 422) in vendor/checkout/checkout-sdk-php/src/Library/HttpHandler.php:327
Any one can help me to fix this bug ??
Hi @ayafaheem ,
Error 422 is a gateway response for invalid data sent. Double check if Apple data is well decoded when sending to your PHP file from the front-end.
You can always catch CheckoutHttpException exception, print $e->getErrors();
or $e->getBody();
to help you on debugging.
Same here, The endpoint did not accept the request. (Code: 422)
Hi @Amaraciuri ,
I believe you are sending invalid data to the gateway. Could you catch the error and see what field is invalid?
Are your payment credentials valid? Check if you are sending request to sandbox or live
Same issue with me. My Secret key and cart token is correct. Did anyone found the solution?
public function store(Request $request)
{
// Initialize the Checkout API
$checkout = new CheckoutApi('sk_test_b5065bb5-f1b1-4dd3-b21a-bd9f2d99375b');
// Create a payment method instance with card details
$method = new TokenSource("$request->checkout_token");
// Prepare the payment parameters
$payment = new Payment($method, 'GBP');
$payment->amount = 10000; // = 10.00
// Send the request and retrieve the response
$response = $checkout->payments()->request($payment);
dd($response);
}
@iamsajidjaved ,
I've tried to run your example and is working fine. Error code 422 means you are sending invalid data to the gateway (see more here).
Try wrapping $response = $checkout->payments()->request($payment);
with a try-catch and see what data is invalid. Here's an example:
try {
$response = $checkout->payments()->request($payment);
} catch(Checkout\Library\Exceptions\CheckoutHttpException $ex) {
print_r($ex->getBody());
}
Here's a link about error handling of the PHP SDK: https://github.com/checkout/checkout-sdk-php/wiki#error-handling
I am facing the same issue is it because I am using the sandbox endpoint ?
@Paula2001 ,
There are many reasons why gateway can respond with 422. You will find more details in the reference.
I've read this several times already and the data is correct ,The only thing left is that I am using the testing token and I want to know if there's a proof that supports that .
I am getting "Your API key is invalid." and I double checked the token also there's something I don't understand $method = new TokenSource('tok_ubfj2q76miwundwlk72vxt2i7q');
what's that @iamsajidjaved
worth to mention that I am using the testing account
thanks appreciate your share