Solved

After creating a draft order using GraphQL how do I apply a payment using GraphQL?

Schmidtc63
Shopify Partner
89 13 23

Using GraphQL, I can create a draft order and then complete it, which creates a "real" order. How do I apply a payment to that order using GraphQL?

 

I know how to create and submit a CC transaction, paypal transaction or even gift card but I don't know how to pay the order from those transactions.

 

Thank you.

Accepted Solution (1)
Schmidtc63
Shopify Partner
89 13 23

This is an accepted solution.

Ok. Got this figured out.

 

First, I created a graphql draft order object, complete with billing and shipping address, line items and the shopify customer id.

 

Then, I submit that object to graphql  mutation draftOrderCalculate.

 

From the returned draftOrderCalculate object, I get the shipping lines and the user chooses one of those.

 

Finally, the draft order object is recreated and calculated  to account for any new line items the user chose, plus the shipping option. This returns a draftOrder object, complete with taxes, etc.

 

That object is submitted to graphql mutation draftOrderCreate.

 

That mutation returns a graphql draftOrder object.

 

 

That object is submitted to graphql mutation draftOrderComplete with paymentPending=true.

 

And now I have a non-paid order to which I can submit payment transactions.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

View solution in original post

Replies 4 (4)

mikerowave
Shopify Staff (Retired)
22 3 2

Hi @Schmidtc63!


To capture a transaction on an order use the 
orderCapture mutation from the GraphQL Order API. You must query the order's transactions field first to get the transaction details, and then plug that data into the required inputs of the mutation (amountcurrencyid, and parentTransactionId ).

Mike M (mikerowave) | API Support @ Shopify 
 - Was my reply helpful? Click Like to let me know!
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit shopify.dev or the Shopify Web Design and Development Blog

Schmidtc63
Shopify Partner
89 13 23

I don't want to capture a transaction. I want to create one. The order is unpaid. How do I create a transaction on an unpaid order?

mikerowave
Shopify Staff (Retired)
22 3 2

I think there might be some confusion here so here's a good breakdown of the types of transactions from our REST documentation. Reading through the test order example is also great for better understanding transactions and checkout flow.

You could also take a look at the orderMarkAsPaid mutation. This allows you to mark an order as paid for when no transaction has taken place. It is the equivalent of a merchant collecting payment outside of Shopify and using the Mark a paid button in the admin.

Mike M (mikerowave) | API Support @ Shopify 
 - Was my reply helpful? Click Like to let me know!
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit shopify.dev or the Shopify Web Design and Development Blog

Schmidtc63
Shopify Partner
89 13 23

This is an accepted solution.

Ok. Got this figured out.

 

First, I created a graphql draft order object, complete with billing and shipping address, line items and the shopify customer id.

 

Then, I submit that object to graphql  mutation draftOrderCalculate.

 

From the returned draftOrderCalculate object, I get the shipping lines and the user chooses one of those.

 

Finally, the draft order object is recreated and calculated  to account for any new line items the user chose, plus the shipping option. This returns a draftOrder object, complete with taxes, etc.

 

That object is submitted to graphql mutation draftOrderCreate.

 

That mutation returns a graphql draftOrder object.

 

 

That object is submitted to graphql mutation draftOrderComplete with paymentPending=true.

 

And now I have a non-paid order to which I can submit payment transactions.