stripe 1.43.1 → 1.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +4 -0
  3. data/VERSION +1 -1
  4. data/lib/stripe.rb +1 -1
  5. data/lib/stripe/account.rb +2 -2
  6. data/lib/stripe/alipay_account.rb +5 -1
  7. data/lib/stripe/api_operations/{update.rb → save.rb} +24 -1
  8. data/lib/stripe/application_fee_refund.rb +5 -1
  9. data/lib/stripe/bank_account.rb +5 -1
  10. data/lib/stripe/bitcoin_receiver.rb +1 -1
  11. data/lib/stripe/card.rb +5 -1
  12. data/lib/stripe/charge.rb +1 -1
  13. data/lib/stripe/coupon.rb +1 -1
  14. data/lib/stripe/customer.rb +1 -1
  15. data/lib/stripe/dispute.rb +1 -1
  16. data/lib/stripe/invoice.rb +1 -1
  17. data/lib/stripe/invoice_item.rb +1 -1
  18. data/lib/stripe/order.rb +1 -1
  19. data/lib/stripe/plan.rb +1 -1
  20. data/lib/stripe/product.rb +1 -1
  21. data/lib/stripe/recipient.rb +1 -1
  22. data/lib/stripe/refund.rb +1 -1
  23. data/lib/stripe/reversal.rb +5 -1
  24. data/lib/stripe/sku.rb +1 -2
  25. data/lib/stripe/subscription.rb +2 -2
  26. data/lib/stripe/transfer.rb +1 -2
  27. data/lib/stripe/version.rb +1 -1
  28. data/test/stripe/account_test.rb +26 -1
  29. data/test/stripe/api_operations_test.rb +20 -0
  30. data/test/stripe/charge_test.rb +8 -0
  31. data/test/stripe/coupon_test.rb +9 -1
  32. data/test/stripe/customer_test.rb +9 -1
  33. data/test/stripe/dispute_test.rb +8 -0
  34. data/test/stripe/invoice_item_test.rb +19 -0
  35. data/test/stripe/invoice_test.rb +8 -0
  36. data/test/stripe/order_test.rb +9 -1
  37. data/test/stripe/plan_test.rb +31 -0
  38. data/test/stripe/product_test.rb +9 -1
  39. data/test/stripe/recipient_test.rb +21 -0
  40. data/test/stripe/refund_test.rb +10 -1
  41. data/test/stripe/sku_test.rb +8 -0
  42. data/test/stripe/subscription_test.rb +11 -0
  43. data/test/stripe/transfer_test.rb +8 -0
  44. data/test/test_data.rb +42 -2
  45. metadata +11 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 57598a9b03ea0fbec114906e397d77c1269dec18
4
- data.tar.gz: e40cb1a5699707e7279aba5abe1b0f4ee71a624c
3
+ metadata.gz: 119a28c4474b441d0acfc5e6ebbbf47038e9e509
4
+ data.tar.gz: 14c9aeb9e6f6a78a73b7bfa2cd94b4135a627eff
5
5
  SHA512:
6
- metadata.gz: 0aaff9bcd96782e96d992c44d4d2af47131af21e508b0adcc3d92c9eb385bfc472bfb6d31dfbdcc413565160cf20a524f9763b1ba0bec06c4a84152b96465930
7
- data.tar.gz: 856a3bcced4ff4830c13e58103febde22ab7c81cd058cff779996d2b574aa85fead3a5961716c9407061d9f49c2f46b6804e2ce1da6426837e780227cf6c33d3
6
+ metadata.gz: 0f7809e7801f9a9f32b82680b8d0ff02fa90348cd7753a08c46aa61745e8b70900465fe263635e07ac01df29abc424b5bfe38320bd82ea723cf652edb4101430
7
+ data.tar.gz: efede3fa5a4f1e3f4ffbb3c2f21820aa4f7b948442d1ab83acf79485826735068bce355331bfc005770a8ad0d77611c106ae156faae4bcc998576abafdfc269d
@@ -1,3 +1,7 @@
1
+ === 1.44.0 2016-06-29
2
+
3
+ * Add `update` class method to all resources that can be updated
4
+
1
5
  === 1.43.1 2016-06-17
2
6
 
3
7
  * Fix type of resource returned from `Order#return_order`
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.43.1
1
+ 1.44.0
@@ -14,7 +14,7 @@ require 'stripe/version'
14
14
 
15
15
  # API operations
16
16
  require 'stripe/api_operations/create'
17
- require 'stripe/api_operations/update'
17
+ require 'stripe/api_operations/save'
18
18
  require 'stripe/api_operations/delete'
19
19
  require 'stripe/api_operations/list'
20
20
  require 'stripe/api_operations/request'
@@ -1,9 +1,9 @@
1
1
  module Stripe
2
2
  class Account < APIResource
