每次我测试Stripe时都会给出错误:
Couldn't find Product with 'id'=@product.id
这是我的付款管理员:
class PaymentsController < ApplicationController
def create
@product = Product.find(params[:product_id])
@user = current_user
token = params[:stripeToken]
# Create the charge on Stripe's servers - this will charge the user's card
begin
charge = Stripe::Charge.create(
amount: product.price, # amount in cents, again
currency: "usd",
source: token,
description: params[:stripeEmail]
)
rescue Stripe::CardError => e
# The card has been declined
end
redirect_to product_path(@product), notice: "Payment processed successfully!"
end
end