0
我已將條形支付集成到我的應用程序中。它的配置方式使得用戶可以在銷釘型號上輸入他們想要銷售的商品的價格作爲小數。當價格在表單中輸入時,它在視圖中顯示爲美元金額。但是,當您選擇該項目的立即購買按鈕並且條紋付款模式彈出時,它會以美分顯示價格(即,我輸入「10.0」並提交,因此它顯示「價格$:10.0,但是當我選擇立即購買Stripe將其解釋爲美分,並在條形支付模式中顯示「Pay $ .10」。)條紋支付金額
我想過如何將用戶的輸入價格更改爲美分,Stripe可以更好地解釋它,但這會導致糟糕的用戶界面。
是否有任何簡單的方法來解決這一問題使得所顯示的量是用於輸入和輸出均勻的?
應用/視圖/針/
<%= 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>
應用/數據庫/遷移
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