3
3
  extend Stripe::APIOperations::Create
4
- include Stripe::APIOperations::Delete
5
4
  extend Stripe::APIOperations::List
6
- include Stripe::APIOperations::Update
5
+ include Stripe::APIOperations::Delete
6
+ include Stripe::APIOperations::Save
7
7
 
8
8
  def resource_url
9
9
  if self['id']
@@ -1,6 +1,6 @@
1
1
  module Stripe
2
2
  class AlipayAccount < APIResource
3
- include Stripe::APIOperations::Update
3
+ include Stripe::APIOperations::Save
4
4
  include Stripe::APIOperations::Delete
5
5
 
6
6
  def resource_url
@@ -9,6 +9,10 @@ module Stripe
9
9
  end
10
10
  end
11
11
 
12
+ def self.update(id, params=nil, opts=nil)
13
+ raise NotImplementedError.new("Alipay accounts cannot be updated without a customer ID. Update an Alipay account by `a = customer.sources.retrieve('alipay_account_id'); a.save`")
14
+ end
15
+
12
16
  def self.retrieve(id, opts=nil)
13
17
  raise NotImplementedError.new("Alipay accounts cannot be retrieved without a customer ID. Retrieve an Alipay account using customer.sources.retrieve('alipay_account_id')")
14
18
  end
@@ -1,6 +1,25 @@
1
1
  module Stripe
2
2
  module APIOperations
3
- module Update
3
+ module Save
4
+ module ClassMethods
5
+ # Updates an API resource
6
+ #
7
+ # Updates the identified resource with the passed in parameters.
8
+ #
9
+ # ==== Attributes
10
+ #
11
+ # * +id+ - ID of the resource to update.
12
+ # * +params+ - A hash of parameters to pass to the API
13
+ # * +opts+ - A Hash of additional options (separate from the params /
14
+ # object values) to be added to the request. E.g. to allow for an
15
+ # idempotency_key to be passed in the request headers, or for the
16
+ # api_key to be overwritten. See {APIOperations::Request.request}.
17
+ def update(id, params={}, opts={})
18
+ response, opts = request(:post, "#{resource_url}/#{id}", params, opts)
19
+ Util.convert_to_stripe_object(response, opts)
20
+ end
21
+ end
22
+
4
23
  # Creates or updates an API resource.
5
24
  #
6
25
  # If the resource doesn't yet have an assigned ID and the resource is one
@@ -38,6 +57,10 @@ module Stripe
38
57
  self
39
58
  end
40
59
 
60
+ def self.included(base)
61
+ base.extend(ClassMethods)
62
+ end
63
+
41
64
  private
42
65
 
43
66
  def save_url
@@ -1,12 +1,16 @@
1
1
  module Stripe
2
2
  class ApplicationFeeRefund < APIResource
3
- include Stripe::APIOperations::Update
3
+ include Stripe::APIOperations::Save
4
4
  extend Stripe::APIOperations::List
5
5
 
6
6
  def resource_url
7
7
  "#{ApplicationFee.resource_url}/#{CGI.escape(fee)}/refunds/#{CGI.escape(id)}"
8
8
  end
9
9
 
10
+ def self.update(id, params=nil, opts=nil)
11
+ raise NotImplementedError.new("Refunds cannot be updated without an application fee ID. Update a refund by using `a = appfee.refunds.retrieve('refund_id'); a.save`")
12
+ end
13
+
10
14
  def self.retrieve(id, api_key=nil)
11
15
  raise NotImplementedError.new("Refunds cannot be retrieved without an application fee ID. Retrieve a refund using appfee.refunds.retrieve('refund_id')")
12
16
  end
@@ -1,6 +1,6 @@
1
1
  module Stripe
2
2
  class BankAccount < APIResource
3
- include Stripe::APIOperations::Update
3
+ include Stripe::APIOperations::Save
4
4
  include Stripe::APIOperations::Delete
5
5
  extend Stripe::APIOperations::List
6
6
 
@@ -17,6 +17,10 @@ module Stripe
17
17
  end
18
18
  end
19
19
 
20
+ def self.update(id, params=nil, opts=nil)
21
+ raise NotImplementedError.new("Bank accounts cannot be updated without an account ID. Update a bank account by using `a = account.external_accounts.retrieve('card_id'); a.save`")
22
+ end
23
+
20
24
  def self.retrieve(id, opts=nil)
21
25
  raise NotImplementedError.new("Bank accounts cannot be retrieved without an account ID. Retrieve a bank account using account.external_accounts.retrieve('card_id')")
22
26
  end
@@ -1,7 +1,7 @@
1
1
  module Stripe
2
2
  class BitcoinReceiver < APIResource
3
3
  extend Stripe::APIOperations::Create
4
- include Stripe::APIOperations::Update
4
+ include Stripe::APIOperations::Save
5
5
  include Stripe::APIOperations::Delete
