2017-02-02 6 views
0

ストライプとルビーの新機能です。ストライプの支払いフローにアプリケーション料金を追加しようとしています。料金はすべて私のストライプアカウントに反映されていますが、ストライプアプリケーション料金コードを追加する方法と場所を把握できていないようです。ルビーのストライプ支払いには手数料を加算できません

料金/ new.html.erb

<%= form_tag charges_path do %> 
    <div id="error_explanation"> 
    <% if flash[:error].present? %> 
     <p><%= flash[:error] %></p> 
    <% end %> 
    </div> 
    <article> 
    <%= label_tag(:amount, 'Payment Amount:') %> 
    <%= text_field_tag(:amount) %> 
    </article> 
    <article> 
    <%= hidden_field_tag(:stripeToken) %> 
    </article> 
    <button id='donateButton'>Pay</button> 
<% end %> 

<script src="https://checkout.stripe.com/checkout.js"></script> 

<script> 


var handler = StripeCheckout.configure({ 
    key: '<%= Rails.configuration.stripe[:publishable_key] %>', 
    locale: 'auto', 
    name: 'Payments', 
    description: 'Pay Someone', 
    token: function(token) { 
    $('input#stripeToken').val(token.id); 
    $('form').submit(); 
    } 
}); 

$('#donateButton').on('click', function(e) { 
    e.preventDefault(); 

    $('#error_explanation').html(''); 

    var amount = $('input#amount').val(); 
    amount = amount.replace(/\$/g, '').replace(/\,/g, '') 

    amount = parseFloat(amount); 

    if (isNaN(amount)) { 
    $('#error_explanation').html('<p>Please enter a valid amount in CAD ($).</p>'); 
    } 
    else if (amount < 5.00) { 
    $('#error_explanation').html('<p>Wage amount must be at least $5.</p>'); 
    } 
    else { 
    amount = amount * 100; // Needs to be an integer! 
    handler.open({ 
     amount: Math.round(amount) 
    }) 
    } 
}); 

// Close Checkout on page navigation 
$(window).on('popstate', function() { 
    handler.close(); 
}); 
</script> 

charges_controller.rb

class ChargesController < ApplicationController 

def new 
end 

def create 
    @amount = params[:amount] 

    @amount = @amount.gsub('$', '').gsub(',', '') 

    begin 
    @amount = Float(@amount).round(2) 
    rescue 
    flash[:error] = 'Charge not completed. Please enter a valid amount in USD ($).' 
    redirect_to new_charge_path 
    return 
    end 

    @amount = (@amount * 100).to_i # Must be an integer! 

    if @amount < 500 
    flash[:error] = 'Charge not completed. Donation amount must be at least $5.' 
    redirect_to new_charge_path 
    return 
    end 

    Stripe::Charge.create(
    :amount => @amount, 
    :currency => 'usd', 
    :source => params[:stripeToken], 
    :description => 'Custom donation' 
) 

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

私が述べてきたように、支払いフローが正常に動作し、ストライプのドキュメントは、それが数でなければならないと言いますが、それが可能ならば、私はパーセンテージを好むだろう。これは例で与えられたコードです:

# See your keys here: https://dashboard.stripe.com/account/apikeys 
Stripe.api_key = "secret key" 

# Get the credit card details submitted by the form 
token = params[:stripeToken] 

# Create the charge with Stripe 
charge = Stripe::Charge.create({ 
    :amount => 1000, # amount in cents 
    :currency => "cad", 
    :source => token, 
    :description => "Example charge", 
    :application_fee => 123 # amount in cents 
    }, 
    {:stripe_account => CONNECTED_STRIPE_ACCOUNT_ID} 
) 

私はちょうどどこでどのようにアプリケーション料金コードを追加するのか知りません!私の支払いフローは、ユーザーが自分の支払い額を入力できるという点で機能しています。ここでは答えが見つからないようです。私はそのシンプルなソリューションだと確信していますが、私はStripeを使って作業するのがとても新しいです。

答えて

1

Connectと電荷を作成する場合にのみ、directly on a connected accountStripe-Accountヘッダを有する)またはthrough the platformdestinationパラメータを使用して)のいずれかをapplication_feeを指定することができます。

あなたのコードからは、Connectをまったく使用していないようですので、アプリケーション料金はかかりません。正確に何をしようとしているのかを明確にすることはできますか?料金からの資金をどのように分割すべきですか?

+0

はい、私はまだストライプコネクトを使用していなかったことに気付きませんでした。私はconnectを使い始めましたし、別の初心者の問題を抱えています。おそらくあなたは答えを知っていますか?あなたのhelp.http://stackoverflow.com/q/42045316/5644106ありがとう – ChrisJC2017

関連する問題