stripe 1.30.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +4 -0
  3. data/.github/ISSUE_TEMPLATE.md +5 -0
  4. data/.travis.yml +3 -14
  5. data/Gemfile +28 -4
  6. data/History.txt +180 -0
  7. data/README.md +147 -0
  8. data/Rakefile +10 -0
  9. data/VERSION +1 -1
  10. data/bin/stripe-console +12 -5
  11. data/lib/data/ca-certificates.crt +3868 -5114
  12. data/lib/stripe/account.rb +43 -23
  13. data/lib/stripe/alipay_account.rb +20 -0
  14. data/lib/stripe/api_operations/create.rb +2 -2
  15. data/lib/stripe/api_operations/delete.rb +2 -2
  16. data/lib/stripe/api_operations/list.rb +2 -3
  17. data/lib/stripe/api_operations/request.rb +9 -3
  18. data/lib/stripe/api_operations/save.rb +85 -0
  19. data/lib/stripe/api_resource.rb +38 -5
  20. data/lib/stripe/apple_pay_domain.rb +12 -0
  21. data/lib/stripe/application_fee.rb +8 -8
  22. data/lib/stripe/application_fee_refund.rb +7 -3
  23. data/lib/stripe/balance_transaction.rb +1 -1
  24. data/lib/stripe/bank_account.rb +13 -4
  25. data/lib/stripe/bitcoin_receiver.rb +6 -6
  26. data/lib/stripe/bitcoin_transaction.rb +1 -1
  27. data/lib/stripe/card.rb +9 -5
  28. data/lib/stripe/charge.rb +38 -20
  29. data/lib/stripe/country_spec.rb +9 -0
  30. data/lib/stripe/coupon.rb +1 -1
  31. data/lib/stripe/customer.rb +12 -10
  32. data/lib/stripe/dispute.rb +4 -5
  33. data/lib/stripe/errors.rb +92 -0
  34. data/lib/stripe/file_upload.rb +1 -1
  35. data/lib/stripe/invoice.rb +7 -7
  36. data/lib/stripe/invoice_item.rb +1 -1
  37. data/lib/stripe/list_object.rb +8 -7
  38. data/lib/stripe/order.rb +12 -4
  39. data/lib/stripe/order_return.rb +9 -0
  40. data/lib/stripe/plan.rb +1 -1
  41. data/lib/stripe/product.rb +2 -10
  42. data/lib/stripe/recipient.rb +1 -1
  43. data/lib/stripe/refund.rb +1 -1
  44. data/lib/stripe/reversal.rb +7 -3
  45. data/lib/stripe/singleton_api_resource.rb +3 -3
  46. data/lib/stripe/sku.rb +2 -2
  47. data/lib/stripe/source.rb +11 -0
  48. data/lib/stripe/stripe_client.rb +396 -0
  49. data/lib/stripe/stripe_object.rb +167 -91
  50. data/lib/stripe/stripe_response.rb +48 -0
  51. data/lib/stripe/subscription.rb +15 -9
  52. data/lib/stripe/subscription_item.rb +12 -0
  53. data/lib/stripe/three_d_secure.rb +9 -0
  54. data/lib/stripe/transfer.rb +4 -5
  55. data/lib/stripe/util.rb +105 -33
  56. data/lib/stripe/version.rb +1 -1
  57. data/lib/stripe.rb +69 -266
  58. data/spec/fixtures.json +1409 -0
  59. data/spec/fixtures.yaml +1153 -0
  60. data/spec/spec.json +19949 -0
  61. data/spec/spec.yaml +15504 -0
  62. data/stripe.gemspec +5 -18
  63. data/test/api_fixtures.rb +29 -0
  64. data/test/api_stub_helpers.rb +125 -0
  65. data/test/stripe/account_test.rb +163 -211
  66. data/test/stripe/alipay_account_test.rb +19 -0
  67. data/test/stripe/api_operations_test.rb +31 -0
  68. data/test/stripe/api_resource_test.rb +174 -340
  69. data/test/stripe/apple_pay_domain_test.rb +33 -0
  70. data/test/stripe/application_fee_refund_test.rb +22 -31
  71. data/test/stripe/application_fee_test.rb +6 -14
  72. data/test/stripe/balance_test.rb +3 -3
  73. data/test/stripe/bank_account_test.rb +41 -0
  74. data/test/stripe/bitcoin_receiver_test.rb +51 -42
  75. data/test/stripe/bitcoin_transaction_test.rb +11 -19
  76. data/test/stripe/charge_test.rb +39 -98
  77. data/test/stripe/country_spec_test.rb +20 -0
  78. data/test/stripe/coupon_test.rb +35 -11
  79. data/test/stripe/customer_card_test.rb +25 -46
  80. data/test/stripe/customer_test.rb +89 -61
  81. data/test/stripe/dispute_test.rb +28 -31
  82. data/test/stripe/errors_test.rb +18 -0
  83. data/test/stripe/file_upload_test.rb +32 -24
  84. data/test/stripe/invoice_item_test.rb +55 -0
  85. data/test/stripe/invoice_test.rb +50 -24
  86. data/test/stripe/list_object_test.rb +57 -45
  87. data/test/stripe/order_return_test.rb +21 -0
  88. data/test/stripe/order_test.rb +41 -34
  89. data/test/stripe/plan_test.rb +52 -0
  90. data/test/stripe/product_test.rb +31 -25
  91. data/test/stripe/recipient_card_test.rb +23 -40
  92. data/test/stripe/recipient_test.rb +50 -0
  93. data/test/stripe/refund_test.rb +20 -36
  94. data/test/stripe/reversal_test.rb +27 -31
  95. data/test/stripe/sku_test.rb +39 -13
  96. data/test/stripe/source_test.rb +43 -0
  97. data/test/stripe/stripe_client_test.rb +428 -0
  98. data/test/stripe/stripe_object_test.rb +186 -13
  99. data/test/stripe/stripe_response_test.rb +46 -0
  100. data/test/stripe/subscription_item_test.rb +54 -0
  101. data/test/stripe/subscription_test.rb +40 -52
  102. data/test/stripe/three_d_secure_test.rb +23 -0
  103. data/test/stripe/transfer_test.rb +38 -13
  104. data/test/stripe/util_test.rb +48 -16
  105. data/test/stripe_test.rb +25 -0
  106. data/test/test_data.rb +5 -621
  107. data/test/test_helper.rb +24 -24
  108. metadata +60 -139
  109. data/README.rdoc +0 -68
  110. data/gemfiles/default-with-activesupport.gemfile +0 -10
  111. data/gemfiles/json.gemfile +0 -12
  112. data/gemfiles/yajl.gemfile +0 -12
  113. data/lib/stripe/api_operations/update.rb +0 -58
  114. data/lib/stripe/errors/api_connection_error.rb +0 -4
  115. data/lib/stripe/errors/api_error.rb +0 -4
  116. data/lib/stripe/errors/authentication_error.rb +0 -4
  117. data/lib/stripe/errors/card_error.rb +0 -12
  118. data/lib/stripe/errors/invalid_request_error.rb +0 -11
  119. data/lib/stripe/errors/rate_limit_error.rb +0 -4
  120. data/lib/stripe/errors/stripe_error.rb +0 -26
  121. data/test/stripe/charge_refund_test.rb +0 -55
  122. data/test/stripe/metadata_test.rb +0 -129
