stripe 1.31.0 → 1.58.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +5 -0
  3. data/.travis.yml +2 -12
  4. data/Gemfile +29 -4
  5. data/History.txt +168 -0
  6. data/README.md +134 -0
  7. data/Rakefile +10 -0
  8. data/VERSION +1 -1
  9. data/bin/stripe-console +12 -5
  10. data/lib/data/ca-certificates.crt +3868 -5114
  11. data/lib/stripe/account.rb +41 -21
  12. data/lib/stripe/alipay_account.rb +20 -0
  13. data/lib/stripe/api_operations/create.rb +1 -1
  14. data/lib/stripe/api_operations/delete.rb +1 -1
  15. data/lib/stripe/api_operations/list.rb +1 -2
  16. data/lib/stripe/api_operations/save.rb +87 -0
  17. data/lib/stripe/api_resource.rb +37 -4
  18. data/lib/stripe/apple_pay_domain.rb +12 -0
  19. data/lib/stripe/application_fee.rb +8 -8
  20. data/lib/stripe/application_fee_refund.rb +7 -3
  21. data/lib/stripe/balance_transaction.rb +1 -1
  22. data/lib/stripe/bank_account.rb +9 -5
  23. data/lib/stripe/bitcoin_receiver.rb +6 -6
  24. data/lib/stripe/bitcoin_transaction.rb +1 -1
  25. data/lib/stripe/card.rb +9 -5
  26. data/lib/stripe/charge.rb +30 -12
  27. data/lib/stripe/country_spec.rb +9 -0
  28. data/lib/stripe/coupon.rb +1 -1
  29. data/lib/stripe/customer.rb +6 -4
  30. data/lib/stripe/dispute.rb +2 -2
  31. data/lib/stripe/errors.rb +82 -0
  32. data/lib/stripe/file_upload.rb +1 -1
  33. data/lib/stripe/invoice.rb +3 -3
  34. data/lib/stripe/invoice_item.rb +1 -1
  35. data/lib/stripe/list_object.rb +7 -6
  36. data/lib/stripe/order.rb +10 -2
  37. data/lib/stripe/order_return.rb +9 -0
  38. data/lib/stripe/plan.rb +1 -1
  39. data/lib/stripe/product.rb +2 -10
  40. data/lib/stripe/recipient.rb +1 -1
  41. data/lib/stripe/refund.rb +1 -1
  42. data/lib/stripe/reversal.rb +7 -3
  43. data/lib/stripe/singleton_api_resource.rb +3 -3
  44. data/lib/stripe/sku.rb +2 -2
  45. data/lib/stripe/source.rb +11 -0
  46. data/lib/stripe/stripe_object.rb +167 -91
  47. data/lib/stripe/subscription.rb +15 -9
  48. data/lib/stripe/subscription_item.rb +12 -0
  49. data/lib/stripe/three_d_secure.rb +9 -0
  50. data/lib/stripe/transfer.rb +3 -4
  51. data/lib/stripe/util.rb +100 -28
  52. data/lib/stripe/version.rb +1 -1
  53. data/lib/stripe.rb +283 -140
  54. data/stripe.gemspec +5 -18
  55. data/test/stripe/account_test.rb +55 -9
  56. data/test/stripe/alipay_account_test.rb +11 -0
  57. data/test/stripe/api_operations_test.rb +31 -0
  58. data/test/stripe/api_resource_test.rb +204 -10
  59. data/test/stripe/apple_pay_domain_test.rb +34 -0
  60. data/test/stripe/application_fee_test.rb +8 -5
  61. data/test/stripe/bitcoin_receiver_test.rb +2 -2
  62. data/test/stripe/charge_refund_test.rb +12 -0
  63. data/test/stripe/charge_test.rb +32 -4
  64. data/test/stripe/country_spec_test.rb +43 -0
  65. data/test/stripe/coupon_test.rb +9 -1
  66. data/test/stripe/customer_card_test.rb +2 -2
  67. data/test/stripe/customer_test.rb +24 -1
  68. data/test/stripe/dispute_test.rb +8 -0
  69. data/test/stripe/errors_test.rb +18 -0
  70. data/test/stripe/invoice_item_test.rb +19 -0
  71. data/test/stripe/invoice_test.rb +27 -1
  72. data/test/stripe/list_object_test.rb +36 -15
  73. data/test/stripe/order_return_test.rb +25 -0
  74. data/test/stripe/order_test.rb +21 -1
  75. data/test/stripe/plan_test.rb +31 -0
  76. data/test/stripe/product_test.rb +17 -7
  77. data/test/stripe/recipient_card_test.rb +2 -2
  78. data/test/stripe/recipient_test.rb +21 -0
  79. data/test/stripe/refund_test.rb +10 -1
  80. data/test/stripe/sku_test.rb +15 -6
  81. data/test/stripe/source_test.rb +83 -0
  82. data/test/stripe/stripe_object_test.rb +180 -11
  83. data/test/stripe/subscription_item_test.rb +76 -0
  84. data/test/stripe/subscription_test.rb +161 -37
  85. data/test/stripe/three_d_secure_test.rb +22 -0
  86. data/test/stripe/transfer_test.rb +8 -0
  87. data/test/stripe/util_test.rb +48 -16
  88. data/test/stripe_test.rb +58 -0
  89. data/test/test_data.rb +337 -27
  90. data/test/test_helper.rb +7 -3
  91. metadata +47 -133
  92. data/README.rdoc +0 -68
  93. data/gemfiles/default-with-activesupport.gemfile +0 -10
  94. data/gemfiles/json.gemfile +0 -12
  95. data/gemfiles/yajl.gemfile +0 -12
  96. data/lib/stripe/api_operations/update.rb +0 -58
  97. data/lib/stripe/errors/api_connection_error.rb +0 -4
  98. data/lib/stripe/errors/api_error.rb +0 -4
  99. data/lib/stripe/errors/authentication_error.rb +0 -4
  100. data/lib/stripe/errors/card_error.rb +0 -12
  101. data/lib/stripe/errors/invalid_request_error.rb +0 -11
  102. data/lib/stripe/errors/rate_limit_error.rb +0 -4
  103. data/lib/stripe/errors/stripe_error.rb +0 -26
