user upgrades: add bank payment methods for European countries.
Add the following bank redirect payment methods: * https://stripe.com/docs/payments/bancontact * https://stripe.com/docs/payments/eps * https://stripe.com/docs/payments/giropay * https://stripe.com/docs/payments/ideal * https://stripe.com/docs/payments/p24 These methods are used in Austria, Belgium, Germany, the Netherlands, and Poland. These methods require payments to be denominated in EUR, which means we have to set prices in both USD and EUR, and we have to automatically detect which currency to use based on the user's country. We also have to automatically detect which payment methods to offer based on the user's country. We do this by using Cloudflare's CF-IPCountry header to geolocate the user's country. This also switches to using prices and products defined in Stripe instead of generated on-the-fly when creating the checkout.
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
require 'test_helper'
|
||||
|
||||
class WebhooksControllerTest < ActionDispatch::IntegrationTest
|
||||
mock_stripe!
|
||||
setup do
|
||||
StripeMock.start
|
||||
end
|
||||
|
||||
teardown do
|
||||
StripeMock.stop
|
||||
end
|
||||
|
||||
def post_webhook(*args, payment_status: "paid", **metadata)
|
||||
event = StripeMock.mock_webhook_event(*args, payment_status: payment_status, metadata: metadata)
|
||||
|
||||
@@ -3,11 +3,11 @@ StripeMock.webhook_fixture_path = "test/fixtures/stripe-webhooks"
|
||||
module StripeTestHelper
|
||||
def mock_stripe!
|
||||
setup do
|
||||
StripeMock.start
|
||||
StripeMock.start unless UserUpgrade.enabled?
|
||||
end
|
||||
|
||||
teardown do
|
||||
StripeMock.stop
|
||||
StripeMock.stop unless UserUpgrade.enabled?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -58,6 +58,116 @@ class UserUpgradeTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "for each upgrade type" do
|
||||
setup do
|
||||
skip unless UserUpgrade.enabled?
|
||||
end
|
||||
|
||||
should "choose the right price in USD for a gold upgrade" do
|
||||
@user_upgrade = create(:self_gold_upgrade)
|
||||
@checkout = @user_upgrade.create_checkout!(country: "US")
|
||||
|
||||
assert_equal(UserUpgrade.gold_price, @user_upgrade.payment_intent.amount)
|
||||
assert_equal("usd", @user_upgrade.payment_intent.currency)
|
||||
end
|
||||
|
||||
should "choose the right price in USD for a platinum upgrade" do
|
||||
@user_upgrade = create(:self_platinum_upgrade)
|
||||
@checkout = @user_upgrade.create_checkout!(country: "US")
|
||||
|
||||
assert_equal(UserUpgrade.platinum_price, @user_upgrade.payment_intent.amount)
|
||||
assert_equal("usd", @user_upgrade.payment_intent.currency)
|
||||
end
|
||||
|
||||
should "choose the right price in USD for a gold to platinum upgrade" do
|
||||
@user_upgrade = create(:self_gold_to_platinum_upgrade)
|
||||
@checkout = @user_upgrade.create_checkout!(country: "US")
|
||||
|
||||
assert_equal(UserUpgrade.gold_to_platinum_price, @user_upgrade.payment_intent.amount)
|
||||
assert_equal("usd", @user_upgrade.payment_intent.currency)
|
||||
end
|
||||
|
||||
should "choose the right price in EUR for a gold upgrade" do
|
||||
@user_upgrade = create(:self_gold_upgrade)
|
||||
@checkout = @user_upgrade.create_checkout!(country: "DE")
|
||||
|
||||
assert_equal(0.8 * UserUpgrade.gold_price, @user_upgrade.payment_intent.amount)
|
||||
assert_equal("eur", @user_upgrade.payment_intent.currency)
|
||||
end
|
||||
|
||||
should "choose the right price in EUR for a platinum upgrade" do
|
||||
@user_upgrade = create(:self_platinum_upgrade)
|
||||
@checkout = @user_upgrade.create_checkout!(country: "DE")
|
||||
|
||||
assert_equal(0.8 * UserUpgrade.platinum_price, @user_upgrade.payment_intent.amount)
|
||||
assert_equal("eur", @user_upgrade.payment_intent.currency)
|
||||
end
|
||||
|
||||
should "choose the right price in EUR for a gold to platinum upgrade" do
|
||||
@user_upgrade = create(:self_gold_to_platinum_upgrade)
|
||||
@checkout = @user_upgrade.create_checkout!(country: "DE")
|
||||
|
||||
assert_equal(0.8 * UserUpgrade.gold_to_platinum_price, @user_upgrade.payment_intent.amount)
|
||||
assert_equal("eur", @user_upgrade.payment_intent.currency)
|
||||
end
|
||||
end
|
||||
|
||||
context "for each country" do
|
||||
setup do
|
||||
@user_upgrade = create(:self_gold_upgrade)
|
||||
skip unless UserUpgrade.enabled?
|
||||
end
|
||||
|
||||
should "choose the right payment methods for US" do
|
||||
@checkout = @user_upgrade.create_checkout!(country: "US")
|
||||
|
||||
assert_equal(["card"], @checkout.payment_method_types)
|
||||
assert_equal("usd", @user_upgrade.payment_intent.currency)
|
||||
end
|
||||
|
||||
should "choose the right payment methods for AT" do
|
||||
@checkout = @user_upgrade.create_checkout!(country: "AT")
|
||||
|
||||
assert_equal(["card", "eps"], @checkout.payment_method_types)
|
||||
assert_equal("eur", @user_upgrade.payment_intent.currency)
|
||||
end
|
||||
|
||||
should "choose the right payment methods for BE" do
|
||||
@checkout = @user_upgrade.create_checkout!(country: "BE")
|
||||
|
||||
assert_equal(["card", "bancontact"], @checkout.payment_method_types)
|
||||
assert_equal("eur", @user_upgrade.payment_intent.currency)
|
||||
end
|
||||
|
||||
should "choose the right payment methods for DE" do
|
||||
@checkout = @user_upgrade.create_checkout!(country: "DE")
|
||||
|
||||
assert_equal(["card", "giropay"], @checkout.payment_method_types)
|
||||
assert_equal("eur", @user_upgrade.payment_intent.currency)
|
||||
end
|
||||
|
||||
should "choose the right payment methods for NL" do
|
||||
@checkout = @user_upgrade.create_checkout!(country: "NL")
|
||||
|
||||
assert_equal(["card", "ideal"], @checkout.payment_method_types)
|
||||
assert_equal("eur", @user_upgrade.payment_intent.currency)
|
||||
end
|
||||
|
||||
should "choose the right payment methods for PL" do
|
||||
@checkout = @user_upgrade.create_checkout!(country: "PL")
|
||||
|
||||
assert_equal(["card", "p24"], @checkout.payment_method_types)
|
||||
assert_equal("eur", @user_upgrade.payment_intent.currency)
|
||||
end
|
||||
|
||||
should "choose the right payment methods for an unsupported country" do
|
||||
@checkout = @user_upgrade.create_checkout!(country: "MX")
|
||||
|
||||
assert_equal(["card"], @checkout.payment_method_types)
|
||||
assert_equal("usd", @user_upgrade.payment_intent.currency)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "the #receipt_url method" do
|
||||
@@ -65,6 +175,8 @@ class UserUpgradeTest < ActiveSupport::TestCase
|
||||
|
||||
context "a pending upgrade" do
|
||||
should "not have a receipt" do
|
||||
skip unless UserUpgrade.enabled?
|
||||
|
||||
@user_upgrade = create(:self_gold_upgrade, status: "pending")
|
||||
@user_upgrade.create_checkout!
|
||||
|
||||
|
||||
Reference in New Issue
Block a user