6
6
  extend Stripe::APIOperations::List
7
7
 
@@ -1,6 +1,6 @@
1
1
  module Stripe
2
2
  class Card < APIResource
3
- include Stripe::APIOperations::Update
3
+ include Stripe::APIOperations::Save
4
4
  include Stripe::APIOperations::Delete
5
5
  extend Stripe::APIOperations::List
6
6
 
@@ -14,6 +14,10 @@ module Stripe
14
14
  end
15
15
  end
16
16
 
17
+ def self.update(id, params=nil, opts=nil)
18
+ raise NotImplementedError.new("Cards cannot be updated without a customer ID. Update a card using `c = customer.sources.retrieve('card_id'); c.save`")
19
+ end
20
+
17
21
  def self.retrieve(id, opts=nil)
18
22
  raise NotImplementedError.new("Cards cannot be retrieved without a customer ID. Retrieve a card using customer.sources.retrieve('card_id')")
19
23
  end
@@ -2,7 +2,7 @@ module Stripe
2
2
  class Charge < APIResource
3
3
  extend Stripe::APIOperations::List
4
4
  extend Stripe::APIOperations::Create
5
- include Stripe::APIOperations::Update
5
+ include Stripe::APIOperations::Save
6
6
 
7
7
  def refund(params={}, opts={})
8
8
  # Old versions of charge objects included a `refunds` field that was just
@@ -1,7 +1,7 @@
1
1
  module Stripe
2
2
  class Coupon < APIResource
3
3
  extend Stripe::APIOperations::Create
4
- include Stripe::APIOperations::Update
4
+ include Stripe::APIOperations::Save
5
5
  include Stripe::APIOperations::Delete
6
6
  extend Stripe::APIOperations::List
7
7
  end
@@ -2,7 +2,7 @@ module Stripe
2
2
  class Customer < APIResource
3
3
  extend Stripe::APIOperations::Create
4
4
  include Stripe::APIOperations::Delete
5
- include Stripe::APIOperations::Update
5
+ include Stripe::APIOperations::Save
6
6
  extend Stripe::APIOperations::List
7
7
 
8
8
  def add_invoice_item(params, opts={})
@@ -2,7 +2,7 @@ module Stripe
2
2
  class Dispute < APIResource
3
3
  extend Stripe::APIOperations::List
4
4
  extend Stripe::APIOperations::Create
5
- include Stripe::APIOperations::Update
5
+ include Stripe::APIOperations::Save
6
6
 
7
7
  def close(params={}, opts={})
8
8
  response, opts = request(:post, close_url, params, opts)
@@ -1,7 +1,7 @@
1
1
  module Stripe
2
2
  class Invoice < APIResource
3
3
  extend Stripe::APIOperations::List
4
- include Stripe::APIOperations::Update
4
+ include Stripe::APIOperations::Save
5
5
  extend Stripe::APIOperations::Create
6
6
 
7
7
  def self.upcoming(params, opts={})
@@ -3,6 +3,6 @@ module Stripe
3
3
  extend Stripe::APIOperations::List
4
4
  extend Stripe::APIOperations::Create
5
5
  include Stripe::APIOperations::Delete
6
- include Stripe::APIOperations::Update
6
+ include Stripe::APIOperations::Save
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@ module Stripe
2
2
  class Order < APIResource
3
3
  extend Stripe::APIOperations::List
4
4
  extend Stripe::APIOperations::Create
5
- include Stripe::APIOperations::Update
5
+ include Stripe::APIOperations::Save
6
6
 
7
7
  def pay(params, opts={})
8
8
  response, opts = request(:post, pay_url, params, opts)
@@ -3,6 +3,6 @@ module Stripe
3
3
  extend Stripe::APIOperations::Create
4
4
  include Stripe::APIOperations::Delete
5
5
  extend Stripe::APIOperations::List
6
- include Stripe::APIOperations::Update
6
+ include Stripe::APIOperations::Save
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@ module Stripe
2
2
  class Product < APIResource
3
3
  extend Stripe::APIOperations::List
4
4
  extend Stripe::APIOperations::Create
5
- include Stripe::APIOperations::Update
5
+ include Stripe::APIOperations::Save
6
6
  include Stripe::APIOperations::Delete
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@ module Stripe
2
2
  class Recipient < APIResource
3
3
  extend Stripe::APIOperations::Create
4
4
  include Stripe::APIOperations::Delete
5
- include Stripe::APIOperations::Update
5
+ include Stripe::APIOperations::Save
6
6
  extend Stripe::APIOperations::List
7
7
 
8
8
  def transfers
@@ -2,6 +2,6 @@ module Stripe
2
2
  class Refund < APIResource
3
3
  extend Stripe::APIOperations::Create
4
4
  extend Stripe::APIOperations::List
