Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 422测试条带webhook时出错_Ruby On Rails_Webhooks - Fatal编程技术网

Ruby on rails 422测试条带webhook时出错

Ruby on rails 422测试条带webhook时出错,ruby-on-rails,webhooks,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 rec

在为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

我不确定我是否应该将数据放入事件或这意味着什么

当您从stripe获取post数据时,需要从应用程序返回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

不,那不行吗?仍然得到这个错误422不可处理的实体尝试读取在博客文章中,我认为我的authenticy令牌弄乱了允许webhook工作。我现在在heroku日志中发现此错误JSON::ParserError JSON文本必须至少包含两个八位字节!:有没有办法解决这个问题?
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