@@ -17,14 +17,14 @@ module Stripe
17
17
  assert cards[0].kind_of? Stripe::Card
18
18
  end
19
19
 
20
- should "customer cards should have the correct url" do
20
+ should "customer cards should have the correct resource url" do
21
21
  c = customer
22
22
  @mock.expects(:get).once.returns(make_response(make_card(
23
23
  :id => 'test_card',
24
24
  :customer => 'test_customer'
25
25
  )))
26
26
  card = c.sources.retrieve('card')
27
- assert_equal CUSTOMER_CARD_URL, card.url
27
+ assert_equal CUSTOMER_CARD_URL, card.resource_url
28
28
  end
29
29
 
30
30
  should "customer cards should be deletable" do
@@ -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
@@ -84,5 +92,20 @@ module Stripe
84
92
  c.delete_discount
85
93
  assert_equal nil, c.discount
86
94
  end
95
+
96
+ should "can have a token source set" do
97
+ c = Stripe::Customer.new("test_customer")
98
+ c.source = "tok_123"
99
+ assert_equal "tok_123", c.source
100
+ end
101
+
102
+ should "set a flag if given an object source" do
103
+ c = Stripe::Customer.new("test_customer")
104
+ c.source = {
105
+ :object => 'card'
106
+ }
107
+ assert_equal true, c.source.save_with_parent
108
+ end
87
109
  end
88
110
  end
