"Token signature verification failed" when creating an order

MarkyMark1000
Contributor
Contributor

Hi,

 

I have been trying to learn how to use PayPal by using the following link:

https://developer.paypal.com/docs/business/checkout/

 

In particular, I am getting stuck on the 'Advanced Credit and Debit Card Payments' and I seem to be getting an error indicating that my token signature is invalid.   I am in the UK and have setup a personal and business sandbox account in GBP.   At present I am following this procedure:

 

1 - Get an access token using something similar to this:

curl -v POST https://api-m.sandbox.paypal.com/v1/oauth2/token \
-H "Accept: application/json" \
-H "Accept-Language: en_US" \
-u "[CLIENT_ID]:[SECRET]" \
-d "grant_type=client_credentials"

 

This works and returns data containing an access token.

 

2 - Next I try to get a client token using something similar to this:

curl -X POST https://api-m.sandbox.paypal.com/v1/identity/generate-token \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer ...[ACCESS_TOKEN].....' \
-H 'Accept-Language: en_US'

 

This works and returns a very large client token.

 

3 - Finally I try to create an order by running something similar to this:

curl -v -X POST https://api-m.sandbox.paypal.com/v2/checkout/orders \-H "Content-Type: application/json" \-H "Authorization: Bearer ...[CLIENT_TOKEN]...." \
-d '{
"intent": "CAPTURE",
"purchase_units": [
{
"amount": {
"currency_code": "USD",
"value": "100.00"
}
}
]
}'

 

This is where I hit a problem.   It returns the following error:

{"error":"invalid_token","error_description":"Token signature verification failed"}

 

I decided to change the Accept-Language: en_US to Accept-Language: en_GP and change the "currency_code": "USD", to "currency_code": "GBP", just incase it was something to do with the account currency.   Unfortunately I get the same error:

{"error":"invalid_token","error_description":"Token signature verification failed"}

 

I would really appreciate if you could help with this.   Also if you have any suggestions on how to get better with this and debug API calls, I would really appreciate it.   Is there a quick way to get support ?

 

Thanks

 

Mark

Login to Me Too
2 REPLIES 2

proofbyconcept
New Community Member

Hey @MarkyMark1000 - I had the same issue when I was using Shell environment variables, specifically when using the single quotes with a variable.

 

This:

 

curl -X POST https://api-m.sandbox.paypal.com/v1/identity/generate-token \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer ${ACCESS_TOKEN}' \
-H 'Accept-Language: en_US'

 

Returns:

 

{"error":"invalid_token","error_description":"Token signature verification failed"}

 

 

 

This will work (using double quotes):

 

curl -X POST https://api-m.sandbox.paypal.com/v1/identity/generate-token \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
-H 'Accept-Language: en_US'

 

 

Login to Me Too

JBuggsy
New Community Member

I'm having a similar problem but I am coding in VS code.  When I click the paypal button I get:

"Could not initiate PayPal Checkout...
Error: {"error":"invalid_token","error_description":"Token signature verification failed"}".  

 

How can I fix this in my environment?

 

here is a code snippet where I found the problem to be.  the "orderData.id" is returning false.  why?

window.paypal
  .Buttons({
    async createOrder() {
      try {
        const response = await fetch("/api/orders", {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
          },
          // use the "body" param to optionally pass additional order information
          // like product ids and quantities
          body: JSON.stringify({
            cart: [
              {
                id: "YOUR_PRODUCT_ID",
                quantity: "YOUR_PRODUCT_QUANTITY",
              },
            ],
          }),
        });

        const orderData = await response.json();

        if (orderData.id) {
          return orderData.id;
        } else {
          const errorDetail = orderData?.details?.[0];
          const errorMessage = errorDetail
            ?`${errorDetail.issue} ${errorDetail.description} (${orderData.debug_id})`
            : JSON.stringify(orderData);

          throw new Error(errorMessage);
        }
      } catch (error) {
        console.error(error);
        resultMessage(`Could not initiate PayPal Checkout...<br><br>${error}`);
      }
    }
Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.