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

feat: added presentCodeRedemptionSheetIOS #1201

Merged
merged 3 commits into from
Dec 7, 2020
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ _*deprecated_<br>~~`buySubscription(sku: string)`~~<ul><li>sku: subscription ID/
`getReceiptIOS()` | `Promise<string>` | **iOS only**<br>Get the current receipt.
`getPendingPurchasesIOS()` | `Promise<ProductPurchase[]>` | **IOS only**<br>Gets all the transactions which are pending to be finished.
`validateReceiptIos(body: Record<string, unknown>, devMode: boolean)`<ul><li>body: receiptBody</li><li>devMode: isTest</li></ul> | `Object\|boolean` | **iOS only**<br>Validate receipt.
`presentCodeRedemptionSheetIOS()` | `Promise<null>` | **iOS only**<br>Availability: `iOS 14.0+`<br>Displays a sheet that enables users to redeem subscription offer codes that you generated in App Store Connect.
`endConnection()` | `Promise<void>` | End billing connection.
`consumeAllItemsAndroid()` | `Promise<void>` | **Android only**<br>Consume all items so they are able to buy again. ⚠️ Use in dev only (as you should deliver the purchased feature BEFORE consuming it)
`flushFailedPurchasesCachedAsPendingAndroid()` | `Promise<void>` | **Android only**<br>Consume all 'ghost' purchases (that is, pending payment that already failed but is still marked as pending in Play Store cache)
Expand Down
13 changes: 13 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,18 @@ export const getPendingPurchasesIOS = async (): Promise<ProductPurchase[]> => {
}
};

/**
* Launches a modal to register the redeem offer code in IOS.
* @returns {Promise<null>}
*/
export const presentCodeRedemptionSheetIOS = async (): Promise<null> => {
if (Platform.OS === 'ios') {
await checkNativeiOSAvailable();

return RNIapIos.presentCodeRedemptionSheet();
}
};

const iapUtils = {
IAPErrorCode,
initConnection,
Expand Down Expand Up @@ -963,6 +975,7 @@ const iapUtils = {
getReceiptIOS,
getPromotedProductIOS,
buyPromotedProductIOS,
presentCodeRedemptionSheetIOS,
};

export default iapUtils;
10 changes: 10 additions & 0 deletions ios/RNIapIos.m
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,16 @@ - (BOOL)paymentQueue:(SKPaymentQueue *)queue shouldAddStorePayment:(SKPayment *)
}];
}

RCT_EXPORT_METHOD(presentCodeRedemptionSheet:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
if (@available(iOS 14.0, *)) {
[[SKPaymentQueue defaultQueue] presentCodeRedemptionSheet];
resolve(nil);
} else {
reject([self standardErrorCode:2], @"This method only available above iOS 14", nil);
}
}

#pragma mark ===== StoreKit Delegate

-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
Expand Down