stripe 1.58.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +4 -0
  3. data/.travis.yml +1 -2
  4. data/Gemfile +11 -12
  5. data/History.txt +8 -0
  6. data/README.md +44 -31
  7. data/Rakefile +1 -1
  8. data/VERSION +1 -1
  9. data/lib/stripe.rb +4 -344
  10. data/lib/stripe/account.rb +4 -4
  11. data/lib/stripe/api_operations/create.rb +2 -2
  12. data/lib/stripe/api_operations/delete.rb +2 -2
  13. data/lib/stripe/api_operations/list.rb +2 -2
  14. data/lib/stripe/api_operations/request.rb +9 -3
  15. data/lib/stripe/api_operations/save.rb +4 -6
  16. data/lib/stripe/api_resource.rb +2 -2
  17. data/lib/stripe/bank_account.rb +2 -2
  18. data/lib/stripe/bitcoin_receiver.rb +1 -1
  19. data/lib/stripe/charge.rb +12 -12
  20. data/lib/stripe/customer.rb +6 -6
  21. data/lib/stripe/dispute.rb +2 -3
  22. data/lib/stripe/errors.rb +20 -10
  23. data/lib/stripe/invoice.rb +4 -4
  24. data/lib/stripe/list_object.rb +2 -2
  25. data/lib/stripe/order.rb +4 -4
  26. data/lib/stripe/reversal.rb +1 -1
  27. data/lib/stripe/source.rb +2 -2
  28. data/lib/stripe/stripe_client.rb +396 -0
  29. data/lib/stripe/stripe_response.rb +48 -0
  30. data/lib/stripe/transfer.rb +2 -2
  31. data/lib/stripe/util.rb +6 -6
  32. data/lib/stripe/version.rb +1 -1
  33. data/spec/fixtures.json +0 -0
  34. data/spec/fixtures.yaml +0 -0
  35. data/spec/spec.json +0 -0
  36. data/spec/spec.yaml +0 -0
  37. data/stripe.gemspec +1 -1
  38. data/test/api_fixtures.rb +29 -0
  39. data/test/api_stub_helpers.rb +125 -0
  40. data/test/stripe/account_test.rb +153 -247
  41. data/test/stripe/alipay_account_test.rb +10 -2
  42. data/test/stripe/api_operations_test.rb +3 -3
  43. data/test/stripe/api_resource_test.rb +139 -499
  44. data/test/stripe/apple_pay_domain_test.rb +22 -23
  45. data/test/stripe/application_fee_refund_test.rb +22 -31
  46. data/test/stripe/application_fee_test.rb +6 -17
  47. data/test/stripe/balance_test.rb +3 -3
  48. data/test/stripe/bank_account_test.rb +31 -11
  49. data/test/stripe/bitcoin_receiver_test.rb +51 -42
  50. data/test/stripe/bitcoin_transaction_test.rb +11 -19
  51. data/test/stripe/charge_test.rb +39 -126
  52. data/test/stripe/country_spec_test.rb +7 -30
  53. data/test/stripe/coupon_test.rb +33 -17
  54. data/test/stripe/customer_card_test.rb +25 -46
  55. data/test/stripe/customer_test.rb +86 -81
  56. data/test/stripe/dispute_test.rb +27 -38
  57. data/test/stripe/errors_test.rb +2 -2
  58. data/test/stripe/file_upload_test.rb +32 -24
  59. data/test/stripe/invoice_item_test.rb +46 -10
  60. data/test/stripe/invoice_test.rb +48 -48
  61. data/test/stripe/list_object_test.rb +22 -31
  62. data/test/stripe/order_return_test.rb +11 -15
  63. data/test/stripe/order_test.rb +38 -51
  64. data/test/stripe/plan_test.rb +39 -18
  65. data/test/stripe/product_test.rb +29 -33
  66. data/test/stripe/recipient_card_test.rb +23 -40
  67. data/test/stripe/recipient_test.rb +39 -10
  68. data/test/stripe/refund_test.rb +20 -45
  69. data/test/stripe/reversal_test.rb +27 -31
  70. data/test/stripe/sku_test.rb +36 -19
  71. data/test/stripe/source_test.rb +26 -66
  72. data/test/stripe/stripe_client_test.rb +428 -0
  73. data/test/stripe/stripe_object_test.rb +6 -2
  74. data/test/stripe/stripe_response_test.rb +46 -0
  75. data/test/stripe/subscription_item_test.rb +37 -59
  76. data/test/stripe/subscription_test.rb +40 -176
  77. data/test/stripe/three_d_secure_test.rb +13 -12
  78. data/test/stripe/transfer_test.rb +36 -19
  79. data/test/stripe_test.rb +3 -36
  80. data/test/test_data.rb +5 -931
  81. data/test/test_helper.rb +21 -25
  82. metadata +22 -17
  83. data/test/stripe/charge_refund_test.rb +0 -67
  84. data/test/stripe/metadata_test.rb +0 -129
