mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
Tighten Stripe payment link lookup tests
Agent-Logs-Url: https://github.com/we-promise/sure/sessions/efba0c75-5f82-41a1-b618-532d38e222da Co-authored-by: jjmata <187772+jjmata@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
f1f1bc91cc
commit
7a9d207626
@@ -5,10 +5,14 @@ class Settings::PaymentsController < ApplicationController
|
||||
|
||||
def show
|
||||
@family = Current.family
|
||||
@one_time_contribution_url = stripe&.payment_link_url
|
||||
@one_time_contribution_url = stripe&.payment_link_url(payment_link_id:)
|
||||
end
|
||||
|
||||
private
|
||||
def payment_link_id
|
||||
ENV["STRIPE_PAYMENT_LINK_ID"]
|
||||
end
|
||||
|
||||
def stripe
|
||||
@stripe ||= Provider::Registry.get_provider(:stripe)
|
||||
end
|
||||
|
||||
@@ -67,7 +67,7 @@ class Provider::Stripe
|
||||
client.v1.customers.update(customer_id, metadata: metadata)
|
||||
end
|
||||
|
||||
def payment_link_url(payment_link_id: ENV["STRIPE_PAYMENT_LINK_ID"])
|
||||
def payment_link_url(payment_link_id:)
|
||||
return nil if payment_link_id.blank?
|
||||
|
||||
client.v1.payment_links.retrieve(payment_link_id).url
|
||||
|
||||
@@ -15,8 +15,11 @@ class Settings::PaymentsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
test "shows payment settings when family has stripe_customer_id" do
|
||||
@family.update!(stripe_customer_id: "cus_test123")
|
||||
ENV.stubs(:[]).with("STRIPE_PAYMENT_LINK_ID").returns("plink_test123")
|
||||
stripe = mock
|
||||
stripe.expects(:payment_link_url).returns("https://buy.stripe.com/test_payment_link")
|
||||
stripe.expects(:payment_link_url)
|
||||
.with(payment_link_id: "plink_test123")
|
||||
.returns("https://buy.stripe.com/test_payment_link")
|
||||
Provider::Registry.stubs(:get_provider).with(:stripe).returns(stripe)
|
||||
|
||||
get settings_payment_path
|
||||
@@ -30,8 +33,11 @@ class Settings::PaymentsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
test "shows payment settings without contribution link when payment link is unavailable" do
|
||||
@family.update!(stripe_customer_id: "cus_test123")
|
||||
ENV.stubs(:[]).with("STRIPE_PAYMENT_LINK_ID").returns("plink_test123")
|
||||
stripe = mock
|
||||
stripe.expects(:payment_link_url).returns(nil)
|
||||
stripe.expects(:payment_link_url)
|
||||
.with(payment_link_id: "plink_test123")
|
||||
.returns(nil)
|
||||
Provider::Registry.stubs(:get_provider).with(:stripe).returns(stripe)
|
||||
|
||||
get settings_payment_path
|
||||
|
||||
@@ -72,6 +72,8 @@ class Provider::StripeTest < ActiveSupport::TestCase
|
||||
|
||||
Stripe::StripeClient.stubs(:new).returns(client)
|
||||
Sentry.expects(:capture_exception).with(instance_of(StandardError))
|
||||
Rails.logger.expects(:error)
|
||||
.with("Error fetching payment link plink_test123: not found")
|
||||
stripe = Provider::Stripe.new(secret_key: "foo", webhook_secret: "bar")
|
||||
|
||||
assert_nil stripe.payment_link_url(payment_link_id: "plink_test123")
|
||||
|
||||
Reference in New Issue
Block a user