stripe-ruby-mock 2.5.8 → 4.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.
- checksums.yaml +5 -5
- data/.github/workflows/rspec_tests.yml +38 -0
- data/.gitignore +1 -1
- data/.rspec +2 -1
- data/CHANGELOG.md +77 -0
- data/Gemfile +1 -5
- data/README.md +19 -11
- data/lib/stripe_mock/api/client.rb +2 -2
- data/lib/stripe_mock/api/errors.rb +34 -28
- data/lib/stripe_mock/api/instance.rb +1 -1
- data/lib/stripe_mock/api/webhooks.rb +68 -24
- data/lib/stripe_mock/client.rb +2 -1
- data/lib/stripe_mock/data/list.rb +42 -9
- data/lib/stripe_mock/data.rb +359 -21
- data/lib/stripe_mock/instance.rb +23 -5
- 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/balance_transactions.rb +2 -2
- data/lib/stripe_mock/request_handlers/charges.rb +31 -5
- data/lib/stripe_mock/request_handlers/checkout_session.rb +179 -0
- data/lib/stripe_mock/request_handlers/customers.rb +47 -19
- 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 +6 -0
- data/lib/stripe_mock/request_handlers/helpers/search_helpers.rb +67 -0
- data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +36 -12
- data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +1 -1
- data/lib/stripe_mock/request_handlers/invoices.rb +26 -6
- data/lib/stripe_mock/request_handlers/payment_intents.rb +202 -0
- data/lib/stripe_mock/request_handlers/payment_methods.rb +124 -0
- data/lib/stripe_mock/request_handlers/plans.rb +1 -1
- data/lib/stripe_mock/request_handlers/prices.rb +71 -0
- data/lib/stripe_mock/request_handlers/products.rb +15 -5
- 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 +100 -0
- data/lib/stripe_mock/request_handlers/sources.rb +12 -6
- data/lib/stripe_mock/request_handlers/subscriptions.rb +146 -25
- 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 +124 -9
- data/lib/stripe_mock/server.rb +2 -2
- data/lib/stripe_mock/test_strategies/base.rb +98 -12
- data/lib/stripe_mock/test_strategies/live.rb +23 -12
- data/lib/stripe_mock/test_strategies/mock.rb +6 -2
- 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 +101 -44
- 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 -45
- 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 -46
- 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 +40 -0
- data/lib/stripe_mock/webhook_fixtures/product.deleted.json +40 -0
- data/lib/stripe_mock/webhook_fixtures/product.updated.json +47 -0
- 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 +11 -0
- data/spec/instance_spec.rb +13 -13
- data/spec/integration_examples/completing_checkout_sessions_example.rb +37 -0
- data/spec/list_spec.rb +38 -0
- data/spec/readme_spec.rb +1 -1
- data/spec/server_spec.rb +6 -3
- data/spec/shared_stripe_examples/account_examples.rb +10 -2
- 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/balance_transaction_examples.rb +3 -3
- data/spec/shared_stripe_examples/bank_examples.rb +3 -3
- data/spec/shared_stripe_examples/bank_token_examples.rb +5 -7
- data/spec/shared_stripe_examples/card_examples.rb +4 -4
- data/spec/shared_stripe_examples/card_token_examples.rb +17 -21
- data/spec/shared_stripe_examples/charge_examples.rb +106 -22
- data/spec/shared_stripe_examples/checkout_session_examples.rb +99 -0
- data/spec/shared_stripe_examples/coupon_examples.rb +1 -1
- data/spec/shared_stripe_examples/customer_examples.rb +149 -53
- data/spec/shared_stripe_examples/dispute_examples.rb +2 -2
- data/spec/shared_stripe_examples/error_mock_examples.rb +8 -7
- data/spec/shared_stripe_examples/express_login_link_examples.rb +12 -0
- data/spec/shared_stripe_examples/external_account_examples.rb +3 -3
- data/spec/shared_stripe_examples/invoice_examples.rb +148 -40
- data/spec/shared_stripe_examples/invoice_item_examples.rb +1 -1
- data/spec/shared_stripe_examples/payment_intent_examples.rb +283 -0
- data/spec/shared_stripe_examples/payment_method_examples.rb +454 -0
- data/spec/shared_stripe_examples/payout_examples.rb +2 -2
- data/spec/shared_stripe_examples/plan_examples.rb +135 -92
- data/spec/shared_stripe_examples/price_examples.rb +292 -0
- data/spec/shared_stripe_examples/product_examples.rb +215 -0
- data/spec/shared_stripe_examples/promotion_code_examples.rb +68 -0
- data/spec/shared_stripe_examples/refund_examples.rb +38 -21
- data/spec/shared_stripe_examples/setup_intent_examples.rb +85 -0
- data/spec/shared_stripe_examples/subscription_examples.rb +706 -324
- data/spec/shared_stripe_examples/subscription_items_examples.rb +3 -2
- data/spec/shared_stripe_examples/transfer_examples.rb +16 -7
- data/spec/shared_stripe_examples/webhook_event_examples.rb +62 -16
- data/spec/spec_helper.rb +8 -5
- data/spec/stripe_mock_spec.rb +4 -4
- data/spec/support/shared_contexts/stripe_validator_spec.rb +8 -0
- data/spec/support/stripe_examples.rb +11 -1
- data/stripe-ruby-mock.gemspec +9 -5
- metadata +115 -47
- data/.travis.yml +0 -28
- data/spec/shared_stripe_examples/product_example.rb +0 -65
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
shared_examples "Product API" do
|
|
4
|
+
let(:product_attributes) { {id: "prod_123", name: "My Mock Product"} }
|
|
5
|
+
let(:product) { Stripe::Product.create(product_attributes) }
|
|
6
|
+
|
|
7
|
+
it "creates a stripe product" do
|
|
8
|
+
expect(product.id).to eq("prod_123")
|
|
9
|
+
expect(product.name).to eq("My Mock Product")
|
|
10
|
+
expect(product.type).to eq("service")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "stores a created stripe product in memory" do
|
|
14
|
+
product = Stripe::Product.create(product_attributes)
|
|
15
|
+
product2 = Stripe::Product.create(product_attributes.merge({id: "prod_456", name: "My Other Product"}))
|
|
16
|
+
|
|
17
|
+
data = test_data_source(:products)
|
|
18
|
+
expect(data[product.id]).to_not be_nil
|
|
19
|
+
expect(data[product.id][:id]).to eq("prod_123")
|
|
20
|
+
expect(data[product.id][:name]).to eq("My Mock Product")
|
|
21
|
+
expect(data[product2.id]).to_not be_nil
|
|
22
|
+
expect(data[product2.id][:id]).to eq("prod_456")
|
|
23
|
+
expect(data[product2.id][:name]).to eq("My Other Product")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "retrieves a stripe product" do
|
|
27
|
+
original = stripe_helper.create_product(product_attributes)
|
|
28
|
+
product = Stripe::Product.retrieve(original.id)
|
|
29
|
+
|
|
30
|
+
expect(product.id).to eq(original.id)
|
|
31
|
+
expect(product.name).to eq(original.name)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "updates a stripe product" do
|
|
35
|
+
stripe_helper.create_product(id: "prod_XYZ", name: "Future Product")
|
|
36
|
+
|
|
37
|
+
product = Stripe::Product.retrieve("prod_XYZ")
|
|
38
|
+
expect(product.name).to eq("Future Product")
|
|
39
|
+
|
|
40
|
+
product.name = "Updated Product"
|
|
41
|
+
product.save
|
|
42
|
+
product = Stripe::Product.retrieve("prod_XYZ")
|
|
43
|
+
expect(product.name).to eq("Updated Product")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "cannot retrieve a stripe product that doesn't exist" do
|
|
47
|
+
expect { Stripe::Product.retrieve('nope') }.to raise_error {|e|
|
|
48
|
+
expect(e).to be_a Stripe::InvalidRequestError
|
|
49
|
+
expect(e.param).to eq("product")
|
|
50
|
+
expect(e.http_status).to eq(404)
|
|
51
|
+
}
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "deletes a stripe product" do
|
|
55
|
+
stripe_helper.create_product(id: "prod_DEL", name: "Aging Product")
|
|
56
|
+
|
|
57
|
+
product = Stripe::Product.retrieve("prod_DEL")
|
|
58
|
+
expect(product).to_not be_nil
|
|
59
|
+
|
|
60
|
+
product.delete
|
|
61
|
+
|
|
62
|
+
expect { Stripe::Product.retrieve("prod_DEL") }.to raise_error {|e|
|
|
63
|
+
expect(e).to be_a Stripe::InvalidRequestError
|
|
64
|
+
expect(e.param).to eq("product")
|
|
65
|
+
expect(e.http_status).to eq(404)
|
|
66
|
+
}
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "retrieves all products" do
|
|
70
|
+
stripe_helper.create_product(id: "prod_123", name: "First Product")
|
|
71
|
+
stripe_helper.create_product(id: "prod_456", name: "Second Product")
|
|
72
|
+
|
|
73
|
+
all = Stripe::Product.list
|
|
74
|
+
expect(all.count).to eq(2)
|
|
75
|
+
expect(all.map &:id).to include("prod_123", "prod_456")
|
|
76
|
+
expect(all.map &:name).to include("First Product", "Second Product")
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it 'retrieves products with limit' do
|
|
80
|
+
101.times do |i|
|
|
81
|
+
stripe_helper.create_product(id: "Product #{i}", name: "My Product ##{i}")
|
|
82
|
+
end
|
|
83
|
+
all = Stripe::Product.list(limit: 100)
|
|
84
|
+
|
|
85
|
+
expect(all.count).to eq(100)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
context "searching products" do
|
|
89
|
+
# the Search API requires about a minute between writes and reads, so add sleeps accordingly when running live
|
|
90
|
+
it "searches products for exact matches", :aggregate_failures do
|
|
91
|
+
response = Stripe::Product.search({query: 'name:"one"'}, stripe_version: '2020-08-27')
|
|
92
|
+
expect(response.data.size).to eq(0)
|
|
93
|
+
|
|
94
|
+
one = stripe_helper.create_product(
|
|
95
|
+
id: "product_1",
|
|
96
|
+
name: "one",
|
|
97
|
+
description: "un",
|
|
98
|
+
shippable: true,
|
|
99
|
+
url: "http://example.com/one",
|
|
100
|
+
metadata: {key: "uno"},
|
|
101
|
+
)
|
|
102
|
+
two = stripe_helper.create_product(
|
|
103
|
+
id: "product_2",
|
|
104
|
+
name: "two",
|
|
105
|
+
active: false,
|
|
106
|
+
description: "deux",
|
|
107
|
+
url: "http://example.com/two",
|
|
108
|
+
metadata: {key: "dos"},
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
response = Stripe::Product.search({query: 'active:"true"'}, stripe_version: '2020-08-27')
|
|
112
|
+
expect(response.data.map(&:id)).to match_array([one.id])
|
|
113
|
+
|
|
114
|
+
response = Stripe::Product.search({query: 'description:"deux"'}, stripe_version: '2020-08-27')
|
|
115
|
+
expect(response.data.map(&:id)).to match_array([two.id])
|
|
116
|
+
|
|
117
|
+
response = Stripe::Product.search({query: 'name:"one"'}, stripe_version: '2020-08-27')
|
|
118
|
+
expect(response.data.map(&:id)).to match_array([one.id])
|
|
119
|
+
|
|
120
|
+
response = Stripe::Product.search({query: 'shippable:"true"'}, stripe_version: '2020-08-27')
|
|
121
|
+
expect(response.data.map(&:id)).to match_array([one.id])
|
|
122
|
+
|
|
123
|
+
response = Stripe::Product.search({query: 'url:"http://example.com/two"'}, stripe_version: '2020-08-27')
|
|
124
|
+
expect(response.data.map(&:id)).to match_array([two.id])
|
|
125
|
+
|
|
126
|
+
response = Stripe::Product.search({query: 'metadata["key"]:"uno"'}, stripe_version: '2020-08-27')
|
|
127
|
+
expect(response.data.map(&:id)).to match_array([one.id])
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
it "respects limit", :aggregate_failures do
|
|
131
|
+
11.times do |i|
|
|
132
|
+
stripe_helper.create_product(id: "product_#{i}", name: "Product #{i}")
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
response = Stripe::Product.search({query: 'active:"true"'}, stripe_version: '2020-08-27')
|
|
136
|
+
expect(response.data.size).to eq(10)
|
|
137
|
+
response = Stripe::Product.search({query: 'active:"true"', limit: 1}, stripe_version: '2020-08-27')
|
|
138
|
+
expect(response.data.size).to eq(1)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it "reports search errors", :aggregate_failures do
|
|
142
|
+
expect {
|
|
143
|
+
Stripe::Product.search({limit: 1}, stripe_version: '2020-08-27')
|
|
144
|
+
}.to raise_error(Stripe::InvalidRequestError, /Missing required param: query./)
|
|
145
|
+
|
|
146
|
+
expect {
|
|
147
|
+
Stripe::Product.search({query: 'asdf'}, stripe_version: '2020-08-27')
|
|
148
|
+
}.to raise_error(Stripe::InvalidRequestError, /We were unable to parse your search query./)
|
|
149
|
+
|
|
150
|
+
expect {
|
|
151
|
+
Stripe::Product.search({query: 'foo:"bar"'}, stripe_version: '2020-08-27')
|
|
152
|
+
}.to raise_error(Stripe::InvalidRequestError, /Field `foo` is an unsupported search field for resource `products`./)
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
describe "Validation", :live => true do
|
|
157
|
+
include_context "stripe validator"
|
|
158
|
+
let(:params) { stripe_helper.create_product_params }
|
|
159
|
+
let(:subject) { Stripe::Product.create(params) }
|
|
160
|
+
before { stripe_helper.delete_product(params[:id]) }
|
|
161
|
+
|
|
162
|
+
describe "Required Parameters" do
|
|
163
|
+
after do
|
|
164
|
+
params.delete(@attribute_name)
|
|
165
|
+
message = stripe_validator.missing_param_message(@attribute_name)
|
|
166
|
+
expect { subject }.to raise_error(Stripe::InvalidRequestError, message)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it("requires a name") { @attribute_name = :name }
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
describe "Uniqueness" do
|
|
173
|
+
let(:already_exists_message){ stripe_validator.already_exists_message(Stripe::Product) }
|
|
174
|
+
|
|
175
|
+
it "validates uniqueness of identifier" do
|
|
176
|
+
stripe_helper.delete_product(params[:id])
|
|
177
|
+
|
|
178
|
+
Stripe::Product.create(params)
|
|
179
|
+
expect {
|
|
180
|
+
Stripe::Product.create(params)
|
|
181
|
+
}.to raise_error(Stripe::InvalidRequestError, already_exists_message)
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
describe "Mock Data" do
|
|
187
|
+
let(:mock_object) { StripeMock::Data.mock_product }
|
|
188
|
+
let(:known_attributes) { [
|
|
189
|
+
:id,
|
|
190
|
+
:object,
|
|
191
|
+
:active,
|
|
192
|
+
:attributes,
|
|
193
|
+
:caption,
|
|
194
|
+
:created,
|
|
195
|
+
:deactivate_on,
|
|
196
|
+
:description,
|
|
197
|
+
:images,
|
|
198
|
+
:livemode,
|
|
199
|
+
:metadata,
|
|
200
|
+
:name,
|
|
201
|
+
:package_dimensions,
|
|
202
|
+
:shippable,
|
|
203
|
+
:statement_descriptor,
|
|
204
|
+
:type,
|
|
205
|
+
:unit_label,
|
|
206
|
+
:updated,
|
|
207
|
+
:url
|
|
208
|
+
] }
|
|
209
|
+
|
|
210
|
+
it "includes all retreived attributes" do
|
|
211
|
+
expect(mock_object.keys).to eql(known_attributes)
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
end
|
|
@@ -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,
|
|
@@ -30,9 +43,7 @@ shared_examples 'Refund API' do
|
|
|
30
43
|
description: 'card charge'
|
|
31
44
|
)
|
|
32
45
|
|
|
33
|
-
Stripe::Refund.create(
|
|
34
|
-
charge: charge.id
|
|
35
|
-
)
|
|
46
|
+
Stripe::Refund.create(charge: charge.id)
|
|
36
47
|
|
|
37
48
|
charge = Stripe::Charge.retrieve(charge.id)
|
|
38
49
|
|
|
@@ -262,7 +273,7 @@ shared_examples 'Refund API' do
|
|
|
262
273
|
end
|
|
263
274
|
|
|
264
275
|
it "stores all charges in memory" do
|
|
265
|
-
expect(Stripe::Refund.
|
|
276
|
+
expect(Stripe::Refund.list.data.map(&:id)).to eq([@refund2.id, @refund.id])
|
|
266
277
|
end
|
|
267
278
|
|
|
268
279
|
it "defaults count to 10 charges" do
|
|
@@ -275,7 +286,7 @@ shared_examples 'Refund API' do
|
|
|
275
286
|
Stripe::Refund.create(charge: charge.id)
|
|
276
287
|
end
|
|
277
288
|
|
|
278
|
-
expect(Stripe::Refund.
|
|
289
|
+
expect(Stripe::Refund.list.data.count).to eq(10)
|
|
279
290
|
end
|
|
280
291
|
|
|
281
292
|
it "is marked as having more when more objects exist" do
|
|
@@ -288,12 +299,12 @@ shared_examples 'Refund API' do
|
|
|
288
299
|
Stripe::Refund.create(charge: charge.id)
|
|
289
300
|
end
|
|
290
301
|
|
|
291
|
-
expect(Stripe::Refund.
|
|
302
|
+
expect(Stripe::Refund.list.has_more).to eq(true)
|
|
292
303
|
end
|
|
293
304
|
|
|
294
305
|
context "when passing limit" do
|
|
295
306
|
it "gets that many charges" do
|
|
296
|
-
expect(Stripe::Refund.
|
|
307
|
+
expect(Stripe::Refund.list(limit: 1).count).to eq(1)
|
|
297
308
|
end
|
|
298
309
|
end
|
|
299
310
|
end
|
|
@@ -318,13 +329,13 @@ shared_examples 'Refund API' do
|
|
|
318
329
|
Stripe::Refund.create(charge: charge.id)
|
|
319
330
|
end
|
|
320
331
|
|
|
321
|
-
|
|
332
|
+
all_refunds = Stripe::Refund.list
|
|
322
333
|
default_limit = 10
|
|
323
|
-
half = Stripe::Refund.
|
|
334
|
+
half = Stripe::Refund.list(starting_after: all_refunds.data.at(1).id)
|
|
324
335
|
|
|
325
336
|
expect(half).to be_a(Stripe::ListObject)
|
|
326
337
|
expect(half.data.count).to eq(default_limit)
|
|
327
|
-
expect(half.data.first.id).to eq(
|
|
338
|
+
expect(half.data.first.id).to eq(all_refunds.data.at(2).id)
|
|
328
339
|
end
|
|
329
340
|
|
|
330
341
|
describe "idempotency" do
|
|
@@ -378,7 +389,8 @@ shared_examples 'Refund API' do
|
|
|
378
389
|
description: 'card charge'
|
|
379
390
|
)
|
|
380
391
|
|
|
381
|
-
charge
|
|
392
|
+
Stripe::Refund.create(charge: charge.id, amount: 999)
|
|
393
|
+
charge.refresh
|
|
382
394
|
|
|
383
395
|
expect(charge.refunded).to eq(true)
|
|
384
396
|
expect(charge.refunds.data.first.amount).to eq(999)
|
|
@@ -392,10 +404,10 @@ shared_examples 'Refund API' do
|
|
|
392
404
|
source: stripe_helper.generate_card_token,
|
|
393
405
|
description: 'card charge'
|
|
394
406
|
)
|
|
395
|
-
refund = charge.
|
|
407
|
+
refund = Stripe::Refund.create(charge: charge.id)
|
|
396
408
|
|
|
397
409
|
expect(charge.id).to match(/^(test_)?ch/)
|
|
398
|
-
expect(refund.
|
|
410
|
+
expect(refund.charge).to eq(charge.id)
|
|
399
411
|
end
|
|
400
412
|
|
|
401
413
|
it "creates a stripe refund with a refund ID" do
|
|
@@ -405,10 +417,12 @@ shared_examples 'Refund API' do
|
|
|
405
417
|
source: stripe_helper.generate_card_token,
|
|
406
418
|
description: 'card charge'
|
|
407
419
|
)
|
|
408
|
-
refund = charge.refund
|
|
409
420
|
|
|
410
|
-
|
|
411
|
-
|
|
421
|
+
Stripe::Refund.create(charge: charge.id)
|
|
422
|
+
refunds = Stripe::Refund.list(charge: charge.id)
|
|
423
|
+
|
|
424
|
+
expect(refunds.data.count).to eq 1
|
|
425
|
+
expect(refunds.data.first.id).to match(/^test_re/)
|
|
412
426
|
end
|
|
413
427
|
|
|
414
428
|
it "creates a stripe refund with a status" do
|
|
@@ -418,10 +432,12 @@ shared_examples 'Refund API' do
|
|
|
418
432
|
source: stripe_helper.generate_card_token,
|
|
419
433
|
description: 'card charge'
|
|
420
434
|
)
|
|
421
|
-
refund = charge.refund
|
|
422
435
|
|
|
423
|
-
|
|
424
|
-
|
|
436
|
+
Stripe::Refund.create(charge: charge.id)
|
|
437
|
+
refunds = Stripe::Refund.list(charge: charge.id)
|
|
438
|
+
|
|
439
|
+
expect(refunds.data.count).to eq 1
|
|
440
|
+
expect(refunds.data.first.status).to eq("succeeded")
|
|
425
441
|
end
|
|
426
442
|
|
|
427
443
|
it "creates a stripe refund with a different balance transaction than the charge" do
|
|
@@ -431,9 +447,10 @@ shared_examples 'Refund API' do
|
|
|
431
447
|
source: stripe_helper.generate_card_token,
|
|
432
448
|
description: 'card charge'
|
|
433
449
|
)
|
|
434
|
-
|
|
450
|
+
Stripe::Refund.create(charge: charge.id)
|
|
451
|
+
refunds = Stripe::Refund.list(charge: charge.id)
|
|
435
452
|
|
|
436
|
-
expect(charge.balance_transaction).not_to eq(
|
|
453
|
+
expect(charge.balance_transaction).not_to eq(refunds.data.first.balance_transaction)
|
|
437
454
|
end
|
|
438
455
|
|
|
439
456
|
it "creates a refund off a charge", :live => true do
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
shared_examples 'SetupIntent API' do
|
|
4
|
+
|
|
5
|
+
it "creates a stripe setup_intent" do
|
|
6
|
+
setup_intent = Stripe::SetupIntent.create()
|
|
7
|
+
|
|
8
|
+
expect(setup_intent.id).to match(/^test_si/)
|
|
9
|
+
expect(setup_intent.metadata.to_hash).to eq({})
|
|
10
|
+
expect(setup_intent.status).to eq('requires_payment_method')
|
|
11
|
+
end
|
|
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
|
+
|
|
21
|
+
describe "listing setup_intent" do
|
|
22
|
+
before do
|
|
23
|
+
3.times do
|
|
24
|
+
Stripe::SetupIntent.create()
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "without params retrieves all stripe setup_intent" do
|
|
29
|
+
expect(Stripe::SetupIntent.list.count).to eq(3)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "accepts a limit param" do
|
|
33
|
+
expect(Stripe::SetupIntent.list(limit: 2).count).to eq(2)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "retrieves a stripe setup_intent" do
|
|
38
|
+
original = Stripe::SetupIntent.create()
|
|
39
|
+
setup_intent = Stripe::SetupIntent.retrieve(original.id)
|
|
40
|
+
|
|
41
|
+
expect(setup_intent.id).to eq(original.id)
|
|
42
|
+
expect(setup_intent.metadata.to_hash).to eq(original.metadata.to_hash)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "cannot retrieve a setup_intent that doesn't exist" do
|
|
46
|
+
expect { Stripe::SetupIntent.retrieve('nope') }.to raise_error {|e|
|
|
47
|
+
expect(e).to be_a Stripe::InvalidRequestError
|
|
48
|
+
expect(e.param).to eq('setup_intent')
|
|
49
|
+
expect(e.http_status).to eq(404)
|
|
50
|
+
}
|
|
51
|
+
end
|
|
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
|
+
|
|
62
|
+
it "confirms a stripe setup_intent" do
|
|
63
|
+
setup_intent = Stripe::SetupIntent.create()
|
|
64
|
+
confirmed_setup_intent = setup_intent.confirm()
|
|
65
|
+
expect(confirmed_setup_intent.status).to eq("succeeded")
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "cancels a stripe setup_intent" do
|
|
69
|
+
setup_intent = Stripe::SetupIntent.create()
|
|
70
|
+
confirmed_setup_intent = setup_intent.cancel()
|
|
71
|
+
expect(confirmed_setup_intent.status).to eq("canceled")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "updates a stripe setup_intent" do
|
|
75
|
+
original = Stripe::SetupIntent.create()
|
|
76
|
+
setup_intent = Stripe::SetupIntent.retrieve(original.id)
|
|
77
|
+
|
|
78
|
+
setup_intent.metadata[:foo] = :bar
|
|
79
|
+
setup_intent.save
|
|
80
|
+
|
|
81
|
+
updated = Stripe::SetupIntent.retrieve(original.id)
|
|
82
|
+
|
|
83
|
+
expect(updated.metadata[:foo]).to eq(:bar)
|
|
84
|
+
end
|
|
85
|
+
end
|