我想知道成功結帳后如何向用戶發送電子郵件
我的Webhook控制器:
class WebhooksController < ApplicationController
skip_before_action :verify_authenticity_token
def create
payload = request.body.read
sig_header = request.env['HTTP_STRIPE_SIGNATURE']
event = nil
begin
event = Stripe::Webhook.construct_event(
payload, sig_header, Rails.application.credentials[:stripe][:webhook]
)
rescue JSON::ParserError => e
status 400
return
rescue Stripe::SignatureVerificationError => e
# Invalid signature
puts "Signature error"
return
end
# Handle the event
case event.type
when 'checkout.session.completed'
session = event.data.object
session_with_expand = Stripe::Checkout::Session.retrieve({id: session.id, expand: ["line_items"] })
session_with_expand.line_items.data.each do |line_item|
product = Product.find_by(stripe_product_id: line_item.price.product)
product.increment!(:sales_count)
end
end
render json: { message: 'success' }
end
end
uj5u.com熱心網友回復:
如果您使用 Ruby SDK 創建付款意圖,您可以添加收據_email 欄位以添加客戶電子郵件。(請參閱Stripe PaymentIntent 檔案)
Stripe.api_key = 'API_KEY'
intent = Stripe::PaymentIntent.create({
amount: 1099,
currency: 'cad',
payment_method_types: ['card'],
receipt_email: '[email protected]',
})
如果您正在創建結帳會話服務器端,您可以根據Stripe Checkout Docs預先配置結帳頁面的屬性/設定
require 'stripe'
Stripe.api_key ='API_KEY'
Stripe::Checkout::Session.create({
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
customer_email:'email',
line_items: [
{price: 'price_H5ggYwtDq4fbrJ', quantity: 2},
],
mode: 'payment',
})
這是每個 Stripe 檔案關于客戶電子郵件欄位的注釋:
如果提供,則在創建 Customer 物件時將使用此值。如果未提供,客戶將被要求輸入他們的電子郵件地址。如果您已存檔電子郵件,請使用此引數預填充客戶資料。要在會話完成后訪問有關客戶的資訊,請使用客戶欄位。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/495315.html
上一篇:無樹最寬路徑的Ruby演算法
下一篇:無法使用設計從一頁重定向到另一頁
