Skip to content

Instantly share code, notes, and snippets.

@alternacrow
Last active August 3, 2023 14:17
Show Gist options
  • Save alternacrow/95326c7735cf8d827c7361125b1dc5eb to your computer and use it in GitHub Desktop.
Save alternacrow/95326c7735cf8d827c7361125b1dc5eb to your computer and use it in GitHub Desktop.
RevenueCat / Stripe

RevenueCat

モバイルアプリケーション向けのサブスクリプションプラットフォーム。
iOS/Android のアプリ内課金の導入が簡単になる。
Stripe との連携も可能で、Web にも対応している。

REST API

Web 上からは REST API を使用して CRUD が可能。

RevenueCat REST API
https://www.revenuecat.com/reference/revenuecat-rest-api

Stripe との連携

Stripe 上での商品購入やサブスクリプションを RevenueCat の Customer と紐付けることができる。
設定のみでは連携できない。

RevenueCat 上で Stripe App を作成すると Public API Key が発行されので、Stripe 上の商品購入やサブスクリプションを Public API Key を利用して Customer と紐付ける必要がある。
そのため、基本的には Webhook 設定と合わせて Webhook 用のサーバーが必要になる。

Stripe Web Payments
https://ww.revenuecat.com/docs/stripe

Stripe Server Notifications
https://www.revenuecat.com/docs/stripe-server-notifications

RevenueCat 公式のストライプ連携サンプル
https://github.com/RevenueCat-Samples/stripe-no-website-example

RevenueCat

react-native-purchases

https://github.com/RevenueCat/react-native-purchases
https://www.revenuecat.com/docs/reactnative
https://www.revenuecat.com/docs/getting-started#4-using-revenuecats-purchases-sdk

初期化

Purchases.configure({ apiKey: process.env.API_KEY });

オファーリングの取得

Offerings を利用することで、アプリケーションコードを変更せずに、アプリ課金の商品一覧を更新することが可能。

const offerings = await Purchases.getOfferings();

商品の購入

ProductID から Product を取得し、購入処理を行う。 Android はプラン変更の場合に、変更前の ProductID を指定する必要がある。

const product = await Purchases.getProducts([process.env.PRODUCT_ID])[0];

await Purchases.purchaseStoreProduct(
  product,
  Platform.OS === "android" && currentProductId
    ? { oldProductIdentifier: currentProductId }
    : null
);
// @deprecated
await Purchases.purchaseProduct(
  nextProductId,
  Platform.OS === "android" && currentProductId
    ? { oldSKU: currentProductId }
    : null
);

購入の復元

const customerInfo = await Purchases.restorePurchases();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment