ドキュメントその他の Stripe の支払い

03 · 売上

残りの Stripe の決済を紐づける

Stripe の決済がすべてチェックアウトから始まるわけではありません。種類ごとに、訪問者 ID を載せられる場所か、照合に使えるメールアドレスがあります。

01自分で作成する PaymentIntent

Payment Element や、サーバーで PaymentIntent を作成するあらゆるフローでは、PaymentIntent のメタデータに訪問者 ID を入れます。

Node.js
// Where your server creates the PaymentIntent (the Payment Element, Elements).
const visitorId = req.cookies['_tally_vid'];
const paymentIntent = await stripe.paymentIntents.create({
  amount: 4900,
  currency: 'usd',
  automatic_payment_methods: { enabled: true },
  metadata: visitorId ? { 'tally_visitor_id': visitorId } : {},
});

02自分で作成するサブスクリプション

API で作成したサブスクリプションはメタデータをすべての請求書に引き継ぐため、初回決済にも各更新にも ID が付きます。

Node.js
// A subscription your server creates: its invoices carry its metadata.
const visitorId = req.cookies['_tally_vid'];
const subscription = await stripe.subscriptions.create({
  customer: customerId,
  items: [{ price: 'price_123' }],
  metadata: visitorId ? { 'tally_visitor_id': visitorId } : {},
});

03顧客に保存する

顧客のメタデータも読み取るため、顧客に保存した ID は、請求書を含むその顧客のすべての決済に届きます。

Node.js
// When you create the customer (or later, with stripe.customers.update).
const visitorId = req.cookies['_tally_vid'];
const customer = await stripe.customers.create({
  email: user.email,
  metadata: visitorId ? { 'tally_visitor_id': visitorId } : {},
});

04請求書と手動の請求

手動で送る請求書や Stripe のダッシュボードで作成した請求には、ID を運ぶチェックアウトがありません。顧客がログインしたら(または完了ページで)、支払いに使うメールアドレスで identify してください。顧客のメールアドレスが一致した決済が紐づきます(確度:中)。メールアドレスは受信時にハッシュ化され、保持されるのはハッシュだけです。

JavaScript
// Once the customer is signed in (or on your success page), with the email they pay with.
// It is hashed when it arrives; only the hash is kept.
window.tally = window.tally || function () { (tally.q = tally.q || []).push(arguments); };
tally('identify', { email: user.email });

05更新、アップグレード、返金

これらは自動で引き継がれます。更新やアップグレードはサブスクリプションの初回決済と同じように、返金やチャージバックは取り消す対象の決済と同じように、同じ確度で紐づきます。

06うまくいったか確認する

足りない情報や、実際の画面と違う点はありませんか? どのページかを添えて support@tallybyoutpost.com までお知らせください。