@@ -0,0 +1,33 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Stripe
4
+ class ApplePayDomainTest < Test::Unit::TestCase
5
+ FIXTURE = API_FIXTURES.fetch(:apple_pay_domain)
6
+
7
+ should "be listable" do
8
+ domains = Stripe::ApplePayDomain.list
9
+ assert_requested :get, "#{Stripe.api_base}/v1/apple_pay/domains"
10
+ assert domains.data.kind_of?(Array)
11
+ assert domains.data[0].kind_of?(Stripe::ApplePayDomain)
12
+ end
13
+
14
+ should "be retrievable" do
15
+ domain = Stripe::ApplePayDomain.retrieve(FIXTURE[:id])
16
+ assert_requested :get, "#{Stripe.api_base}/v1/apple_pay/domains/#{FIXTURE[:id]}"
17
+ assert domain.kind_of?(Stripe::ApplePayDomain)
18
+ end
19
+
20
+ should "be creatable" do
21
+ domain = Stripe::ApplePayDomain.create(:domain_name => "example.com")
22
+ assert_requested :post, "#{Stripe.api_base}/v1/apple_pay/domains"
23
+ assert domain.kind_of?(Stripe::ApplePayDomain)
24
+ end
25
+
26
+ should "be deletable" do
27
+ domain = Stripe::ApplePayDomain.retrieve(FIXTURE[:id])
28
+ domain = domain.delete
29
+ assert_requested :delete, "#{Stripe.api_base}/v1/apple_pay/domains/#{FIXTURE[:id]}"
30
+ assert domain.kind_of?(Stripe::ApplePayDomain)
31
+ end
32
+ end
33
+ end
@@ -2,46 +2,37 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class ApplicationFeeRefundTest < Test::Unit::TestCase
5
- should "refunds should be listable" do
6
- @mock.expects(:get).once.returns(make_response(make_application_fee))
5
+ FIXTURE = API_FIXTURES.fetch(:fee_refund)
7
6
 
