stripe 2.0.3 → 5.55.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +1036 -0
  3. data/CODE_OF_CONDUCT.md +77 -0
  4. data/Gemfile +24 -23
  5. data/History.txt +1 -593
  6. data/Makefile +7 -0
  7. data/README.md +252 -53
  8. data/Rakefile +18 -24
  9. data/VERSION +1 -1
  10. data/bin/stripe-console +5 -3
  11. data/lib/stripe/api_operations/create.rb +4 -2
  12. data/lib/stripe/api_operations/delete.rb +31 -3
  13. data/lib/stripe/api_operations/list.rb +4 -13
  14. data/lib/stripe/api_operations/nested_resource.rb +73 -0
  15. data/lib/stripe/api_operations/request.rb +92 -10
  16. data/lib/stripe/api_operations/save.rb +25 -13
  17. data/lib/stripe/api_operations/search.rb +19 -0
  18. data/lib/stripe/api_resource.rb +55 -11
  19. data/lib/stripe/api_resource_test_helpers.rb +47 -0
  20. data/lib/stripe/connection_manager.rb +200 -0
  21. data/lib/stripe/error_object.rb +93 -0
  22. data/lib/stripe/errors.rb +98 -13
  23. data/lib/stripe/instrumentation.rb +84 -0
  24. data/lib/stripe/list_object.rb +55 -21
  25. data/lib/stripe/multipart_encoder.rb +131 -0
  26. data/lib/stripe/oauth.rb +65 -0
  27. data/lib/stripe/object_types.rb +119 -0
  28. data/lib/stripe/{account.rb → resources/account.rb} +75 -38
  29. data/lib/stripe/resources/account_link.rb +10 -0
  30. data/lib/stripe/resources/alipay_account.rb +34 -0
  31. data/lib/stripe/{apple_pay_domain.rb → resources/apple_pay_domain.rb} +6 -1
  32. data/lib/stripe/resources/application_fee.rb +14 -0
  33. data/lib/stripe/resources/application_fee_refund.rb +31 -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/{bitcoin_receiver.rb → resources/bitcoin_receiver.rb} +8 -4
  40. data/lib/stripe/resources/bitcoin_transaction.rb +16 -0
  41. data/lib/stripe/resources/capability.rb +34 -0
  42. data/lib/stripe/resources/card.rb +38 -0
  43. data/lib/stripe/resources/cash_balance.rb +22 -0
  44. data/lib/stripe/resources/charge.rb +32 -0
  45. data/lib/stripe/resources/checkout/session.rb +27 -0
  46. data/lib/stripe/resources/country_spec.rb +10 -0
  47. data/lib/stripe/{coupon.rb → resources/coupon.rb} +6 -1
  48. data/lib/stripe/resources/credit_note.rb +33 -0
  49. data/lib/stripe/resources/credit_note_line_item.rb +8 -0
  50. data/lib/stripe/resources/customer.rb +74 -0
  51. data/lib/stripe/resources/customer_balance_transaction.rb +31 -0
  52. data/lib/stripe/resources/discount.rb +8 -0
  53. data/lib/stripe/resources/dispute.rb +22 -0
  54. data/lib/stripe/resources/ephemeral_key.rb +20 -0
  55. data/lib/stripe/resources/event.rb +10 -0
  56. data/lib/stripe/resources/exchange_rate.rb +10 -0
  57. data/lib/stripe/resources/file.rb +36 -0
  58. data/lib/stripe/resources/file_link.rb +12 -0
  59. data/lib/stripe/resources/financial_connections/account.rb +31 -0
  60. data/lib/stripe/resources/financial_connections/account_owner.rb +10 -0
  61. data/lib/stripe/resources/financial_connections/account_ownership.rb +10 -0
  62. data/lib/stripe/resources/financial_connections/session.rb +12 -0
  63. data/lib/stripe/resources/funding_instructions.rb +16 -0
  64. data/lib/stripe/resources/identity/verification_report.rb +12 -0
  65. data/lib/stripe/resources/identity/verification_session.rb +35 -0
  66. data/lib/stripe/resources/invoice.rb +83 -0
  67. data/lib/stripe/{invoice_item.rb → resources/invoice_item.rb} +6 -1
  68. data/lib/stripe/resources/invoice_line_item.rb +8 -0
  69. data/lib/stripe/resources/issuing/authorization.rb +34 -0
  70. data/lib/stripe/resources/issuing/card.rb +25 -0
  71. data/lib/stripe/resources/issuing/card_details.rb +10 -0
  72. data/lib/stripe/resources/issuing/cardholder.rb +14 -0
  73. data/lib/stripe/resources/issuing/dispute.rb +25 -0
  74. data/lib/stripe/resources/issuing/transaction.rb +13 -0
  75. data/lib/stripe/resources/line_item.rb +8 -0
  76. data/lib/stripe/resources/login_link.rb +15 -0
  77. data/lib/stripe/resources/mandate.rb +8 -0
  78. data/lib/stripe/resources/order.rb +33 -0
  79. data/lib/stripe/resources/order_return.rb +10 -0
  80. data/lib/stripe/resources/payment_intent.rb +82 -0
  81. data/lib/stripe/resources/payment_link.rb +23 -0
  82. data/lib/stripe/resources/payment_method.rb +33 -0
  83. data/lib/stripe/resources/payout.rb +33 -0
  84. data/lib/stripe/resources/person.rb +32 -0
  85. data/lib/stripe/{plan.rb → resources/plan.rb} +5 -0
  86. data/lib/stripe/resources/price.rb +21 -0
  87. data/lib/stripe/resources/product.rb +22 -0
  88. data/lib/stripe/resources/promotion_code.rb +12 -0
  89. data/lib/stripe/resources/quote.rb +105 -0
  90. data/lib/stripe/resources/radar/early_fraud_warning.rb +12 -0
  91. data/lib/stripe/resources/radar/value_list.rb +15 -0
  92. data/lib/stripe/resources/radar/value_list_item.rb +14 -0
  93. data/lib/stripe/resources/recipient.rb +14 -0
  94. data/lib/stripe/resources/recipient_transfer.rb +7 -0
  95. data/lib/stripe/resources/refund.rb +42 -0
  96. data/lib/stripe/resources/reporting/report_run.rb +13 -0
  97. data/lib/stripe/resources/reporting/report_type.rb +13 -0
  98. data/lib/stripe/resources/reversal.rb +30 -0
  99. data/lib/stripe/resources/review.rb +21 -0
  100. data/lib/stripe/resources/setup_attempt.rb +10 -0
  101. data/lib/stripe/resources/setup_intent.rb +43 -0
  102. data/lib/stripe/resources/shipping_rate.rb +12 -0
  103. data/lib/stripe/resources/sigma/scheduled_query_run.rb +16 -0
  104. data/lib/stripe/{sku.rb → resources/sku.rb} +7 -2
  105. data/lib/stripe/resources/source.rb +47 -0
  106. data/lib/stripe/resources/source_transaction.rb +8 -0
  107. data/lib/stripe/resources/subscription.rb +35 -0
  108. data/lib/stripe/resources/subscription_item.rb +26 -0
  109. data/lib/stripe/resources/subscription_schedule.rb +33 -0
  110. data/lib/stripe/resources/tax_code.rb +10 -0
  111. data/lib/stripe/resources/tax_id.rb +27 -0
  112. data/lib/stripe/{product.rb → resources/tax_rate.rb} +7 -3
  113. data/lib/stripe/resources/terminal/configuration.rb +15 -0
  114. data/lib/stripe/resources/terminal/connection_token.rb +12 -0
  115. data/lib/stripe/resources/terminal/location.rb +15 -0
  116. data/lib/stripe/resources/terminal/reader.rb +75 -0
  117. data/lib/stripe/resources/test_helpers/test_clock.rb +25 -0
  118. data/lib/stripe/{three_d_secure.rb → resources/three_d_secure.rb} +5 -0
  119. data/lib/stripe/resources/token.rb +10 -0
  120. data/lib/stripe/resources/topup.rb +23 -0
  121. data/lib/stripe/resources/transfer.rb +27 -0
  122. data/lib/stripe/resources/usage_record.rb +8 -0
  123. data/lib/stripe/resources/usage_record_summary.rb +8 -0
  124. data/lib/stripe/{recipient.rb → resources/webhook_endpoint.rb} +6 -5
  125. data/lib/stripe/resources.rb +100 -0
  126. data/lib/stripe/search_result_object.rb +86 -0
  127. data/lib/stripe/singleton_api_resource.rb +10 -4
  128. data/lib/stripe/stripe_client.rb +886 -223
  129. data/lib/stripe/stripe_configuration.rb +194 -0
  130. data/lib/stripe/stripe_object.rb +301 -132
  131. data/lib/stripe/stripe_response.rb +89 -27
  132. data/lib/stripe/util.rb +272 -122
  133. data/lib/stripe/version.rb +3 -1
  134. data/lib/stripe/webhook.rb +121 -0
  135. data/lib/stripe.rb +94 -116
  136. data/stripe.gemspec +35 -16
  137. metadata +127 -156
  138. data/.gitattributes +0 -4
  139. data/.github/ISSUE_TEMPLATE.md +0 -5
  140. data/.gitignore +0 -5
  141. data/.travis.yml +0 -15
  142. data/lib/stripe/alipay_account.rb +0 -20
  143. data/lib/stripe/application_fee.rb +0 -20
  144. data/lib/stripe/application_fee_refund.rb +0 -18
  145. data/lib/stripe/balance.rb +0 -4
  146. data/lib/stripe/balance_transaction.rb +0 -9
  147. data/lib/stripe/bank_account.rb +0 -28
  148. data/lib/stripe/bitcoin_transaction.rb +0 -9
  149. data/lib/stripe/card.rb +0 -25
  150. data/lib/stripe/charge.rb +0 -80
  151. data/lib/stripe/country_spec.rb +0 -9
  152. data/lib/stripe/customer.rb +0 -77
  153. data/lib/stripe/dispute.rb +0 -15
  154. data/lib/stripe/event.rb +0 -5
  155. data/lib/stripe/file_upload.rb +0 -31
  156. data/lib/stripe/invoice.rb +0 -27
  157. data/lib/stripe/order.rb +0 -27
  158. data/lib/stripe/order_return.rb +0 -9
  159. data/lib/stripe/refund.rb +0 -7
  160. data/lib/stripe/reversal.rb +0 -18
  161. data/lib/stripe/source.rb +0 -11
  162. data/lib/stripe/subscription.rb +0 -31
  163. data/lib/stripe/subscription_item.rb +0 -12
  164. data/lib/stripe/token.rb +0 -5
  165. data/lib/stripe/transfer.rb +0 -16
  166. data/openapi/fixtures.json +0 -1383
  167. data/openapi/fixtures.yaml +0 -1130
  168. data/openapi/spec.json +0 -19749
  169. data/openapi/spec.yaml +0 -15359
  170. data/test/api_fixtures.rb +0 -29
  171. data/test/api_stub_helpers.rb +0 -125
  172. data/test/stripe/account_test.rb +0 -204
  173. data/test/stripe/alipay_account_test.rb +0 -19
  174. data/test/stripe/api_operations_test.rb +0 -31
  175. data/test/stripe/api_resource_test.rb +0 -496
  176. data/test/stripe/apple_pay_domain_test.rb +0 -33
  177. data/test/stripe/application_fee_refund_test.rb +0 -38
  178. data/test/stripe/application_fee_test.rb +0 -14
  179. data/test/stripe/balance_test.rb +0 -11
  180. data/test/stripe/bank_account_test.rb +0 -41
  181. data/test/stripe/bitcoin_receiver_test.rb +0 -70
  182. data/test/stripe/bitcoin_transaction_test.rb +0 -21
  183. data/test/stripe/charge_test.rb +0 -59
  184. data/test/stripe/country_spec_test.rb +0 -20
  185. data/test/stripe/coupon_test.rb +0 -44
  186. data/test/stripe/customer_card_test.rb +0 -42
  187. data/test/stripe/customer_test.rb +0 -116
  188. data/test/stripe/dispute_test.rb +0 -42
  189. data/test/stripe/errors_test.rb +0 -18
  190. data/test/stripe/file_upload_test.rb +0 -66
  191. data/test/stripe/invoice_item_test.rb +0 -55
  192. data/test/stripe/invoice_test.rb +0 -66
  193. data/test/stripe/list_object_test.rb +0 -170
  194. data/test/stripe/order_return_test.rb +0 -21
  195. data/test/stripe/order_test.rb +0 -59
  196. data/test/stripe/plan_test.rb +0 -52
  197. data/test/stripe/product_test.rb +0 -47
  198. data/test/stripe/recipient_card_test.rb +0 -40
  199. data/test/stripe/recipient_test.rb +0 -50
  200. data/test/stripe/refund_test.rb +0 -39
  201. data/test/stripe/reversal_test.rb +0 -43
  202. data/test/stripe/sku_test.rb +0 -50
  203. data/test/stripe/source_test.rb +0 -43
  204. data/test/stripe/stripe_client_test.rb +0 -440
  205. data/test/stripe/stripe_object_test.rb +0 -361
  206. data/test/stripe/stripe_response_test.rb +0 -46
  207. data/test/stripe/subscription_item_test.rb +0 -54
  208. data/test/stripe/subscription_test.rb +0 -60
  209. data/test/stripe/three_d_secure_test.rb +0 -23
  210. data/test/stripe/transfer_test.rb +0 -50
  211. data/test/stripe/util_test.rb +0 -149
  212. data/test/stripe_test.rb +0 -41
  213. data/test/test_data.rb +0 -59
  214. data/test/test_helper.rb +0 -41
