A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
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.
Solved! Go to the solution
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.
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 (amount
, currency
, id
, 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
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?
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
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.