@@ -2,33 +2,32 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class ApplePayDomainTest < Test::Unit::TestCase
5
- should "create should return a new Apple Pay domain" do
6
- @mock.expects(:post).once
7
- .with('https://api.stripe.com/v1/apple_pay/domains', nil, '')
8
- .returns(make_response(make_apple_pay_domain))
9
- d = Stripe::ApplePayDomain.create
10
- assert_equal "apwc_test_domain", d.id
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)
11
12
  end
12
13
 
13
- should "domains should be deletable" do
14
- @mock.expects(:get).once
15
- .with('https://api.stripe.com/v1/apple_pay/domains/apwc_test_domain', nil, nil)
16
- .returns(make_response(make_apple_pay_domain))
17
- @mock.expects(:delete).once.returns(make_response(make_apple_pay_domain(:deleted => true)))
18
- domain = Stripe::ApplePayDomain.retrieve('apwc_test_domain')
19
- domain.delete
20
- assert domain.deleted
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)
21
18
  end
22
19
 
23
- should "domains should be listable" do
24
- @mock.expects(:get).once.with('https://api.stripe.com/v1/apple_pay/domains', nil, nil)
25
- .returns(make_response(make_apple_pay_domain_array))
26
- domains = Stripe::ApplePayDomain.list
27
- assert domains.data.kind_of?(Array)
28
- assert_equal 3, domains.data.length
29
- domains.each do |domain|
30
- assert domain.kind_of?(Stripe::ApplePayDomain)
31
- end
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)
32
31
  end
33
32
  end
34
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,24 +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
13
-
14
- should "application fees should be refundable" do
15
- fee = Stripe::ApplicationFee.construct_from(make_application_fee)
5
+ FIXTURE = API_FIXTURES.fetch(:platform_earning)
16
6
 
17
- @mock.expects(:post).once.
18
- with("#{Stripe.api_base}/v1/application_fees/#{fee.id}/refunds", nil, '').
19
- returns(make_response(make_application_fee_refund))
20
-
21
- refund = fee.refunds.create
22
- assert refund.is_a?(Stripe::ApplicationFeeRefund)
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)
23
12
  end
24
13
  end
25
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
@@ -2,20 +2,40 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Stripe
4
4
  class BankAccountTest < Test::Unit::TestCase
5
+ FIXTURE = API_FIXTURES.fetch(:external_account_source)
5
6
 
6
- should 'be verifiable' do
7
- bank = Stripe::BankAccount.construct_from({
8
- :id => 'ba_foo',
9
- :customer => 'cus_bar'
10
- })
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
11
17
 
12
- @mock.expects(:post).
13
- once.
14
- with('https://api.stripe.com/v1/customers/cus_bar/sources/ba_foo/verify', nil, 'amounts[]=1&amounts[]=2').
15
- returns(make_response(:status => 'verified'))
16
-
17
- bank.verify(:amounts => [1,2])
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
18
27
  end
19
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
20
40
  end
21
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
- 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
- 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,145 +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
5
+ FIXTURE = API_FIXTURES.fetch(:charge)
13
6
 
14
- should "charges should be refundable" do
15
- c = Stripe::Charge.construct_from(make_charge)
16
- @mock.expects(:get).never
17
- @mock.expects(:post).once.returns(make_response(make_refund(:charge => c)))
18
- r = c.refunds.create
19
- assert r.is_a?(Stripe::Refund)
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)
20
12
  end
21
13
 
22
- should "charges should be refundable for old API versions" do
23
- # "refunds" was a plain array in old API versions but is not a Stripe
24
- # list (see the implementation of `make_charge` for a current example)
25
- data = make_charge.merge!(:refunds => [])
26
- c = Stripe::Charge.construct_from(data)
27
- @mock.expects(:get).never
28
- @mock.expects(:post).once.
29
- with("#{Stripe.api_base}/v1/charges/#{c.id}/refund", nil, '').
30
- returns(make_response(data.merge(:refunded => true)))
31
- c = c.refund
32
- assert c.is_a?(Stripe::Charge)
33
- assert c.refunded
34
- end
35
-
36
- should "charges should not be deletable" do
37
- assert_raises NoMethodError do
38
- @mock.expects(:get).once.returns(make_response(make_charge))
39
- c = Stripe::Charge.retrieve("test_charge")
40
- c.delete
41
- end
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)
42
18
  end
