stripe 1.27.2 → 5.33.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +942 -0
  3. data/CODE_OF_CONDUCT.md +77 -0
  4. data/Gemfile +29 -4
  5. data/History.txt +1 -361
  6. data/README.md +349 -0
  7. data/Rakefile +33 -3
  8. data/VERSION +1 -1
  9. data/bin/stripe-console +14 -5
  10. data/lib/data/ca-certificates.crt +4016 -5138
  11. data/lib/stripe.rb +102 -320
  12. data/lib/stripe/api_operations/create.rb +5 -9
  13. data/lib/stripe/api_operations/delete.rb +32 -4
  14. data/lib/stripe/api_operations/list.rb +11 -9
  15. data/lib/stripe/api_operations/nested_resource.rb +73 -0
  16. data/lib/stripe/api_operations/request.rb +66 -11
  17. data/lib/stripe/api_operations/save.rb +97 -0
  18. data/lib/stripe/api_resource.rb +96 -12
  19. data/lib/stripe/connection_manager.rb +164 -0
  20. data/lib/stripe/error_object.rb +94 -0
  21. data/lib/stripe/errors.rb +177 -0
  22. data/lib/stripe/instrumentation.rb +82 -0
  23. data/lib/stripe/list_object.rb +118 -13
  24. data/lib/stripe/multipart_encoder.rb +131 -0
  25. data/lib/stripe/oauth.rb +65 -0
  26. data/lib/stripe/object_types.rb +104 -0
  27. data/lib/stripe/resources.rb +87 -0
  28. data/lib/stripe/resources/account.rb +170 -0
  29. data/lib/stripe/resources/account_link.rb +10 -0
  30. data/lib/stripe/resources/alipay_account.rb +34 -0
  31. data/lib/stripe/resources/apple_pay_domain.rb +17 -0
  32. data/lib/stripe/resources/application_fee.rb +14 -0
  33. data/lib/stripe/resources/application_fee_refund.rb +30 -0
  34. data/lib/stripe/resources/balance.rb +8 -0
  35. data/lib/stripe/resources/balance_transaction.rb +10 -0
  36. data/lib/stripe/resources/bank_account.rb +43 -0
  37. data/lib/stripe/resources/billing_portal/configuration.rb +14 -0
  38. data/lib/stripe/resources/billing_portal/session.rb +12 -0
  39. data/lib/stripe/resources/bitcoin_receiver.rb +24 -0
  40. data/lib/stripe/resources/bitcoin_transaction.rb +15 -0
  41. data/lib/stripe/resources/capability.rb +33 -0
  42. data/lib/stripe/resources/card.rb +38 -0
  43. data/lib/stripe/resources/charge.rb +23 -0
  44. data/lib/stripe/resources/checkout/session.rb +16 -0
  45. data/lib/stripe/resources/country_spec.rb +10 -0
  46. data/lib/stripe/resources/coupon.rb +13 -0
  47. data/lib/stripe/resources/credit_note.rb +33 -0
  48. data/lib/stripe/resources/credit_note_line_item.rb +7 -0
  49. data/lib/stripe/resources/customer.rb +41 -0
  50. data/lib/stripe/resources/customer_balance_transaction.rb +30 -0
  51. data/lib/stripe/resources/discount.rb +7 -0
  52. data/lib/stripe/resources/dispute.rb +22 -0
  53. data/lib/stripe/resources/ephemeral_key.rb +20 -0
  54. data/lib/stripe/resources/event.rb +10 -0
  55. data/lib/stripe/resources/exchange_rate.rb +10 -0
  56. data/lib/stripe/resources/file.rb +36 -0
  57. data/lib/stripe/resources/file_link.rb +12 -0
  58. data/lib/stripe/resources/identity/verification_report.rb +12 -0
  59. data/lib/stripe/resources/identity/verification_session.rb +35 -0
  60. data/lib/stripe/resources/invoice.rb +74 -0
  61. data/lib/stripe/resources/invoice_item.rb +13 -0
  62. data/lib/stripe/resources/invoice_line_item.rb +7 -0
  63. data/lib/stripe/resources/issuing/authorization.rb +34 -0
  64. data/lib/stripe/resources/issuing/card.rb +25 -0
  65. data/lib/stripe/resources/issuing/card_details.rb +9 -0
  66. data/lib/stripe/resources/issuing/cardholder.rb +14 -0
  67. data/lib/stripe/resources/issuing/dispute.rb +25 -0
  68. data/lib/stripe/resources/issuing/transaction.rb +13 -0
  69. data/lib/stripe/resources/line_item.rb +7 -0
  70. data/lib/stripe/resources/login_link.rb +14 -0
  71. data/lib/stripe/resources/mandate.rb +8 -0
  72. data/lib/stripe/resources/order.rb +33 -0
  73. data/lib/stripe/resources/order_return.rb +10 -0
  74. data/lib/stripe/resources/payment_intent.rb +43 -0
  75. data/lib/stripe/resources/payment_method.rb +33 -0
  76. data/lib/stripe/resources/payout.rb +33 -0
  77. data/lib/stripe/resources/person.rb +31 -0
  78. data/lib/stripe/resources/plan.rb +13 -0
  79. data/lib/stripe/resources/price.rb +12 -0
  80. data/lib/stripe/resources/product.rb +13 -0
  81. data/lib/stripe/resources/promotion_code.rb +12 -0
  82. data/lib/stripe/resources/radar/early_fraud_warning.rb +12 -0
  83. data/lib/stripe/resources/radar/value_list.rb +15 -0
  84. data/lib/stripe/resources/radar/value_list_item.rb +14 -0
  85. data/lib/stripe/resources/recipient.rb +14 -0
  86. data/lib/stripe/resources/recipient_transfer.rb +7 -0
  87. data/lib/stripe/resources/refund.rb +12 -0
  88. data/lib/stripe/resources/reporting/report_run.rb +13 -0
  89. data/lib/stripe/resources/reporting/report_type.rb +13 -0
  90. data/lib/stripe/resources/reversal.rb +29 -0
  91. data/lib/stripe/resources/review.rb +21 -0
  92. data/lib/stripe/resources/setup_attempt.rb +10 -0
  93. data/lib/stripe/resources/setup_intent.rb +33 -0
  94. data/lib/stripe/resources/sigma/scheduled_query_run.rb +16 -0
  95. data/lib/stripe/resources/sku.rb +13 -0
  96. data/lib/stripe/resources/source.rb +47 -0
  97. data/lib/stripe/resources/source_transaction.rb +7 -0
  98. data/lib/stripe/resources/subscription.rb +26 -0
  99. data/lib/stripe/resources/subscription_item.rb +26 -0
  100. data/lib/stripe/resources/subscription_schedule.rb +33 -0
  101. data/lib/stripe/resources/tax_id.rb +26 -0
  102. data/lib/stripe/resources/tax_rate.rb +12 -0
  103. data/lib/stripe/resources/terminal/connection_token.rb +12 -0
  104. data/lib/stripe/resources/terminal/location.rb +15 -0
  105. data/lib/stripe/resources/terminal/reader.rb +15 -0
  106. data/lib/stripe/resources/three_d_secure.rb +14 -0
  107. data/lib/stripe/resources/token.rb +10 -0
  108. data/lib/stripe/resources/topup.rb +23 -0
  109. data/lib/stripe/resources/transfer.rb +27 -0
  110. data/lib/stripe/resources/usage_record.rb +7 -0
  111. data/lib/stripe/resources/usage_record_summary.rb +7 -0
  112. data/lib/stripe/resources/webhook_endpoint.rb +13 -0
  113. data/lib/stripe/singleton_api_resource.rb +13 -7
  114. data/lib/stripe/stripe_client.rb +989 -0
  115. data/lib/stripe/stripe_configuration.rb +194 -0
  116. data/lib/stripe/stripe_object.rb +481 -148
  117. data/lib/stripe/stripe_response.rb +82 -0
  118. data/lib/stripe/util.rb +265 -70
  119. data/lib/stripe/version.rb +3 -1
  120. data/lib/stripe/webhook.rb +121 -0
  121. data/stripe.gemspec +35 -21
  122. metadata +118 -198
  123. data/.gitignore +0 -4
  124. data/.travis.yml +0 -22
  125. data/README.rdoc +0 -43
  126. data/gemfiles/default-with-activesupport.gemfile +0 -10
  127. data/gemfiles/json.gemfile +0 -12
  128. data/gemfiles/yajl.gemfile +0 -12
  129. data/lib/stripe/account.rb +0 -39
  130. data/lib/stripe/api_operations/update.rb +0 -19
  131. data/lib/stripe/application_fee.rb +0 -20
  132. data/lib/stripe/application_fee_refund.rb +0 -14
  133. data/lib/stripe/balance.rb +0 -4
  134. data/lib/stripe/balance_transaction.rb +0 -9
  135. data/lib/stripe/bank_account.rb +0 -19
  136. data/lib/stripe/bitcoin_receiver.rb +0 -20
  137. data/lib/stripe/bitcoin_transaction.rb +0 -9
  138. data/lib/stripe/card.rb +0 -21
  139. data/lib/stripe/charge.rb +0 -62
  140. data/lib/stripe/coupon.rb +0 -8
  141. data/lib/stripe/customer.rb +0 -75
  142. data/lib/stripe/dispute.rb +0 -16
  143. data/lib/stripe/errors/api_connection_error.rb +0 -4
  144. data/lib/stripe/errors/api_error.rb +0 -4
  145. data/lib/stripe/errors/authentication_error.rb +0 -4
  146. data/lib/stripe/errors/card_error.rb +0 -12
  147. data/lib/stripe/errors/invalid_request_error.rb +0 -11
  148. data/lib/stripe/errors/rate_limit_error.rb +0 -4
  149. data/lib/stripe/errors/stripe_error.rb +0 -26
  150. data/lib/stripe/event.rb +0 -5
  151. data/lib/stripe/file_upload.rb +0 -22
  152. data/lib/stripe/invoice.rb +0 -27
  153. data/lib/stripe/invoice_item.rb +0 -8
  154. data/lib/stripe/order.rb +0 -19
  155. data/lib/stripe/plan.rb +0 -8
  156. data/lib/stripe/product.rb +0 -16
  157. data/lib/stripe/recipient.rb +0 -12
  158. data/lib/stripe/refund.rb +0 -7
  159. data/lib/stripe/reversal.rb +0 -14
  160. data/lib/stripe/sku.rb +0 -8
  161. data/lib/stripe/subscription.rb +0 -25
  162. data/lib/stripe/token.rb +0 -5
  163. data/lib/stripe/transfer.rb +0 -17
  164. data/test/stripe/account_test.rb +0 -118
  165. data/test/stripe/api_resource_test.rb +0 -632
  166. data/test/stripe/application_fee_refund_test.rb +0 -47
  167. data/test/stripe/application_fee_test.rb +0 -22
  168. data/test/stripe/balance_test.rb +0 -11
  169. data/test/stripe/bitcoin_receiver_test.rb +0 -61
  170. data/test/stripe/bitcoin_transaction_test.rb +0 -29
  171. data/test/stripe/charge_refund_test.rb +0 -55
  172. data/test/stripe/charge_test.rb +0 -118
  173. data/test/stripe/coupon_test.rb +0 -20
  174. data/test/stripe/customer_card_test.rb +0 -63
  175. data/test/stripe/customer_test.rb +0 -88
  176. data/test/stripe/dispute_test.rb +0 -45
  177. data/test/stripe/file_upload_test.rb +0 -28
  178. data/test/stripe/invoice_test.rb +0 -40
  179. data/test/stripe/list_object_test.rb +0 -16
  180. data/test/stripe/metadata_test.rb +0 -129
  181. data/test/stripe/order_test.rb +0 -52
  182. data/test/stripe/product_test.rb +0 -41
  183. data/test/stripe/recipient_card_test.rb +0 -57
  184. data/test/stripe/refund_test.rb +0 -55
  185. data/test/stripe/reversal_test.rb +0 -47
  186. data/test/stripe/sku_test.rb +0 -24
  187. data/test/stripe/stripe_object_test.rb +0 -28
  188. data/test/stripe/subscription_test.rb +0 -72
  189. data/test/stripe/transfer_test.rb +0 -25
  190. data/test/stripe/util_test.rb +0 -34
  191. data/test/test_data.rb +0 -666
  192. data/test/test_helper.rb +0 -41
