[英]uninitialized constant ChargesController::CONNECTED_STRIPE_ACCOUNT_ID
我在我的應用程序中使用Stripe Connect Standalone。 到目前為止,用戶可以成功連接其帶區帳戶,並且付款已進入我的帶區帳戶。 問題是我需要用戶能夠互相付款,並且我保留了申請費。
目前,所有付款都只進入我的(平台)帳戶,無需支付任何申請費,最終用戶也不會收到任何款項。 搜索解決方案后,我向我的收費控制器添加了一個數據條頭,並使用了Stripes文檔中顯示的charge方法。 提交信用卡表格后,我會收到以下錯誤消息:
未初始化的常量ChargesController :: CONNECTED_STRIPE_ACCOUNT_ID
這是對我的費用控制器中的這一行的回應:
Stripe::Account.retrieve(CONNECTED_STRIPE_ACCOUNT_ID)
這是我的charges_controller.rb:
class ChargesController < ApplicationController
def new
end
def create
Stripe.api_key = "sk_test_1q2w3e4r5t6y...."
Stripe::Account.retrieve(CONNECTED_STRIPE_ACCOUNT_ID)
token = params[:stripeToken]
# Create a customer
Stripe::Customer.create(
{:description => "example@stripe.com"},
{:stripe_account => CONNECTED_STRIPE_ACCOUNT_ID}
)
# Create a Charge:
charge = Stripe::Charge.create({
:amount => 1000,
:currency => "cad",
:source => token,
:application_fee => 200 # amount in cents
}, :stripe_account => "{CONNECTED_STRIPE_ACCOUNT_ID}")
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to new_charge_path
end
end
初始值設定項/stripe.rb
Rails.configuration.stripe = {
:publishable_key => ENV['PUBLISHABLE_KEY'],
:secret_key => ENV['STRIPE_SECRET_KEY'],
:stripe_account => ENV['CONNECTED_STRIPE_ACCOUNT_ID']
}
Stripe.api_key = Rails.configuration.stripe[:secret_key]
application.yml
development:
PUBLISHABLE_KEY: pk_test_###########
STRIPE_SECRET_KEY: sk_test_##########
STRIPE_CLIENT_ID: ca_###########
Charges / new.html.erb
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<script type="text/javascript">
Stripe.setPublishableKey('pk_test_###############');
$(function() {
var $form = $('#payment-form');
$form.submit(function(event) {
// Disable the submit button to prevent repeated clicks:
$form.find('.submit').prop('disabled', true);
// Request a token from Stripe:
Stripe.card.createToken($form, stripeResponseHandler);
// Prevent the form from being submitted:
return false;
});
});
function stripeResponseHandler(status, response) {
// Grab the form:
var $form = $('#payment-form');
if (response.error) { // Problem!
// Show the errors on the form:
$form.find('.payment-errors').text(response.error.message);
$form.find('.submit').prop('disabled', false); // Re-enable submission
} else { // Token was created!
// Get the token ID:
var token = response.id;
// Insert the token ID into the form so it gets submitted to the server:
$form.append($('<input type="hidden" name="stripeToken">').val(token));
// Submit the form:
$form.get(0).submit();
}
};
</script>
<%= form_tag charges_path, :id => 'payment-form' do %>
<article>
<% if flash[:error].present? %>
<div id="error_explanation">
<p><%= flash[:error] %></p>
</div>
<% end %>
<label class="amount">
<span>Amount: $10.00</span>
</label>
</article>
<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="1000"
data-locale="auto"></script>
<% end %>
我是Stripe Connect的新手,並且在該部件上停留了一段時間。 快把我逼瘋。 我在用戶個人資料上有一個“立即付款”按鈕,該按鈕應允許“用戶A”向“用戶B”付款,同時向我發送申請費。 如何解決此錯誤? 這是我付款流程中的主要問題嗎(允許用戶通過個人資料中的按鈕互相付款)?
更新:
CONNECTED_STRIPE_ACCOUNT_ID尚未初始化,因為必須將其替換為已連接的用戶stripe_user_id。 在我的數據庫中,將其另存為“ uid”。 因此,現在的問題是將其調用到我的應用程序中。
更新2:
當用戶連接時,他們的可發布密鑰和帶區用戶ID(我的數據庫中的uid)將保存到我的數據庫中。 看起來像這樣:
名稱:“ Testguy”,publishable_key:“ pk_test_6IgEWlj4y ##########”,提供者:“ stripe_connect”,uid:“ acct_19l9 ##########”,訪問代碼:“ sk_test_vldP ### ######“>]
現在,如何在應用程序中調用他們的用戶ID?
Stripe::Account.retrieve(UID)
獲取未初始化的錯誤
未初始化的常量ChargesController :: UID
您需要用已連接帳戶的ID替換CONNECTED_STRIPE_ACCOUNT_ID
。 帳戶ID是以"acct_"
開頭的字符串,后跟隨機的字母數字字符。
當一個帳戶使用OAuth流連接到平台的帳戶時,您將在流的最后一步 ,在stripe_user_id
字段中獲得其帳戶ID。 然后,您應該將此ID保存在數據庫中。
然后,您可以使用Stripe-Account
標頭使用該ID代表該帳戶處理費用或發出任何API請求。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.