Re: trying to post to payments.json gives BadRequestError

Solved

trying to post to payments.json gives BadRequestError

mike_batch
Shopify Partner
17 1 15

Hey Shopify community

 

I am trying to get to payments.json endpoint working and it's been a real struggle.

 

I have been following this guideline: https://shopify.dev/tutorials/complete-a-sales-channel-payment-with-checkout-api

 

My steps are as follows:

1. On the frontend the user fills out the necessary information (e.g. what items they want, their card information which is tokenized by stripe, shipping address...)

2. on the backend I create a checkout and get back the shopify_payments_account_id and the shopify checkout token

3. I use the customer information and credit card information to create a stripe customer with an attached source

4. I create a token using that stripe customer and the attached source with my shopify_payments_account_id which uses the stripe connect mechanism to create a token to pass to shopify's payments.json endpoint

 

The issue is at the last step

When I call

`/admin/api/2019-04/checkouts/${token}/payments.json`

with the following body

{
   "payment":{
      "amount":"81.63",
      "payment_token":{
         "payment_data":"tok_1xxxxxxaly",
         "type":"stripe_vault_token"
      },
      "request_details":{ 
"accept_language": 'en-US,en;q=0.9,fr;q=0.8,ru;q=0.7,it;q=0.6',
"ip_address": '172.26.0.3',
"user_agent": 'BATCH-API' }, "unique_token":"d792c843-0910-48b9-a53f-0c1f80870117" //this is a uuid, is that an issue? } }

I constantly get the error back:

 '{"errors":{"request_details":"Required parameter missing or invalid"}}',

I have no idea what to do with this error message. Which field could be missing, or what is invalid?

Any help would be appreciated.

 

p.s.

I noticed that the payments documentation under the sales channel section went missing today. The link I used up until today (https://shopify.dev/docs/admin-api/rest/reference/sales-channels/payment) now returns a 500. The docs in the tutorial I linked above show code from the API version from 2016. 

Accepted Solution (1)

mike_batch
Shopify Partner
17 1 15

This is an accepted solution.

for anyone struggling I solved it.

Turns out the API documents are just wrong.

The one I was following is: https://shopify.dev/tutorials/complete-a-sales-channel-payment-with-checkout-api and it states the body should be:

{
  "payment": {
    "amount": "33.00",
    "unique_token": "12345",
    "payment_token": {
      "payment_data": "tok_1AgzvXGp4JCfxblBH7gs5kLB",
      "type": "stripe_vault_token" },
    "request_details": {
      "ip_address": "123.1.1.1",
      "accept_language": "en"
      "user_agent": "Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/54.0.2840.98 Safari\/537.36"
    },
  }
}

However this is just wrong as it should be:

{
  "payment": {
    "amount": "33.00",
    "unique_token": "12345",
    "payment_token": {
      "payment_data": "tok_1AgzvXGp4JCfxblBH7gs5kLB",
      "type": "stripe_vault_token" }
  },
    "request_details": {
      "ip_address": "123.1.1.1",
      "accept_language": "en"
      "user_agent": "Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/54.0.2840.98 Safari\/537.36"
    }
}

Request_details have to be a level above and at the same level as payment.

 

Still no idea why the the docs for the payments.json endpoint went missing though. It really feels like working in the dark and I figured it out by intuition and a lucky guess.

View solution in original post

Reply 1 (1)

mike_batch
Shopify Partner
17 1 15

This is an accepted solution.

for anyone struggling I solved it.

Turns out the API documents are just wrong.

The one I was following is: https://shopify.dev/tutorials/complete-a-sales-channel-payment-with-checkout-api and it states the body should be:

{
  "payment": {
    "amount": "33.00",
    "unique_token": "12345",
    "payment_token": {
      "payment_data": "tok_1AgzvXGp4JCfxblBH7gs5kLB",
      "type": "stripe_vault_token" },
    "request_details": {
      "ip_address": "123.1.1.1",
      "accept_language": "en"
      "user_agent": "Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/54.0.2840.98 Safari\/537.36"
    },
  }
}

However this is just wrong as it should be:

{
  "payment": {
    "amount": "33.00",
    "unique_token": "12345",
    "payment_token": {
      "payment_data": "tok_1AgzvXGp4JCfxblBH7gs5kLB",
      "type": "stripe_vault_token" }
  },
    "request_details": {
      "ip_address": "123.1.1.1",
      "accept_language": "en"
      "user_agent": "Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/54.0.2840.98 Safari\/537.36"
    }
}

Request_details have to be a level above and at the same level as payment.

 

Still no idea why the the docs for the payments.json endpoint went missing though. It really feels like working in the dark and I figured it out by intuition and a lucky guess.