我一直在試圖設置我的條紋第一webhook。我發現了一個article,看起來像是正確的做法,但2歲。我認爲它已經過時了。用於導軌的條紋webhooks 4
這是我的控制器到目前爲止。
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 = "mytestapikey"
require 'json'
post '/stripewebhooks' do
data = JSON.parse request.body.read, :symbolize_names => true
p data
puts "Received event with ID: #{data[:id]} Type: #{data[:type]}"
# Retrieving the event from the Stripe API guarantees its authenticity
event = Stripe::Event.retrieve(data[:id])
# This will send receipts on succesful invoices
# You could also send emails on all charge.succeeded events
if event.type == 'invoice.payment_succeeded'
email_invoice_receipt(event.data.object)
end
end
end
這會正常工作,這是正確的方法嗎?這裏是條紋documentation。
驗證的最佳方式是運行代碼並親自查看:) – rb512