代理说明

Tap App Link + Stripe

您是一名编码助理,帮助开发人员将 Tap App Link(创作者仪表板、跟踪安装链接和应用程序折扣代码)与 Stripe 集成。 Tap App Link 通过 SDK 匹配安装客户端,并通过 Stripe webhook 属性购买收入服务器端。 当观看者在结账时输入代码时,促销代码是第二个归因路径。

1.安装和配置Tap App Link SDK

如果项目缺少 SDK,请为目标平台添加它,然后在启动时调用一次配置。 在测试构建中使用沙箱密钥和环境,在商店构建中使用生产环境。

  • React Native / Expo(开发客户端;Expo Go 无法加载 Play Install Referrer):安装 @tapapplink/react-native@^0.3.3 和可选的同级 @react-native-async-storage/async-storage (yarn add、npm install 或 npx expo install)。 如果没有 AsyncStorage,每次冷启动都会再次发布。
  • iOS:来自“0.3.3”的 Swift 包 https://github.com/tapapplink/tapapplink-ios
  • Android:实现(“com.github.tapapplink:tapapplink-android:0.3.3”)
  • Flutter: tapapplink: ^ 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-storage
import { 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

  1. 在订阅上设置metadata.app_user_id(例如Checkout中的subscription_data.metadata),以便它到达发票。 将相同的 ID 传递给应用程序中的 setAppUserId(),以便网络和应用程序购买结合起来。
  2. Tap App Link 还从发票元数据、订阅元数据和第一个行项目中读取 app_user_id / appUserId / tal_app_user_id。 如果缺少这些,它将使用 Stripe 客户 ID (cus_…)。 仅当没有客户 ID 时才使用电子邮件。
  3. 当存在促销代码或 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.配置StripeWebhook

人类点击路径: https://tapapplink.com/docs/integrations/stripe/。遵循这些仪表板步骤。摘要:

  1. 在 Tap App Link 中,打开应用程序 → 收入,选择 Stripe。 受限密钥 (rk_...) 适用于任何 Stripe 帐户。 如果您的工作区设置了 Connect with Stripe,则您可以使用它。
  2. 如果您使用受限密钥:复制 Webhook URL,在 Stripe → 开发人员 → Webhooks 中添加端点,订阅 Invoice.paid、charge.refunded 和 Credit_note.created,然后在保存密钥之前将 Stripe 的签名密钥 (whsec_…) 粘贴到 Tap App Link 中。
  3. 如果您使用 Connect with Stripe:端点和事件已为您设置。 跳至测试购买。 不要在 Stripe 中创建第二个端点。
  4. 创作者代码在连接后同步为 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.验证

  1. 在Tap App Link中,切换到Sandbox并打开Live Attribution Debugger。
  2. In Tap App Link, switch to Sandbox and open the Live Attribution Debugger.
  3. 确认时间表达到安装匹配和计费客户链接。 如果重试,请首先在调试版本中调用resetForTesting()。
  4. 触发沙箱购买并确认 webhook 返回 2xx。
  5. (可选)启动促销代码观察并使用 applyCode() 兑换创作者代码。

硬约束

  • 请勿修改账单验证、收据验证或购买流程。 Tap App Link 仅限归属。
  • 将 Production 和 Sandbox 密钥保留在匹配的版本上。 切勿将沙盒密钥运送到商店。
  • 在更改 SDK 初始化、用户 ID 桥接、优惠演示和代码兑换之外的代码之前,请询问开发人员。
  • 更喜欢 https://tapapplink.com/docs/ 上的公共文档,而不是猜测 API 形状。

人类快速入门: https://tapapplink.com/docs/quick-start/. 问题: support@tapapplink.com.