Ruby on rails 更新条带订阅支付卡详细信息

Ruby on rails 更新条带订阅支付卡详细信息,ruby-on-rails,rubygems,stripe-payments,Ruby On Rails,Rubygems,Stripe Payments,我使用的是ruby 2.4.0p0(2016-12-24修订版57164)[x86_64-linux],Rails 5.2.4.4和stripe 5.26.0 我已经创建了条带订阅 customer = if current_user.stripe_customer_id? Stripe::Customer.retrieve(current_user.stripe_customer_id) else

我使用的是ruby 2.4.0p0(2016-12-24修订版57164)[x86_64-linux],Rails 5.2.4.4和stripe 5.26.0
我已经创建了条带订阅

 customer = if current_user.stripe_customer_id?
                 Stripe::Customer.retrieve(current_user.stripe_customer_id)
               else
                 Stripe::Customer.create({
                                             :email => current_user.email,
                                             :source => params[:stripeToken],
                                             :description => "Tukaweb Stripe Subscriptions customer= #{current_user.email}"
                                         },
                                         {
                                             api_key: Rails.configuration.stripe[:secret_key]
                                         }
                 )
               end
    ## check if user have already took the subscription
    if current_user.subscriptions.where(payment_status: 'paid', software_package_id:  @subscription.software_package_id).empty?
      ## with trail period
      subscription = Stripe::Subscription.create({
                                                     customer: customer,
                                                     items: [
                                                         {price: 'price_1HVF68E9ijv19IzXdDVmKN5e'},
                                                     ],
                                                     trial_end: (Time.now + 1.month).to_i,
                                                 })
    else
      ## without trail period
      subscription = Stripe::Subscription.create({
                                                     customer: customer,
                                                     items: [
                                                         {price: 'price_1HVF68E9ijv19IzXdDVmKN5e'},
                                                     ],
                                                 })
    end

    current_user.update({
                            stripe_customer_id: customer.id
                        })
现在我想更新条带订阅卡的详细信息,但出现以下错误:

customer = Stripe::Customer.retrieve(current_user.stripe_customer_id)
stripe_subscription = SoftwareUser.find(params[:software_user_id])
subscription = customer.subscriptions.retrieve(stripe_subscription.stripe_subscription_id)
subscription.source = params[:stripeToken]
subscription.save
错误为:

Stripe::InvalidRequestError (Received unknown parameter: source):

您能建议如何更新订阅的卡详细信息吗。

这是失败的,因为订阅上没有源属性

在这种特殊情况下,您依赖的是这样一个事实,即创建订阅时,它将退回到使用客户的默认来源为订阅[1]提供资金,因为没有默认的付款方式。如果要更改支付订阅的来源,则必须更改客户的默认来源[2]

尽管如此,今天的建议根本不是使用源代码,而是使用Stripe.js和元素创建PaymentMethod[3]。将此付款方式附加到客户[4],然后在发票[5]、订阅[6]或客户[7]上将此付款方式设置为默认付款方式

此处更详细地概述了这些步骤[8]

[1]

[2]

[3]

[4]

[5]

[6]

[7]


[8]

因此,要创建支付方式,服务器需要有支付卡行业数据安全标准,因为创建支付方式,服务器应该有卡号和cvc,或者有一些js会给出目的。很抱歉,服务器端PaymentMethod创建的链接有点误导。要最大限度地减少PCI负担并确保以符合PCI的方式将卡详细信息安全地发送到Stripe,最好的方法是使用Stripe.js和元素标记卡详细信息,或使用Stripe Checkout收集PaymentMethod详细信息。这两种方法(与订阅相关)在这些指南中均有概述: