2

私はWebhookを機能させるために一生懸命努力してきました。コントローラーとポストルートを作成する方法と、ストライプイベントジェムを使用する方法の両方を試しました。どちらも私に失敗しました。

誰かが私が間違っていることを手伝ってくれますか?

これが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