stripe 1.58.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitattributes +4 -0
- data/.travis.yml +1 -2
- data/Gemfile +11 -12
- data/History.txt +8 -0
- data/README.md +44 -31
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/stripe.rb +4 -344
- data/lib/stripe/account.rb +4 -4
- data/lib/stripe/api_operations/create.rb +2 -2
- data/lib/stripe/api_operations/delete.rb +2 -2
- data/lib/stripe/api_operations/list.rb +2 -2
- data/lib/stripe/api_operations/request.rb +9 -3
- data/lib/stripe/api_operations/save.rb +4 -6
- data/lib/stripe/api_resource.rb +2 -2
- data/lib/stripe/bank_account.rb +2 -2
- data/lib/stripe/bitcoin_receiver.rb +1 -1
- data/lib/stripe/charge.rb +12 -12
- data/lib/stripe/customer.rb +6 -6
- data/lib/stripe/dispute.rb +2 -3
- data/lib/stripe/errors.rb +20 -10
- data/lib/stripe/invoice.rb +4 -4
- data/lib/stripe/list_object.rb +2 -2
- data/lib/stripe/order.rb +4 -4
- data/lib/stripe/reversal.rb +1 -1
- data/lib/stripe/source.rb +2 -2
- data/lib/stripe/stripe_client.rb +396 -0
- data/lib/stripe/stripe_response.rb +48 -0
- data/lib/stripe/transfer.rb +2 -2
- data/lib/stripe/util.rb +6 -6
- data/lib/stripe/version.rb +1 -1
- data/spec/fixtures.json +0 -0
- data/spec/fixtures.yaml +0 -0
- data/spec/spec.json +0 -0
- data/spec/spec.yaml +0 -0
- data/stripe.gemspec +1 -1
- data/test/api_fixtures.rb +29 -0
- data/test/api_stub_helpers.rb +125 -0
- data/test/stripe/account_test.rb +153 -247
- data/test/stripe/alipay_account_test.rb +10 -2
- data/test/stripe/api_operations_test.rb +3 -3
- data/test/stripe/api_resource_test.rb +139 -499
- data/test/stripe/apple_pay_domain_test.rb +22 -23
- data/test/stripe/application_fee_refund_test.rb +22 -31
- data/test/stripe/application_fee_test.rb +6 -17
- data/test/stripe/balance_test.rb +3 -3
- data/test/stripe/bank_account_test.rb +31 -11
- data/test/stripe/bitcoin_receiver_test.rb +51 -42
- data/test/stripe/bitcoin_transaction_test.rb +11 -19
- data/test/stripe/charge_test.rb +39 -126
- data/test/stripe/country_spec_test.rb +7 -30
- data/test/stripe/coupon_test.rb +33 -17
- data/test/stripe/customer_card_test.rb +25 -46
- data/test/stripe/customer_test.rb +86 -81
- data/test/stripe/dispute_test.rb +27 -38
- data/test/stripe/errors_test.rb +2 -2
- data/test/stripe/file_upload_test.rb +32 -24
- data/test/stripe/invoice_item_test.rb +46 -10
- data/test/stripe/invoice_test.rb +48 -48
- data/test/stripe/list_object_test.rb +22 -31
- data/test/stripe/order_return_test.rb +11 -15
- data/test/stripe/order_test.rb +38 -51
- data/test/stripe/plan_test.rb +39 -18
- data/test/stripe/product_test.rb +29 -33
- data/test/stripe/recipient_card_test.rb +23 -40
- data/test/stripe/recipient_test.rb +39 -10
- data/test/stripe/refund_test.rb +20 -45
- data/test/stripe/reversal_test.rb +27 -31
- data/test/stripe/sku_test.rb +36 -19
- data/test/stripe/source_test.rb +26 -66
- data/test/stripe/stripe_client_test.rb +428 -0
- data/test/stripe/stripe_object_test.rb +6 -2
- data/test/stripe/stripe_response_test.rb +46 -0
- data/test/stripe/subscription_item_test.rb +37 -59
- data/test/stripe/subscription_test.rb +40 -176
- data/test/stripe/three_d_secure_test.rb +13 -12
- data/test/stripe/transfer_test.rb +36 -19
- data/test/stripe_test.rb +3 -36
- data/test/test_data.rb +5 -931
- data/test/test_helper.rb +21 -25
- metadata +22 -17
- data/test/stripe/charge_refund_test.rb +0 -67
- 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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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 "
|
14
|
-
|
15
|
-
|
16
|
-
|
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 "
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
6
|
-
@mock.expects(:get).once.returns(make_response(make_application_fee))
|
5
|
+
FIXTURE = API_FIXTURES.fetch(:fee_refund)
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
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 "
|
14
|
-
@
|
12
|
+
should "be listable" do
|
13
|
+
refunds = @fee.refunds
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
19
|
+
assert refunds.data.kind_of?(Array)
|
20
|
+
assert refunds.first.kind_of?(Stripe::ApplicationFeeRefund)
|
21
21
|
end
|
22
22
|
|
23
|
-
should "
|
24
|
-
@
|
25
|
-
|
26
|
-
|
27
|
-
|
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 "
|
39
|
-
@
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
data/test/stripe/balance_test.rb
CHANGED
@@ -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 "
|
6
|
-
@mock.expects(:get).once.returns(make_response(make_balance))
|
5
|
+
should "be retrievable" do
|
7
6
|
balance = Stripe::Balance.retrieve
|
8
|
-
|
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
|
-
|
7
|
-
|
8
|
-
:id
|
9
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
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
|
-
|
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 "
|
12
|
-
|
13
|
-
|
14
|
-
|
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 "
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
assert
|
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 "
|
31
|
-
|
32
|
-
|
33
|
-
|
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 "
|
39
|
-
|
40
|
-
|
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 "
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
assert
|
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 "
|
55
|
-
|
56
|
-
receiver =
|
57
|
-
|
58
|
-
|
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
|
-
|
5
|
+
FIXTURE = API_FIXTURES.fetch(:bitcoin_transaction)
|
6
6
|
|
7
|
-
should "
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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 "
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
data/test/stripe/charge_test.rb
CHANGED
@@ -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
|
-
|
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 "
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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 "
|
23
|
-
|
24
|
-
|
25
|
-
|
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 "
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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 "
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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 "
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
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
|