111
+
@@ -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,18 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Stripe
4
+ class StripeErrorTest < Test::Unit::TestCase
5
+ context "#to_s" do
6
+ should "convert to string" do
7
+ e = StripeError.new("message")
8
+ assert_equal "message", e.to_s
9
+
10
+ e = StripeError.new("message", 200)
11
+ assert_equal "(Status 200) message", e.to_s
12
+
13
+ e = StripeError.new("message", nil, nil, nil, { :request_id => "request-id" })
14
+ assert_equal "(Request request-id) message", e.to_s
15
+ end
16
+ end
17
+ end
18
+ end
@@ -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'})
@@ -30,11 +38,29 @@ module Stripe
30
38
  Stripe.expects(:execute_request).with do |opts|
31
39
  opts[:url] == "#{Stripe.api_base}/v1/invoices/in_test_invoice/pay" &&
32
40
  opts[:method] == :post &&
33
- opts[:headers][:authorization] == 'Bearer foobar'
41
+ opts[:headers]['Authorization'] == 'Bearer foobar'
34
42
  end.returns(make_response(make_paid_invoice))
35
43
 
36
44
  i.pay
37
45
  assert_equal nil, i.next_payment_attempt
38
46
  end
47
+
48
+ should "be able to retrieve upcoming invoices" do
49
+ base = "#{Stripe.api_base}/v1/invoices/upcoming?"
50
+ cus_sub = "customer=c_test_customer&subscription=s_test_subscription&"
51
+ item0 = "subscription_items[][plan]=gold&subscription_items[][quantity]=1&"
52
+ item1 = "subscription_items[][plan]=silver&subscription_items[][quantity]=2"
53
+ @mock.expects(:get).once.with(base + cus_sub + item0 + item1, nil, nil).
54
+ returns(make_response(make_invoice(:customer => 'c_test_customer', :subscription => 's_test_subscription')))
55
+
56
+ i = Stripe::Invoice.upcoming(
57
+ :customer => 'c_test_customer',
58
+ :subscription => 's_test_subscription',
59
+ :subscription_items => [{:plan => 'gold', :quantity =>1}, {:plan => 'silver', :quantity =>2}]
60
+ )
61
+
62
+ assert_equal 'c_test_customer', i.customer
63
+ assert_equal 's_test_subscription', i.subscription
64
+ end
39
65
  end
40
66
  end
@@ -31,7 +31,11 @@ module Stripe
31
31
  ]
32
32
  expected = Util.convert_to_stripe_object(arr, {})
33
33
 
34
- list = TestListObject.construct_from({ :data => [{ :id => 1 }], :has_more => true })
34
+ list = TestListObject.construct_from({
35
+ :data => [{ :id => 1 }],
36
+ :has_more => true,
37
+ :url => "/things",
38
+ })
35
39
  @mock.expects(:get).once.with("#{Stripe.api_base}/things?starting_after=1", nil, nil).
36
40
  returns(make_response({ :data => [{ :id => 2 }, { :id => 3}], :has_more => false }))
37
41
 
@@ -46,7 +50,11 @@ module Stripe
46
50
  ]
47
51
  expected = Util.convert_to_stripe_object(arr, {})
48
52
 
49
- list = TestListObject.construct_from({ :data => [{ :id => 1 }], :has_more => true })
53
+ list = TestListObject.construct_from({
54
+ :data => [{ :id => 1 }],
55
+ :has_more => true,
56
+ :url => "/things",
57
+ })
50
58
  @mock.expects(:get).once.with("#{Stripe.api_base}/things?starting_after=1", nil, nil).
51
59
  returns(make_response({ :data => [{ :id => 2 }, { :id => 3}], :has_more => false }))
52
60
 
@@ -70,7 +78,11 @@ module Stripe
70
78
  #
71
79
 
72
80
  should "fetch a next page through #next_page" do
