Skip to content

Commit

Permalink
Update redemption link instructions for current hybrid SDKs (#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonidero authored Jan 24, 2025
1 parent def8bae commit 73aa4fd
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 3 deletions.
24 changes: 24 additions & 0 deletions code_blocks/web/revenuecat-billing/redemption_flutter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
String redemptionUrl = 'YOUR_REDEMPTION_URL';

final webPurchaseRedemption = await Purchases.parseAsWebPurchaseRedemption(redemptionUrl);

if (webPurchaseRedemption != null) {
final result = await Purchases.redeemWebPurchase(webPurchaseRedemption);
result.when(
success: (customerInfo) {
// Redemption was successful and entitlements were granted to the user.
},
error: (error) {
// Redemption failed due to an error.
},
purchaseBelongsToOtherUser: () {
// The purchase associated to the link belongs to a different user and it cannot be redeemed.
},
invalidToken: () {
// The redemption link is invalid.
},
expired: (obfuscatedEmail) {
// The redemption link has expired. A new one has been sent to the user to the provided obfuscated email.
}
);
}
26 changes: 26 additions & 0 deletions code_blocks/web/revenuecat-billing/redemption_react.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
String redemptionUrl = 'YOUR_REDEMPTION_URL';

const webPurchaseRedemption = await Purchases.parseAsWebPurchaseRedemption(redemptionUrl);
if (webPurchaseRedemption) {
const result = await Purchases.redeemWebPurchase(webPurchaseRedemption);
switch (result.result) {
case WebPurchaseRedemptionResultType.SUCCESS:
const customerInfo: CustomerInfo = result.customerInfo;
// Redemption was successful and entitlements were granted to the user.
break;
case WebPurchaseRedemptionResultType.ERROR:
const error: PurchasesError = result.error;
// Redemption failed due to an error.
break;
case WebPurchaseRedemptionResultType.PURCHASE_BELONGS_TO_OTHER_USER:
// The purchase associated to the link belongs to a different user and it cannot be redeemed.
break;
case WebPurchaseRedemptionResultType.INVALID_TOKEN:
// The redemption link is invalid.
break;
case WebPurchaseRedemptionResultType.EXPIRED:
const obfuscatedEmail: string = result.obfuscatedEmail;
// The redemption link has expired. A new one has been sent to the user to the provided obfuscated email.
break;
}
}
32 changes: 32 additions & 0 deletions code_blocks/web/revenuecat-billing/redemption_unity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
string redemptionUrl = 'YOUR_REDEMPTION_URL';

purchases.ParseAsWebPurchaseRedemption(redemptionUrl, (webPurchaseRedemption) =>
{
if (webPurchaseRedemption != null)
{
purchases.RedeemWebPurchase(webPurchaseRedemption, (result) =>
{
switch (result)
{
case Purchases.WebPurchaseRedemptionResult.Success success:
Purchases.CustomerInfo customerInfo = success.CustomerInfo;
// Redemption was successful and entitlements were granted to the user.
break;
case Purchases.WebPurchaseRedemptionResult.RedemptionError error:
Purchases.Error error = error.Error;
// Redemption failed due to an error.
break;
case Purchases.WebPurchaseRedemptionResult.InvalidToken:
// The redemption link is invalid.
break;
case Purchases.WebPurchaseRedemptionResult.PurchaseBelongsToOtherUser:
// The purchase associated to the link belongs to a different user and it cannot be redeemed.
break;
case Purchases.WebPurchaseRedemptionResult.Expired expired:
string obfuscatedEmail = expired.ObfuscatedEmail;
// The redemption link has expired. A new one has been sent to the user to the provided obfuscated email.
break;
}
});
}
});
42 changes: 39 additions & 3 deletions docs/web/revenuecat-billing/redemption-links.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ The SDK versions supporting Redemption Links are:
| :----------------------- | :------------------------------- |
| purchases-android | 8.10.6 and above |
| purchases-ios | 5.14.1 and above |
| purchases-flutter | Coming soon |
| purchases-unity | Coming soon |
| react-native-purchases | Coming soon |
| purchases-flutter | 8.4.0 and above |
| purchases-unity | 7.4.1 and above |
| react-native-purchases | 8.5.0 and above |
| purchases-kmp | Coming soon |
| purchases-capacitor | Coming soon |

Expand Down Expand Up @@ -108,6 +108,42 @@ import androidRedemption1 from "!!raw-loader!@site/code_blocks/web/revenuecat-bi
{ type: 'kotlin', title: "Android Redemption", content: androidRedemption1, },
]}/>

##### Flutter

In our Flutter SDK, you will need to obtain the deep link first. Please read the official docs on how to parse deep links: https://docs.flutter.dev/ui/navigation/deep-linking. You can use [app_links](https://pub.dev/packages/app_links) or similar libraries to obtain the deep link.

Once you have the deep link, you can use the following snippet to perform the redemption:

import flutterRedemption from "!!raw-loader!@site/code_blocks/web/revenuecat-billing/redemption_flutter.dart";

<RCCodeBlock tabs={[
{ type: 'dart', title: "Flutter Redemption", content: flutterRedemption, },
]}/>

##### React Native

In our React Native SDK, you will need to obtain the deep link first. Please read the official docs on how to parse deep links: https://reactnavigation.org/docs/deep-linking/.

Once you have the deep link, you can use the following snippet to perform the redemption:

import reactNativeRedemption from "!!raw-loader!@site/code_blocks/web/revenuecat-billing/redemption_react.ts";

<RCCodeBlock tabs={[
{ type: 'typescript', title: "React Native Redemption", content: reactNativeRedemption, },
]}/>

##### Unity

In our Unity SDK, you will need to obtain the deep link first. Please read the official docs on how to parse deep links: https://docs.unity3d.com/Manual/deep-linking.html.

Once you have the deep link, you can use the following snippet to perform the redemption:

import unityRedemption from "!!raw-loader!@site/code_blocks/web/revenuecat-billing/redemption_unity.cs";

<RCCodeBlock tabs={[
{ type: 'csharp', title: "Unity Redemption", content: unityRedemption, },
]}/>

#### 4. Verify your setup

Once you’ve followed the steps above, in order to verify that your integration worked correctly you can open your app using a deep link in the format: `<YOUR_CUSTOM_SCHEME>://redeem_web_purchase?redemption_token=<ANY_TOKEN>`
Expand Down

0 comments on commit 73aa4fd

Please sign in to comment.