Skip to content

Commit

Permalink
fixup! Upgrade Stripe API version
Browse files Browse the repository at this point in the history
  • Loading branch information
gbp committed Nov 7, 2024
1 parent 499acb0 commit eb0f277
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
6 changes: 4 additions & 2 deletions app/controllers/alaveteli_pro/stripe_webhooks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ def invoice_payment_succeeded
charge = Stripe::Charge.retrieve(charge_id)

subscription_id = @stripe_event.data.object.subscription
subscription = Stripe::Subscription.retrieve(subscription_id)
plan_name = subscription.plan.name
subscription = Stripe::Subscription.retrieve(
id: subscription_id, expand: ['plan.product']
)
plan_name = subscription.plan.product.name

Stripe::Charge.update(
charge.id, description: "#{pro_site_name}: #{plan_name}"
Expand Down
25 changes: 21 additions & 4 deletions spec/controllers/alaveteli_pro/stripe_webhooks_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let(:signing_secret) { config_secret }
let(:stripe_helper) { StripeMock.create_test_helper }

let(:product) { stripe_helper.create_product }
let(:product) { stripe_helper.create_product(name: 'Test') }

let(:stripe_customer) do
Stripe::Customer.create(source: stripe_helper.generate_card_token,
Expand All @@ -16,7 +16,7 @@

let(:stripe_plan) do
stripe_helper.create_plan(
id: 'test', name: 'Test', product: product.id,
id: 'test', product: product.id,
amount: 10, currency: 'gbp'
)
end
Expand All @@ -37,7 +37,7 @@
currency: stripe_plan.currency,
type: 'subscription'
},
plan: { id: stripe_plan.id, name: stripe_plan.name }
plan: { id: stripe_plan.id }
}
],
subscription: stripe_subscription.id
Expand Down Expand Up @@ -203,7 +203,7 @@ def send_request
context 'the webhook is for a matching namespaced plan' do
let(:stripe_plan) do
stripe_helper.create_plan(
id: 'WDTK-test', name: 'Test', product: product.id,
id: 'WDTK-test', product: product.id,
amount: 10, currency: 'gbp'
)
end
Expand All @@ -219,7 +219,16 @@ def send_request
end

it 'returns a 200 OK response' do
allow(Stripe::Subscription).to receive(:retrieve).with(
id: stripe_subscription.id, expand: ['plan.product']
).and_return(stripe_subscription)

allow(stripe_subscription.plan).to receive(:product).and_return(
product
)

send_request

expect(response.status).to eq(200)
expect(response.body).to match('OK')
end
Expand Down Expand Up @@ -330,6 +339,14 @@ def send_request

describe 'updating the Stripe charge description when a payment succeeds' do
before do
allow(Stripe::Subscription).to receive(:retrieve).with(
id: stripe_subscription.id, expand: ['plan.product']
).and_return(stripe_subscription)

allow(stripe_subscription.plan).to receive(:product).and_return(
product
)

send_request
end

Expand Down

0 comments on commit eb0f277

Please sign in to comment.