@@ -1,70 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class BitcoinReceiverTest < Test::Unit::TestCase
5
- FIXTURE = API_FIXTURES.fetch(:bitcoin_receiver)
6
-
7
- should "be listable" do
8
- receivers = Stripe::BitcoinReceiver.list
9
- assert_requested :get, "#{Stripe.api_base}/v1/bitcoin/receivers"
10
- assert receivers.data.kind_of?(Array)
11
- assert receivers.first.kind_of?(Stripe::BitcoinReceiver)
12
- end
13
-
14
- should "be retrievable" do
15
- receiver = Stripe::BitcoinReceiver.retrieve(FIXTURE[:id])
16
- assert_requested :get,
17
- "#{Stripe.api_base}/v1/bitcoin/receivers/#{FIXTURE[:id]}"
18
- assert receiver.kind_of?(Stripe::BitcoinReceiver)
19
- end
20
-
21
- should "be creatable" do
22
- receiver = Stripe::BitcoinReceiver.create(amount: 100, currency: "USD")
23
- assert_requested :post, "#{Stripe.api_base}/v1/bitcoin/receivers"
24
- assert receiver.kind_of?(Stripe::BitcoinReceiver)
25
- end
26
-
27
- should "be saveable" do
28
- receiver = Stripe::BitcoinReceiver.retrieve(FIXTURE[:id])
29
- receiver.metadata['key'] = 'value'
30
- receiver.save
31
- assert_requested :post,
32
- "#{Stripe.api_base}/v1/bitcoin/receivers/#{FIXTURE[:id]}"
33
- end
34
-
35
- should "be updateable" do
36
- receiver = Stripe::BitcoinReceiver.update(FIXTURE[:id], metadata: { key: 'value' })
37
- assert_requested :post,
38
- "#{Stripe.api_base}/v1/bitcoin/receivers/#{FIXTURE[:id]}"
39
- assert receiver.kind_of?(Stripe::BitcoinReceiver)
40
- end
41
-
42
- should "be deletable" do
43
- receiver = Stripe::BitcoinReceiver.retrieve(FIXTURE[:id])
44
- receiver = receiver.delete
45
- assert_requested :delete,
46
- "#{Stripe.api_base}/v1/bitcoin/receivers/#{FIXTURE[:id]}"
47
- assert receiver.kind_of?(Stripe::BitcoinReceiver)
48
- end
49
-
50
- context "#resource_url" do
51
- should "return a customer URL" do
52
- customer_id = API_FIXTURES.fetch(:customer)[:id]
53
- receiver = Stripe::BitcoinReceiver.construct_from(
54
- customer: customer_id,
55
- id: FIXTURE[:id]
56
- )
57
- assert_equal "/v1/customers/#{customer_id}/sources/#{FIXTURE[:id]}",
58
- receiver.resource_url
59
- end
60
-
61
- should "return an absolute URL" do
62
- receiver = Stripe::BitcoinReceiver.construct_from(
63
- id: FIXTURE[:id]
64
- )
65
- assert_equal "/v1/bitcoin/receivers/#{FIXTURE[:id]}",
66
- receiver.resource_url
67
- end
68
- end
69
- end
70
- end
@@ -1,21 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class BitcoinTransactionTest < Test::Unit::TestCase
5
- FIXTURE = API_FIXTURES.fetch(:bitcoin_transaction)
6
-
7
- should "be listable" do
8
- transactions = Stripe::BitcoinTransaction.list
9
- assert_requested :get, "#{Stripe.api_base}/v1/bitcoin/transactions"
10
- assert transactions.data.kind_of?(Array)
11
- assert transactions.first.kind_of?(Stripe::BitcoinTransaction)
12
- end
13
-
14
- should "be retrievable" do
15
- transaction = Stripe::BitcoinTransaction.retrieve(FIXTURE[:id])
16
- assert_requested :get,
17
- "#{Stripe.api_base}/v1/bitcoin/transactions/#{FIXTURE[:id]}"
18
- assert transaction.kind_of?(Stripe::BitcoinTransaction)
19
- end
20
- end
21
- end
@@ -1,59 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class ChargeTest < Test::Unit::TestCase
5
- FIXTURE = API_FIXTURES.fetch(:charge)
6
-
7
- should "be listable" do
8
- charges = Stripe::Charge.list
9
- assert_requested :get, "#{Stripe.api_base}/v1/charges"
10
- assert charges.data.kind_of?(Array)
11
- assert charges.data[0].kind_of?(Stripe::Charge)
12
- end
13
-
14
- should "be retrievable" do
15
- charge = Stripe::Charge.retrieve(FIXTURE[:id])
16
- assert_requested :get, "#{Stripe.api_base}/v1/charges/#{FIXTURE[:id]}"
17
- assert charge.kind_of?(Stripe::Charge)
18
- end
19
-
20
- should "be creatable" do
21
- charge = Stripe::Charge.create(
22
- amount: 100,
23
- currency: "USD",
24
- source: API_FIXTURES.fetch(:source)[:id]
25
- )
26
- assert_requested :post, "#{Stripe.api_base}/v1/charges"
27
- assert charge.kind_of?(Stripe::Charge)
28
- end
29
-
30
- should "be saveable" do
31
- charge = Stripe::Charge.retrieve(FIXTURE[:id])
32
- charge.metadata['key'] = 'value'
33
- charge.save
34
- assert_requested :post, "#{Stripe.api_base}/v1/charges/#{FIXTURE[:id]}"
35
- end
36
-
37
- should "be updateable" do
38
- charge = Stripe::Charge.update(FIXTURE[:id], metadata: {foo: 'bar'})
39
- assert_requested :post, "#{Stripe.api_base}/v1/charges/#{FIXTURE[:id]}"
40
- assert charge.kind_of?(Stripe::Charge)
41
- end
42
-
43
- context "#mark_as_fraudulent" do
44
- should "charges should be able to be marked as fraudulent" do
45
- charge = Stripe::Charge.retrieve(FIXTURE[:id])
46
- charge = charge.mark_as_fraudulent
47
- assert charge.kind_of?(Stripe::Charge)
48
- end
49
- end
50
-
51
- context "#mark_as_safe" do
52
- should "charges should be able to be marked as safe" do
53
- charge = Stripe::Charge.retrieve(FIXTURE[:id])
54
- charge = charge.mark_as_safe
55
- assert charge.kind_of?(Stripe::Charge)
56
- end
57
- end
58
- end
59
- end
@@ -1,20 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class CountrySpecTest < Test::Unit::TestCase
5
- FIXTURE = API_FIXTURES.fetch(:country_spec)
6
-
7
- should "be listable" do
8
- c = Stripe::CountrySpec.list
9
- assert_requested :get, "#{Stripe.api_base}/v1/country_specs"
10
- assert c.data.kind_of?(Array)
11
- assert c.data[0].kind_of?(Stripe::CountrySpec)
12
- end
13
-
14
- should "be retrievable" do
15
- s = Stripe::CountrySpec.retrieve(FIXTURE[:id])
16
- assert_requested :get, "#{Stripe.api_base}/v1/country_specs/#{FIXTURE[:id]}"
17
- assert(s.kind_of?(Stripe::CountrySpec))
18
- end
19
- end
20
- end
@@ -1,44 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class CouponTest < Test::Unit::TestCase
5
- FIXTURE = API_FIXTURES.fetch(:coupon)
6
-
7
- should "be listable" do
8
- coupons = Stripe::Coupon.list
9
- assert_requested :get, "#{Stripe.api_base}/v1/coupons"
10
- assert coupons.data.kind_of?(Array)
11
- assert coupons.first.kind_of?(Stripe::Coupon)
12
- end
13
-
14
- should "be retrievable" do
15
- coupon = Stripe::Coupon.retrieve(FIXTURE[:id])
16
- assert_requested :get, "#{Stripe.api_base}/v1/coupons/#{FIXTURE[:id]}"
17
- assert coupon.kind_of?(Stripe::Coupon)
18
- end
19
-
20
- should "be creatable" do
21
- coupon = Stripe::Coupon.create(
22
- percent_off: 25,
23
- duration: 'repeating',
24
- duration_in_months: 3,
25
- id: '25OFF'
26
- )
27
- assert_requested :post, "#{Stripe.api_base}/v1/coupons"
28
- assert coupon.kind_of?(Stripe::Coupon)
29
- end
30
-
31
- should "be saveable" do
32
- coupon = Stripe::Coupon.retrieve(FIXTURE[:id])
33
- coupon.metadata['key'] = 'value'
34
- coupon.save
35
- assert_requested :post, "#{Stripe.api_base}/v1/coupons/#{FIXTURE[:id]}"
36
- end
37
-
38
- should "be updateable" do
39
- coupon = Stripe::Coupon.update(FIXTURE[:id], metadata: { key: 'value' })
40
- assert_requested :post, "#{Stripe.api_base}/v1/coupons/#{FIXTURE[:id]}"
41
- assert coupon.kind_of?(Stripe::Coupon)
42
- end
43
- end
44
- end
@@ -1,42 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class CustomerCardTest < Test::Unit::TestCase
5
- FIXTURE = API_FIXTURES.fetch(:source)
6
-
7
- setup do
8
- @customer =
9
- Stripe::Customer.retrieve(API_FIXTURES.fetch(:customer)[:id])
10
- end
11
-
12
- should "be listable" do
13
- sources = @customer.sources.list
14
- assert sources.data.kind_of?(Array)
15
- # because of the terrible :wildcard nature of sources, the API stub
16
- # cannot currently replace this response with anything meaningful so we
17
- # don't assert on the type of individual items like we do in other tests
18
- end
19
-
20
- should "be creatable" do
21
- card = @customer.sources.create(
22
- source: API_FIXTURES.fetch(:token)[:id]
23
- )
24
- assert_requested :post, "#{Stripe.api_base}/v1/customers/#{@customer.id}/sources"
25
- assert card.kind_of?(Stripe::BankAccount)
26
- end
27
-
28
- should "be deletable" do
29
- card = Stripe::Card.construct_from(FIXTURE.merge(customer: @customer.id))
30
- card = card.delete
31
- assert_requested :delete, "#{Stripe.api_base}/v1/customers/#{@customer.id}/sources/#{FIXTURE[:id]}"
32
- assert card.kind_of?(Stripe::Card)
33
- end
34
-
35
- should "be saveable" do
36
- card = Stripe::Card.construct_from(FIXTURE.merge(customer: @customer.id))
37
- card.metadata['key'] = 'value'
38
- card.save
39
- assert_requested :post, "#{Stripe.api_base}/v1/customers/#{@customer.id}/sources/#{FIXTURE[:id]}"
40
- end
41
- end
42
- end
@@ -1,116 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class CustomerTest < Test::Unit::TestCase
5
- FIXTURE = API_FIXTURES.fetch(:customer)
6
-
7
- should "be listable" do
8
- customers = Stripe::Customer.list
9
- assert_requested :get, "#{Stripe.api_base}/v1/customers"
10
- assert customers.data.kind_of?(Array)
11
- assert customers.first.kind_of?(Stripe::Customer)
12
- end
13
-
14
- should "be retrievable" do
15
- customer = Stripe::Customer.retrieve(FIXTURE[:id])
16
- assert_requested :get, "#{Stripe.api_base}/v1/customers/#{FIXTURE[:id]}"
17
- assert customer.kind_of?(Stripe::Customer)
18
- end
19
-
20
- should "be creatable" do
21
- customer = Stripe::Customer.create
22
- assert_requested :post, "#{Stripe.api_base}/v1/customers"
23
- assert customer.kind_of?(Stripe::Customer)
24
- end
25
-
26
- should "be saveable" do
27
- customer = Stripe::Customer.retrieve(FIXTURE[:id])
28
- customer.metadata['key'] = 'value'
29
- customer.save
30
- assert_requested :post, "#{Stripe.api_base}/v1/customers/#{FIXTURE[:id]}"
31
- end
32
-
33
- should "be updateable" do
34
- customer = Stripe::Customer.update(FIXTURE[:id], metadata: { key: 'value' })
35
- assert_requested :post, "#{Stripe.api_base}/v1/customers/#{FIXTURE[:id]}"
36
- assert customer.kind_of?(Stripe::Customer)
37
- end
38
-
39
- should "be deletable" do
40
- customer = Stripe::Customer.retrieve(FIXTURE[:id])
41
- customer = customer.delete
42
- assert_requested :delete, "#{Stripe.api_base}/v1/customers/#{FIXTURE[:id]}"
43
- assert customer.kind_of?(Stripe::Customer)
44
- end
45
-
46
- context "#create_subscription" do
47
- should "create a new subscription" do
48
- customer = Stripe::Customer.retrieve(FIXTURE[:id])
49
- subscription = customer.create_subscription({:plan => 'silver'})
50
- assert subscription.kind_of?(Stripe::Subscription)
51
- end
52
- end
53
-
54
- context "#create_upcoming_invoice" do
55
- should "create a new invoice" do
56
- customer = Stripe::Customer.retrieve(FIXTURE[:id])
57
- invoice = customer.create_upcoming_invoice
58
- assert invoice.kind_of?(Stripe::Invoice)
59
- end
60
- end
61
-
62
- context "#update_subscription" do
63
- should "update a subscription" do
64
- customer = Stripe::Customer.retrieve(FIXTURE[:id])
65
-
66
- # deprecated API and not in schema
67
- stub_request(:post, "#{Stripe.api_base}/v1/customers/#{customer.id}/subscription").
68
- with(body: { plan: "silver" }).
69
- to_return(body: JSON.generate(API_FIXTURES[:subscription]))
70
- subscription = customer.update_subscription({:plan => 'silver'})
71
- assert subscription.kind_of?(Stripe::Subscription)
72
- end
73
- end
74
-
75
- context "#cancel_subscription" do
76
- should "cancel a subscription" do
77
- customer = Stripe::Customer.retrieve(FIXTURE[:id])
78
-
79
- # deprecated API and not in schema
80
- stub_request(:delete, "#{Stripe.api_base}/v1/customers/#{customer.id}/subscription").
81
- with(query: { at_period_end: "true" }).
82
- to_return(body: JSON.generate(API_FIXTURES[:subscription]))
83
- subscription = customer.cancel_subscription({:at_period_end => 'true'})
84
- assert subscription.kind_of?(Stripe::Subscription)
85
- end
86
- end
87
-
88
- context "#delete_discount" do
89
- should "delete a discount" do
90
- customer = Stripe::Customer.retrieve(FIXTURE[:id])
91
-
92
- stub_request(:delete, "#{Stripe.api_base}/v1/customers/#{customer.id}/discount").
93
- to_return(body: JSON.generate(API_FIXTURES[:discount]))
94
- discount = customer.delete_discount
95
- assert discount.kind_of?(Stripe::Customer)
96
- end
97
- end
98
-
99
- context "source field" do
100
- should "allow setting source with token" do
101
- c = Stripe::Customer.new("test_customer")
102
- c.source = "tok_123"
103
- assert_equal "tok_123", c.source
104
- end
105
-
106
- should "allow setting source with hash and set flag" do
107
- c = Stripe::Customer.new("test_customer")
108
- c.source = {
109
- :object => 'card'
110
- }
111
- assert_equal true, c.source.save_with_parent
112
- end
113
- end
114
- end
115
- end
116
-
@@ -1,42 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class DisputeTest < Test::Unit::TestCase
5
- FIXTURE = API_FIXTURES.fetch(:dispute)
6
-
7
- should "be listable" do
8
- disputes = Stripe::Dispute.list
9
- assert_requested :get, "#{Stripe.api_base}/v1/disputes"
10
- assert disputes.data.kind_of?(Array)
11
- assert disputes.first.kind_of?(Stripe::Dispute)
12
- end
13
-
14
- should "be retrievable" do
15
- dispute = Stripe::Dispute.retrieve(FIXTURE[:id])
16
- assert_requested :get, "#{Stripe.api_base}/v1/disputes/#{FIXTURE[:id]}"
17
- assert dispute.kind_of?(Stripe::Dispute)
18
- end
19
-
20
- should "be saveable" do
21
- dispute = Stripe::Dispute.retrieve(FIXTURE[:id])
22
- dispute.metadata['key'] = 'value'
23
- dispute.save
24
- assert_requested :post, "#{Stripe.api_base}/v1/disputes/#{FIXTURE[:id]}"
25
- end
26
-
27
- should "be updateable" do
28
- dispute = Stripe::Dispute.update(FIXTURE[:id], metadata: { key: 'value' })
29
- assert_requested :post, "#{Stripe.api_base}/v1/disputes/#{FIXTURE[:id]}"
30
- assert dispute.kind_of?(Stripe::Dispute)
31
- end
32
-
33
- context "#close" do
34
- should "be closeable" do
35
- dispute = Stripe::Dispute.retrieve(FIXTURE[:id])
36
- dispute.close
37
- assert_requested :post,
38
- "#{Stripe.api_base}/v1/disputes/#{FIXTURE[:id]}/close"
39
- end
40
- end
41
- end
42
- end
@@ -1,18 +0,0 @@
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", http_status: 200)
11
- assert_equal "(Status 200) message", e.to_s
12
-
13
- e = StripeError.new("message", http_status: nil, http_body: nil, json_body: nil, http_headers: { :request_id => "request-id" })
14
- assert_equal "(Request request-id) message", e.to_s
15
- end
16
- end
17
- end
18
- end
@@ -1,66 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class FileUploadTest < Test::Unit::TestCase
5
- # Note that these tests are written different from others because we
6
- # don't have anything on the uploads service in our OpenAPI spec. This is
7
- # something that should be looked into at some point. We may need to ship
8
- # a separate spec for it though, so it's high effort with low reward for
9
- # the time being.
10
- FIXTURE = {
11
- id: "fil_15ABpV2eZvKYlo2C7vu7XS5l",
12
- object: "file_upload",
13
- }.freeze
14
-
15
- should "be listable" do
16
- stub_request(:get, "#{Stripe.uploads_base}/v1/files").
17
- to_return(body: JSON.generate({
18
- data: [FIXTURE],
19
- object: 'list',
20
- resource_url: '/v1/files'
21
- }))
22
-
23
- files = Stripe::FileUpload.list
24
- assert files.data.kind_of?(Array)
25
- assert files.data[0].kind_of?(Stripe::FileUpload)
26
- end
27
-
28
- should "be retrievable" do
29
- stub_request(:get, "#{Stripe.uploads_base}/v1/files/#{FIXTURE[:id]}").
30
- to_return(body: JSON.generate(FIXTURE))
31
-
32
- file = Stripe::FileUpload.retrieve(FIXTURE[:id])
33
- assert file.kind_of?(Stripe::FileUpload)
34
- end
35
-
36
- should "be creatable" do
37
- stub_request(:post, "#{Stripe.uploads_base}/v1/files").
38
- with(:headers => {
39
- "Content-Type" => %r|\A#{Faraday::Request::Multipart.mime_type}|
40
- }) { |request|
41
- request.body =~ /FileUploadTest/
42
- }.to_return(body: JSON.generate(FIXTURE))
43
-
44
- file = Stripe::FileUpload.create(
45
- purpose: "dispute_evidence",
46
- file: File.new(__FILE__),
47
- )
48
- assert file.kind_of?(Stripe::FileUpload)
49
- end
50
-
51
- should "be creatable with Faraday::UploadIO" do
52
- stub_request(:post, "#{Stripe.uploads_base}/v1/files").
53
- with(:headers => {
54
- "Content-Type" => %r|\A#{Faraday::Request::Multipart.mime_type}|
55
- }) { |request|
56
- request.body =~ /FileUploadTest/
57
- }.to_return(body: JSON.generate(FIXTURE))
58
-
59
- file = Stripe::FileUpload.create(
60
- purpose: "dispute_evidence",
61
- file: Faraday::UploadIO.new(File.new(__FILE__), nil),
62
- )
63
- assert file.kind_of?(Stripe::FileUpload)
64
- end
65
- end
66
- end
@@ -1,55 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class InvoiceItemTest < Test::Unit::TestCase
5
- FIXTURE = API_FIXTURES.fetch(:invoice_item)
6
-
7
- should "be listable" do
8
- invoiceitems = Stripe::InvoiceItem.list
9
- assert_requested :get, "#{Stripe.api_base}/v1/invoiceitems"
10
- assert invoiceitems.data.kind_of?(Array)
11
- assert invoiceitems.first.kind_of?(Stripe::InvoiceItem)
12
- end
13
-
14
- should "be retrievable" do
15
- item = Stripe::InvoiceItem.retrieve(FIXTURE[:id])
16
- assert_requested :get,
17
- "#{Stripe.api_base}/v1/invoiceitems/#{FIXTURE[:id]}"
18
- assert item.kind_of?(Stripe::InvoiceItem)
19
- end
20
-
21
- should "be creatable" do
22
- item = Stripe::InvoiceItem.create(
23
- amount: 100,
24
- currency: "USD",
25
- customer: API_FIXTURES[:customer][:id]
26
- )
27
- assert_requested :post,
28
- "#{Stripe.api_base}/v1/invoiceitems"
29
- assert item.kind_of?(Stripe::InvoiceItem)
30
- end
31
-
32
- should "be saveable" do
33
- item = Stripe::InvoiceItem.retrieve(FIXTURE[:id])
34
- item.metadata['key'] = 'value'
35
- item.save
36
- assert_requested :post,
37
- "#{Stripe.api_base}/v1/invoiceitems/#{FIXTURE[:id]}"
38
- end
39
-
40
- should "be updateable" do
41
- item = Stripe::InvoiceItem.update(FIXTURE[:id], metadata: { key: 'value' })
42
- assert_requested :post,
43
- "#{Stripe.api_base}/v1/invoiceitems/#{FIXTURE[:id]}"
44
- assert item.kind_of?(Stripe::InvoiceItem)
45
- end
46
-
47
- should "be deletable" do
48
- item = Stripe::InvoiceItem.retrieve(FIXTURE[:id])
49
- item = item.delete
50
- assert_requested :delete,
51
- "#{Stripe.api_base}/v1/invoiceitems/#{FIXTURE[:id]}"
52
- assert item.kind_of?(Stripe::InvoiceItem)
53
- end
54
- end
55
- end
@@ -1,66 +0,0 @@
1
- require File.expand_path('../../test_helper', __FILE__)
2
-
3
- module Stripe
4
- class InvoiceTest < Test::Unit::TestCase
5
- FIXTURE = API_FIXTURES.fetch(:invoice)
6
-
7
- should "be listable" do
8
- invoices = Stripe::Invoice.list
9
- assert_requested :get, "#{Stripe.api_base}/v1/invoices"
10
- assert invoices.data.kind_of?(Array)
11
- assert invoices.first.kind_of?(Stripe::Invoice)
12
- end
13
-
14
- should "be retrievable" do
15
- invoice = Stripe::Invoice.retrieve(FIXTURE[:id])
16
- assert_requested :get, "#{Stripe.api_base}/v1/invoices/#{FIXTURE[:id]}"
17
- assert invoice.kind_of?(Stripe::Invoice)
18
- end
19
-
20
- should "be creatable" do
21
- invoice = Stripe::Invoice.create(
22
- :customer => API_FIXTURES[:customer][:id]
23
- )
24
- assert_requested :post, "#{Stripe.api_base}/v1/invoices"
25
- assert invoice.kind_of?(Stripe::Invoice)
26
- end
27
-
28
- should "be saveable" do
29
- invoice = Stripe::Invoice.retrieve(FIXTURE[:id])
30
- invoice.metadata['key'] = 'value'
31
- invoice.save
32
- assert_requested :post, "#{Stripe.api_base}/v1/invoices/#{FIXTURE[:id]}"
33
- end
34
-
35
- should "be updateable" do
36
- invoice = Stripe::Invoice.update(FIXTURE[:id], metadata: { key: 'value' })
37
- assert_requested :post, "#{Stripe.api_base}/v1/invoices/#{FIXTURE[:id]}"
38
- assert invoice.kind_of?(Stripe::Invoice)
39
- end
40
-
41
- context "#pay" do
42
- should "pay invoice" do
43
- invoice = Stripe::Invoice.retrieve(FIXTURE[:id])
44
- invoice = invoice.pay
45
- assert_requested :post,
46
- "#{Stripe.api_base}/v1/invoices/#{FIXTURE[:id]}/pay"
47
- assert invoice.kind_of?(Stripe::Invoice)
48
- end
49
- end
50
-
51
- context "#upcoming" do
52
- should "retrieve upcoming invoices" do
53
- invoice = Stripe::Invoice.upcoming(
54
- customer: API_FIXTURES[:customer][:id],
55
- subscription: API_FIXTURES[:subscription][:id]
56
- )
57
- assert_requested :get, "#{Stripe.api_base}/v1/invoices/upcoming",
58
- query: {
59
- customer: API_FIXTURES[:customer][:id],
60
- subscription: API_FIXTURES[:subscription][:id]
61
- }
62
- assert invoice.kind_of?(Stripe::Invoice)
63
- end
64
- end
65
- end
66
- end