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.
59 lines
1.5 KiB
Ruby
59 lines
1.5 KiB
Ruby
class UserUpgradesController < ApplicationController
|
|
respond_to :js, :html, :json, :xml
|
|
|
|
def create
|
|
@user_upgrade = authorize UserUpgrade.create(recipient: recipient, purchaser: CurrentUser.user, status: "pending", upgrade_type: params[:upgrade_type])
|
|
@country = params[:country] || CurrentUser.country || "US"
|
|
@checkout = @user_upgrade.create_checkout!(country: @country)
|
|
|
|
respond_with(@user_upgrade)
|
|
end
|
|
|
|
def new
|
|
@user_upgrade = authorize UserUpgrade.new(recipient: recipient, purchaser: CurrentUser.user)
|
|
@recipient = @user_upgrade.recipient
|
|
|
|
respond_with(@user_upgrade)
|
|
end
|
|
|
|
def index
|
|
@user_upgrades = authorize UserUpgrade.visible(CurrentUser.user).paginated_search(params, count_pages: true)
|
|
@user_upgrades = @user_upgrades.includes(:recipient, :purchaser) if request.format.html?
|
|
|
|
respond_with(@user_upgrades)
|
|
end
|
|
|
|
def show
|
|
@user_upgrade = authorize UserUpgrade.find(params[:id])
|
|
respond_with(@user_upgrade)
|
|
end
|
|
|
|
def refund
|
|
@user_upgrade = authorize UserUpgrade.find(params[:id])
|
|
@user_upgrade.refund!
|
|
flash[:notice] = "Upgrade refunded"
|
|
|
|
respond_with(@user_upgrade)
|
|
end
|
|
|
|
def receipt
|
|
@user_upgrade = authorize UserUpgrade.find(params[:id])
|
|
redirect_to @user_upgrade.receipt_url
|
|
end
|
|
|
|
def payment
|
|
@user_upgrade = authorize UserUpgrade.find(params[:id])
|
|
redirect_to @user_upgrade.payment_url
|
|
end
|
|
|
|
private
|
|
|
|
def recipient
|
|
if params[:user_id]
|
|
User.find(params[:user_id])
|
|
else
|
|
CurrentUser.user
|
|
end
|
|
end
|
|
end
|