Skip to content

Commit

Permalink
Merge branch 'master' of github.com:pay-rails/pay
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed Feb 22, 2021
2 parents d18881b + d5ddf9d commit 5f0574c
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/pay/stripe/webhooks/customer_updated.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def call(event)
# Couldn't find user, we can skip
return unless billable.present?

billable.sync_card_from_stripe
Pay::Stripe::Billable.new(billable).sync_card_from_stripe
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pay/stripe/webhooks/payment_method_updated.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def call(event)
# Couldn't find user, we can skip
return unless billable.present?

billable.sync_card_from_stripe
Pay::Stripe::Billable.new(billable).sync_card_from_stripe
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/pay/stripe/webhooks/customer_updated_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Pay::Stripe::Webhooks::CustomerUpdatedTest < ActiveSupport::TestCase
status: "active"
)

User.any_instance.expects(:sync_card_from_stripe)
Pay::Stripe::Billable.any_instance.expects(:sync_card_from_stripe)
Pay::Stripe::Webhooks::CustomerUpdated.new.call(@event)
end

Expand All @@ -38,7 +38,7 @@ class Pay::Stripe::Webhooks::CustomerUpdatedTest < ActiveSupport::TestCase
status: "active"
)

User.any_instance.expects(:sync_card_from_stripe).never
Pay::Stripe::Billable.any_instance.expects(:sync_card_from_stripe).never
Pay::Stripe::Webhooks::CustomerUpdated.new.call(@event)
end
end
44 changes: 44 additions & 0 deletions test/pay/stripe/webhooks/payment_method_updated_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require "test_helper"

class Pay::Stripe::Webhooks::PaymentMethodUpdatedtest < ActiveSupport::TestCase
setup do
@event = OpenStruct.new
@event.data = JSON.parse(File.read("test/support/fixtures/stripe/payment_method.updated.json"), object_class: OpenStruct)
end

test "update_card_from stripe is called upon customer update" do
user = User.create!(
email: "[email protected]",
processor: :stripe,
processor_id: @event.data.object.customer
)
user.subscriptions.create!(
processor: :stripe,
processor_id: "sub_someid",
name: "default",
processor_plan: "some-plan",
status: "active"
)

Pay::Stripe::Billable.any_instance.expects(:sync_card_from_stripe)
Pay::Stripe::Webhooks::PaymentMethodUpdated.new.call(@event)
end

test "update_card_from stripe is not called if user can't be found" do
user = User.create!(
email: "[email protected]",
processor: :stripe,
processor_id: "does-not-exist"
)
user.subscriptions.create!(
processor: :stripe,
processor_id: "sub_someid",
name: "default",
processor_plan: "some-plan",
status: "active"
)

Pay::Stripe::Billable.any_instance.expects(:sync_card_from_stripe).never
Pay::Stripe::Webhooks::PaymentMethodUpdated.new.call(@event)
end
end
51 changes: 51 additions & 0 deletions test/support/fixtures/stripe/payment_method.updated.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"object": {
"id": "pm_1INhmtKXBGcbgpbZd73T5GF5",
"object": "payment_method",
"billing_details": {
"address": {
"city": null,
"country": null,
"line1": null,
"line2": null,
"postal_code": "12345",
"state": null
},
"email": "[email protected]",
"name": null,
"phone": "+15555555555"
},
"card": {
"brand": "visa",
"checks": {
"address_line1_check": null,
"address_postal_code_check": null,
"cvc_check": "pass"
},
"country": "US",
"exp_month": 8,
"exp_year": 2022,
"fingerprint": "w4XDzQOFakih5EZM",
"funding": "credit",
"generated_from": null,
"last4": "4242",
"networks": {
"available": [
"visa"
],
"preferred": null
},
"three_d_secure_usage": {
"supported": true
},
"wallet": null
},
"created": 123456789,
"customer": "cus_1234567890",
"livemode": false,
"metadata": {
"order_id": "123456789"
},
"type": "card"
}
}

0 comments on commit 5f0574c

Please sign in to comment.