测试条纹webhook时出现422错误

时间:2013-11-03 05:53:18

标签: ruby-on-rails webhooks

在为customer.subscription.deleted测试stripe的webhook时,我一直收到422错误

我把它放在我的配置路线

post 'stripewebhooks/receive'

这是我的控制器

class StripewebhooksController < ApplicationController

    Stripe::api_key = ENV['STRIPE_SECRET_KEY']

    require 'json'

    def receive

    data_json = JSON.parse request.body.read

    p data_json['data']['object']['customer']

    if data_json[:type] == "customer.subscription.deleted"
      cancel_subscription(data_event)
    end

  end

    def cancel_subscription(data_event)
    @subscription = Subscription.find_by_stripe_customer_token(data['data']['object']['customer'])
    @subscription.update_attribute(:subscription_status, "inactive")
  end
end

我不清楚

之后假设在括号中的内容
def cancel_subscription

我不确定我是想放置data_event还是这意味着什么。

1 个答案:

答案 0 :(得分:0)

从条带获取发布数据时,需要从应用程序返回200状态代码。

试试这个

def receive

    data_json = JSON.parse request.body.read

    p data_json['data']['object']['customer']

    if data_json[:type] == "customer.subscription.deleted"
      # Why did you send data_event? send the parsed data_json as parameter
      cancel_subscription(data_json)
    end

    # Return a 200 status code
    render :text => '{}', :status => :ok

end