使用 Stripe API 提交卡詳細信息后,我不斷遇到這兩個錯誤,然后應用程序應該創建一個新的訂閱者并將它們重定向到庫,但我卻得到:#Stripe::Customer:0x00007f1ac4d0b548 的未定義方法“訂閱”和找不到 SubscriptionsController 的操作“index”我總是先遇到第一個錯誤,然后當我刷新頁面時,它會更改為第二個錯誤。這是我的訂閱控制器(/app/controllers/subscriptions_controller.rb): class SubscriptionsController < ApplicationController layout "subscribe" before_action :authenticate_user!, except: [:new, :create] def new if user_signed_in? && current_user.subscribed? redirect_to root_path, notice: "You are already a subscriber!" end end def create Stripe.api_key = Rails.application.credentials.stripe_api_key plan_id = params[:plan_id] plan = Stripe::Plan.retrieve(plan_id) token = params[:stripeToken] customer = if current_user.stripe_id? Stripe::Customer.retrieve(current_user.stripe_id) else Stripe::Customer.create(email: current_user.email, source: token) end subscription = customer.subscriptions.create(plan: plan.id) options = { stripe_id: customer.id, stripe_subscription_id: subscription.id, subscribed: true, } options.merge!( card_last4: params[:user][:card_last4], card_exp_month: params[:user][:card_exp_month], card_exp_year: params[:user][:card_exp_year], card_type: params[:user][:card_type] ) if params[:user][:card_last4] current_user.update(options) redirect_to root_path, notice: "Your subscription was set up successfully!" end def destroy customer = Stripe::Customer.retrieve(current_user.stripe_id) customer.subscriptions.retrieve(current_user.stripe_subscription_id).delete current_user.update(stripe_subscription_id: nil) redirect_to root_path, notice: "Your subscription has been cancelled." endend
#<Stripe::Customer:0x00007f1ac4d0b548> 的未定義方法
心有法竹
2023-11-02 19:59:13