Joe Sansalone 6 Posted January 18, 2023 Hi, I'm looking to use InApp purchase in an iOS and Android app created with Delphi. According to ChatGPT, the code below will work and also work with for a subscription based purchase. IS THIS CORRECT? uses FMX.InAppPurchase; var InAppPurchase: TInAppPurchase; ProductIdentifier: string; begin InAppPurchase := TInAppPurchase.Create; try // Set up the product identifier for the consumable IAP ProductIdentifier := 'com.yourcompany.yourproduct.consumable'; // <-- if subscription, 'com.yourcompany.yourproduct.subscription'; // Request product information from the App Store InAppPurchase.RequestProductInfo(ProductIdentifier); // Wait for the product information to be returned while not InAppPurchase.ProductInfoReceived do begin Application.ProcessMessages; Sleep(100); end; // Check if the product is valid and available for purchase if InAppPurchase.ProductValid then begin // Show the purchase dialog to the user InAppPurchase.PurchaseProduct(ProductIdentifier); // Wait for the purchase to complete while not InAppPurchase.PurchaseComplete do begin Application.ProcessMessages; Sleep(100); end; // Check if the purchase was successful if InAppPurchase.PurchaseSuccess then begin // Grant the user access to the purchased content // or Add the item to the user inventory or do whatever you want after the purchase end else ShowMessage('Purchase failed'); end else ShowMessage('Product not available'); finally InAppPurchase.Free; end; end; Joe Share this post Link to post
Brian Evans 105 Posted January 18, 2023 Read the help topics and use the events not some Sleep/ProcessMessages messages loop. Using the iOS In-App Purchase Service - RAD Studio (embarcadero.com) Using the Google Play In-app Billing Service - RAD Studio (embarcadero.com) There is also a demo that includes in app purchases: FMX.CapitalIAP Sample - RAD Studio Code Examples (embarcadero.com) 1 Share this post Link to post
Dave Nottage 557 Posted January 18, 2023 3 hours ago, Joe Sansalone said: According to ChatGPT Looks like it still has some learning to do Share this post Link to post
Joe Sansalone 6 Posted January 18, 2023 Thanks for the links. Does the current version Delphi 11.2 support In-App Subscriptions on iOS? Share this post Link to post
Dave Nottage 557 Posted January 18, 2023 4 hours ago, Joe Sansalone said: Does the current version Delphi 11.2 support In-App Subscriptions on iOS? Yes.. it supports Android and iOS Share this post Link to post
Joe Sansalone 6 Posted January 18, 2023 Was In-App Subscriptions (weekly, monthly, yearly) something that was added recently? I don't know why, but I remember Subscriptions not being supported. Just consumables purchases and non-consumable purchases. Share this post Link to post
Eli M. 38 Posted February 1, 2023 On 1/18/2023 at 10:39 AM, Dave Nottage said: Yes.. it supports Android and iOS Dave, is this really the case? The current documentation still says subscriptions are not supported. This guy shows how to add them. Which I am going to try. https://delphitoptips.blogspot.com/2018/03/supporting-in-app-purchase.html?m=1 Share this post Link to post
Dave Nottage 557 Posted February 2, 2023 8 hours ago, Eli M. said: Dave, is this really the case? The current documentation still says subscriptions are not supported. According the code, they're supported on at least Android. Check the FMX.InAppPurchase.Android unit. Not sure about iOS. 8 hours ago, Eli M. said: https://delphitoptips.blogspot.com/2018/03/supporting-in-app-purchase.html?m=1 The current implementation for Android was updated after that article was written. Share this post Link to post