73
- list = TestListObject.construct_from({ :data => [{ :id => 1 }], :has_more => true })
81
+ list = TestListObject.construct_from({
82
+ :data => [{ :id => 1 }],
83
+ :has_more => true,
84
+ :url => "/things",
85
+ })
74
86
  @mock.expects(:get).once.with("#{Stripe.api_base}/things?starting_after=1", nil, nil).
75
87
  returns(make_response({ :data => [{ :id => 2 }], :has_more => false }))
76
88
  next_list = list.next_page
@@ -78,13 +90,15 @@ module Stripe
78
90
  end
79
91
 
80
92
  should "fetch a next page through #next_page and respect limit" do
81
- list = TestListObject.construct_from({ :data => [{ :id => 1 }], :has_more => true })
93
+ list = TestListObject.construct_from({
94
+ :data => [{ :id => 1 }],
95
+ :has_more => true,
96
+ :url => "/things",
97
+ })
82
98
  list.filters = { :expand => ['data.source'], :limit => 3 }
83
99
  @mock.expects(:get).with do |url, _, _|
84
- # apparently URI.parse in 1.8.7 doesn't support query parameters ...
85
- url, query = url.split("?")
86
100
  u = URI.parse(url)
87
- params = CGI.parse(query)
101
+ params = CGI.parse(u.query)
88
102
  u.host == URI.parse(Stripe.api_base).host && u.path == "/things" && params == {
89
103
  "expand[]" => ["data.source"],
90
104
  "limit" => ["3"],
@@ -96,7 +110,11 @@ module Stripe
96
110
  end
97
111
 
98
112
  should "fetch an empty page through #next_page" do
99
- list = TestListObject.construct_from({ :data => [{ :id => 1 }], :has_more => false })
113
+ list = TestListObject.construct_from({
114
+ :data => [{ :id => 1 }],
115
+ :has_more => false,
116
+ :url => "/things",
117
+ })
100
118
  next_list = list.next_page
101
119
  assert_equal Stripe::ListObject.empty_list, next_list
102
120
  end
@@ -106,7 +124,10 @@ module Stripe
106
124
  #
107
125
 
108
126
  should "fetch a next page through #previous_page" do
109
- list = TestListObject.construct_from({ :data => [{ :id => 2 }] })
127
+ list = TestListObject.construct_from({
128
+ :data => [{ :id => 2 }],
129
+ :url => "/things",
130
+ })
110
131
  @mock.expects(:get).once.with("#{Stripe.api_base}/things?ending_before=2", nil, nil).
111
132
  returns(make_response({ :data => [{ :id => 1 }] }))
112
133
  next_list = list.previous_page
@@ -114,7 +135,10 @@ module Stripe
114
135
  end
115
136
 
116
137
  should "fetch a next page through #previous_page and respect limit" do
117
- list = TestListObject.construct_from({ :data => [{ :id => 2 }] })
138
+ list = TestListObject.construct_from({
139
+ :data => [{ :id => 2 }],
140
+ :url => "/things",
141
+ })
118
142
  list.filters = { :expand => ['data.source'], :limit => 3 }
119
143
  @mock.expects(:get).with do |url, _, _|
120
144
  # apparently URI.parse in 1.8.7 doesn't support query parameters ...
@@ -141,10 +165,10 @@ module Stripe
141
165
  @mock.expects(:get).twice.returns(make_response(make_charge_array))
142
166
  c = Stripe::Charge.all
143
167
  assert c.kind_of?(Stripe::ListObject)
144
- assert_equal('/v1/charges', c.url)
168
+ assert_equal('/v1/charges', c.resource_url)
145
169
  all = c.all
146
170
  assert all.kind_of?(Stripe::ListObject)
147
- assert_equal('/v1/charges', all.url)
171
+ assert_equal('/v1/charges', all.resource_url)
148
172
  assert all.data.kind_of?(Array)
149
173
  end
150
174
  end
@@ -152,7 +176,4 @@ end
152
176
 
153
177
  # A helper class with a URL that allows us to try out pagination.
154
178
  class TestListObject < Stripe::ListObject
155
- def url
156
- "/things"
157
- end
158
179
  end
@@ -0,0 +1,25 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Stripe
4
+ class OrderReturnTest < Test::Unit::TestCase
5
+ should "returns should be listable" do
6
+ @mock.expects(:get).once.returns(make_response(make_order_return_array))
7
+ returns = Stripe::OrderReturn.list
8
+ assert returns.data.kind_of?(Array)
9
+ returns.each do |ret|
10
+ assert ret.kind_of?(Stripe::OrderReturn)
11
+ end
12
+ end
13
+
14
+ should "returns should not be deletable" do
15
+ p = Stripe::OrderReturn.new("test_order")
16
+ assert_raises(NoMethodError) { p.delete }
17
+ end
18
+
19
+ should "returns should be immutable" do
20
+ p = Stripe::OrderReturn.new("test_order")
21
+ p.items = []
22
+ assert_raises(NoMethodError) { p.save }
23
+ end
24
+ end
25
+ end
@@ -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))
@@ -48,5 +56,17 @@ module Stripe
48
56
  order.pay(:token => 'test_token')
