亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

#<Stripe::Customer:0x00007f1ac4d0b548> 的未定義方法

#<Stripe::Customer:0x00007f1ac4d0b548> 的未定義方法

心有法竹 2023-11-02 19:59:13
使用 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
查看完整描述

1 回答

?
慕神8447489

TA貢獻1780條經驗 獲得超1個贊

創建訂閱的方法有多種,如果我記得的話,那是一種較舊的方法,但現在您可以 - 并且應該 -像這樣創建它:

Stripe::Subscription.create({

? customer: customer.id,

? items: [

? ? {price: plan.id},

? ],

})


查看完整回答
反對 回復 2023-11-02
  • 1 回答
  • 0 關注
  • 110 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號