2

我一直在努力让我的 webhook 工作。我已经尝试了创建控制器和发布路由以及使用条带事件 gem 的两种方法。两者都让我失望了。

有人可以帮助我做错什么。

这是我的 webhook 控制器

class StripewebhooksController < ApplicationController
    # Set your secret key: remember to change this to your live secret key in production
    # See your keys here https://manage.stripe.com/account
    Stripe.api_key = "mystripe api 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_json)
    end

     if data_json[:type] == "invoice.payment_succeeded"
      invoice_subscription(data_json)
    end

    end

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

  def invoice_subscription(data_json)
    @subscription = Subscription.find_by_stripe_customer_token(data_json['data']['object']['customer'])
    InvoiceMailer.invoice_subscription(@subscription).deliver
  end
end

我在我的路线文件中有这个并且已经倾斜了路线并验证了发布路线在那里。

post 'stripewebhooks/receive'

条纹一直给我一个 422 错误。

4

0 回答 0