代理須知
Tap App Link + Stripe
您是一名編碼助理,幫助開發人員將 Tap App Link(創作者儀表板、追蹤安裝連結和應用程式折扣代碼)與 Stripe 整合。 Tap App Link 透過 SDK 匹配安裝客戶端,並透過 Stripe Webhook 在伺服器端分配購買收入。 當觀看者在結帳時輸入代碼時,促銷代碼是第二個歸因路徑。
1.安裝並配置Tap App Link SDK
如果專案缺少 SDK,請為目標平台新增它,然後在啟動時呼叫一次配置。 在測試建置中使用沙箱密鑰和環境,在商店建置中使用生產環境。
- React Native / Expo (development client; Expo Go cannot load Play Install Referrer): install @Tap App Link/react-native@^0.3.3 and the optional peer @react-native-async-storage/async-storage (yarn add, npm install, or npx expo install). Without AsyncStorage, each cold launch posts again.
- iOS: Swift Package https://github.com/tapapplink/tapapplink-ios from "0.3.3"
- Android: implementation("com.github.Tap App Link:Tap App Link-android:0.3.3")
- Flutter: Tap App Link: ^0.3.3
在每個平台上使用 SDK 0.3.3 或更高版本。
yarn add @tapapplink/react-native@^0.3.3 @react-native-async-storage/async-storage
# or: npm install @tapapplink/react-native@^0.3.3 @react-native-async-storage/async-storage
# or: npx expo install @tapapplink/react-native@^0.3.3 @react-native-async-storage/async-storageimport { TapAppLink } from "@tapapplink/react-native";
TapAppLink.configure({
publicKey: "YOUR_TAPAPPLINK_KEY",
environment: __DEV__ ? "sandbox" : "production",
});
await TapAppLink.trackInstall();
// Same id you put on Stripe subscription_data.metadata.app_user_id
await TapAppLink.setAppUserId(currentUser.id);
const offer = TapAppLink.getOffer();
// Present your Stripe Checkout / paywall. Creator codes sync as promotion codes.2. 追蹤安裝,然後橋接 Stripe 用戶 ID
trackInstall()每次從 SDK 0.3.0 或更高版本啟動時都可以安全地呼叫(React Native 也需要@react-native-async-storage/async-storage安裝)。 之後立即致電setAppUserId()使用 webhook 上的 id。 該橋將 Webhook 事件附加到驅動安裝的創作者。
subscription_data.metadata.app_user_id / setAppUserId
- 在訂閱上設定metadata.app_user_id(例如Checkout中的subscription_data.metadata),以便它到達發票。 將相同的 ID 傳遞給應用程式中的 setAppUserId(),以便網路和應用程式購買結合。
- Tap App Link 也從發票元資料、訂閱元資料和第一個行項目讀取 app_user_id / appUserId / tal_app_user_id。 如果缺少這些,它將使用 Stripe 客戶 ID (cus_…)。 僅當沒有客戶 ID 時才使用電子郵件。
- 當存在促銷代碼或 tap_creator_code 元資料時,網路上的創作者歸因不需要開啟應用程式。
// Checkout Session (subscription)
const session = await stripe.checkout.sessions.create({
mode: "subscription",
// Optional: keep for your own records. Invoice webhooks do not receive this field.
// client_reference_id: buyerId,
subscription_data: {
metadata: {
app_user_id: buyerId, // same id you pass to TapAppLink.setAppUserId()
tap_creator_code: creatorCode, // optional when a promotion code is applied
},
},
// ...
});3. 電匯折扣碼
一場比賽結束後,getOffer()返回創作者的折扣。 如果使用者在應用程式中輸入代碼,請調用applyCode()所以他們仍然歸因於那個創造者。
await TapAppLink.applyCode("SARAH10");
const offer = TapAppLink.getOffer();連接 Stripe 时,创作者折扣代码会同步为 Stripe 促销代码。 買家可以在結帳時兌換它們。 元数据键 tal_code 和 tap_creator_code 也归功于創作者。
完整產品指南: https://tapapplink.com/docs/concepts/promo-codes/
4. 配置 Stripe webhook
人類點擊路徑: https://tapapplink.com/docs/integrations/stripe/。 請依照這些儀表板步驟操作。 概括:
- 在 Tap App Link 中,開啟應用程式 → 收入,選擇 Stripe。 受限密鑰 (rk_...) 適用於任何 Stripe 帳戶。 如果您的工作區設定了 Connect with Stripe,則您可以使用它。
- 如果您使用受限金鑰:複製 Webhook URL,在 Stripe → 開發人員 → Webhooks 中新增端點,訂閱 Invoice.paid、charge.refunded 和 Credit_note.created,然後在儲存金鑰之前將 Stripe 的簽署金鑰 (whsec_…) 貼上到 Tap App Link 中。
- 如果您使用 Connect with Stripe:端點和事件已為您設定。 跳至測試購買。 不要在 Stripe 中建立第二個端點。
- 創作者代碼在連線後同步為 Stripe 促銷代碼。 當您建立折扣時,新代碼會同步。
受限金鑰適用於任何 Stripe 帳號:在 Stripe 中新增端點,然後將簽章秘密 Stripe 顯示 (whsec_...) 貼到 Tap App Link 中。 如果您改用 Connect with Stripe,Tap App Link 會為您建立 Webhook 端點。
啟用事件: invoice.paid, charge.refunded, Credit_note.created。 額外的事件將被忽略。 Sandbox Stripe 事件必須命中 Tap App Link 沙箱環境 URL。 Production 事件必須投入生產。 將它們混合在一起可以在您的即時佣金報表中進行測試購買。
5. 驗證
- 在Tap App Link中,切換到Sandbox並開啟Live Attribution Debugger。
- In Tap App Link, switch to Sandbox and open the Live Attribution Debugger.
- 確認時間表達到安裝匹配和計費客戶連結。 如果重試,請先在偵錯版本中呼叫resetForTesting()。
- 觸發沙箱購買並確認 webhook 返回 2xx。
- (可選)啟動促銷代碼觀察並使用 applyCode() 兌換創作者代碼。
硬約束
- 請勿修改帳單驗證、收據驗證或購買流程。 Tap App Link 僅限歸屬。
- 將 Production 和 Sandbox 金鑰保留在相符的版本上。 切勿將沙盒密鑰運送到商店。
- 在更改 SDK 初始化、使用者 ID 橋接、優惠演示和代碼兌換之外的代碼之前,請詢問開發人員。
- 更喜歡 https://tapapplink.com/docs/ 上的公共文檔,而不是猜測 API 形狀。
人類快速啟動: https://tapapplink.com/docs/quick-start/. 問題: support@tapapplink.com.