Skip to content

Commit

Permalink
Merge pull request stripe-ruby-mock#917 from espen/latest_charge
Browse files Browse the repository at this point in the history
Removed charges on PI and added latest_charge
  • Loading branch information
alexmamonchik authored Oct 24, 2024
2 parents 14b92a3 + 3c6b95c commit ba6b6e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/stripe_mock/request_handlers/payment_intents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def succeeded_payment_intent(payment_intent)
payment_method: payment_intent[:payment_method]
)

payment_intent[:charges][:data] << charges[charge_id].clone
payment_intent[:latest_charge] = charge_id

payment_intent
end
Expand Down
26 changes: 13 additions & 13 deletions spec/shared_stripe_examples/payment_intent_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@
amount: 100, currency: 'usd', confirm: true
)
expect(payment_intent.status).to eq('succeeded')
expect(payment_intent.charges.data.size).to eq(1)
expect(payment_intent.charges.data.first.object).to eq('charge')
balance_txn = payment_intent.charges.data.first.balance_transaction
charge = Stripe::Charge.retrieve(payment_intent.latest_charge)
expect(charge.object).to eq('charge')
balance_txn = charge.balance_transaction
expect(balance_txn).to match(/^test_txn/)
expect(Stripe::BalanceTransaction.retrieve(balance_txn).id).to eq(balance_txn)
end
Expand All @@ -104,7 +104,7 @@
customer: customer,
payment_method: customer.sources.first

charge = payment_intent.charges.data.first
charge = Stripe::Charge.retrieve(payment_intent.latest_charge)
expect(charge.amount).to eq(payment_intent.amount)
expect(charge.payment_intent).to eq(payment_intent.id)
expect(charge.description).to be_nil
Expand All @@ -121,17 +121,17 @@
amount: 100, currency: "usd", confirm: true, payment_method: "test_pm_1"
)
expect(payment_intent.status).to eq("succeeded")
expect(payment_intent.charges.data.size).to eq(1)
expect(payment_intent.charges.data.first.object).to eq("charge")
expect(payment_intent.charges.data.first.payment_method).to eq("test_pm_1")
charge = Stripe::Charge.retrieve(payment_intent.latest_charge)
expect(charge.object).to eq("charge")
expect(charge.payment_method).to eq("test_pm_1")
end

it "confirms a stripe payment_intent" do
payment_intent = Stripe::PaymentIntent.create(amount: 100, currency: "usd")
confirmed_payment_intent = payment_intent.confirm()
expect(confirmed_payment_intent.status).to eq("succeeded")
expect(confirmed_payment_intent.charges.data.size).to eq(1)
expect(confirmed_payment_intent.charges.data.first.object).to eq('charge')
charge = Stripe::Charge.retrieve(confirmed_payment_intent.latest_charge)
expect(charge.object).to eq('charge')
end

it 'creates a charge for a confirmed stripe payment_intent' do
Expand All @@ -141,7 +141,7 @@
payment_method: customer.sources.first

confirmed_payment_intent = payment_intent.confirm
charge = confirmed_payment_intent.charges.data.first
charge = Stripe::Charge.retrieve(payment_intent.latest_charge)
expect(charge.amount).to eq(confirmed_payment_intent.amount)
expect(charge.payment_intent).to eq(confirmed_payment_intent.id)
expect(charge.description).to be_nil
Expand All @@ -157,8 +157,8 @@
payment_intent = Stripe::PaymentIntent.create(amount: 100, currency: "usd")
confirmed_payment_intent = payment_intent.capture()
expect(confirmed_payment_intent.status).to eq("succeeded")
expect(confirmed_payment_intent.charges.data.size).to eq(1)
expect(confirmed_payment_intent.charges.data.first.object).to eq('charge')
charge = Stripe::Charge.retrieve(confirmed_payment_intent.latest_charge)
expect(charge.object).to eq('charge')
end

it 'creates a charge for a captured stripe payment_intent' do
Expand All @@ -170,7 +170,7 @@
capture_method: 'manual'

captured_payment_intent = payment_intent.capture
charge = captured_payment_intent.charges.data.first
charge = Stripe::Charge.retrieve(captured_payment_intent.latest_charge)
expect(charge.amount).to eq(captured_payment_intent.amount)
expect(charge.payment_intent).to eq(captured_payment_intent.id)
expect(charge.description).to be_nil
Expand Down

0 comments on commit ba6b6e8

Please sign in to comment.