3
votes

In the Shopify admin area there is a button on each order to "Accept Payment". Is there an equivalent action that can be performed via the API?

2

2 Answers

3
votes

Yes. You can create a transaction and capture the amount that was previously authorized.

 ShopifyAPI::Transaction.create({:order_id => order.id, :kind => 'capture'})
1
votes

Yes, make sure the original order is created through the API and has a status of "pending", transaction kind of "authorization", and transaction status of "success". Then when you capture the payment it is only changing the financial status. You cannot just change the financial status value on the order without capturing the transaction.

So this is the original request to create the order using the API:

POST /admin/orders.json

{
   "financial_status": "pending",
   "fulfillment_status": "fulfilled",
   "transactions": [{
      "amount": "21",
      "kind": "authorization",
      "gateway": "Gateway",
      "status": "success",
      "source_name": "My API"
   }]
}

And then to capture the transaction do this:

POST /admin/orders/{order_id}/transactions.json

{
  "transaction": {
    "kind": "capture"
  }
}

Make sure you have write permissions enabled for orders on your API: https://redeeem.myshopify.com/admin/apps/private