Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endpoint did not accept the request. (Code: 422) #44

Closed
ayafaheem opened this issue Dec 18, 2019 · 16 comments
Closed

Endpoint did not accept the request. (Code: 422) #44

ayafaheem opened this issue Dec 18, 2019 · 16 comments
Labels
help wanted Extra attention is needed

Comments

@ayafaheem
Copy link

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 ??

@aquila-freitas-cko
Copy link
Contributor

aquila-freitas-cko commented Dec 18, 2019

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.

@aquila-freitas-cko aquila-freitas-cko added the help wanted Extra attention is needed label Dec 18, 2019
@Amaraciuri
Copy link

Same here, The endpoint did not accept the request. (Code: 422)

@aquila-freitas-cko
Copy link
Contributor

Hi @Amaraciuri ,
I believe you are sending invalid data to the gateway. Could you catch the error and see what field is invalid?

@therajibhossain
Copy link

therajibhossain commented Feb 11, 2020

Are your payment credentials valid? Check if you are sending request to sandbox or live

@iamsajidjaved
Copy link

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);
    }

@aquila-freitas-cko
Copy link
Contributor

aquila-freitas-cko commented Apr 11, 2020

@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

@Paula2001
Copy link

I am facing the same issue is it because I am using the sandbox endpoint ?

@aquila-freitas-cko
Copy link
Contributor

@Paula2001 ,
There are many reasons why gateway can respond with 422. You will find more details in the reference.

@Paula2001
Copy link

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 .

@iamsajidjaved
Copy link

iamsajidjaved commented Apr 14, 2020 via email

@Paula2001
Copy link

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

@Paula2001
Copy link

worth to mention that I am using the testing account

@iamsajidjaved
Copy link

iamsajidjaved commented Apr 14, 2020 via email

@iamsajidjaved
Copy link

iamsajidjaved commented Apr 14, 2020 via email

@iamsajidjaved
Copy link

iamsajidjaved commented Apr 14, 2020 via email

@Paula2001
Copy link

thanks appreciate your share

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Development

No branches or pull requests

7 participants