From 06b2675dd8e998e9b6a0c40a147eaf5e5b8f6b7b Mon Sep 17 00:00:00 2001 From: Andres Aguilar Date: Thu, 25 Aug 2022 09:53:24 -0700 Subject: [PATCH] product purchase lifecycle (#1888) * Able to purchase products * swift lint * fixed lint issues, removed methods Co-authored-by: Andres Aguilar --- IapExample/ios/Configuration.storekit | 48 +++++ .../ios/IapExample.xcodeproj/project.pbxproj | 4 + .../xcschemes/IapExample.xcscheme | 3 + IapExample/ios/Podfile.lock | 4 +- IapExample/src/screens/ClassSetup.tsx | 16 +- IapExample/src/screens/Products.tsx | 33 +--- IapExample/src/screens/Subscriptions.tsx | 11 +- ios/IapSerializationUtils.swift | 7 +- ios/RNIapIos.m | 6 +- ios/RNIapIos.swift | 175 +++++++++--------- src/eventEmitter.ts | 3 +- src/hooks/useIAP.ts | 7 +- src/hooks/withIAPContext.tsx | 25 +-- src/iap.ts | 129 +------------ src/types/index.ts | 13 +- 15 files changed, 187 insertions(+), 297 deletions(-) create mode 100644 IapExample/ios/Configuration.storekit diff --git a/IapExample/ios/Configuration.storekit b/IapExample/ios/Configuration.storekit new file mode 100644 index 000000000..e57a4bbcb --- /dev/null +++ b/IapExample/ios/Configuration.storekit @@ -0,0 +1,48 @@ +{ + "identifier" : "5BB04EE6", + "nonRenewingSubscriptions" : [ + + ], + "products" : [ + { + "displayPrice" : "0.99", + "familyShareable" : false, + "internalID" : "FF5725DC", + "localizations" : [ + { + "description" : "", + "displayName" : "", + "locale" : "en_US" + } + ], + "productID" : "com.cooni.point1000", + "referenceName" : "1000 points", + "type" : "Consumable" + }, + { + "displayPrice" : "2.99", + "familyShareable" : false, + "internalID" : "47DD16EA", + "localizations" : [ + { + "description" : "", + "displayName" : "", + "locale" : "en_US" + } + ], + "productID" : "com.cooni.point5000", + "referenceName" : "5000 points", + "type" : "NonConsumable" + } + ], + "settings" : { + + }, + "subscriptionGroups" : [ + + ], + "version" : { + "major" : 1, + "minor" : 2 + } +} diff --git a/IapExample/ios/IapExample.xcodeproj/project.pbxproj b/IapExample/ios/IapExample.xcodeproj/project.pbxproj index 86fd3f4fc..4bbae8907 100644 --- a/IapExample/ios/IapExample.xcodeproj/project.pbxproj +++ b/IapExample/ios/IapExample.xcodeproj/project.pbxproj @@ -14,6 +14,7 @@ 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; 7699B88040F8A987B510C191 /* libPods-IapExample-IapExampleTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 19F6CBCC0A4E27FBF8BF4A61 /* libPods-IapExample-IapExampleTests.a */; }; 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; }; + 8553967928B5A2D700E7E3CE /* Configuration.storekit in Resources */ = {isa = PBXBuildFile; fileRef = 8553967828B5A2D700E7E3CE /* Configuration.storekit */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -42,6 +43,7 @@ 5B7EB9410499542E8C5724F5 /* Pods-IapExample-IapExampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-IapExample-IapExampleTests.debug.xcconfig"; path = "Target Support Files/Pods-IapExample-IapExampleTests/Pods-IapExample-IapExampleTests.debug.xcconfig"; sourceTree = ""; }; 5DCACB8F33CDC322A6C60F78 /* libPods-IapExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-IapExample.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = IapExample/LaunchScreen.storyboard; sourceTree = ""; }; + 8553967828B5A2D700E7E3CE /* Configuration.storekit */ = {isa = PBXFileReference; lastKnownFileType = text; path = Configuration.storekit; sourceTree = ""; }; 89C6BE57DB24E9ADA2F236DE /* Pods-IapExample-IapExampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-IapExample-IapExampleTests.release.xcconfig"; path = "Target Support Files/Pods-IapExample-IapExampleTests/Pods-IapExample-IapExampleTests.release.xcconfig"; sourceTree = ""; }; ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; /* End PBXFileReference section */ @@ -92,6 +94,7 @@ 13B07FB61A68108700A75B9A /* Info.plist */, 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */, 13B07FB71A68108700A75B9A /* main.m */, + 8553967828B5A2D700E7E3CE /* Configuration.storekit */, ); name = IapExample; sourceTree = ""; @@ -243,6 +246,7 @@ buildActionMask = 2147483647; files = ( 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */, + 8553967928B5A2D700E7E3CE /* Configuration.storekit in Resources */, 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/IapExample/ios/IapExample.xcodeproj/xcshareddata/xcschemes/IapExample.xcscheme b/IapExample/ios/IapExample.xcodeproj/xcshareddata/xcschemes/IapExample.xcscheme index 84938ba74..c7beab13b 100644 --- a/IapExample/ios/IapExample.xcodeproj/xcshareddata/xcschemes/IapExample.xcscheme +++ b/IapExample/ios/IapExample.xcodeproj/xcshareddata/xcschemes/IapExample.xcscheme @@ -60,6 +60,9 @@ ReferencedContainer = "container:IapExample.xcodeproj"> + + { if (isAndroid) { await flushFailedPurchasesCachedAsPendingAndroid(); - } else { - /** - * WARNING This line should not be included in production code - * This call will call finishTransaction in all pending purchases - * on every launch, effectively consuming purchases that you might - * not have verified the receipt or given the consumer their product - * - * TL;DR you will no longer receive any updates from Apple on - * every launch for pending purchases - */ - await clearTransactionIOS(); } } catch (error) { if (error instanceof PurchaseError) { @@ -199,7 +187,7 @@ export class ClassSetup extends Component<{}, State> { {productList.map((product, index) => ( { >