8
- application_fee = Stripe::ApplicationFee.retrieve('test_application_fee')
9
-
10
- assert application_fee.refunds.first.kind_of?(Stripe::ApplicationFeeRefund)
7
+ setup do
8
+ application_fee_fixture = API_FIXTURES.fetch(:platform_earning)
9
+ @fee = Stripe::ApplicationFee.retrieve(application_fee_fixture[:id])
11
10
  end
12
11
 
13
- should "refunds should be refreshable" do
14
- @mock.expects(:get).twice.returns(make_response(make_application_fee), make_response(make_application_fee_refund(:id => 'refreshed_refund')))
12
+ should "be listable" do
13
+ refunds = @fee.refunds
15
14
 
16
- application_fee = Stripe::ApplicationFee.retrieve('test_application_fee')
17
- refund = application_fee.refunds.first
18
- refund.refresh
15
+ # notably this *doesn't* make an API call
16
+ assert_not_requested :get,
17
+ "#{Stripe.api_base}/v1/application_fees/#{@fee.id}/refunds"
19
18
 
20
- assert_equal 'refreshed_refund', refund.id
19
+ assert refunds.data.kind_of?(Array)
20
+ assert refunds.first.kind_of?(Stripe::ApplicationFeeRefund)
21
21
  end
22
22
 
23
- should "refunds should be updateable" do
24
- @mock.expects(:get).once.returns(make_response(make_application_fee))
25
- @mock.expects(:post).once.returns(make_response(make_application_fee_refund(:metadata => {'key' => 'value'})))
26
-
27
- application_fee = Stripe::ApplicationFee.retrieve('test_application_fee')
28
- refund = application_fee.refunds.first
29
-
30
- assert_equal nil, refund.metadata['key']
31
-
32
- refund.metadata['key'] = 'valu'
33
- refund.save
34
-
35
- assert_equal 'value', refund.metadata['key']
23
+ should "be creatable" do
24
+ refund = @fee.refunds.create
25
+ assert_requested :post,
26
+ "#{Stripe.api_base}/v1/application_fees/#{@fee.id}/refunds"
27
+ assert refund.kind_of?(Stripe::ApplicationFeeRefund)
36
28
  end
37
29
 
38
- should "create should return a new refund" do
39
- @mock.expects(:get).once.returns(make_response(make_application_fee))
40
- @mock.expects(:post).once.returns(make_response(make_application_fee_refund(:id => 'test_new_refund')))
41
-
42
- application_fee = Stripe::ApplicationFee.retrieve('test_application_fee')
43
- refund = application_fee.refunds.create(:amount => 20)
44
- assert_equal 'test_new_refund', refund.id
30
+ should "be saveable" do
31
+ refund = @fee.refunds.first
32
+ refund.metadata['key'] = 'value'
33
+ refund.save
34
+ assert_requested :post,
35
+ "#{Stripe.api_base}/v1/application_fees/#{@fee.id}/refunds/#{FIXTURE[:id]}"
45
36
  end
46
37
  end
47
38
  end
@@ -2,21 +2,13 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class ApplicationFeeTest < Test::Unit::TestCase
5
- should "application fees should be listable" do
6
- @mock.expects(:get).once.returns(make_response(make_application_fee_array))
7
- fees = Stripe::ApplicationFee.list
8
- assert fees.data.kind_of? Array
9
- fees.each do |fee|
10
- assert fee.kind_of?(Stripe::ApplicationFee)
11
- end
12
- end
5
+ FIXTURE = API_FIXTURES.fetch(:platform_earning)
13
6
 
14
- should "application fees should be refundable" do
15
- @mock.expects(:get).never
16
- @mock.expects(:post).once.returns(make_response({:id => "fee_test_fee", :refunded => true}))
17
- fee = Stripe::ApplicationFee.new("test_application_fee")
18
- fee.refund
19
- assert fee.refunded
7
+ should "be listable" do
8
+ fees = Stripe::ApplicationFee.list
9
+ assert_requested :get, "#{Stripe.api_base}/v1/application_fees"
10
+ assert fees.data.kind_of?(Array)
11
+ assert fees.data[0].kind_of?(Stripe::ApplicationFee)
20
12
  end
