Can i pass different currency in active-merchant w

2019-09-12 06:24发布

I am developing Rails 4 application where user can subscribe one time pay with application.

For subscription, use Active Merchant with stripe where now user pay $50 right now and payment done successfully. Below code :

 ActiveMerchant::Billing::Base.mode = :test

    transaction = ActiveMerchant::Billing::StripeGateway.new(:login => Rails.application.secrets.stripe_secret_key)

    paymentInfo = ActiveMerchant::Billing::CreditCard.new(
                :number             => purchage_params[:card_holder_number],
                :month              => purchage_params[:expiry_month],
                :year               => purchage_params[:expiry_year],
                :verification_value => purchage_params[:cvv])


    purchaseOptions = {:billing_address => {
        :name     => purchage_params[:card_holder_name],
        :currency => @country.currency,
        :address1 => session[:address],
        :city     => session[:city],
        :state    => @region.name,
        :zip      => session[:zip_postal]
    }}

    response = transaction.purchase((amount * 100).to_i, paymentInfo, purchaseOptions)

Now my issue, I want to deduct payment as per user country wise. As per below country and payment.

 USA = $50 USD
 South Africa = 355 ZAR
 India = 520 INR
 Australia = $50 AUD

So how can i set currency and payment country wise. Any one have a idea in it?

Thanks

2条回答
Root(大扎)
2楼-- · 2019-09-12 06:55

I am not entirely clear as to what you're seeking but from what I understand, you're trying to charge a specified price per sub based on country. From what I have read, you shouldn't need to have it determine the country of origin as the gem charges in U.S. currency and the card company should, in theory, automatically convert it to that price.

--Edit--

Okay, after I did some digging around, it looks as though I was slightly incorrect. If you managed to do what you're trying to do you will get this error response.message: The transaction currency specified must be the same as previously specified.

The default currency of the Active Merchant currency is USD. When the transaction goes through, it will go through as a USD charge and you can't actually change it when you add the purchase. Therefore, you have to change it before it is set to the purchase method. Since you are basing it on a subscription, which requires a sign up, then you can set the user to have a default country, since you have to collect their private information anyway to have a billing address. This way the option is predefined and you just use your currency converter before applying an item to the cart.

查看更多
倾城 Initia
3楼-- · 2019-09-12 07:14

I got my solutions. Please check below code how to pass currency.

purchaseOptions = {:billing_address => {
        :name     => purchage_params[:card_holder_name],
        :currency => @country.currency,
        :address1 => session[:address],
        :city     => session[:city],
        :state    => @region.name,
        :zip      => session[:zip_postal]
    },
    :currency => "CAD"}

We can place dynamic code instead of "CAD".

查看更多
登录 后发表回答