条纹和红宝石的新手。试图在我的条带支付流程中添加申请费。这些费用都是通过我的条带帐户进行的,但我似乎无法弄清楚如何/在何处添加条带应用程序费用代码。
充电/ new.html.erb
double factor(int width, int height, int a, int b){
double factorX = (double) Math.min(a, width - a) / width * 2;
double factorY = (double) Math.min(b, height - b) / height * 2;
return Math.min(factorX, factorY);
}
charges_controller.rb
<%= 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>
正如我所提到的,支付流程运行正常,Stripe docs说它必须是一个数字,但如果可能的话我会更喜欢百分比。这是示例中给出的代码:
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
我只是不知道在哪里或如何添加申请费代码!我的付款流程的工作原理是用户可以输入自己的付款金额,我似乎无法在此处或反映该表格中的代码的文档中找到任何答案。我确信它是一个简单的解决方案,但我对使用Stripe非常新。
答案 0 :(得分:1)
使用application_fee
创建费用时,您只能指定Connect,directly on a connected account(带Stripe-Account
标头)或through the platform(带{ {3}}参数)。
从您的代码来看,它看起来并不像您正在使用Connect,因此申请费用将不适用。你能澄清一下你究竟想做什么吗?如何分摊费用?