21
13
  end
22
14
  end
@@ -2,10 +2,10 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class BalanceTest < Test::Unit::TestCase
5
- should "balance should be retrievable" do
6
- @mock.expects(:get).once.returns(make_response(make_balance))
5
+ should "be retrievable" do
7
6
  balance = Stripe::Balance.retrieve
8
- assert_equal('balance', balance['object'])
7
+ assert_requested :get, "#{Stripe.api_base}/v1/balance"
8
+ assert balance.kind_of?(Stripe::Balance)
9
9
  end
10
10
  end
11
11
  end
@@ -0,0 +1,41 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Stripe
4
+ class BankAccountTest < Test::Unit::TestCase
5
+ FIXTURE = API_FIXTURES.fetch(:external_account_source)
6
+
7
+ context "#resource_url" do
8
+ should "return an external account URL" do
9
+ account_id = API_FIXTURES.fetch(:account)[:id]
10
+ bank_account = Stripe::BankAccount.construct_from(
11
+ account: account_id,
12
+ id: FIXTURE[:id]
13
+ )
14
+ assert_equal "/v1/accounts/#{account_id}/external_accounts/#{FIXTURE[:id]}",
15
+ bank_account.resource_url
16
+ end
17
+
18
+ should "return a customer URL" do
19
+ customer_id = API_FIXTURES.fetch(:customer)[:id]
20
+ bank_account = Stripe::BankAccount.construct_from(
21
+ customer: customer_id,
22
+ id: FIXTURE[:id]
23
+ )
24
+ assert_equal "/v1/customers/#{customer_id}/sources/#{FIXTURE[:id]}",
25
+ bank_account.resource_url
26
+ end
27
+ end
28
+
29
+ context "#verify" do
30
+ should 'verify the account' do
31
+ customer_id = API_FIXTURES.fetch(:customer)[:id]
32
+ bank_account = Stripe::BankAccount.construct_from({
33
+ customer: customer_id,
34
+ id: FIXTURE[:id]
35
+ })
36
+ bank_account = bank_account.verify(amounts: [1,2])
37
+ assert bank_account.kind_of?(Stripe::BankAccount)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -2,60 +2,69 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class BitcoinReceiverTest < Test::Unit::TestCase
5
- should "retrieve should retrieve bitcoin receiver" do
6
- @mock.expects(:get).once.returns(make_response(make_bitcoin_receiver))
7
- receiver = Stripe::BitcoinReceiver.retrieve('btcrcv_test_receiver')
8
- assert_equal 'btcrcv_test_receiver', receiver.id
9
- end
5
+ FIXTURE = API_FIXTURES.fetch(:bitcoin_receiver)
10
6
 
11
- should "create should create a bitcoin receiver" do
12
- @mock.expects(:post).once.returns(make_response(make_bitcoin_receiver))
13
- receiver = Stripe::BitcoinReceiver.create
14
- assert_equal "btcrcv_test_receiver", receiver.id
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)
15
12
  end
16
13
 
17
- should "all should list bitcoin receivers" do
18
- @mock.expects(:get).once.returns(make_response(make_bitcoin_receiver_array))
19
- receivers = Stripe::BitcoinReceiver.list
20
- assert_equal 3, receivers.data.length
21
- assert receivers.data.kind_of? Array
22
- receivers.each do |receiver|
23
- assert receiver.kind_of?(Stripe::BitcoinReceiver)
24
- receiver.transactions.data.each do |transaction|
25
- assert transaction.kind_of?(Stripe::BitcoinTransaction)
26
- end
27
- end
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)
28
19
  end
29
20
 
30
- should "maintain bitcoin transaction sublist" do
31
- @mock.expects(:get).with("#{Stripe.api_base}/v1/bitcoin/receivers/btcrcv_test_receiver", nil, nil).once.returns(make_response(make_bitcoin_receiver))
32
- receiver = Stripe::BitcoinReceiver.retrieve('btcrcv_test_receiver')
33
- @mock.expects(:get).with("#{Stripe.api_base}/v1/bitcoin/receivers/btcrcv_test_receiver/transactions", nil, nil).once.returns(make_response(make_bitcoin_transaction_array))
34
- transactions = receiver.transactions.list
35
- assert_equal(3, transactions.data.length)
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)
36
25
  end
37
26
 
