在为 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 或这意味着什么。