私は自分のアプリケーションにストライプ支払いを統合しました。これは、ユーザーがピンモデルで小数点として販売したいアイテムの価格を入力できるように構成されています。フォームに価格を入力すると、ビューにドル金額として表示されます。ただし、そのアイテムの[今すぐ購入]ボタンを選択すると、ストライプ支払いモーダルのポップアップが表示されます(つまり、「10.0」を入力して送信すると「Price $:10.0」と表示されますが、ストライプはそれをセントとして解釈し、ストライプペイメントモーダルで「Pay $ .10」と表示します)。ストライプ支払い金額
ストライプがそれをよりよく解釈できるように入力コストをセントに変更することを考えましたが、 。
表示量は、入力と出力の両方に均一になるように、この問題を解決するための任意の簡単な方法はありますか?
アプリ/ビュー/ピン/
<%= form_tag charges_path, id: 'chargesForm' do %>
<script src="https://checkout.stripe.com/checkout.js"></script>
<%= hidden_field_tag 'stripeToken' %>
<%= hidden_field_tag 'stripeEmail' %>
<button id="btn-buy" type="button" class="btn btn-success btn-lg btn-block"><span class="glyphicon glyphicon-heart"></span> Buy Now!</button>
<script>
var handler = StripeCheckout.configure({
key: '<%= Rails.configuration.stripe[:publishable_key] %>',
token: function(token, arg) {
document.getElementById("stripeToken").value = token.id;
document.getElementById("stripeEmail").value = token.email;
document.getElementById("chargesForm").submit();
}
});
document.getElementById('btn-buy').addEventListener('click', function(e) {
handler.open({
name: <%= @pin.manufacturer %>',
description: '<%= @pin.description %>',
amount: '<%= @pin.price %>'
});
e.preventDefault();
})
</script>
<% end %>
アプリ/ビュー/ピン/ index.html.erb
<div id="pins" class="transitions-enabled">
<% @pins.each do |pin| %>
<div class="box panel panel-default">
<div class="panel-body">
<%= link_to (image_tag pin.image.url(:medium)), pin %>
<p></p>
<strong>Manufacturer:</strong>
<%= pin.manufacturer %>
<p></p>
<strong>Price:</strong>
<%= pin.price %>
<p></p>
<strong>Description:</strong>
<%= pin.description %>
<% if pin.is_multi? %>
<strong>Quantity:</strong>
<%= pin.quantity %>
<% end %>
<p></p>
アプリ/ DB /移行
class AddPriceToPins < ActiveRecord::Migration
def change
add_column :pins, :price, :decimal
end
end
ピン/コントローラ
class PinsController < ApplicationController
before_action :set_pin, only: [:show, :edit, :update, :destroy, :bid]
before_action :correct_user, only: [:edit, :update, :destroy]
before_action :authenticate_user!, except: [:index, :show]
def index
@pins = Pin.all.order("created_at DESC").paginate(:page => params[:page], :per_page => 9)
end
def pin_params
params.require(:pin).permit(:description, :price, :image, :image2, :image3, :image4, :image5, :manufacturer, :model)
end
end