5
- include Stripe::APIOperations::Update
5
+ include Stripe::APIOperations::Save
6
6
  end
7
7
  end
@@ -1,12 +1,16 @@
1
1
  module Stripe
2
2
  class Reversal < APIResource
3
- include Stripe::APIOperations::Update
3
+ include Stripe::APIOperations::Save
4
4
  extend Stripe::APIOperations::List
5
5
 
6
6
  def resource_url
7
7
  "#{Transfer.resource_url}/#{CGI.escape(transfer)}/reversals/#{CGI.escape(id)}"
8
8
  end
9
9
 
10
+ def self.update(id, params=nil, opts=nil)
11
+ raise NotImplementedError.new("Reversals cannot be updated without a transfer ID. Update a reversal using `r = transfer.reversals.retrieve('reversal_id'); r.save`")
12
+ end
13
+
10
14
  def self.retrieve(id, opts={})
11
15
  raise NotImplementedError.new("Reversals cannot be retrieved without a transfer ID. Retrieve a reversal using transfer.reversals.retrieve('reversal_id')")
12
16
  end
@@ -2,8 +2,7 @@ module Stripe
2
2
  class SKU < APIResource
3
3
  extend Stripe::APIOperations::List
4
4
  extend Stripe::APIOperations::Create
5
- include Stripe::APIOperations::Update
5
+ include Stripe::APIOperations::Save
6
6
  include Stripe::APIOperations::Delete
7
-
8
7
  end
9
8
  end
@@ -1,9 +1,9 @@
1
1
  module Stripe
2
2
  class Subscription < APIResource
3
+ extend Stripe::APIOperations::List
3
4
  extend Stripe::APIOperations::Create
4
- include Stripe::APIOperations::Update
5
+ include Stripe::APIOperations::Save
5
6
  include Stripe::APIOperations::Delete
6
- extend Stripe::APIOperations::List
7
7
 
8
8
  def delete_discount
9
9
  _, opts = request(:delete, discount_url)
@@ -2,7 +2,7 @@ module Stripe
2
2
  class Transfer < APIResource
3
3
  extend Stripe::APIOperations::List
4
4
  extend Stripe::APIOperations::Create
5
- include Stripe::APIOperations::Update
5
+ include Stripe::APIOperations::Save
6
6
 
7
7
  def cancel
8
8
  response, api_key = self.request(:post, cancel_url)
@@ -12,6 +12,5 @@ module Stripe
12
12
  def cancel_url
13
13
  resource_url + '/cancel'
14
14
  end
15
-
16
15
  end
17
16
  end
@@ -1,3 +1,3 @@
1
1
  module Stripe
2
- VERSION = '1.43.1'
2
+ VERSION = '1.44.0'
3
3
  end
@@ -68,7 +68,7 @@ module Stripe
68
68
  account.reject(:reason => 'fraud')
69
69
  end
70
70
 
