0
我正在設置我的應用程序條紋,我有一個可怕的時間哈。 我終於意識到我的令牌返回零。 我日誌中的錯誤是如何獲取條紋標記?
Parameters: {"utf8"=>"✓", "authenticity_token"=>"RqCVc9YMVLA4pQ1DkOyfw4c0+1Fvohq/TLCxkBl/dQJLKOdvdutHv65A6xU7c2m/f262JhP2h5knhSAcZoz6/w==", "order"=>{"address"=>"", "city"=>"", "state"=>""}, "listing_id"=>"1"}
User Load (9.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 4], ["LIMIT", 1]]
Listing Load (11.4ms) SELECT "listings".* FROM "listings" WHERE "listings"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
TOKEN IS:
Completed 500 Internal Server Error in 1474ms (ActiveRecord: 22.8ms)
我已經打印出來我的令牌,該令牌將返回零。這反過來又給了我一個必須提供來源或客戶。錯誤。我的heroku日誌說同樣的事情。我的應用程序是在這裏(https://abound.herokuapp.com/listings/16/orders/new)
def create
@order = Order.new(order_params)
@listing = Listing.find(params[:listing_id])
@seller = @listing.user
@order.listing_id = @listing.id
@order.buyer_id = current_user.id
@order.seller_id = @seller.id
require "stripe"
Stripe.api_key = ENV["STRIPE_API_KEY"]
token = params[:stripeToken]
logger.debug "TOKEN IS: #{token}"
begin
>>ERROR charge = Stripe::Charge.create(
:amount => (@listing.price * 100).floor,
:currency => "usd",
:source => token,
)
flash[:notice] = "Thanks for ordering!"
rescue Stripe::CardError => e
flash[:danger] = e.message
end
respond_to do |format|
if @order.save
format.html { redirect_to root_url, notice: "Thanks for ordering!" }
format.json { render action: 'show', status: :created, location: @order }
else
format.html { render action: 'new' }
format.json { render json: @order.errors, status: :unprocessable_entity }
end
end
end
文檔說的格式應該是
require "stripe"
Stripe.api_key = "sk_test_wCVovzzFUCYefEcIDpnCzcNq"
Stripe::Charge.create(
:amount => 2000,
:currency => "usd",
:source => "tok_1A4KM1LAntdwOYiPJCq8tGRn", # obtained with Stripe.js
:description => "Charge for [email protected]"
)
你怎麼得到令牌?通常,這是通過AJAX調用完成的,然後在來自Stripe的響應返回時作爲表單的一部分提交。 – ellitt
您使用的是條紋簽出嗎?我無法檢查您的網站,因爲它需要登錄/註冊... – Jeremie
@ellitt這是我如何驗證帳戶信息。我會更多地關注AJAX。 – user7811328