38
- should "update should update a bitcoin receiver" do
39
- @mock.expects(:get).once.returns(make_response(make_bitcoin_receiver))
40
- @mock.expects(:post).with("#{Stripe.api_base}/v1/bitcoin/receivers/btcrcv_test_receiver", nil, "description=details").once.returns(make_response(make_bitcoin_receiver))
41
- receiver = Stripe::BitcoinReceiver.construct_from(make_bitcoin_receiver)
42
- receiver.refresh
43
- receiver.description = "details"
27
+ should "be saveable" do
28
+ receiver = Stripe::BitcoinReceiver.retrieve(FIXTURE[:id])
29
+ receiver.metadata['key'] = 'value'
44
30
  receiver.save
31
+ assert_requested :post,
32
+ "#{Stripe.api_base}/v1/bitcoin/receivers/#{FIXTURE[:id]}"
45
33
  end
46
34
 
47
- should "delete a bitcoin receiver with no customer through top-level API" do
48
- @mock.expects(:delete).with("#{Stripe.api_base}/v1/bitcoin/receivers/btcrcv_test_receiver", nil, nil).once.returns(make_response({:deleted => true, :id => "btcrcv_test_receiver"}))
49
- receiver = Stripe::BitcoinReceiver.construct_from(make_bitcoin_receiver)
50
- response = receiver.delete
51
- assert(receiver.deleted)
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)
52
40
  end
53
41
 
54
- should "delete a bitcoin receiver with a customer through customer's subresource API" do
55
- @mock.expects(:delete).with("#{Stripe.api_base}/v1/customers/customer_foo/sources/btcrcv_test_receiver", nil, nil).once.returns(make_response({:deleted => true, :id => "btcrcv_test_receiver"}))
56
- receiver = Stripe::BitcoinReceiver.construct_from(make_bitcoin_receiver(:customer => 'customer_foo'))
57
- response = receiver.delete
58
- assert(receiver.deleted)
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
59
68
  end
60
69
  end
61
70
  end
@@ -2,28 +2,20 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class BitcoinTransactionTest < Test::Unit::TestCase
5
- TEST_ID = "btctxn_test_transaction".freeze
5
+ FIXTURE = API_FIXTURES.fetch(:bitcoin_transaction)
6
6
 
7
- should "retrieve should retrieve bitcoin receiver" do
8
- @mock.expects(:get).
9
- with("#{Stripe.api_base}/v1/bitcoin/transactions/#{TEST_ID}", nil, nil).
10
- once.
11
- returns(make_response(make_bitcoin_transaction))
12
- receiver = Stripe::BitcoinTransaction.retrieve(TEST_ID)
13
- assert_equal TEST_ID, receiver.id
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)
14
12
  end
15
13
 
16
- should "all should list bitcoin transactions" do
17
- @mock.expects(:get).
18
- with("#{Stripe.api_base}/v1/bitcoin/transactions", nil, nil).
19
- once.
20
- returns(make_response(make_bitcoin_transaction_array))
21
- transactions = Stripe::BitcoinTransaction.list
22
- assert_equal 3, transactions.data.length
23
- assert transactions.data.kind_of? Array
24
- transactions.each do |transaction|
25
- assert transaction.kind_of?(Stripe::BitcoinTransaction)
26
- end
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)
27
19
  end
28
20
  end
29
21
  end
@@ -2,117 +2,58 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class ChargeTest < Test::Unit::TestCase
5
- should "charges should be listable" do
6
- @mock.expects(:get).once.returns(make_response(make_charge_array))
7
- c = Stripe::Charge.list
8
- assert c.data.kind_of? Array
9
- c.each do |charge|
10
- assert charge.kind_of?(Stripe::Charge)
11
- end
12
- end
13
-
14
- should "charges should be refundable" do
15
- @mock.expects(:get).never
16
- @mock.expects(:post).once.returns(make_response({:id => "ch_test_charge", :refunded => true}))
17
- c = Stripe::Charge.new("test_charge")
18
- c.refund
19
- assert c.refunded
20
- end
5
+ FIXTURE = API_FIXTURES.fetch(:charge)
21
6
 
22
- should "charges should not be deletable" do
23
- assert_raises NoMethodError do
24
- @mock.expects(:get).once.returns(make_response(make_charge))
25
- c = Stripe::Charge.retrieve("test_charge")
26
- c.delete
27
- end
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)
28
12
  end
29
13
 
