Prechádzať zdrojové kódy

Add optional currency parameter to Order#capture

Jamie Dwyer 6 rokov pred
rodič
commit
b653102f31
2 zmenil súbory, kde vykonal 25 pridanie a 2 odobranie
  1. 9 2
      lib/shopify_api/resources/order.rb
  2. 16 0
      test/order_test.rb

+ 9 - 2
lib/shopify_api/resources/order.rb

@@ -19,8 +19,15 @@ module ShopifyAPI
       Transaction.find(:all, :params => { :order_id => id })
     end
 
-    def capture(amount = "")
-      Transaction.create(:amount => amount, :kind => "capture", :order_id => id)
+    def capture(amount = "", currency: nil)
+      capture_transaction = {
+        amount: amount,
+        kind: "capture",
+        order_id: id,
+      }
+      capture_transaction[:currency] = currency if currency
+
+      Transaction.create(capture_transaction)
     end
 
     class ClientDetails < Base

+ 16 - 0
test/order_test.rb

@@ -56,4 +56,20 @@ class OrderTest < Test::Unit::TestCase
     order.cancel(email: false, restock: true)
     assert_request_body({'email' => false, 'restock' => true}.to_json)
   end
+
+  test "capture an order with currency param" do
+    fake 'orders/450789469', body: load_fixture('order')
+    order = ShopifyAPI::Order.find(450789469)
+
+    fake 'orders/450789469/transactions', method: :post, status: 201, body: load_fixture('transaction')
+    order.capture(100.00, currency: 'CAD')
+
+    assert_request_body({
+      transaction: {
+        amount: 100.00,
+        kind: 'capture',
+        currency: 'CAD',
+      },
+    }.to_json)
+  end
 end