条纹订阅 - 服务器响应状态 400

ARTLoe

为什么我的条带订阅不起作用?我收到以下错误,但我无法解决问题。

当我在 Stripe 管理面板中创建付款时,我得到了 ID 参考。我目前使用表中的 ID 来匹配条带中的 ID。我不确定如何纠正这个问题。

payment = customer.subscriptions.create(
        source: params[:stripeToken],
        plan: @subscription
        # the subscription.id is the database id
        # the plan.id in stripe uses the same id as that of the subscription.id in the database in order to select the right subsciption in stripe
      )

终端错误:

Stripe::InvalidRequestError(此客户没有附加支付来源):服务器响应状态为 400

2018-06-09T16:27:10.457567+00:00 app[web.1]: Completed 500 Internal Server Error in 987ms
2018-06-09T16:27:10.459118+00:00 app[web.1]: 
2018-06-09T16:27:10.459122+00:00 app[web.1]: Stripe::InvalidRequestError (This customer has no attached payment source):
2018-06-09T16:27:10.459124+00:00 app[web.1]: app/controllers/payments_controller.rb:58:in `create'
2018-06-09T16:27:10.459125+00:00 app[web.1]: 
2018-06-09T16:27:10.459127+00:00 app[web.1]: 
2018-06-09T16:27:10.774887+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=www.spefz.com request_id=81e62211-2807-4dd3-a9bb-ea260afe0998 fwd="37.152.39.155" dyno=web.1 connect=0ms service=2ms status=200 bytes=202 protocol=https
2018-06-09T16:27:50.921236+00:00 app[api]: Starting process with command `bin/rails console` by user richill
2018-06-09T16:28:01.326416+00:00 heroku[run.7880]: Awaiting client
2018-06-09T16:28:01.346795+00:00 heroku[run.7880]: Starting process with command `bin/rails console`
2018-06-09T16:28:01.714175+00:00 heroku[run.7880]: State changed from starting to up

在此处输入图片说明

在我的条纹帐户中,我有这个:

在此处输入图片说明

Payments_controller.rb [在支付控制器中创建操作]

def create
    @payment = Payment.new(payment_params)
    @subscription_id = @payment.subscription_id
    @event_id = @payment.event_id

    # ------- PAYMENT_SUBSCRIPTION -------
    if @subscription_id.present?
      @user = current_user
      @payment = Payment.new(payment_params)
      @subscription = @payment.subscription_id
      @payment.user_id = current_user.id

      if current_user.stripe_id?
        customer = Stripe::Customer.retrieve(current_user.stripe_id)
      else
        customer = Stripe::Customer.create(email: current_user.email)
      end

      payment = customer.subscriptions.create(
        source: params[:stripeToken],
        plan: @subscription
        # the subscription.id is the database id
        # the plan.id in stripe uses the same id as that of the subscription.id in the database in order to select the right subsciption in stripe
      )

      current_user.update(
        stripe_id: customer.id,
        stripe_subscription_pymt_id: payment.id,
        card_last4: params[:card_last4],
        card_exp_month: params[:card_exp_month],
        card_exp_year: params[:card_exp_year],
        card_type: params[:card_brand],
        recent_subscription_pymt_date: DateTime.now,
        recent_subscription_cancel_date: nil
      )


      # if payment is true/successful save the below params under payments table
      if payment.present?
        @payment.update(
          stripe_customer_id: customer.id,
          stripe_subscription_id: payment.id,
          stripe_payment_id: "none",
          subscription_payment_date: DateTime.now,
          event_payment_date: "none",
          event_payment_date_status: "none",
          user_card_type: params[:card_brand],
          user_card_last4: params[:card_last4],
          user_card_exp_month: params[:card_exp_month],
          user_card_exp_year:params[:card_exp_year],
          status: "success"
        )
      else
        @payment.update(
          stripe_customer_id: customer.id,
          stripe_subscription_id: payment.id,
          stripe_payment_id: "none",
          subscription_payment_date: DateTime.now,
          event_payment_date: "none",
          user_card_type: params[:card_brand],
          user_card_last4: params[:card_last4],
          user_card_exp_month: params[:card_exp_month],
          user_card_exp_year:params[:card_exp_year],
          status: "fail"
        )
      end

      respond_to do |format|
        if @payment.save
          MailerPaymentuserreceipt.paymentreceipt(@payment).deliver
          format.html { redirect_to account_user_path(current_user), notice: 'Your Subscription Payment was successful.' }
          format.json { render :show, status: :created, location: @payment }
        else
          format.html { redirect_to new_payment_path(subscription_id: @subscription.id), alert: 'Ensure all fields are completed'}
          format.json { render json: @payment.errors, status: :unprocessable_entity }
        end
      end

    end
  end

架构 [架构中的付款表]

create_table "payments", force: :cascade do |t|
    t.string   "email"
    t.integer  "user_id"
    t.integer  "subscription_id"
    t.string   "reference"
    t.datetime "created_at",                       null: false
    t.datetime "updated_at",                       null: false
    t.integer  "event_id"
    t.string   "stripe_customer_id"
    t.string   "stripe_subscription_id"
    t.string   "stripe_payment_id"
    t.datetime "subscription_payment_date"
    t.datetime "event_payment_date"
    t.string   "user_card_type"
    t.string   "user_card_last4"
    t.integer  "user_card_exp_month"
    t.integer  "user_card_exp_year"
    t.string   "status"
    t.string   "event_payment_date_status"
    t.string   "subscription_payment_date_status"
  end
山库尔卡尼

要在条带上创建订阅,必须传递客户 ID。虽然来源是可选的,但它用于为该客户添加支付来源(卡)。并且还尝试在添加创建订阅时传递项目

例子:

Stripe::Subscription.create(
  :customer => "cus_D1nB01mz17dzfM",
  :items => [
    {
      :plan => "plan_D1keP6TJp3tjTA",
    },
  ]
)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Google adsense响应服务器的状态为400()

来自分类Dev

Google adsense响应服务器的状态为400()

来自分类Dev

无法加载资源:服务器在Angular + NodeJS上以400(错误请求)的状态响应

来自分类Dev

服务器返回状态码400时,使用Powershell检索响应内容

来自分类Dev

angularjs:加载资源失败:服务器响应状态为 400(错误请求)

来自分类Dev

Flask & AJAX:加载资源失败:服务器响应状态为 400(BAD REQUEST)

来自分类Dev

PHP 表单:服务器响应状态为 400(错误请求)

来自分类Dev

Azure 文件存储服务器以 400 状态响应(不支持条件标头。)

来自分类Dev

如果节点服务器发送状态 400,则获取 axios 响应

来自分类Dev

条纹-使用其他订阅欺骗我的服务器

来自分类Dev

服务器返回 HTTP 响应代码:openConnection() 后 400

来自分类Dev

条纹订阅

来自分类Dev

条纹订阅

来自分类Dev

WCF IIS服务文件流式传输远程服务器返回意外响应:(400)错误的请求。

来自分类Dev

AS400在线服务器练习

来自分类Dev

java.io.IOException:服务器返回的HTTP响应代码:URL的400

来自分类Dev

将XElement传递给Webservice。远程服务器返回意外响应:(400)错误的WebService请求

来自分类Dev

远程服务器返回了意外的响应:(400)错误的请求WCF REST

来自分类Dev

服务器返回URL的HTTP响应代码:400:java.io.IOException

来自分类Dev

服务器未返回状态代码为400(.net)的JSON

来自分类Dev

远程服务器返回错误 (400) Bad Request,状态为 ProtocolError

来自分类Dev

条纹收费和订阅

来自分类Dev

条纹PHP订阅Webhook

来自分类Dev

条纹订阅事件Django

来自分类Dev

条纹。每月订阅

来自分类Dev

Redhat订阅服务器

来自分类Dev

WCF IIS服务文件流式传输远程服务器返回了意外的响应:(400)错误的请求。

来自分类Dev

Azure ServiceBus订阅客户端<->服务器通信(接收和响应)

来自分类Dev

条纹,取消订阅Ruby on Rails

Related 相关文章

  1. 1

    Google adsense响应服务器的状态为400()

  2. 2

    Google adsense响应服务器的状态为400()

  3. 3

    无法加载资源:服务器在Angular + NodeJS上以400(错误请求)的状态响应

  4. 4

    服务器返回状态码400时,使用Powershell检索响应内容

  5. 5

    angularjs:加载资源失败:服务器响应状态为 400(错误请求)

  6. 6

    Flask & AJAX:加载资源失败:服务器响应状态为 400(BAD REQUEST)

  7. 7

    PHP 表单:服务器响应状态为 400(错误请求)

  8. 8

    Azure 文件存储服务器以 400 状态响应(不支持条件标头。)

  9. 9

    如果节点服务器发送状态 400,则获取 axios 响应

  10. 10

    条纹-使用其他订阅欺骗我的服务器

  11. 11

    服务器返回 HTTP 响应代码:openConnection() 后 400

  12. 12

    条纹订阅

  13. 13

    条纹订阅

  14. 14

    WCF IIS服务文件流式传输远程服务器返回意外响应:(400)错误的请求。

  15. 15

    AS400在线服务器练习

  16. 16

    java.io.IOException:服务器返回的HTTP响应代码:URL的400

  17. 17

    将XElement传递给Webservice。远程服务器返回意外响应:(400)错误的WebService请求

  18. 18

    远程服务器返回了意外的响应:(400)错误的请求WCF REST

  19. 19

    服务器返回URL的HTTP响应代码:400:java.io.IOException

  20. 20

    服务器未返回状态代码为400(.net)的JSON

  21. 21

    远程服务器返回错误 (400) Bad Request,状态为 ProtocolError

  22. 22

    条纹收费和订阅

  23. 23

    条纹PHP订阅Webhook

  24. 24

    条纹订阅事件Django

  25. 25

    条纹。每月订阅

  26. 26

    Redhat订阅服务器

  27. 27

    WCF IIS服务文件流式传输远程服务器返回了意外的响应:(400)错误的请求。

  28. 28

    Azure ServiceBus订阅客户端<->服务器通信(接收和响应)

  29. 29

    条纹,取消订阅Ruby on Rails

热门标签

归档