@@ -1,47 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class ReversalTest < Test::Unit::TestCase
5
- should "reversals should be listable" do
6
- @mock.expects(:get).once.returns(make_response(make_transfer))
7
-
8
- transfer = Stripe::Transfer.retrieve('test_transfer')
9
-
10
- assert transfer.reversals.first.kind_of?(Stripe::Reversal)
11
- end
12
-
13
- should "reversals should be refreshable" do
14
- @mock.expects(:get).twice.returns(make_response(make_transfer), make_response(make_reversal(:id => 'refreshed_reversal')))
15
-
16
- transfer = Stripe::Transfer.retrieve('test_transfer')
17
- reversal = transfer.reversals.first
18
- reversal.refresh
19
-
20
- assert_equal 'refreshed_reversal', reversal.id
21
- end
22
-
23
- should "reversals should be updateable" do
24
- @mock.expects(:get).once.returns(make_response(make_transfer))
25
- @mock.expects(:post).once.returns(make_response(make_reversal(:metadata => {'key' => 'value'})))
26
-
27
- transfer = Stripe::Transfer.retrieve('test_transfer')
28
- reversal = transfer.reversals.first
29
-
30
- assert_equal nil, reversal.metadata['key']
31
-
32
- reversal.metadata['key'] = 'value'
33
- reversal.save
34
-
35
- assert_equal 'value', reversal.metadata['key']
36
- end
37
-
38
- should "create should return a new reversal" do
39
- @mock.expects(:get).once.returns(make_response(make_transfer))
40
- @mock.expects(:post).once.returns(make_response(make_reversal(:id => 'test_new_reversal')))
41
-
42
- transfer = Stripe::Transfer.retrieve('test_transfer')
43
- reversals = transfer.reversals.create(:amount => 20)
44
- assert_equal 'test_new_reversal', reversals.id
45
- end
46
- end
47
- end
@@ -1,24 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class SKUTest < Test::Unit::TestCase
5
- should "SKUs should be listable" do
6
- @mock.expects(:get).once.
7
- returns(make_response(make_sku_array("test_product")))
8
- skus = Stripe::SKU.all
9
- assert skus.data.kind_of? Array
10
- skus.each do |sku|
11
- assert sku.kind_of?(Stripe::SKU)
12
- end
13
- end
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
21
- end
22
-
23
- end
24
- end
@@ -1,28 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class StripeObjectTest < Test::Unit::TestCase
5
- should "implement #respond_to correctly" do
6
- obj = Stripe::StripeObject.construct_from({ :id => 1, :foo => 'bar' })
7
- assert obj.respond_to?(:id)
8
- assert obj.respond_to?(:foo)
9
- assert !obj.respond_to?(:baz)
10
- end
11
-
12
- should "marshal a stripe object correctly" do
13
- obj = Stripe::StripeObject.construct_from({ :id => 1, :name => 'Stripe' }, {:api_key => 'apikey'})
14
- m = Marshal.load(Marshal.dump(obj))
15
- assert_equal 1, m.id
16
- assert_equal 'Stripe', m.name
17
- expected_hash = {:api_key => 'apikey'}
18
- assert_equal expected_hash, m.instance_variable_get('@opts')
19
- end
20
-
21
- should "recursively call to_hash on its values" do
22
- nested = Stripe::StripeObject.construct_from({ :id => 7, :foo => 'bar' })
23
- obj = Stripe::StripeObject.construct_from({ :id => 1, :nested => nested })
24
- expected_hash = { :id => 1, :nested => { :id => 7, :foo => 'bar' } }
25
- assert_equal expected_hash, obj.to_hash
26
- end
27
- end
28
- end
@@ -1,72 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class SubscriptionTest < Test::Unit::TestCase
5
- should "subscriptions should be listable" do
6
- @mock.expects(:get).once.returns(make_response(make_customer))
7
-
8
- customer = Stripe::Customer.retrieve('test_customer')
9
-
10
- assert customer.subscriptions.first.kind_of?(Stripe::Subscription)
11
- end
12
-
13
- should "subscriptions should be refreshable" do
14
- @mock.expects(:get).twice.returns(make_response(make_customer), make_response(make_subscription(:id => 'refreshed_subscription')))
15
-
16
- customer = Stripe::Customer.retrieve('test_customer')
17
- subscription = customer.subscriptions.first
18
- subscription.refresh
19
-
20
- assert_equal 'refreshed_subscription', subscription.id
21
- end
22
-
23
- should "subscriptions should be deletable" do
24
- @mock.expects(:get).once.returns(make_response(make_customer))
25
- customer = Stripe::Customer.retrieve('test_customer')
26
- subscription = customer.subscriptions.first
27
-
28
- @mock.expects(:delete).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/subscriptions/#{subscription.id}?at_period_end=true", nil, nil).returns(make_response(make_subscription))
29
- subscription.delete :at_period_end => true
30
-
31
- @mock.expects(:delete).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/subscriptions/#{subscription.id}", nil, nil).returns(make_response(make_subscription))
32
- subscription.delete
33
- end
34
-
35
- should "subscriptions should be updateable" do
36
- @mock.expects(:get).once.returns(make_response(make_customer))
37
- @mock.expects(:post).once.returns(make_response(make_subscription({:status => 'active'})))
38
-
39
- customer = Stripe::Customer.retrieve('test_customer')
40
- subscription = customer.subscriptions.first
41
- assert_equal 'trialing', subscription.status
42
-
43
- subscription.status = 'active'
44
- subscription.save
45
-
46
- assert_equal 'active', subscription.status
47
- end
48
-
49
- should "create should return a new subscription" do
50
- @mock.expects(:get).once.returns(make_response(make_customer))
51
- @mock.expects(:post).once.returns(make_response(make_subscription(:id => 'test_new_subscription')))
52
-
53
- customer = Stripe::Customer.retrieve('test_customer')
54
- subscription = customer.subscriptions.create(:plan => 'silver')
55
- assert_equal 'test_new_subscription', subscription.id
56
- end
57
-
58
- should "be able to delete a subscriptions's discount" do
59
- @mock.expects(:get).once.returns(make_response(make_customer))
60
- @mock.expects(:post).once.returns(make_response(make_subscription(:id => 'test_new_subscription')))
61
-
62
-
63
- customer = Stripe::Customer.retrieve('test_customer')
64
- subscription = customer.subscriptions.create(:plan => 'silver')
65
-
66
- url = "#{Stripe.api_base}/v1/customers/c_test_customer/subscriptions/test_new_subscription/discount"
67
- @mock.expects(:delete).once.with(url, nil, nil).returns(make_response(make_delete_discount_response))
68
- subscription.delete_discount
69
- assert_equal nil, subscription.discount
70
- end
71
- end
72
- end
@@ -1,25 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class TransferTest < Test::Unit::TestCase
5
- should "retrieve should retrieve transfer" do
6
- @mock.expects(:get).once.returns(make_response(make_transfer))
7
- transfer = Stripe::Transfer.retrieve('tr_test_transfer')
8
- assert_equal 'tr_test_transfer', transfer.id
9
- end
10
-
11
- should "create should create a transfer" do
12
- @mock.expects(:post).once.returns(make_response(make_transfer))
13
- transfer = Stripe::Transfer.create
14
- assert_equal "tr_test_transfer", transfer.id
15
- end
16
-
17
- should "cancel should cancel a transfer" do
18
- @mock.expects(:get).once.returns(make_response(make_transfer))
19
- transfer = Stripe::Transfer.retrieve('tr_test_transfer')
20
-
21
- @mock.expects(:post).once.with('https://api.stripe.com/v1/transfers/tr_test_transfer/cancel', nil, '').returns(make_response(make_canceled_transfer))
22
- transfer.cancel
23
- end
24
- end
25
- end
@@ -1,34 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class UtilTest < Test::Unit::TestCase
5
- should "symbolize_names should convert names to symbols" do
6
- start = {
7
- 'foo' => 'bar',
8
- 'array' => [{ 'foo' => 'bar' }],
9
- 'nested' => {
10
- 1 => 2,
11
- :symbol => 9,
12
- 'string' => nil
13
- }
14
- }
15
- finish = {
16
- :foo => 'bar',
17
- :array => [{ :foo => 'bar' }],
18
- :nested => {
19
- 1 => 2,
20
- :symbol => 9,
21
- :string => nil
22
- }
23
- }
24
-
25
- symbolized = Stripe::Util.symbolize_names(start)
26
- assert_equal(finish, symbolized)
27
- end
28
-
29
- should "normalize_opts should reject nil keys" do
30
- assert_raise { Stripe::Util.normalize_opts(nil) }
31
- assert_raise { Stripe::Util.normalize_opts(:api_key => nil) }
32
- end
33
- end
34
- end
data/test/test_data.rb DELETED
@@ -1,666 +0,0 @@
1
- module Stripe
2
- module TestData
3
- def make_response(body, code=200)
4
- # When an exception is raised, restclient clobbers method_missing. Hence we
5
- # can't just use the stubs interface.
6
- body = JSON.generate(body) if !(body.kind_of? String)
7
- m = mock
8
- m.instance_variable_set('@stripe_values', {
9
- :body => body,
10
- :code => code,
11
- :headers => {},
12
- })
13
- def m.body; @stripe_values[:body]; end
14
- def m.code; @stripe_values[:code]; end
15
- def m.headers; @stripe_values[:headers]; end
16
- m
17
- end
18
-
19
- def make_balance(params={})
20
- {
21
- :pending => [
22
- {:amount => 12345, :currency => "usd"}
23
- ],
24
- :available => [
25
- {:amount => 6789, :currency => "usd"}
26
- ],
27
- :livemode => false,
28
- :object => "balance"
29
- }.merge(params)
30
- end
31
-
32
- def make_balance_transaction(params={})
33
- {
34
- :amount => 100,
35
- :net => 41,
36
- :currency => "usd",
37
- :type => "charge",
38
- :created => 1371945005,
39
- :available_on => 1372549805,
40
- :status => "pending",
41
- :description => "A test balance transaction",
42
- :fee => 59,
43
- :object => "balance_transaction"
44
- }.merge(params)
45
- end
46
-
47
- def make_balance_transaction_array
48
- {
49
- :data => [make_balance_transaction, make_balance_transaction, make_balance_transaction],
50
- :object => "list",
51
- :url => "/v1/balance/history"
52
- }
53
- end
54
-
55
- def make_application_fee(params={})
56
- id = params[:id] || 'fee_test_fee'
57
- {
58
- :refunded => false,
59
- :amount => 100,
60
- :application => "ca_test_application",
61
- :user => "acct_test_user",
62
- :charge => "ch_test_charge",
63
- :id => id,
64
- :livemode => false,
65
- :currency => "usd",
66
- :object => "application_fee",
67
- :refunds => make_application_fee_refund_array(id),
68
- :created => 1304114826
69
- }.merge(params)
70
- end
71
-
72
- def make_application_fee_refund(params = {})
73
- {
74
- :object => 'fee_refund',
75
- :amount => 30,
76
- :currency => "usd",
77
- :created => 1308595038,
78
- :id => "ref_test_app_fee_refund",
79
- :fee => "ca_test_application",
80
- :metadata => {}
81
- }.merge(params)
82
- end
83
-
84
- def make_application_fee_array
85
- {
86
- :data => [make_application_fee, make_application_fee, make_application_fee],
87
- :object => 'list',
88
- :url => '/v1/application_fees'
89
- }
90
- end
91
-
92
- def make_application_fee_refund_array(fee_id)
93
- {
94
- :data => [make_application_fee_refund, make_application_fee_refund, make_application_fee_refund],
95
- :object => 'list',
96
- :url => '/v1/application_fees/' + fee_id + '/refunds'
97
- }
98
- end
99
-
100
- def make_customer(params={})
101
- id = params[:id] || 'c_test_customer'
102
- {
103
- :subscription_history => [],
104
- :bills => [],
105
- :charges => [],
106
- :livemode => false,
107
- :object => "customer",
108
- :id => id,
109
- :default_card => "cc_test_card",
110
- :created => 1304114758,
111
- :sources => make_customer_card_array(id),
112
- :metadata => {},
113
- :subscriptions => make_subscription_array(id)
114
- }.merge(params)
115
- end
116
-
117
- def make_customer_array
118
- {
119
- :data => [make_customer, make_customer, make_customer],
120
- :object => 'list',
121
- :url => '/v1/customers'
122
- }
123
- end
124
-
125
- def make_charge(params={})
126
- id = params[:id] || 'ch_test_charge'
127
- {
128
- :refunded => false,
129
- :paid => true,
130
- :amount => 100,
131
- :card => {
132
- :type => "Visa",
133
- :last4 => "4242",
134
- :exp_month => 11,
135
- :country => "US",
136
- :exp_year => 2012,
137
- :id => "cc_test_card",
138
- :object => "card"
139
- },
140
- :id => id,
141
- :reason => "execute_charge",
142
- :livemode => false,
143
- :currency => "usd",
144
- :object => "charge",
145
- :created => 1304114826,
146
- :refunds => make_refund_array(id),
147
- :metadata => {}
148
- }.merge(params)
149
- end
150
-
151
- def make_charge_array
152
- {
153
- :data => [make_charge, make_charge, make_charge],
154
- :object => 'list',
155
- :url => '/v1/charges'
156
- }
157
- end
158
-
159
-
160
- def make_dispute(params={})
161
- id = params[:id] || 'dp_test_dispute'
162
- {
163
- :id => id,
164
- :charge => "ch_test_charge",
165
- :amount => 500,
166
- :created => 1304114758,
167
- :status => 'needs_response',
168
- :livemode => false,
169
- :currency => 'usd',
170
- :object => 'dispute',
171
- :reason => 'fraudulent',
172
- :evidence => {},
173
- }.merge(params)
174
- end
175
-
176
- def make_dispute_array
177
- {
178
- :data => [make_dispute, make_dispute, make_dispute],
179
- :object => 'list',
180
- :url => '/v1/disputes'
181
- }
182
- end
183
-
184
- def make_recipient_card_array(recipient_id)
185
- {
186
- :data => [make_card, make_card, make_card],
187
- :object => 'list',
188
- :url => '/v1/recipients/' + recipient_id + '/cards'
189
- }
190
- end
191
-
192
- def make_customer_card_array(customer_id)
193
- {
194
- :data => [make_card, make_card, make_card],
195
- :object => 'list',
196
- :url => '/v1/customers/' + customer_id + '/sources'
197
- }
198
- end
199
-
200
- def make_card(params={})
201
- {
202
- :type => "Visa",
203
- :last4 => "4242",
204
- :exp_month => 11,
205
- :country => "US",
206
- :exp_year => 2012,
207
- :id => "cc_test_card",
208
- :customer => 'c_test_customer',
209
- :object => "card"
210
- }.merge(params)
211
- end
212
-
213
- def make_coupon(params={})
214
- {
215
- :duration => 'repeating',
216
- :duration_in_months => 3,
217
- :percent_off => 25,
218
- :id => "co_test_coupon",
219
- :object => "coupon",
220
- :metadata => {},
221
- }.merge(params)
222
- end
223
-
224
- def make_file(params={})
225
- {
226
- :object => "file_upload",
227
- :id => "fil_test_file",
228
- :created => 1403047735,
229
- :size => 4908,
230
- :purpose => params[:purpose] || "dispute_evidence",
231
- :url => nil,
232
- :type => nil,
233
- }
234
- end
235
-
236
- def make_file_array
237
- {
238
- :data => [make_file, make_file, make_file],
239
- :object => 'list',
240
- :url => '/v1/files'
241
- }
242
- end
243
-
244
- #FIXME nested overrides would be better than hardcoding plan_id
245
- def make_subscription(params = {})
246
- plan = params.delete(:plan) || 'gold'
247
- {
248
- :current_period_end => 1308681468,
249
- :status => "trialing",
250
- :plan => {
251
- :interval => "month",
252
- :amount => 7500,
253
- :trial_period_days => 30,
254
- :object => "plan",
255
- :identifier => plan
256
- },
257
- :current_period_start => 1308595038,
258
- :start => 1308595038,
259
- :object => "subscription",
260
- :trial_start => 1308595038,
261
- :trial_end => 1308681468,
262
- :customer => "c_test_customer",
263
- :id => 's_test_subscription'
264
- }.merge(params)
265
- end
266
-
267
- def make_refund(params = {})
268
- {
269
- :object => 'refund',
270
- :amount => 30,
271
- :currency => "usd",
272
- :created => 1308595038,
273
- :id => "ref_test_refund",
274
- :charge => "ch_test_charge",
275
- :metadata => {}
276
- }.merge(params)
277
- end
278
-
279
- def make_subscription_array(customer_id)
280
- {
281
- :data => [make_subscription, make_subscription, make_subscription],
282
- :object => 'list',
283
- :url => '/v1/customers/' + customer_id + '/subscriptions'
284
- }
285
- end
286
-
287
- def make_refund_array(charge=nil)
288
- p = charge ? {:charge => charge} : {}
289
-
290
- {
291
- :data => [make_refund(p), make_refund(p), make_refund(p)],
292
- :object => 'list',
293
- :url => charge ? "/v1/charges/#{charge}/refunds" : '/v1/refunds'
294
- }
295
- end
296
-
297
- def make_reversal_array(transfer_id)
298
- {
299
- :data => [make_reversal, make_reversal, make_reversal],
300
- :object => 'list',
301
- :url => '/v1/transfers/' + transfer_id + '/reversals'
302
- }
303
- end
304
-
305
- def make_invoice
306
- {
307
- :id => 'in_test_invoice',
308
- :object => 'invoice',
309
- :livemode => false,
310
- :amount_due => 1000,
311
- :attempt_count => 0,
312
- :attempted => false,
313
- :closed => false,
314
- :currency => 'usd',
315
- :customer => 'c_test_customer',
316
- :date => 1349738950,
317
- :lines => {
318
- "invoiceitems" => [
319
- {
320
- :id => 'ii_test_invoice_item',
321
- :object => '',
322
- :livemode => false,
323
- :amount => 1000,
324
- :currency => 'usd',
325
- :customer => 'c_test_customer',
326
- :date => 1349738950,
327
- :description => "A Test Invoice Item",
328
- :invoice => 'in_test_invoice'
329
- },
330
- ],
331
- },
332
- :paid => false,
333
- :period_end => 1349738950,
334
- :period_start => 1349738950,
335
- :starting_balance => 0,
336
- :subtotal => 1000,
337
- :total => 1000,
338
- :charge => nil,
339
- :discount => nil,
340
- :ending_balance => nil,
341
- :next_payemnt_attempt => 1349825350,
342
- }
343
- end
344
-
345
- def make_paid_invoice
346
- make_invoice.merge({
347
- :attempt_count => 1,
348
- :attempted => true,
349
- :closed => true,
350
- :paid => true,
351
- :charge => 'ch_test_charge',
352
- :ending_balance => 0,
353
- :next_payment_attempt => nil,
354
- })
355
- end
356
-
357
- def make_invoice_customer_array
358
- {
359
- :data => [make_invoice],
360
- :object => 'list',
361
- :url => '/v1/invoices?customer=test_customer'
362
- }
363
- end
364
-
365
- def make_recipient(params={})
366
- id = params[:id] || 'rp_test_recipient'
367
- {
368
- :name => "Stripe User",
369
- :type => "individual",
370
- :livemode => false,
371
- :object => "recipient",
372
- :id => "rp_test_recipient",
373
- :cards => make_recipient_card_array(id),
374
- :default_card => "debit_test_card",
375
- :active_account => {
376
- :last4 => "6789",
377
- :bank_name => "STRIPE TEST BANK",
378
- :country => "US",
379
- :object => "bank_account"
380
- },
381
- :created => 1304114758,
382
- :verified => true,
383
- :metadata => {}
384
- }.merge(params)
385
- end
386
-
387
- def make_recipient_array
388
- {
389
- :data => [make_recipient, make_recipient, make_recipient],
390
- :object => 'list',
391
- :url => '/v1/recipients'
392
- }
393
- end
394
-
395
- def make_transfer(params={})
396
- {
397
- :status => 'pending',
398
- :amount => 100,
399
- :account => {
400
- :object => 'bank_account',
401
- :country => 'US',
402
- :bank_name => 'STRIPE TEST BANK',
403
- :last4 => '6789'
404
- },
405
- :recipient => 'test_recipient',
406
- :fee => 0,
407
- :fee_details => [],
408
- :id => "tr_test_transfer",
409
- :reversals => make_reversal_array('tr_test_transfer'),
410
- :livemode => false,
411
- :currency => "usd",
412
- :object => "transfer",
413
- :date => 1304114826,
414
- :metadata => {}
415
- }.merge(params)
416
- end
417
-
418
- def make_transfer_array
419
- {
420
- :data => [make_transfer, make_transfer, make_transfer],
421
- :object => 'list',
422
- :url => '/v1/transfers'
423
- }
424
- end
425
-
426
- def make_canceled_transfer
427
- make_transfer.merge({
428
- :status => 'canceled'
429
- })
430
- end
431
-
432
- def make_reversal(params={})
433
- {
434
- :object => 'transfer_reversal',
435
- :amount => 30,
436
- :currency => "usd",
437
- :created => 1308595038,
438
- :id => "ref_test_reversal",
439
- :transfer => "tr_test_transfer",
440
- :metadata => {}
441
- }.merge(params)
442
- end
443
-
444
- def make_bitcoin_receiver(params={})
445
- {
446
- :id => 'btcrcv_test_receiver',
447
- :amount => 100,
448
- :currency => 'usd',
449
- :description => 'some details',
450
- :metadata => {},
451
- :object => 'bitcoin_receiver',
452
- :transactions => make_bitcoin_transaction_array
453
- }.merge(params)
454
- end
455
-
456
- def make_bitcoin_receiver_array
457
- {
458
- :data => [make_bitcoin_receiver, make_bitcoin_receiver, make_bitcoin_receiver],
459
- :object => 'list',
460
- :url => '/v1/bitcoin/receivers'
461
- }
462
- end
463
-
464
- def make_bitcoin_transaction(params={})
465
- {
466
- :id => 'btctxn_test_transaction',
467
- :object => 'bitcoin_transaction',
468
- :amount => 100,
469
- :currency => 'usd',
470
- :bitcoin_amount => 90,
471
- :receiver => 'btcrcv_test_receiver'
472
- }.merge(params)
473
- end
474
-
475
- def make_bitcoin_transaction_array
476
- {
477
- :data => [make_bitcoin_transaction, make_bitcoin_transaction, make_bitcoin_transaction],
478
- :object => 'list',
479
- :url => "/v1/bitcoin/receivers/btcrcv_test_receiver/transactions"
480
- }
481
- end
482
-
483
- def make_invalid_api_key_error
484
- {
485
- :error => {
486
- :type => "invalid_request_error",
487
- :message => "Invalid API Key provided: invalid"
488
- }
489
- }
490
- end
491
-
492
- def make_invalid_exp_year_error
493
- {
494
- :error => {
495
- :code => "invalid_expiry_year",
496
- :param => "exp_year",
497
- :type => "card_error",
498
- :message => "Your card's expiration year is invalid"
499
- }
500
- }
501
- end
502
-
503
- def make_missing_id_error
504
- {
505
- :error => {
506
- :param => "id",
507
- :type => "invalid_request_error",
508
- :message => "Missing id"
509
- }
510
- }
511
- end
512
-
513
- def make_rate_limit_error
514
- {
515
- :error => {
516
- :type => "invalid_request_error",
517
- :message => "Too many requests in a period of time."
518
- }
519
- }
520
- end
521
-
522
- def make_api_error
523
- {
524
- :error => {
525
- :type => "api_error"
526
- }
527
- }
528
- end
529
-
530
- def make_delete_discount_response
531
- {
532
- :deleted => true,
533
- :id => "di_test_coupon"
534
- }
535
- end
536
-
537
- def make_product(params={})
538
- {
539
- :id => "pr_test_product",
540
- :created => 1441992477,
541
- :updated => 1441992477,
542
- :object => "product",
543
- :livemode => false,
544
- :name => "Test Product",
545
- :caption => "Comfy comfu",
546
- :description => "Testing",
547
- :active => true,
548
- :attributes => [],
549
- :shippable => true,
550
- :metadata => {},
551
- :url => "http://example.com/product",
552
- :package_dimensions => nil,
553
- :images => [],
554
- :skus => make_sku_array("pr_test_product")
555
- }.merge(params)
556
- end
557
-
558
- def make_product_array
559
- {
560
- :object => "list",
561
- :url => "/v1/products",
562
- :data => [
563
- make_product,
564
- make_product,
565
- make_product,
566
- ],
567
- }
568
- end
569
-
570
- def make_sku(params={})
571
- {
572
- :id => "12345",
573
- :created => 1441992494,
574
- :updated => 1441992494,
575
- :object => "sku",
576
- :livemode => false,
577
- :product => "pr_test_product",
578
- :image => nil,
579
- :active => true,
580
- :price => 999,
581
- :currency => "usd",
582
- :inventory => {
583
- :type => "infinite",
584
- :quantity => nil,
585
- :value => nil,
586
- },
587
- :attributes => {},
588
- :metadata => {},
589
- :package_dimensions => nil,
590
- }.merge(params)
591
- end
592
-
593
- def make_sku_array(product_id, params={})
594
- {
595
- :object => "list",
596
- :url => "/v1/skus",
597
- :data => [
598
- make_sku(:product => product_id),
599
- make_sku(:product => product_id),
600
- make_sku(:product => product_id),
601
- ]
602
- }
603
- end
604
-
605
- def make_order(params={})
606
- {
607
- :id => "or_16kg0uDAu10Yox5RReNVCthv",
608
- :created => 1442171988,
609
- :updated => nil,
610
- :object => "order",
611
- :livemode => false,
612
- :status => "created",
613
- :metadata => {},
614
- :customer => nil,
615
- :shipping => {
616
- :name => "Jenny Rosen",
617
- :address => {
618
- :line1 => "1234 Main street",
619
- :line2 => nil,
620
- :city => "Anytown",
621
- :state => nil,
622
- :postal_code => "123456",
623
- :country => "US"
624
- },
625
- :phone => nil,
626
- },
627
- :email => nil,
628
- :items => [
629
- {
630
- :parent => "sk_16bHXrDAu10Yox5RU2007dpU",
631
- :object => "order_item",
632
- :type => "sku",
633
- :description => "T-shirt",
634
- :amount => 1500,
635
- :currency => "usd",
636
- :quantity => nil,
637
- }
638
- ],
639
- :shipping_methods => nil,
640
- :selected_shipping_method => nil,
641
- :amount => 1500,
642
- :currency => "usd",
643
- :charge => nil,
644
- }.merge(params)
645
- end
646
-
647
- def make_order_array(params={})
648
- {
649
- :object => "list",
650
- :url => "/v1/orders",
651
- :data => [
652
- make_order,
653
- make_order,
654
- make_order,
655
- ]
656
- }
657
- end
658
-
659
- def make_paid_order(params={})
660
- make_order.merge({
661
- :status => "paid",
662
- :charge => make_charge,
663
- }).merge(params)
664
- end
665
- end
666
- end