def mark_as_paid
require 'shopify_api'
ShopifyAPI::Base.site = order.site.get_site
ShopifyAPI::Order.find(order.id).open
ShopifyAPI::Order.new(:id => order.id, :readonly => false).capture
return true
end
The third 'ShopifyAPI' line creates a new transaction on the order with type 'capture' and that marks a pending order as paid.
def mark_as_paid(order)
…
end
I originally thought the same thing as you, that that code would create a new order. But in fact it is a new transaction on the order specified by the :id param. We've never used the ShopifyAPI::Transaction for anything, so I'm not sure about that.
I'm not sure if the open call is necessary by the way. We just like to close pending orders as otherwise we end up with thousands. This just makes sure that the order is open when/after the order is marked off.
Creating a new instance of an object with ActiveResource doesn't
actually try to create a new order until you to save it, really all it
is doing is setting the id of the order so that capture can use it
when creating the Transaction for the Order.
John Duff
Developer @ Shopify
ShopifyAPI::Transaction.create(:kind => "capture", :order_id => id)
You can also capture a partial amount by include :amount =>
amount_to_capture as a parameter to the transaction.
John Duff
Developer @ Shopify
On Wed, Oct 5, 2011 at 6:52 AM, David Speake