VixB February 2016

Changing Stripe currency from default USD to GBP

I think I have changed the parts of my code necessary to use GBP rather than USD. However, whilst the correct figures are displaying in my Stripe card charging modal the 'charge' button still displays USD.

My current view:

    <%= link_to 'Enroll', course_enrollments_path(@course), class: 'btn btn-primary', method: :post %>
    <%= form_tag course_enrollments_path(@course) do %>

    <script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
            data-key="<%= Rails.configuration.stripe[:publishable_key] %>"
            data-description="A month's subscription"
            data-amount="<%= (@course.cost * 100).to_i %>"></script>
    <% end %>

My current controller:

def create
    current_user.enrollments.create(course: current_course)

    # Amount in pence
    @amount = (current_course.cost * 100).to_i

    customer = Stripe::Customer.create(
      :email => current_user.email,
      :card  => params[:stripeToken]
    )

    charge = Stripe::Charge.create(
      :customer    => customer.id,
      :amount      => @amount,
      :description => 'Flixter Enrollment',
      :currency    => 'gbp'
    )

    redirect_to course_path(current_course)

  rescue Stripe::CardError => e
    flash[:error] = e.message
    redirect_to root_path
    end

Apologies, if I haven't given enough information or my terminology is wrong - I am new to coding and StackOverflow :)

Thanks!

Answers


Matthew Arkin February 2016

You ned to add the currency to Stripe Checkout as below

<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
        data-key="<%= Rails.configuration.stripe[:publishable_key] %>"
        data-description="A month's subscription"
        data-amount="<%= (@course.cost * 100).to_i %>"
        data-currency="GBP"
        ></script>

Post Status

Asked in February 2016
Viewed 1,377 times
Voted 10
Answered 1 times

Search




Leave an answer