30
- should "charges should be updateable" do
31
- @mock.expects(:get).once.returns(make_response(make_charge))
32
- @mock.expects(:post).once.returns(make_response(make_charge))
33
- c = Stripe::Charge.new("test_charge")
34
- c.refresh
35
- c.mnemonic = "New charge description"
36
- c.save
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)
37
18
  end
38
19
 
39
- should "charges should be able to be marked as fraudulent" do
40
- @mock.expects(:get).once.returns(make_response(make_charge))
41
- @mock.expects(:post).once.returns(make_response(make_charge))
42
- c = Stripe::Charge.new("test_charge")
43
- c.refresh
44
- c.mark_as_fraudulent
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)
45
28
  end
46
29
 
47
- should "charges should be able to be marked as safe" do
48
- @mock.expects(:get).once.returns(make_response(make_charge))
49
- @mock.expects(:post).once.returns(make_response(make_charge))
50
- c = Stripe::Charge.new("test_charge")
51
- c.refresh
52
- c.mark_as_safe
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]}"
53
35
  end
54
36
 
55
- should "charges should have Card objects associated with their Card property" do
56
- @mock.expects(:get).once.returns(make_response(make_charge))
57
- c = Stripe::Charge.retrieve("test_charge")
58
- assert c.card.kind_of?(Stripe::StripeObject) && c.card.object == 'card'
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)
59
41
  end
60
42
 
61
- should "execute should return a new, fully executed charge when passed correct `card` parameters" do
62
- @mock.expects(:post).with do |url, api_key, params|
63
- url == "#{Stripe.api_base}/v1/charges" && api_key.nil? && CGI.parse(params) == {
64
- 'currency' => ['usd'], 'amount' => ['100'],
65
- 'card[exp_year]' => ['2012'],
66
- 'card[number]' => ['4242424242424242'],
67
- 'card[exp_month]' => ['11']
68
- }
69
- end.once.returns(make_response(make_charge))
70
-
71
- c = Stripe::Charge.create({
72
- :amount => 100,
73
- :card => {
74
- :number => "4242424242424242",
75
- :exp_month => 11,
76
- :exp_year => 2012,
77
- },
78
- :currency => "usd"
79
- })
80
- assert c.paid
81
- end
82
-
83
- should "execute should return a new, fully executed charge when passed correct `source` parameters" do
84
- @mock.expects(:post).with do |url, api_key, params|
85
- url == "#{Stripe.api_base}/v1/charges" && api_key.nil? && CGI.parse(params) == {
86
- 'currency' => ['usd'], 'amount' => ['100'],
87
- 'source' => ['btcrcv_test_receiver']
88
- }
89
- end.once.returns(make_response(make_charge))
90
-
91
- c = Stripe::Charge.create({
92
- :amount => 100,
93
- :source => 'btcrcv_test_receiver',
94
- :currency => "usd"
95
- })
96
- assert c.paid
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
97
49
  end
98
50
 
99
- should "properly handle an array or dictionaries" do
100
- @mock.expects(:post).with do |url, api_key, params|
101
- url == "#{Stripe.api_base}/v1/charges" && api_key.nil? && CGI.parse(params) == {
102
- 'currency' => ['usd'], 'amount' => ['100'],
103
- 'source' => ['btcrcv_test_receiver'],
104
- 'level3[][red]' => ['firstred', 'another'],
105
- 'level3[][one]' => ['fish'],
106
- }
107
- end.once.returns(make_response(make_charge))
108
-
109
- c = Stripe::Charge.create({
110
- :amount => 100,
111
- :source => 'btcrcv_test_receiver',
112
- :currency => "usd",
113
- :level3 => [{:red => 'firstred'}, {:one => 'fish', :red => 'another'}]
114
- })
115
- assert c.paid
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
116
57
  end
117
58
  end
118
59
  end
@@ -0,0 +1,20 @@
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
@@ -2,19 +2,43 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class CouponTest < Test::Unit::TestCase
5
- should "create should return a new coupon" do
6
- @mock.expects(:post).once.returns(make_response(make_coupon))
7
- c = Stripe::Coupon.create
8
- assert_equal "co_test_coupon", c.id
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]}"
9
36
  end
10
37
 
11
- should "coupons should be updateable" do
12
- @mock.expects(:get).once.returns(make_response(make_coupon))
13
- @mock.expects(:post).once.returns(make_response(make_coupon))
14
- c = Stripe::Coupon.new("test_coupon")
15
- c.refresh
16
- c.metadata['foo'] = 'bar'
17
- c.save
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)
18
42
  end
19
43
  end
20
44
  end