Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Support fetching/redeeming eligible win-backs #366

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ This plugin is based on [CapGo's Capacitor plugin](https://www.npmjs.com/package
* [`isAnonymous()`](#isanonymous)
* [`checkTrialOrIntroductoryPriceEligibility(...)`](#checktrialorintroductorypriceeligibility)
* [`getPromotionalOffer(...)`](#getpromotionaloffer)
* [`getEligibleWinBackOffersForProduct(...)`](#geteligiblewinbackoffersforproduct)
* [`getEligibleWinBackOffersForPackage(...)`](#geteligiblewinbackoffersforpackage)
* [`purchaseProductWithWinBackOffer(...)`](#purchaseproductwithwinbackoffer)
* [`purchasePackageWithWinBackOffer(...)`](#purchasepackagewithwinbackoffer)
* [`invalidateCustomerInfoCache()`](#invalidatecustomerinfocache)
* [`presentCodeRedemptionSheet()`](#presentcoderedemptionsheet)
* [`setAttributes(...)`](#setattributes)
Expand Down Expand Up @@ -575,6 +579,78 @@ iOS only. Use this function to retrieve the <a href="#purchasespromotionaloffer"
--------------------


### getEligibleWinBackOffersForProduct(...)

```typescript
getEligibleWinBackOffersForProduct(product: PurchasesStoreProduct) => Promise<{ eligibleWinBackOffers: PurchasesWinBackOffer[]; } | undefined>
```

iOS only, requires iOS 18.0 or greater with StoreKit 2. Use this function to retrieve
the eligible `PurchasesWinBackOffer`s that a subscriber is eligible for for a
given <a href="#purchasesstoreproduct">`PurchasesStoreProduct`</a>.

| Param | Type |
| ------------- | ----------------------------------------------------------------------- |
| **`product`** | <code><a href="#purchasesstoreproduct">PurchasesStoreProduct</a></code> |

**Returns:** <code>Promise&lt;{ eligibleWinBackOffers: PurchasesWinBackOffer[]; }&gt;</code>

--------------------


### getEligibleWinBackOffersForPackage(...)

```typescript
getEligibleWinBackOffersForPackage(aPackage: PurchasesPackage) => Promise<{ eligibleWinBackOffers: PurchasesWinBackOffer[]; } | undefined>
```

iOS only, requires iOS 18.0 or greater with StoreKit 2. Use this function to retrieve
the eligible `PurchasesWinBackOffer`s that a subscriber is eligible for for a
given `PurchasesStorePackage`.

| Param | Type |
| -------------- | ------------------------------------------------------------- |
| **`aPackage`** | <code><a href="#purchasespackage">PurchasesPackage</a></code> |

**Returns:** <code>Promise&lt;{ eligibleWinBackOffers: PurchasesWinBackOffer[]; }&gt;</code>

--------------------


### purchaseProductWithWinBackOffer(...)

```typescript
purchaseProductWithWinBackOffer(options: PurchaseProductWithWinBackOfferOptions) => Promise<MakePurchaseResult | undefined>
```

iOS only. Purchase a product applying a given win-back offer.

| Param | Type |
| ------------- | --------------------------------------------------------------------------------------------------------- |
| **`options`** | <code><a href="#purchaseproductwithwinbackofferoptions">PurchaseProductWithWinBackOfferOptions</a></code> |

**Returns:** <code>Promise&lt;<a href="#makepurchaseresult">MakePurchaseResult</a>&gt;</code>

--------------------


### purchasePackageWithWinBackOffer(...)

```typescript
purchasePackageWithWinBackOffer(options: PurchasePackageWithWinBackOfferOptions) => Promise<MakePurchaseResult | undefined>
```

iOS only. Purchase a package applying a given win-back offer.

| Param | Type |
| ------------- | --------------------------------------------------------------------------------------------------------- |
| **`options`** | <code><a href="#purchasepackagewithwinbackofferoptions">PurchasePackageWithWinBackOfferOptions</a></code> |

**Returns:** <code>Promise&lt;<a href="#makepurchaseresult">MakePurchaseResult</a>&gt;</code>

--------------------


### invalidateCustomerInfoCache()

```typescript
Expand Down Expand Up @@ -1478,6 +1554,27 @@ Holds the introductory price status
| **`discount`** | <code><a href="#purchasesstoreproductdiscount">PurchasesStoreProductDiscount</a></code> | The <a href="#purchasesstoreproductdiscount">`PurchasesStoreProductDiscount`</a> to apply to the product. |


#### PurchasesWinBackOffer

Contains information about a Win-Back Offer in Apple's App Store. Req


#### PurchaseProductWithWinBackOfferOptions

| Prop | Type | Description |
| ------------------ | ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| **`product`** | <code><a href="#purchasesstoreproduct">PurchasesStoreProduct</a></code> | The product you want to purchase |
| **`winBackOffer`** | <code><a href="#purchaseswinbackoffer">PurchasesWinBackOffer</a></code> | Win-back offer to apply to this purchase. Retrieve this using getEligibleWinBackOffersForProduct. |


#### PurchasePackageWithWinBackOfferOptions

| Prop | Type | Description |
| ------------------ | ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| **`package`** | <code><a href="#purchasespackage">PurchasesPackage</a></code> | The product you want to purchase |
| **`winBackOffer`** | <code><a href="#purchaseswinbackoffer">PurchasesWinBackOffer</a></code> | Win-back offer to apply to this purchase. Retrieve this using getEligibleWinBackOffersForPackage. |


### Type Aliases


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,30 @@ class PurchasesPlugin : Plugin() {
call.resolve()
}

@PluginMethod(returnType = PluginMethod.RETURN_PROMISE)
fun getEligibleWinBackOffersForProduct(call: PluginCall) {
logNotSupportedFunctionalityInAndroid("getEligibleWinBackOffersForProduct")
call.resolve()
}

@PluginMethod(returnType = PluginMethod.RETURN_PROMISE)
fun getEligibleWinBackOffersForPackage(call: PluginCall) {
logNotSupportedFunctionalityInAndroid("getEligibleWinBackOffersForPackage")
call.resolve()
}

@PluginMethod(returnType = PluginMethod.RETURN_PROMISE)
fun purchaseProductWithWinBackOffer(call: PluginCall) {
logNotSupportedFunctionalityInAndroid("purchaseProductWithWinBackOffer")
call.resolve()
}

@PluginMethod(returnType = PluginMethod.RETURN_PROMISE)
fun purchasePackageWithWinBackOffer(call: PluginCall) {
logNotSupportedFunctionalityInAndroid("purchasePackageWithWinBackOffer")
call.resolve()
}

@PluginMethod(returnType = PluginMethod.RETURN_NONE)
fun invalidateCustomerInfoCache(call: PluginCall) {
if (rejectIfNotConfigured(call)) return
Expand Down
4 changes: 4 additions & 0 deletions example/purchase-tester/ios/App/App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
504EC3121FED79650016851F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 504EC3101FED79650016851F /* LaunchScreen.storyboard */; };
50B271D11FEDC1A000F3C39B /* public in Resources */ = {isa = PBXBuildFile; fileRef = 50B271D01FEDC1A000F3C39B /* public */; };
A084ECDBA7D38E1E42DFC39D /* Pods_App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AF277DCFFFF123FFC6DF26C7 /* Pods_App.framework */; };
FD68EFEC2D00B849000F11DB /* SKConfigFile.storekit in Resources */ = {isa = PBXBuildFile; fileRef = FD68EFEB2D00B849000F11DB /* SKConfigFile.storekit */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -30,6 +31,7 @@
AF277DCFFFF123FFC6DF26C7 /* Pods_App.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_App.framework; sourceTree = BUILT_PRODUCTS_DIR; };
AF51FD2D460BCFE21FA515B2 /* Pods-App.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App.release.xcconfig"; path = "Pods/Target Support Files/Pods-App/Pods-App.release.xcconfig"; sourceTree = "<group>"; };
FC68EB0AF532CFC21C3344DD /* Pods-App.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App.debug.xcconfig"; path = "Pods/Target Support Files/Pods-App/Pods-App.debug.xcconfig"; sourceTree = "<group>"; };
FD68EFEB2D00B849000F11DB /* SKConfigFile.storekit */ = {isa = PBXFileReference; lastKnownFileType = text; path = SKConfigFile.storekit; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -81,6 +83,7 @@
504EC3131FED79650016851F /* Info.plist */,
2FAD9762203C412B000D30F8 /* config.xml */,
50B271D01FEDC1A000F3C39B /* public */,
FD68EFEB2D00B849000F11DB /* SKConfigFile.storekit */,
);
path = App;
sourceTree = "<group>";
Expand Down Expand Up @@ -160,6 +163,7 @@
504EC30F1FED79650016851F /* Assets.xcassets in Resources */,
50379B232058CBB4000EE86E /* capacitor.config.json in Resources */,
504EC30D1FED79650016851F /* Main.storyboard in Resources */,
FD68EFEC2D00B849000F11DB /* SKConfigFile.storekit in Resources */,
2FAD9763203C412B000D30F8 /* config.xml in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
126 changes: 126 additions & 0 deletions example/purchase-tester/ios/App/App/SKConfigFile.storekit
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
{
"appPolicies" : {
"eula" : "",
"policies" : [
{
"locale" : "en_US",
"policyText" : "",
"policyURL" : ""
}
]
},
"identifier" : "EBBCBA0D",
"nonRenewingSubscriptions" : [

],
"products" : [

],
"settings" : {
"_askToBuyEnabled" : false,
"_compatibilityTimeRate" : {
"3" : 6
},
"_failTransactionsEnabled" : false,
"_locale" : "en_US",
"_storefront" : "USA",
"_storeKitErrors" : [
{
"current" : null,
"enabled" : false,
"name" : "Load Products"
},
{
"current" : null,
"enabled" : false,
"name" : "Purchase"
},
{
"current" : null,
"enabled" : false,
"name" : "Verification"
},
{
"current" : null,
"enabled" : false,
"name" : "App Store Sync"
},
{
"current" : null,
"enabled" : false,
"name" : "Subscription Status"
},
{
"current" : null,
"enabled" : false,
"name" : "App Transaction"
},
{
"current" : null,
"enabled" : false,
"name" : "Manage Subscriptions Sheet"
},
{
"current" : null,
"enabled" : false,
"name" : "Refund Request Sheet"
},
{
"current" : null,
"enabled" : false,
"name" : "Offer Code Redeem Sheet"
}
],
"_timeRate" : 1003
},
"subscriptionGroups" : [
{
"id" : "C589F267",
"localizations" : [

],
"name" : "main_subscription_group",
"subscriptions" : [
{
"adHocOffers" : [

],
"codeOffers" : [

],
"displayPrice" : "4.99",
"familyShareable" : false,
"groupNumber" : 1,
"internalID" : "C1E08DA3",
"introductoryOffer" : null,
"localizations" : [
{
"description" : "",
"displayName" : "",
"locale" : "en_US"
}
],
"productID" : "com.revenuecat.monthly_4.99.1_week_intro",
"recurringSubscriptionPeriod" : "P1M",
"referenceName" : "Monthly Sub",
"subscriptionGroupID" : "C589F267",
"type" : "RecurringSubscription",
"winbackOffers" : [
{
"internalID" : "E198B2F2",
"isEligible" : true,
"offerID" : "winBackOffer",
"paymentMode" : "free",
"referenceName" : "Win-Back Offer",
"subscriptionPeriod" : "P1W"
}
]
}
]
}
],
"version" : {
"major" : 4,
"minor" : 0
}
}
4 changes: 4 additions & 0 deletions example/purchase-tester/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Redirect, Route } from 'react-router-dom';
import { IonApp, setupIonicReact } from '@ionic/react';
import { IonReactRouter } from '@ionic/react-router';
import Home from './pages/Home';
import WinBackOfferTesting from './pages/WinBackOfferTesting';

/* Core CSS required for Ionic components to work properly */
import '@ionic/react/css/core.css';
Expand Down Expand Up @@ -33,6 +34,9 @@ const App: React.FC = () => (
<Route exact path="/">
<Redirect to="/home" />
</Route>
<Route exact path="/win-back-offer-testing">
<WinBackOfferTesting />
</Route>
</IonReactRouter>
</IonApp>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,11 @@ const FunctionTesterContainer: React.FC<ContainerProps> = () => {
updateLastFunction('isConfigured', isConfiguredResult);
};

const goToWinBackOfferTestingScreen = async () => {
window.location.href = '/win-back-offer-testing';
updateLastFunctionWithoutContent('goToWinBackOfferTestingScreen');
};

return (
<div id="container">
<IonCard id={'last_request_card'}>
Expand Down Expand Up @@ -717,6 +722,9 @@ const FunctionTesterContainer: React.FC<ContainerProps> = () => {
<IonButton size="small" onClick={isConfigured}>
Is configured?
</IonButton>
<IonButton size="small" onClick={goToWinBackOfferTestingScreen}>
Go to win-back offer testing screen
</IonButton>
</div>
</div>
);
Expand Down
Loading