Jump to content
Joe Sansalone

In App Purchase (consumable and subscription)

Recommended Posts

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
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

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
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:

The current implementation for Android was updated after that article was written.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×