Skip to content

Commit 2618702

Browse files
Merge pull request #6 from Uscreen-video/improve-support-to-13-0
Improve support to 13.0
2 parents 792b449 + 43aec44 commit 2618702

7 files changed

Lines changed: 61 additions & 2 deletions

File tree

lib/stripe_mock/data.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,19 @@ def self.mock_charge(params={})
248248
amount: 0,
249249
application_fee: nil,
250250
application_fee_amount: nil,
251+
billing_details: {
252+
address: {
253+
city: 'New Orleans',
254+
country: 'US',
255+
line1: 'Bourbon Street 23',
256+
line2: nil,
257+
postal_code: '10000',
258+
state: nil
259+
},
260+
email: 'foo@bar.com',
261+
name: 'John Dolton',
262+
phone: nil
263+
},
251264
currency: currency,
252265
destination: nil,
253266
fraud_details: {},
@@ -1252,6 +1265,7 @@ def self.mock_balance_transaction(params = {})
12521265
created: 1461880226,
12531266
currency: currency,
12541267
description: nil,
1268+
exchange_rate: nil,
12551269
fee: 320,
12561270
fee_details: [
12571271
{

lib/stripe_mock/instance.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def initialize
108108
@dispute_counter = 0
109109
@conversion_rate = 1.0
110110
@account_balance = 10000
111+
@account_currency = "usd"
111112

112113
# This is basically a cache for ParamValidators
113114
@base_strategy = TestStrategies::Base.new
@@ -231,7 +232,9 @@ def new_balance_transaction(prefix, params = {})
231232
calculate_fees(params) unless params[:fee]
232233
params[:net] = amount - params[:fee]
233234
params[:amount] = amount * @conversion_rate
235+
params[:currency] = @account_currency
234236
end
237+
params[:exchange_rate] = @conversion_rate if @conversion_rate != 1.0
235238
@balance_transactions[id] = Data.mock_balance_transaction(params.merge(id: id))
236239
id
237240
end

lib/stripe_mock/request_handlers/charges.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def non_positive_charge_amount?(params)
180180
end
181181

182182
def allowed_params(params)
183-
allowed = [:description, :metadata, :receipt_email, :fraud_details, :shipping, :destination]
183+
allowed = [:description, :metadata, :receipt_email, :fraud_details, :shipping, :destination, :billing_details]
184184

185185
# This is a workaround for the way the Stripe API sends params even when they aren't modified.
186186
# Stipe will include those params even when they aren't modified.

lib/stripe_mock/request_handlers/customers.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ def get_customer(route, method_url, params, headers)
135135
end
136136
end
137137

138+
if params[:expand].is_a?(Array) && params[:expand].include?('invoice_credit_balance')
139+
customer[:invoice_credit_balance] = if customer[:balance_transactions]
140+
customer[:balance_transactions].group_by { |bt| bt[:currency] }.transform_values { |v| v.sum { |t| t[:amount] } }
141+
else
142+
{}
143+
end
144+
end
145+
138146
customer
139147
end
140148

lib/stripe_mock/request_handlers/payment_intents.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ def get_payment_intent(route, method_url, params, headers)
6868
payment_intent = assert_existence :payment_intent, payment_intent_id, payment_intents[payment_intent_id]
6969

7070
payment_intent = payment_intent.clone
71+
72+
if params[:expand].is_a?(Array) && params[:expand].include?('latest_charge')
73+
payment_intent[:latest_charge] = charges.values.first
74+
end
75+
7176
payment_intent
7277
end
7378

@@ -180,7 +185,11 @@ def last_payment_error_generator(code: nil, message: nil, decline_code: nil)
180185

181186
def succeeded_payment_intent(payment_intent)
182187
payment_intent[:status] = 'succeeded'
183-
btxn = new_balance_transaction('txn', { source: payment_intent[:id] })
188+
btxn = new_balance_transaction('txn', {
189+
source: payment_intent[:id],
190+
amount: payment_intent[:amount],
191+
currency: payment_intent[:currency]
192+
})
184193

185194
charge_id = new_id('ch')
186195

spec/shared_stripe_examples/customer_examples.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,25 @@ def gen_card_tk
332332
expect(customer.default_source).to be_a(Stripe::Card)
333333
end
334334

335+
it "can expand invoice_credit_balance" do
336+
original = Stripe::Customer.create({
337+
email: 'johnny@appleseed.com',
338+
source: gen_card_tk
339+
})
340+
341+
Stripe::Customer.create_balance_transaction(
342+
original.id,
343+
{ amount: -100, currency: 'usd' }
344+
)
345+
346+
customer = Stripe::Customer.retrieve(
347+
id: original.id,
348+
expand: ['invoice_credit_balance']
349+
)
350+
351+
expect(customer.invoice_credit_balance.to_h).to eq({ usd: -100 })
352+
end
353+
335354
it "cannot retrieve a customer that doesn't exist" do
336355
expect { Stripe::Customer.retrieve('nope') }.to raise_error {|e|
337356
expect(e).to be_a Stripe::InvalidRequestError

spec/shared_stripe_examples/payment_intent_examples.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@
7777
expect(payment_intent.metadata.to_hash).to eq(original.metadata.to_hash)
7878
end
7979

80+
it "can expand latest_charge" do
81+
original = Stripe::PaymentIntent.create(amount: 100, currency: "usd", confirm: true)
82+
payment_intent = Stripe::PaymentIntent.retrieve({ id: original.id, expand: ["latest_charge"] })
83+
expect(payment_intent.latest_charge.object).to eq("charge")
84+
end
85+
8086
it "cannot retrieve a payment_intent that doesn't exist" do
8187
expect { Stripe::PaymentIntent.retrieve('nope') }.to raise_error {|e|
8288
expect(e).to be_a Stripe::InvalidRequestError

0 commit comments

Comments
 (0)