71
- should "be updatable" do
71
+ should "be saveable" do
72
72
  resp = {
73
73
  :id => 'acct_foo',
74
74
  :legal_entity => {
@@ -93,6 +93,31 @@ module Stripe
93
93
  a.save
94
94
  end
95
95
 
96
+ should "be updatable" do
97
+ resp = {
98
+ :id => 'acct_foo',
99
+ :legal_entity => {
100
+ :first_name => 'Bob',
101
+ :address => {
102
+ :line1 => '2 Three Four'
103
+ }
104
+ }
105
+ }
106
+ @mock.expects(:post).
107
+ once.
108
+ with('https://api.stripe.com/v1/accounts/acct_foo', nil, 'legal_entity[address][line1]=2+Three+Four&legal_entity[first_name]=Bob').
109
+ returns(make_response(resp))
110
+
111
+ a = Stripe::Account.update('acct_foo', :legal_entity => {
112
+ :first_name => 'Bob',
113
+ :address => {
114
+ :line1 => '2 Three Four'
115
+ }
116
+ })
117
+ assert_equal('Bob', a.legal_entity.first_name)
118
+ assert_equal('2 Three Four', a.legal_entity.address.line1)
119
+ end
120
+
96
121
  should 'disallow direct overrides of legal_entity' do
97
122
  account = Stripe::Account.construct_from(make_account({
98
123
  :keys => {
@@ -0,0 +1,20 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path('../../test_helper', __FILE__)
3
+
4
+ module Stripe
5
+ class ApiOperationsTest < Test::Unit::TestCase
6
+ class Updater < APIResource
7
+ include Stripe::APIOperations::Save
8
+ end
9
+
10
+ should "the Update API operation should post the correct parameters to the resource URL" do
11
+ @mock.expects(:post).once.
12
+ with("#{Stripe.api_base}/v1/updaters/id", nil, 'foo=bar').
13
+ returns(make_response({foo: 'bar'}))
14
+ resource = Updater::update("id", {foo: "bar"})
15
+ assert_equal('bar', resource.foo)
16
+ end
17
+ end
18
+ end
19
+
20
+
@@ -42,6 +42,14 @@ module Stripe
42
42
  end
43
43
 
44
44
  should "charges should be updateable" do
45
+ @mock.expects(:post).once.
46
+ with('https://api.stripe.com/v1/charges/test_charge', nil, 'metadata[foo]=bar').
47
+ returns(make_response(make_charge(metadata: {'foo' => 'bar'})))
48
+ c = Stripe::Charge.update("test_charge", metadata: {foo: 'bar'})
49
+ assert_equal('bar', c.metadata['foo'])
50
+ end
51
+
52
+ should "charges should be saveable" do
45
53
  @mock.expects(:get).once.returns(make_response(make_charge))
46
54
  @mock.expects(:post).once.returns(make_response(make_charge))
47
55
  c = Stripe::Charge.new("test_charge")
@@ -8,7 +8,7 @@ module Stripe
8
8
  assert_equal "co_test_coupon", c.id
9
9
  end
10
10
 
11
- should "coupons should be updateable" do
11
+ should "coupons should be saveable" do
12
12
  @mock.expects(:get).once.returns(make_response(make_coupon))
13
13
  @mock.expects(:post).once.returns(make_response(make_coupon))
14
14
  c = Stripe::Coupon.new("test_coupon")
@@ -16,5 +16,13 @@ module Stripe
16
16
  c.metadata['foo'] = 'bar'
17
17
  c.save
18
18
  end
19
+
20
+ should "coupons should be updateable" do
21
+ @mock.expects(:post).once.
22
+ with("https://api.stripe.com/v1/coupons/test_coupon", nil, "metadata[foo]=bar").
23
+ returns(make_response(make_coupon(metadata: {foo: 'bar'})))
24
+ c = Stripe::Coupon.update("test_coupon", metadata: {foo: 'bar'})
25
+ assert_equal('bar', c.metadata['foo'])
26
+ end
19
27
  end
20
28
  end
@@ -16,7 +16,7 @@ module Stripe
16
16
  assert c.deleted
17
17
  end
18
18
 
19
- should "customers should be updateable" do
19
+ should "customers should be saveable" do
20
20
  @mock.expects(:get).once.returns(make_response(make_customer({:mnemonic => "foo"})))
21
21
  @mock.expects(:post).once.returns(make_response(make_customer({:mnemonic => "bar"})))
22
22
  c = Stripe::Customer.new("test_customer").refresh
@@ -26,6 +26,14 @@ module Stripe
26
26
  assert_equal "bar", c.mnemonic
27
27
  end
28
28
 
29
+ should "customers should be updateable" do
30
+ @mock.expects(:post).once.
31
+ with("https://api.stripe.com/v1/customers/test_customer", nil, "metadata[foo]=bar").
32
+ returns(make_response(make_customer(metadata: {foo: 'bar'})))
33
+ c = Stripe::Customer.update("test_customer", metadata: {foo: 'bar'})
34
+ assert_equal('bar', c.metadata['foo'])
35
+ end
36
+
29
37
  should "create should return a new customer" do
30
38
  @mock.expects(:post).once.returns(make_response(make_customer))
31
39
  c = Stripe::Customer.create
@@ -29,6 +29,14 @@ module Stripe
29
29
  end
30
30
 
31
31
  should "disputes should be updateable" do
32
+ @mock.expects(:post).once.
33
+ with("https://api.stripe.com/v1/disputes/test_dispute", nil, "metadata[foo]=bar").
34
+ returns(make_response(make_dispute(metadata: {foo: 'bar'})))
35
+ d = Stripe::Dispute.update("test_dispute", metadata: {foo: 'bar'})
36
+ assert_equal('bar', d.metadata['foo'])
37
+ end
38
+
39
+ should "disputes should be saveable" do
32
40
  @mock.expects(:get).once.returns(make_response(make_dispute))
33
41
  @mock.expects(:post).with(
34
42
  "#{Stripe.api_base}/v1/disputes/dp_test_dispute",
@@ -0,0 +1,19 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Stripe
4
+ class InvoiceItemTest < Test::Unit::TestCase
5
+ should "retrieve should retrieve invoice items" do
6
+ @mock.expects(:get).once.returns(make_response(make_invoice_item))
7
+ ii = Stripe::InvoiceItem.retrieve('in_test_invoice_item')
8
+ assert_equal 'ii_test_invoice_item', ii.id
9
+ end
10
+
11
+ should "invoice items should be updateable" do
12
+ @mock.expects(:post).once.
13
+ with('https://api.stripe.com/v1/invoiceitems/test_invoice_item', nil, 'metadata[foo]=bar').
14
+ returns(make_response(make_charge(metadata: {'foo' => 'bar'})))
15
+ ii = Stripe::InvoiceItem.update("test_invoice_item", metadata: {foo: 'bar'})
16
+ assert_equal('bar', ii.metadata['foo'])
17
+ end
18
+ end
19
+ end
@@ -23,6 +23,14 @@ module Stripe
23
23
  assert_equal nil, i.next_payment_attempt
24
24
  end
25
25
 
26
+ should "invoices should be updateable" do
27
+ @mock.expects(:post).once.
28
+ with("https://api.stripe.com/v1/invoices/test_invoice", nil, "metadata[foo]=bar").
29
+ returns(make_response(make_invoice(metadata: {foo: 'bar'})))
30
+ i = Stripe::Invoice.update("test_invoice", metadata: {foo: 'bar'})
31
+ assert_equal('bar', i.metadata['foo'])
32
+ end
33
+
26
34
  should "pay with extra opts should pay an invoice" do
27
35
  @mock.expects(:get).once.returns(make_response(make_invoice))
28
36
  i = Stripe::Invoice.retrieve('in_test_invoice', {:api_key => 'foobar'})
@@ -19,7 +19,7 @@ module Stripe
19
19
  end
20
20
  end
21
21
 
22
- should "orders should be updateable" do
22
+ should "orders should be saveable" do
23
23
  @mock.expects(:get).once.returns(make_response(make_order))
24
24
  @mock.expects(:post).once.returns(make_response(make_order))
25
25
  p = Stripe::Order.new("test_order")
@@ -28,6 +28,14 @@ module Stripe
28
28
  p.save
29
29
  end
30
30
 
31
+ should "orders should be updateable" do
32
+ @mock.expects(:post).once.
33
+ with('https://api.stripe.com/v1/orders/test_order', nil, 'status=fulfilled').
34
+ returns(make_response(make_order(status: 'fulfilled')))
35
+ ii = Stripe::Order.update("test_order", status: 'fulfilled')
36
+ assert_equal('fulfilled', ii.status)
37
+ end
38
+
31
39
  should "orders should allow metadata updates" do
32
40
  @mock.expects(:get).once.returns(make_response(make_order))
33
41
  @mock.expects(:post).once.returns(make_response(make_order))
@@ -0,0 +1,31 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Stripe
4
+ class PlanTest < Test::Unit::TestCase
5
+ should "plans should be listable" do
6
+ @mock.expects(:get).once.returns(make_response(make_plan_array))
7
+ plans = Stripe::Plan.list
8
+ assert plans.data.kind_of?(Array)
9
+ plans.each do |plan|
10
+ assert plan.kind_of?(Stripe::Plan)
11
+ end
12
+ end
13
+
14
+ should "plans should be saveable" do
15
+ @mock.expects(:get).once.returns(make_response(make_plan))
16
+ @mock.expects(:post).once.returns(make_response(make_plan))
17
+ p = Stripe::Plan.new("test_plan")
18
+ p.refresh
19
+ p.metadata['foo'] = 'bar'
20
+ p.save
21
+ end
22
+
23
+ should "plans should be updateable" do
24
+ @mock.expects(:post).once.
25
+ with('https://api.stripe.com/v1/plans/test_plan', nil, 'metadata[foo]=bar').
26
+ returns(make_response(make_plan(metadata: {foo: 'bar'})))
27
+ p = Stripe::Plan.update("test_plan", metadata: {foo: 'bar'})
28
+ assert_equal('bar', p.metadata['foo'])
29
+ end
30
+ end
31
+ end
@@ -21,7 +21,7 @@ module Stripe
21
21
  assert p.deleted
22
22
  end
23
23
 
24
- should "products should be updateable" do
24
+ should "products should be saveable" do
25
25
  @mock.expects(:get).once.returns(make_response(make_product))
26
26
  @mock.expects(:post).once.returns(make_response(make_product))
27
27
  p = Stripe::Product.new("test_product")
@@ -30,6 +30,14 @@ module Stripe
30
30
  p.save
31
31
  end
32
32
 
33
+ should "products should be updateable" do
34
+ @mock.expects(:post).once.
35
+ with('https://api.stripe.com/v1/products/test_product', nil, 'description=update').
36
+ returns(make_response(make_product(description: 'update')))
37
+ p = Stripe::Product.update("test_product", description: 'update')
38
+ assert_equal('update', p.description)
39
+ end
40
+
33
41
  should "products should allow metadata updates" do
34
42
  @mock.expects(:get).once.returns(make_response(make_product))
35
43
  @mock.expects(:post).once.returns(make_response(make_product))
@@ -0,0 +1,21 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Stripe
4
+ class RecipientTest < Test::Unit::TestCase
5
+
6
+ should "recipient should be retrievable" do
7
+ @mock.expects(:get).once.returns(make_response(make_recipient))
8
+ r = Stripe::Recipient.retrieve('test_recipient')
9
+ assert_equal 'rp_test_recipient', r.id
10
+ end
11
+
12
+ should "recipient should be updateable" do
13
+ @mock.expects(:post).once.
14
+ with("https://api.stripe.com/v1/recipients/test_recipient", nil, "metadata[foo]=bar").
15
+ returns(make_response(make_recipient(metadata: {foo: 'bar'})))
16
+ r = Stripe::Recipient.update('test_recipient', metadata: {foo: 'bar'})
17
+ assert_equal 'bar', r.metadata['foo']
18
+ end
19
+ end
20
+ end
21
+
@@ -24,7 +24,7 @@ module Stripe
24
24
  assert_equal 'refreshed_refund', refund.id
25
25
  end
26
26
 
27
- should "refunds should be updateable" do
27
+ should "refunds should be saveable" do
28
28
  @mock.expects(:get).
29
29
  with("#{Stripe.api_base}/v1/refunds/get_refund", nil, nil).
30
30
  once.returns(make_response(make_refund(:id => 'save_refund')))
@@ -43,6 +43,15 @@ module Stripe
43
43
  assert_equal 'value', refund.metadata['key']
44
44
  end
45
45
 
46
+ should "refunds should be updateable" do
47
+ @mock.expects(:post).
48
+ with("#{Stripe.api_base}/v1/refunds/update_refund", nil, 'metadata[key]=value').
49
+ once.returns(make_response(make_refund(:metadata => {'key' => 'value'})))
50
+
51
+ refund = Stripe::Refund.update('update_refund', metadata: {key: 'value'})
52
+ assert_equal 'value', refund.metadata['key']
53
+ end
54
+
46
55
  should "create should return a new refund" do
47
56
  @mock.expects(:post).
48
57
  with("#{Stripe.api_base}/v1/refunds", nil, 'charge=test_charge').
@@ -12,6 +12,14 @@ module Stripe
12
12
  end
13
13
  end
14
14
 
15
+ should "SKUs should be updateable" do
16
+ @mock.expects(:post).once.
17
+ with("#{Stripe.api_base}/v1/skus/test_sku", nil, 'metadata[foo]=bar').
18
+ returns(make_response(make_sku(:metadata => {foo: 'bar'})))
19
+ s = Stripe::SKU.update("test_sku", metadata: {foo: 'bar'})
20
+ assert_equal 'bar', s.metadata['foo']
21
+ end
22
+
15
23
  should "SKUs should be deletable" do
16
24
  @mock.expects(:get).once.returns(make_response(make_sku))
17
25
  @mock.expects(:delete).once.returns(make_response(make_sku(:deleted => true)))
@@ -77,6 +77,17 @@ module Stripe
77
77
  end
78
78
 
79
79
  should "subscriptions should be updateable" do
80
+ sid = 's_test_subscription'
81
+ @mock.expects(:post).once.with do |url, api_key, params|
82
+ url == "#{Stripe.api_base}/v1/subscriptions/#{sid}" && api_key.nil? && CGI.parse(params) == {'status' => ['active']}
83
+ end.returns(make_response(make_subscription(:status => 'active')))
84
+
85
+ sub = Stripe::Subscription.update(sid, :status => 'active')
86
+
87
+ assert_equal 'active', sub.status
88
+ end
89
+
90
+ should "subscriptions should be saveable" do
80
91
  @mock.expects(:get).once.returns(make_response(make_subscription))
81
92
  sub = Stripe::Subscription.retrieve('s_test_subscription')
82
93
  assert_equal 'trialing', sub.status
@@ -14,6 +14,14 @@ module Stripe
14
14
  assert_equal "tr_test_transfer", transfer.id
15
15
  end
16
16
 
17
+ should "create should update a transfer" do
18
+ @mock.expects(:post).once.
19
+ with("#{Stripe.api_base}/v1/transfers/test_transfer", nil, "metadata[foo]=bar").
20
+ returns(make_response(make_transfer(metadata: {foo: 'bar'})))
21
+ transfer = Stripe::Transfer.update("test_transfer", metadata: {foo: 'bar'})
22
+ assert_equal "bar", transfer.metadata['foo']
23
+ end
24
+
17
25
  should "cancel should cancel a transfer" do
18
26
  @mock.expects(:get).once.returns(make_response(make_transfer))
19
27
  transfer = Stripe::Transfer.retrieve('tr_test_transfer')
@@ -323,7 +323,7 @@ module Stripe
323
323
  }
324
324
  end
325
325
 
326
- def make_invoice
326
+ def make_invoice(params={})
327
327
  {
328
328
  :id => 'in_test_invoice',
329
329
  :object => 'invoice',
@@ -361,7 +361,7 @@ module Stripe
361
361
  :discount => nil,
362
362
  :ending_balance => nil,
363
363
  :next_payment_attempt => 1349825350,
364
- }
364
+ }.merge(params)
365
365
  end
366
366
 
367
367
  def make_paid_invoice
@@ -376,6 +376,17 @@ module Stripe
376
376
  })
377
377
  end
378
378
 
379
+ def make_invoice_item(params={})
380
+ {
381
+ id: "ii_test_invoice_item",
382
+ object: "invoiceitem",
383
+ date: 1466982411,
384
+ invoice: "in_test_invoice",
385
+ livemode: false,
386
+ metadata: {},
387
+ }.merge(params)
388
+ end
389
+
379
390
  def make_invoice_customer_array
380
391
  {
381
392
  :data => [make_invoice],
@@ -793,5 +804,34 @@ module Stripe
793
804
  }
794
805
  }.merge(params)
795
806
  end
807
+
808
+ def make_plan(params={})
809
+ {
810
+ id: "silver",
811
+ object: "plan",
812
+ amount: 1000,
813
+ created: 1463962497,
814
+ currency: "usd",
815
+ interval: "year",
816
+ interval_count: 1,
817
+ livemode: false,
818
+ metadata: {},
819
+ name: "Silver",
820
+ statement_descriptor: nil,
821
+ trial_period_days: nil,
822
+ }.merge(params)
823
+ end
824
+
825
+ def make_plan_array
826
+ {
827
+ :object => "list",
828
+ :resource_url => "/v1/plans",
829
+ :data => [
830
+ make_plan,
831
+ make_plan,
832
+ make_plan,
833
+ ]
834
+ }
835
+ end
796
836
  end
797
837
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.43.1
4
+ version: 1.44.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-17 00:00:00.000000000 Z
11
+ date: 2016-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -50,7 +50,7 @@ files:
50
50
  - lib/stripe/api_operations/delete.rb
51
51
  - lib/stripe/api_operations/list.rb
52
52
  - lib/stripe/api_operations/request.rb
53
- - lib/stripe/api_operations/update.rb
53
+ - lib/stripe/api_operations/save.rb
54
54
  - lib/stripe/api_resource.rb
55
55
  - lib/stripe/application_fee.rb
56
56
  - lib/stripe/application_fee_refund.rb
@@ -95,6 +95,7 @@ files:
95
95
  - stripe.gemspec
96
96
  - test/stripe/account_test.rb
97
97
  - test/stripe/alipay_account_test.rb
98
+ - test/stripe/api_operations_test.rb
98
99
  - test/stripe/api_resource_test.rb
99
100
  - test/stripe/application_fee_refund_test.rb
100
101
  - test/stripe/application_fee_test.rb
@@ -110,13 +111,16 @@ files:
110
111
  - test/stripe/customer_test.rb
111
112
  - test/stripe/dispute_test.rb
112
113
  - test/stripe/file_upload_test.rb
114
+ - test/stripe/invoice_item_test.rb
113
115
  - test/stripe/invoice_test.rb
114
116
  - test/stripe/list_object_test.rb
115
117
  - test/stripe/metadata_test.rb
116
118
  - test/stripe/order_return_test.rb
117
119
  - test/stripe/order_test.rb
120
+ - test/stripe/plan_test.rb
118
121
  - test/stripe/product_test.rb
119
122
  - test/stripe/recipient_card_test.rb
123
+ - test/stripe/recipient_test.rb
120
124
  - test/stripe/refund_test.rb
121
125
  - test/stripe/reversal_test.rb
122
126
  - test/stripe/sku_test.rb
@@ -154,6 +158,7 @@ summary: Ruby bindings for the Stripe API
154
158
  test_files:
155
159
  - test/stripe/account_test.rb
156
160
  - test/stripe/alipay_account_test.rb
161
+ - test/stripe/api_operations_test.rb
157
162
  - test/stripe/api_resource_test.rb
158
163
  - test/stripe/application_fee_refund_test.rb
159
164
  - test/stripe/application_fee_test.rb
@@ -169,13 +174,16 @@ test_files:
169
174
  - test/stripe/customer_test.rb
170
175
  - test/stripe/dispute_test.rb
171
176
  - test/stripe/file_upload_test.rb
177
+ - test/stripe/invoice_item_test.rb
172
178
  - test/stripe/invoice_test.rb
173
179
  - test/stripe/list_object_test.rb
174
180
  - test/stripe/metadata_test.rb
175
181
  - test/stripe/order_return_test.rb
176
182
  - test/stripe/order_test.rb
183
+ - test/stripe/plan_test.rb
177
184
  - test/stripe/product_test.rb
178
185
  - test/stripe/recipient_card_test.rb
186
+ - test/stripe/recipient_test.rb
179
187
  - test/stripe/refund_test.rb
180
188
  - test/stripe/reversal_test.rb
181
189
  - test/stripe/sku_test.rb