stripe-ruby-mock 3.0.1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/rspec_tests.yml +38 -0
- data/.rspec +2 -1
- data/CHANGELOG.md +62 -15
- data/Gemfile +1 -0
- data/README.md +5 -3
- data/lib/stripe_mock/api/client.rb +1 -1
- data/lib/stripe_mock/api/instance.rb +1 -1
- data/lib/stripe_mock/api/webhooks.rb +66 -25
- data/lib/stripe_mock/client.rb +2 -1
- data/lib/stripe_mock/data/list.rb +31 -6
- data/lib/stripe_mock/data.rb +201 -30
- data/lib/stripe_mock/instance.rb +12 -3
- data/lib/stripe_mock/request_handlers/account_links.rb +15 -0
- data/lib/stripe_mock/request_handlers/accounts.rb +17 -6
- data/lib/stripe_mock/request_handlers/charges.rb +11 -4
- data/lib/stripe_mock/request_handlers/checkout_session.rb +179 -0
- data/lib/stripe_mock/request_handlers/customers.rb +22 -13
- data/lib/stripe_mock/request_handlers/ephemeral_key.rb +1 -1
- data/lib/stripe_mock/request_handlers/events.rb +30 -3
- data/lib/stripe_mock/request_handlers/express_login_links.rb +15 -0
- data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +1 -0
- data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +36 -12
- data/lib/stripe_mock/request_handlers/invoices.rb +10 -4
- data/lib/stripe_mock/request_handlers/payment_intents.rb +13 -2
- data/lib/stripe_mock/request_handlers/payment_methods.rb +11 -4
- data/lib/stripe_mock/request_handlers/prices.rb +62 -0
- data/lib/stripe_mock/request_handlers/promotion_codes.rb +43 -0
- data/lib/stripe_mock/request_handlers/refunds.rb +13 -2
- data/lib/stripe_mock/request_handlers/setup_intents.rb +16 -9
- data/lib/stripe_mock/request_handlers/sources.rb +12 -6
- data/lib/stripe_mock/request_handlers/subscriptions.rb +120 -21
- data/lib/stripe_mock/request_handlers/tokens.rb +6 -4
- data/lib/stripe_mock/request_handlers/transfers.rb +12 -1
- data/lib/stripe_mock/request_handlers/validators/param_validators.rb +33 -4
- data/lib/stripe_mock/server.rb +2 -2
- data/lib/stripe_mock/test_strategies/base.rb +62 -10
- data/lib/stripe_mock/version.rb +1 -1
- data/lib/stripe_mock/webhook_fixtures/account.updated.json +1 -1
- data/lib/stripe_mock/webhook_fixtures/balance.available.json +27 -15
- data/lib/stripe_mock/webhook_fixtures/charge.captured.json +143 -0
- data/lib/stripe_mock/webhook_fixtures/charge.dispute.created.json +63 -16
- data/lib/stripe_mock/webhook_fixtures/charge.failed.json +49 -120
- data/lib/stripe_mock/webhook_fixtures/charge.refund.updated.json +35 -0
- data/lib/stripe_mock/webhook_fixtures/charge.refunded.json +145 -50
- data/lib/stripe_mock/webhook_fixtures/charge.succeeded.json +114 -43
- data/lib/stripe_mock/webhook_fixtures/checkout.session.completed.json +79 -0
- data/lib/stripe_mock/webhook_fixtures/checkout.session.completed.payment_mode.json +53 -0
- data/lib/stripe_mock/webhook_fixtures/checkout.session.completed.setup_mode.json +45 -0
- data/lib/stripe_mock/webhook_fixtures/customer.created.json +37 -46
- data/lib/stripe_mock/webhook_fixtures/customer.deleted.json +36 -32
- data/lib/stripe_mock/webhook_fixtures/customer.source.created.json +31 -22
- data/lib/stripe_mock/webhook_fixtures/customer.source.updated.json +36 -25
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.created.json +135 -47
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.deleted.json +134 -45
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.updated.json +135 -56
- data/lib/stripe_mock/webhook_fixtures/customer.updated.json +38 -47
- data/lib/stripe_mock/webhook_fixtures/invoice.created.json +176 -49
- data/lib/stripe_mock/webhook_fixtures/invoice.finalized.json +171 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.paid.json +171 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_action_required.json +171 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_failed.json +149 -83
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_succeeded.json +149 -90
- data/lib/stripe_mock/webhook_fixtures/invoice.upcoming.json +70 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.updated.json +178 -50
- data/lib/stripe_mock/webhook_fixtures/invoiceitem.created.json +87 -13
- data/lib/stripe_mock/webhook_fixtures/invoiceitem.updated.json +88 -14
- data/lib/stripe_mock/webhook_fixtures/mandate.updated.json +34 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.amount_capturable_updated.json +170 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.canceled.json +73 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.created.json +86 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.payment_failed.json +225 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.processing.json +162 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.requires_action.json +191 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.succeeded.json +196 -0
- data/lib/stripe_mock/webhook_fixtures/payment_link.created.json +47 -0
- data/lib/stripe_mock/webhook_fixtures/payment_link.updated.json +50 -0
- data/lib/stripe_mock/webhook_fixtures/payment_method.attached.json +63 -0
- data/lib/stripe_mock/webhook_fixtures/payment_method.detached.json +62 -0
- data/lib/stripe_mock/webhook_fixtures/payout.created.json +40 -0
- data/lib/stripe_mock/webhook_fixtures/payout.paid.json +40 -0
- data/lib/stripe_mock/webhook_fixtures/payout.updated.json +46 -0
- data/lib/stripe_mock/webhook_fixtures/plan.created.json +30 -13
- data/lib/stripe_mock/webhook_fixtures/plan.deleted.json +30 -13
- data/lib/stripe_mock/webhook_fixtures/plan.updated.json +34 -14
- data/lib/stripe_mock/webhook_fixtures/price.created.json +42 -0
- data/lib/stripe_mock/webhook_fixtures/price.deleted.json +42 -0
- data/lib/stripe_mock/webhook_fixtures/price.updated.json +48 -0
- data/lib/stripe_mock/webhook_fixtures/product.created.json +19 -13
- data/lib/stripe_mock/webhook_fixtures/product.deleted.json +20 -14
- data/lib/stripe_mock/webhook_fixtures/product.updated.json +24 -15
- data/lib/stripe_mock/webhook_fixtures/quote.accepted.json +92 -0
- data/lib/stripe_mock/webhook_fixtures/quote.canceled.json +92 -0
- data/lib/stripe_mock/webhook_fixtures/quote.created.json +92 -0
- data/lib/stripe_mock/webhook_fixtures/quote.finalized.json +92 -0
- data/lib/stripe_mock/webhook_fixtures/setup_intent.canceled.json +46 -0
- data/lib/stripe_mock/webhook_fixtures/setup_intent.created.json +51 -0
- data/lib/stripe_mock/webhook_fixtures/setup_intent.setup_failed.json +100 -0
- data/lib/stripe_mock/webhook_fixtures/setup_intent.succeeded.json +46 -0
- data/lib/stripe_mock/webhook_fixtures/subscription_schedule.canceled.json +119 -0
- data/lib/stripe_mock/webhook_fixtures/subscription_schedule.created.json +114 -0
- data/lib/stripe_mock/webhook_fixtures/subscription_schedule.released.json +111 -0
- data/lib/stripe_mock/webhook_fixtures/subscription_schedule.updated.json +125 -0
- data/lib/stripe_mock/webhook_fixtures/tax_rate.created.json +32 -0
- data/lib/stripe_mock/webhook_fixtures/tax_rate.updated.json +37 -0
- data/lib/stripe_mock.rb +7 -1
- data/spec/instance_spec.rb +7 -7
- data/spec/integration_examples/completing_checkout_sessions_example.rb +37 -0
- data/spec/list_spec.rb +23 -0
- data/spec/readme_spec.rb +1 -1
- data/spec/server_spec.rb +4 -2
- data/spec/shared_stripe_examples/account_examples.rb +9 -1
- data/spec/shared_stripe_examples/account_link_examples.rb +16 -0
- data/spec/shared_stripe_examples/balance_examples.rb +6 -0
- data/spec/shared_stripe_examples/card_token_examples.rb +17 -21
- data/spec/shared_stripe_examples/checkout_session_examples.rb +99 -0
- data/spec/shared_stripe_examples/customer_examples.rb +11 -13
- data/spec/shared_stripe_examples/express_login_link_examples.rb +12 -0
- data/spec/shared_stripe_examples/invoice_examples.rb +29 -8
- data/spec/shared_stripe_examples/payment_intent_examples.rb +74 -0
- data/spec/shared_stripe_examples/payment_method_examples.rb +336 -67
- data/spec/shared_stripe_examples/price_examples.rb +223 -0
- data/spec/shared_stripe_examples/product_examples.rb +1 -9
- data/spec/shared_stripe_examples/promotion_code_examples.rb +68 -0
- data/spec/shared_stripe_examples/refund_examples.rb +13 -0
- data/spec/shared_stripe_examples/setup_intent_examples.rb +17 -0
- data/spec/shared_stripe_examples/subscription_examples.rb +327 -9
- data/spec/shared_stripe_examples/transfer_examples.rb +10 -1
- data/spec/shared_stripe_examples/webhook_event_examples.rb +51 -5
- data/spec/spec_helper.rb +4 -0
- data/spec/stripe_mock_spec.rb +2 -2
- data/spec/support/stripe_examples.rb +8 -2
- data/stripe-ruby-mock.gemspec +7 -2
- metadata +72 -15
- data/.travis.yml +0 -28
- data/lib/stripe_mock/request_handlers/checkout.rb +0 -15
- data/spec/shared_stripe_examples/checkout_examples.rb +0 -19
@@ -0,0 +1,223 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Price API' do
|
4
|
+
let(:product_id) { "product_id_1" }
|
5
|
+
let(:product) { stripe_helper.create_product(id: product_id) }
|
6
|
+
|
7
|
+
let(:other_product_id) { "product_id_2" }
|
8
|
+
let(:other_product) { stripe_helper.create_product(id: other_product_id) }
|
9
|
+
|
10
|
+
let(:price_attributes) { {
|
11
|
+
:id => "price_abc123",
|
12
|
+
:product => product_id,
|
13
|
+
:nickname => "My Mock price",
|
14
|
+
:amount => 9900,
|
15
|
+
:currency => "usd",
|
16
|
+
:interval => "month"
|
17
|
+
} }
|
18
|
+
let(:price) { Stripe::Price.create(price_attributes) }
|
19
|
+
|
20
|
+
let(:price_attributes_without_id){ price_attributes.merge(id: nil) }
|
21
|
+
let(:price_without_id){ Stripe::Price.create(price_attributes_without_id) }
|
22
|
+
|
23
|
+
let(:price_attributes_with_trial) { price_attributes.merge(id: "prod_TRIAL", :trial_period_days => 30) }
|
24
|
+
let(:price_with_trial) { Stripe::Price.create(price_attributes_with_trial) }
|
25
|
+
|
26
|
+
let(:metadata) { {:description => "desc text", :info => "info text"} }
|
27
|
+
let(:price_attributes_with_metadata) { price_attributes.merge(id: "prod_META", metadata: metadata) }
|
28
|
+
let(:price_with_metadata) { Stripe::Price.create(price_attributes_with_metadata) }
|
29
|
+
|
30
|
+
before(:each) do
|
31
|
+
product
|
32
|
+
other_product
|
33
|
+
end
|
34
|
+
|
35
|
+
it "creates a stripe price" do
|
36
|
+
expect(price.id).to eq('price_abc123')
|
37
|
+
expect(price.nickname).to eq('My Mock price')
|
38
|
+
expect(price.amount).to eq(9900)
|
39
|
+
|
40
|
+
expect(price.currency).to eq('usd')
|
41
|
+
expect(price.interval).to eq("month")
|
42
|
+
|
43
|
+
expect(price_with_metadata.metadata.description).to eq('desc text')
|
44
|
+
expect(price_with_metadata.metadata.info).to eq('info text')
|
45
|
+
|
46
|
+
expect(price_with_trial.trial_period_days).to eq(30)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "creates a stripe price without specifying ID" do
|
50
|
+
expect(price_attributes_without_id[:id]).to be_nil
|
51
|
+
expect(price_without_id.id).to match(/^test_price_1/)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "stores a created stripe price in memory" do
|
55
|
+
price
|
56
|
+
price2 = Stripe::Price.create(price_attributes.merge(id: "price_def456", amount: 299))
|
57
|
+
|
58
|
+
data = test_data_source(:prices)
|
59
|
+
expect(data[price.id]).to_not be_nil
|
60
|
+
expect(data[price.id][:amount]).to eq(9900)
|
61
|
+
expect(data[price2.id]).to_not be_nil
|
62
|
+
expect(data[price2.id][:amount]).to eq(299)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "retrieves a stripe price" do
|
66
|
+
original = stripe_helper.create_price(product: product_id, amount: 1331, id: 'price_943843')
|
67
|
+
price = Stripe::Price.retrieve(original.id)
|
68
|
+
|
69
|
+
expect(price.id).to eq(original.id)
|
70
|
+
expect(price.amount).to eq(original.amount)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "updates a stripe price" do
|
74
|
+
stripe_helper.create_price(id: 'super_member', product: product_id, amount: 111)
|
75
|
+
|
76
|
+
price = Stripe::Price.retrieve('super_member')
|
77
|
+
expect(price.amount).to eq(111)
|
78
|
+
|
79
|
+
price.amount = 789
|
80
|
+
price.save
|
81
|
+
price = Stripe::Price.retrieve('super_member')
|
82
|
+
expect(price.amount).to eq(789)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "cannot retrieve a stripe price that doesn't exist" do
|
86
|
+
expect { Stripe::Price.retrieve('nope') }.to raise_error {|e|
|
87
|
+
expect(e).to be_a Stripe::InvalidRequestError
|
88
|
+
expect(e.param).to eq('price')
|
89
|
+
expect(e.http_status).to eq(404)
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
it "retrieves all prices" do
|
94
|
+
stripe_helper.create_price(id: 'price One', product: product_id, amount: 54321)
|
95
|
+
stripe_helper.create_price(id: 'price Two', product: product_id, amount: 98765)
|
96
|
+
|
97
|
+
all = Stripe::Price.list
|
98
|
+
expect(all.count).to eq(2)
|
99
|
+
expect(all.map &:id).to include('price One', 'price Two')
|
100
|
+
expect(all.map &:amount).to include(54321, 98765)
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'retrieves prices with limit' do
|
104
|
+
101.times do | i|
|
105
|
+
stripe_helper.create_price(id: "price #{i}", product: product_id, amount: 11)
|
106
|
+
end
|
107
|
+
all = Stripe::Price.list(limit: 100)
|
108
|
+
|
109
|
+
expect(all.count).to eq(100)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "retrieves prices with lookup keys" do
|
113
|
+
stripe_helper.create_price(id: 'price One', product: product_id, amount: 54321, lookup_key: 'one')
|
114
|
+
stripe_helper.create_price(id: 'price Two', product: product_id, amount: 98765, lookup_key: 'two')
|
115
|
+
|
116
|
+
all = Stripe::Price.list({lookup_keys: ['one', 'two']})
|
117
|
+
expect(all.count).to eq(2)
|
118
|
+
expect(all.map &:id).to include('price One', 'price Two')
|
119
|
+
expect(all.map &:amount).to include(54321, 98765)
|
120
|
+
|
121
|
+
one = Stripe::Price.list({lookup_keys: ['one']})
|
122
|
+
expect(one.count).to eq(1)
|
123
|
+
expect(one.map &:id).to include('price One')
|
124
|
+
expect(one.map &:amount).to include(54321)
|
125
|
+
|
126
|
+
two = Stripe::Price.list({lookup_keys: ['two']})
|
127
|
+
expect(two.count).to eq(1)
|
128
|
+
expect(two.map &:id).to include('price Two')
|
129
|
+
expect(two.map &:amount).to include(98765)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "retrieves prices filtering by currency" do
|
133
|
+
5.times do | i|
|
134
|
+
stripe_helper.create_price(id: "usd price #{i}", product: product_id, amount: 11, currency: 'usd')
|
135
|
+
stripe_helper.create_price(id: "brl price #{i}", product: product_id, amount: 11, currency: 'brl')
|
136
|
+
end
|
137
|
+
|
138
|
+
all = Stripe::Price.list()
|
139
|
+
expect(all.count).to eq(10)
|
140
|
+
|
141
|
+
usd = Stripe::Price.list({currency: 'usd'})
|
142
|
+
expect(usd.count).to eq(5)
|
143
|
+
expect(usd.all? {|p| p.currency == 'usd' }).to be_truthy
|
144
|
+
|
145
|
+
brl = Stripe::Price.list({currency: 'brl'})
|
146
|
+
expect(brl.count).to eq(5)
|
147
|
+
expect(brl.all? {|p| p.currency == 'brl' }).to be_truthy
|
148
|
+
end
|
149
|
+
|
150
|
+
it "retrieves prices filtering by product" do
|
151
|
+
5.times do | i|
|
152
|
+
stripe_helper.create_price(id: "product 1 price #{i}", product: product_id)
|
153
|
+
stripe_helper.create_price(id: "product 2 price #{i}", product: other_product_id)
|
154
|
+
end
|
155
|
+
|
156
|
+
all = Stripe::Price.list()
|
157
|
+
expect(all.count).to eq(10)
|
158
|
+
|
159
|
+
product_prices = Stripe::Price.list({product: product.id})
|
160
|
+
expect(product_prices.count).to eq(5)
|
161
|
+
expect(product_prices.all? {|p| p.product == product.id }).to be_truthy
|
162
|
+
|
163
|
+
other_product_prices = Stripe::Price.list({product: other_product.id})
|
164
|
+
expect(other_product_prices.count).to eq(5)
|
165
|
+
expect(other_product_prices.all? {|p| p.product == other_product.id }).to be_truthy
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "Validations", :live => true do
|
169
|
+
include_context "stripe validator"
|
170
|
+
let(:params) { stripe_helper.create_price_params(product: product_id) }
|
171
|
+
let(:subject) { Stripe::Price.create(params) }
|
172
|
+
|
173
|
+
describe "Associations" do
|
174
|
+
let(:not_found_product_id){ "prod_NONEXIST" }
|
175
|
+
let(:not_found_message) { stripe_validator.not_found_message(Stripe::Product, not_found_product_id) }
|
176
|
+
let(:params) { stripe_helper.create_price_params(product: not_found_product_id) }
|
177
|
+
let(:products) { stripe_helper.list_products(100).data }
|
178
|
+
|
179
|
+
it "validates associated product" do
|
180
|
+
expect(products.map(&:id)).to_not include(not_found_product_id)
|
181
|
+
expect { subject }.to raise_error(Stripe::InvalidRequestError, not_found_message)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
describe "Presence" do
|
186
|
+
after do
|
187
|
+
params.delete(@name)
|
188
|
+
message = "Missing required param: #{@name}."
|
189
|
+
expect { subject }.to raise_error(Stripe::InvalidRequestError, message)
|
190
|
+
end
|
191
|
+
|
192
|
+
it("validates presence of currency") { @name = :currency }
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
describe "Mock Data" do
|
197
|
+
let(:mock_object) { StripeMock::Data.mock_price }
|
198
|
+
let(:known_attributes) { [
|
199
|
+
:id,
|
200
|
+
:object,
|
201
|
+
:active,
|
202
|
+
:billing_scheme,
|
203
|
+
:created,
|
204
|
+
:currency,
|
205
|
+
:livemode,
|
206
|
+
:lookup_key,
|
207
|
+
:metadata,
|
208
|
+
:nickname,
|
209
|
+
:product,
|
210
|
+
:recurring,
|
211
|
+
:tiers_mode,
|
212
|
+
:transform_quantity,
|
213
|
+
:type,
|
214
|
+
:unit_amount,
|
215
|
+
:unit_amount_decimal
|
216
|
+
] }
|
217
|
+
|
218
|
+
it "includes all retreived attributes" do
|
219
|
+
expect(mock_object.keys).to eql(known_attributes)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
shared_examples "Product API" do
|
4
|
-
let(:product_attributes) { {id: "prod_123", name: "My Mock Product"
|
4
|
+
let(:product_attributes) { {id: "prod_123", name: "My Mock Product"} }
|
5
5
|
let(:product) { Stripe::Product.create(product_attributes) }
|
6
6
|
|
7
7
|
it "creates a stripe product" do
|
@@ -101,14 +101,6 @@ shared_examples "Product API" do
|
|
101
101
|
it("requires a name") { @attribute_name = :name }
|
102
102
|
end
|
103
103
|
|
104
|
-
describe "Inclusion" do
|
105
|
-
it "validates inclusion of type in 'good' or 'service'" do
|
106
|
-
expect {
|
107
|
-
Stripe::Product.create(params.merge({type: "OOPS"}))
|
108
|
-
}.to raise_error(Stripe::InvalidRequestError, "Invalid type: must be one of good or service")
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
104
|
describe "Uniqueness" do
|
113
105
|
let(:already_exists_message){ stripe_validator.already_exists_message(Stripe::Product) }
|
114
106
|
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
shared_examples "PromotionCode API" do
|
4
|
+
let(:coupon) { stripe_helper.create_coupon }
|
5
|
+
|
6
|
+
it "creates a promotion code" do
|
7
|
+
promotion_code = Stripe::PromotionCode.create({id: "promo_123", coupon: coupon.id, code: "FREESTUFF"})
|
8
|
+
|
9
|
+
expect(promotion_code.id).to eq("promo_123")
|
10
|
+
expect(promotion_code.code).to eq("FREESTUFF")
|
11
|
+
expect(promotion_code.coupon).to eq(coupon.id)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "creates a promotion code without specifying code" do
|
15
|
+
promotion_code = Stripe::PromotionCode.create({id: "promo_123", coupon: coupon.id})
|
16
|
+
|
17
|
+
expect(promotion_code.id).to eq("promo_123")
|
18
|
+
expect(promotion_code.code).to eq("TESTCODE")
|
19
|
+
expect(promotion_code.coupon).to eq(coupon.id)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "cannot create a promotion code without a coupon" do
|
23
|
+
expect {
|
24
|
+
Stripe::PromotionCode.create
|
25
|
+
}.to raise_error { |e|
|
26
|
+
expect(e).to be_a(Stripe::InvalidRequestError)
|
27
|
+
expect(e.message).to eq("Missing required param: coupon")
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
it "requires minimum amount currency when minimum amount is provided" do
|
32
|
+
expect {
|
33
|
+
Stripe::PromotionCode.create(coupon: coupon, restrictions: {minimum_amount: 100})
|
34
|
+
}.to raise_error { |e|
|
35
|
+
expect(e).to be_a(Stripe::InvalidRequestError)
|
36
|
+
expect(e.message).to eq("You must pass minimum_amount_currency when passing minimum_amount")
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
it "updates a promotion code" do
|
41
|
+
promotion_code = Stripe::PromotionCode.create({coupon: coupon.id})
|
42
|
+
expect(promotion_code.active).to eq(true)
|
43
|
+
|
44
|
+
updated = Stripe::PromotionCode.update(promotion_code.id, active: false)
|
45
|
+
|
46
|
+
expect(updated.active).to eq(false)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "retrieves a promotion code" do
|
50
|
+
original = Stripe::PromotionCode.create({coupon: coupon.id})
|
51
|
+
|
52
|
+
promotion_code = Stripe::PromotionCode.retrieve(original.id)
|
53
|
+
|
54
|
+
expect(promotion_code.id).to eq(original.id)
|
55
|
+
expect(promotion_code.code).to eq(original.code)
|
56
|
+
expect(promotion_code.coupon).to eq(original.coupon)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "lists all promotion codes" do
|
60
|
+
Stripe::PromotionCode.create({coupon: coupon.id, code: "10PERCENT"})
|
61
|
+
Stripe::PromotionCode.create({coupon: coupon.id, code: "20PERCENT"})
|
62
|
+
|
63
|
+
all = Stripe::PromotionCode.list
|
64
|
+
|
65
|
+
expect(all.count).to eq(2)
|
66
|
+
expect(all.map(&:code)).to include("10PERCENT", "20PERCENT")
|
67
|
+
end
|
68
|
+
end
|
@@ -22,6 +22,19 @@ shared_examples 'Refund API' do
|
|
22
22
|
expect(charge.amount_refunded).to eq(999)
|
23
23
|
end
|
24
24
|
|
25
|
+
it "refunds a stripe payment intent" do
|
26
|
+
payment_intent = Stripe::PaymentIntent.create(
|
27
|
+
amount: 999,
|
28
|
+
currency: 'USD'
|
29
|
+
)
|
30
|
+
|
31
|
+
refund = Stripe::Refund.create(
|
32
|
+
payment_intent: payment_intent.id
|
33
|
+
)
|
34
|
+
expect(refund.amount).to eq(999)
|
35
|
+
end
|
36
|
+
|
37
|
+
|
25
38
|
it "creates a stripe refund with a status" do
|
26
39
|
charge = Stripe::Charge.create(
|
27
40
|
amount: 999,
|
@@ -10,6 +10,14 @@ shared_examples 'SetupIntent API' do
|
|
10
10
|
expect(setup_intent.status).to eq('requires_payment_method')
|
11
11
|
end
|
12
12
|
|
13
|
+
it 'creates a stripe setup intent with payment method' do
|
14
|
+
setup_intent = Stripe::SetupIntent.create(payment_method: 'random')
|
15
|
+
|
16
|
+
expect(setup_intent.id).to match(/^test_si/)
|
17
|
+
expect(setup_intent.metadata.to_hash).to eq({})
|
18
|
+
expect(setup_intent.status).to eq('requires_action')
|
19
|
+
end
|
20
|
+
|
13
21
|
describe "listing setup_intent" do
|
14
22
|
before do
|
15
23
|
3.times do
|
@@ -42,6 +50,15 @@ shared_examples 'SetupIntent API' do
|
|
42
50
|
}
|
43
51
|
end
|
44
52
|
|
53
|
+
it "expands payment_method" do
|
54
|
+
payment_method = Stripe::PaymentMethod.create(type: "card")
|
55
|
+
original = Stripe::SetupIntent.create(payment_method: payment_method.id)
|
56
|
+
|
57
|
+
setup_intent = Stripe::SetupIntent.retrieve({id: original.id, expand: ["payment_method"]})
|
58
|
+
|
59
|
+
expect(setup_intent.payment_method).to eq(payment_method)
|
60
|
+
end
|
61
|
+
|
45
62
|
it "confirms a stripe setup_intent" do
|
46
63
|
setup_intent = Stripe::SetupIntent.create()
|
47
64
|
confirmed_setup_intent = setup_intent.confirm()
|