49
57
  assert_equal "paid", order.status
50
58
  end
59
+
60
+ should "return an order" do
61
+ @mock.expects(:get).once.
62
+ returns(make_response(make_order(:id => 'or_test_order')))
63
+ order = Stripe::Order.retrieve('or_test_order')
64
+
65
+ @mock.expects(:post).once.
66
+ with('https://api.stripe.com/v1/orders/or_test_order/returns', nil, 'items[][parent]=sku_foo').
67
+ returns(make_response(make_order_return({:order => order.id})))
68
+ order_return = order.return_order(:items => [{:parent => 'sku_foo'}])
69
+ assert_equal order.id, order_return.order
70
+ end
51
71
  end
52
72
  end
@@ -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
@@ -11,15 +11,17 @@ module Stripe
11
11
  end
12
12
  end
13
13
 
14
- should "products should not be deletable" do
15
- assert_raises NoMethodError do
16
- @mock.expects(:get).once.returns(make_response(make_product))
17
- p = Stripe::Product.retrieve("test_product")
18
- p.delete
19
- end
14
+ should "products should be deletable" do
15
+ @mock.expects(:get).once.returns(make_response(make_product))
16
+ @mock.expects(:delete).once.
17
+ returns(make_response(make_product(:deleted => true)))
18
+
19
+ p = Stripe::Product.retrieve("test_product")
20
+ p.delete
21
+ assert p.deleted
20
22
  end
21
23
 
22
- should "products should be updateable" do
24
+ should "products should be saveable" do
23
25
  @mock.expects(:get).once.returns(make_response(make_product))
24
26
  @mock.expects(:post).once.returns(make_response(make_product))
25
27
  p = Stripe::Product.new("test_product")
@@ -28,6 +30,14 @@ module Stripe
28
30
  p.save
29
31
  end
30
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
+
31
41
  should "products should allow metadata updates" do
32
42
  @mock.expects(:get).once.returns(make_response(make_product))
33
43
  @mock.expects(:post).once.returns(make_response(make_product))
@@ -17,14 +17,14 @@ module Stripe
17
17
  assert cards[0].kind_of? Stripe::Card
18
18
  end
19
19
 
20
- should "recipient cards should have the correct url" do
20
+ should "recipient cards should have the correct resource url" do
21
21
  c = recipient
22
22
  @mock.expects(:get).once.returns(make_response(make_card(
23
23
  :id => 'test_card',
24
24
  :recipient => 'test_recipient'
25
25
  )))
26
26
  card = c.cards.retrieve('card')
27
- assert_equal RECIPIENT_CARD_URL, card.url
27
+ assert_equal RECIPIENT_CARD_URL, card.resource_url
28
28
  end
29
29
 
