条纹webhook无法使用rails 4 app

时间:2013-11-03 20:32:09

标签: ruby-on-rails webhooks

我一直在努力让我的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

我在我的路线文件中有这个并且有raked路线并且验证了后路线在那里。

post 'stripewebhooks/receive'

stripe一直给我一个422错误。

0 个答案:

没有答案