43
19
 
44
- should "charges should be updateable" do
45
- @mock.expects(:post).once.
46
- with('https://api.stripe.com/v1/charges/test_charge', nil, 'metadata[foo]=bar').
47
- returns(make_response(make_charge(metadata: {'foo' => 'bar'})))
48
- c = Stripe::Charge.update("test_charge", metadata: {foo: 'bar'})
49
- assert_equal('bar', c.metadata['foo'])
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)
50
28
  end
51
29
 
52
- should "charges should be saveable" do
53
- @mock.expects(:get).once.returns(make_response(make_charge))
54
- @mock.expects(:post).once.returns(make_response(make_charge))
55
- c = Stripe::Charge.new("test_charge")
56
- c.refresh
57
- c.mnemonic = "New charge description"
58
- c.save
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]}"
59
35
  end
60
36
 
61
- should "charges should be able to be marked as fraudulent" do
62
- @mock.expects(:get).once.returns(make_response(make_charge))
63
- @mock.expects(:post).once.returns(make_response(make_charge))
64
- c = Stripe::Charge.new("test_charge")
65
- c.refresh
66
- c.mark_as_fraudulent
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)
67
41
  end
68
42
 
69
- should "charges should be able to be marked as safe" do
70
- @mock.expects(:get).once.returns(make_response(make_charge))
71
- @mock.expects(:post).once.returns(make_response(make_charge))
72
- c = Stripe::Charge.new("test_charge")
73
- c.refresh
74
- c.mark_as_safe
75
- end
76
-
77
- should "charges should have Card objects associated with their Card property" do
78
- @mock.expects(:get).once.returns(make_response(make_charge))
79
- c = Stripe::Charge.retrieve("test_charge")
80
- assert c.card.kind_of?(Stripe::StripeObject) && c.card.object == 'card'
81
- end
82
-
83
- should "charges should have Outcome objects associated with their outcome property" do
84
- @mock.expects(:get).once.returns(make_response(make_charge))
85
- c = Stripe::Charge.retrieve("test_charge")
86
- assert c.outcome.kind_of?(Stripe::StripeObject) && c.outcome.type == 'authorized'
87
- end
88
-
89
- should "execute should return a new, fully executed charge when passed correct `card` parameters" do
90
- @mock.expects(:post).with do |url, api_key, params|
91
- url == "#{Stripe.api_base}/v1/charges" && api_key.nil? && CGI.parse(params) == {
92
- 'currency' => ['usd'], 'amount' => ['100'],
93
- 'card[exp_year]' => ['2012'],
94
- 'card[number]' => ['4242424242424242'],
95
- 'card[exp_month]' => ['11']
96
- }
97
- end.once.returns(make_response(make_charge))
98
-
99
- c = Stripe::Charge.create({
100
- :amount => 100,
101
- :card => {
102
- :number => "4242424242424242",
103
- :exp_month => 11,
104
- :exp_year => 2012,
105
- },
106
- :currency => "usd"
107
- })
108
- assert c.paid
109
- end
110
-
111
- should "execute should return a new, fully executed charge when passed correct `source` parameters" do
112
- @mock.expects(:post).with do |url, api_key, params|
113
- url == "#{Stripe.api_base}/v1/charges" && api_key.nil? && CGI.parse(params) == {
114
- 'currency' => ['usd'], 'amount' => ['100'],
115
- 'source' => ['btcrcv_test_receiver']
116
- }
117
- end.once.returns(make_response(make_charge))
118
-
119
- c = Stripe::Charge.create({
120
- :amount => 100,
121
- :source => 'btcrcv_test_receiver',
122
- :currency => "usd"
123
- })
124
- 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
125
49
  end
126
50
 
127
- should "properly handle an array or dictionaries" do
128
- @mock.expects(:post).with do |url, api_key, params|
129
- url == "#{Stripe.api_base}/v1/charges" && api_key.nil? && CGI.parse(params) == {
130
- 'currency' => ['usd'], 'amount' => ['100'],
131
- 'source' => ['btcrcv_test_receiver'],
132
- 'level3[][red]' => ['firstred', 'another'],
133
- 'level3[][one]' => ['fish'],
134
- }
135
- end.once.returns(make_response(make_charge))
136
-
137
- c = Stripe::Charge.create({
138
- :amount => 100,
139
- :source => 'btcrcv_test_receiver',
140
- :currency => "usd",
141
- :level3 => [{:red => 'firstred'}, {:red => 'another', :one => 'fish'}]
142
- })
143
- 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
144
57
  end
145
58
  end
146
59
  end