30
30
  should "recipient cards should be deletable" do
@@ -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,12 +12,21 @@ module Stripe
12
12
  end
13
13
  end
14
14
 
15
- should "SKUs should not be deletable" do
16
- assert_raises NoMethodError do
17
- @mock.expects(:get).once.returns(make_response(make_sku))
18
- p = Stripe::SKU.retrieve("test_product")
19
- p.delete
20
- end
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
+
23
+ should "SKUs should be deletable" do
24
+ @mock.expects(:get).once.returns(make_response(make_sku))
25
+ @mock.expects(:delete).once.returns(make_response(make_sku(:deleted => true)))
26
+
27
+ s = Stripe::SKU.retrieve("test_sku")
28
+ s.delete
29
+ assert s.deleted
21
30
  end
22
31
 
23
32
  end
@@ -0,0 +1,83 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Stripe
4
+ class SourceTest < Test::Unit::TestCase
5
+ should 'be creatable' do
6
+ @mock.expects(:post).once.returns(make_response(make_source_card))
7
+ src = Stripe::Source.create(
8
+ type: 'card',
9
+ token: 'tok_test',
10
+ )
11
+ assert_equal 'src_test_card', src.id
12
+ end
13
+
14
+ should 'be retrievable' do
15
+ @mock.expects(:get).once.returns(make_response(make_source_card))
16
+ src = Stripe::Source.retrieve('src_test_card')
17
+ assert_equal 'src_test_card', src.id
18
+ end
19
+
20
+ should 'be updatable' do
21
+ @mock.expects(:post).once
22
+ .with(
23
+ "#{Stripe.api_base}/v1/sources/src_test_card",
24
+ nil,
25
+ 'metadata[foo]=bar'
26
+ )
27
+ .returns(make_response(make_source_card(metadata: {foo: 'bar'})))
28
+ src = Stripe::Source.update('src_test_card', metadata: {foo: 'bar'})
29
+ assert_equal 'bar', src.metadata['foo']
30
+ end
31
+
32
+ should 'be saveable' do
33
+ @mock.expects(:get).once.returns(make_response(make_source_card))
34
+ src = Stripe::Source.retrieve('src_test_card')
35
+
36
+ @mock.expects(:post).once
37
+ .with(
38
+ "#{Stripe.api_base}/v1/sources/src_test_card",
39
+ nil,
40
+ 'metadata[foo]=bar'
41
+ )
42
+ .returns(make_response(make_source_card(metadata: {foo: 'bar'})))
43
+ src.metadata['foo'] = 'bar'
44
+ src.save
45
+ assert_equal 'bar', src.metadata['foo']
46
+ end
47
+
48
+ should 'not be deletable' do
49
+ @mock.expects(:get).once.returns(make_response(make_source_card))
50
+ src = Stripe::Source.retrieve('src_test_card')
51
+
52
+ assert_raises NoMethodError do
53
+ src.delete
54
+ end
55
+ end
56
+
57
+ should 'not be listable' do
58
+ assert_raises NoMethodError do
59
+ Stripe::Source.list
60
+ end
61
+ end
62
+
63
+ should 'be verifiable' do
64
+ @mock.expects(:get).once.returns(make_response(make_source_ach_debit))
65
+ src = Stripe::Source.retrieve('src_test_ach_debit')
66
+
67
+ @mock.expects(:post).once
68
+ .with(
69
+ 'https://api.stripe.com/v1/sources/src_test_ach_debit/verify',
70
+ nil,
71
+ 'values[]=32&values[]=45'
72
+ )
73
+ .returns(make_response(make_source_ach_debit(
74
+ verification: {
75
+ attempts_remaining: 0,
76
+ status: 'succeeded',
77
+ }
78
+ )))
79
+ src.verify(values: [32, 45])
80
+ assert_equal 'succeeded', src.verification.status
81
+ end
82
+ end
83
+ end