Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed Jul 1, 2024
2 parents 6a4cddf + ed8acdc commit 41410de
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby 3.2.2
ruby 3.3.2
2 changes: 1 addition & 1 deletion docs/1_installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Add these lines to your application's Gemfile:
gem "pay", "~> 7.0"

# To use Stripe, also include:
gem "stripe", "~> 10.0"
gem "stripe", "~> 11.0"

# To use Braintree + PayPal, also include:
gem "braintree", "~> 4.7"
Expand Down
6 changes: 5 additions & 1 deletion lib/pay/fake_processor/billable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ def add_payment_method(payment_method_id, default: false)
}
)

pay_customer.reload_default_payment_method if default
if default
pay_customer.payment_methods.where.not(id: pay_payment_method.id).update_all(default: false)
pay_customer.reload_default_payment_method
end

pay_payment_method
end

Expand Down
2 changes: 1 addition & 1 deletion lib/pay/stripe/webhooks/subscription_trial_will_end.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def call(event)
pay_subscription = Pay::Subscription.find_by_processor_and_id(:stripe, object.id)
return if pay_subscription.nil?

pay_subscription.sync!
pay_subscription.sync!(stripe_account: event.try(:account))

pay_user_mailer = Pay.mailer.with(pay_customer: pay_subscription.customer, pay_subscription: pay_subscription)

Expand Down
9 changes: 7 additions & 2 deletions test/pay/fake_processor/billable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,17 @@ class Pay::FakeProcessor::Billable::Test < ActiveSupport::TestCase
end
end

test "fake processor add payment method" do
test "fake processor add new default payment method" do
old_payment_method = @pay_customer.add_payment_method("old", default: true)
assert_equal old_payment_method.id, @pay_customer.default_payment_method.id

new_payment_method = nil
assert_difference "Pay::PaymentMethod.count" do
@pay_customer.add_payment_method("x", default: true)
new_payment_method = @pay_customer.add_payment_method("new", default: true)
end

payment_method = @pay_customer.default_payment_method
assert_equal new_payment_method.id, payment_method.id
assert_equal "card", payment_method.type
assert_equal "Fake", payment_method.brand
end
Expand Down
11 changes: 11 additions & 0 deletions test/pay/stripe/webhooks/subscription_trial_will_end_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ class Pay::Stripe::Webhooks::SubscriptionTrialWillEndTest < ActiveSupport::TestC
assert_enqueued_emails 0
end

test "sync! is called with stripe_account" do
event = @trial_ended_event.clone
event.account = "connect_account_id"

pay_subscription = Pay::Subscription.new
Pay::Subscription.stubs(:find_by_processor_and_id).returns(pay_subscription)
pay_subscription.expects(:sync!).with(stripe_account: "connect_account_id")

Pay::Stripe::Webhooks::SubscriptionTrialWillEnd.new.call(event)
end

private

def create_subscription(processor_id:, trial_ends_at:)
Expand Down

0 comments on commit 41410de

Please sign in to comment.