Jump to content
toufik

D11, Play billing Library 5.2.0

Recommended Posts

hello everyone a few days ago i did tried to implement a one time purchase (make a paid android app )
there is no error showing except the message that i will show you next 
thing i did consider: 
Make sure the product ID in your code matches the ID of the product you created in the Google Play Console.
Make sure that the product is published and active in the Google Play Console.
Make sure that the account you are using to test the app is not the same account you used to create the product in the Google Play Console.
i don't know what I'm missing i keep thinking that the new library is the problem (because its come with new change to how to implement purchase) 
i did publish the app in Internal testing. 

i did multiply approach and multiply attempt to fix this with no luck yet with the help of chat gpt .
ps : following this topic. 
D11,unsupported version of Play billing - Cross-platform - Delphi-PRAXiS [en] (delphipraxis.net)

my code:

uses 
  FMX.InAppPurchase;

types
      procedure InAppPurchaseSetupComplete(Sender: TObject);
    procedure InAppPurchaseProductsRequestResponse(Sender: TObject;
      const Products: TIAPProductList; const InvalidProductIDs: TStrings);
    procedure InAppPurchasePurchaseCompleted(Sender: TObject;
      const ProductID: string; NewTransaction: Boolean);

private 
  function Purchase(const ProductId: string): Boolean;

const
  NoAdsId = 'barcoderpro';
 var
  FProductIsValid: Boolean;
  fisPurchased :Boolean;

procedure TFormMain.FormCreate(Sender: TObject);
{$IFDEF ANDROID}

  InAppPurchase1.ApplicationLicenseKey := 'key part 1'+ 'key part 2';
   InAppPurchase1.ProductIDs.Add(NoAdsId);
   InAppPurchase1.OnSetupComplete := InAppPurchaseSetupComplete;
   InAppPurchase1.OnProductsRequestResponse := InAppPurchaseProductsRequestResponse;
   InAppPurchase1.OnPurchaseCompleted := InAppPurchasePurchaseCompleted;

 {$ENDIF}
 end;

 procedure TFormMain.InAppPurchaseSetupComplete(Sender: TObject);
begin
  FIsPurchased := False;
  try
    InAppPurchase1.QueryProducts;
  except
    on E: Exception do
      ShowMessage(e.Message);
  end;
end;

 procedure TFormMain.InAppPurchaseProductsRequestResponse(Sender: TObject;
  const Products: TIAPProductList; const InvalidProductIDs: TStrings);
var
  Product: TProduct;
begin
  FIsPurchased := False;
  for Product in Products do
  begin
    if NoAdsId = Product.ProductID then
    begin
      FProductIsValid := True;
      if InAppPurchase1.IsProductPurchased(NoAdsId) then
      begin
        FIsPurchased := True;  // PURCHASED!
        ShowMessage('La version professionnelle est déjà activée');
      end;
    end;
  end;
end;


procedure TFormMain.InAppPurchasePurchaseCompleted(Sender: TObject;
  const ProductID: string; NewTransaction: Boolean);
begin
  if NewTransaction then
  begin
    ShowMessage('La version professionnelle activée');
    FIsPurchased := True;
  end
  else
    ShowMessage('L''achat a été annulé');
end;

function TFormMain.Purchase(const ProductId: string): Boolean;
begin
  Result := False;

  {$IFDEF ANDROID}
  if InAppPurchase1.IsSetupComplete and InAppPurchase1.CanMakeInAppPurchases then
  begin
    InAppPurchase1.PurchaseProduct(ProductId);
    Result := True;
  end
  else
    ShowMessage('L''achat n''est pas possible pour le moment. Essayez plus tard.');

  {$ENDIF}
end;


procedure TFormMain.btn7Click(Sender: TObject);
begin
  // User is not registered yet or trial period has expired, proceed with purchase
  if Purchase(NoAdsId) then begin
    // Purchase successful
//active the app pro // no  trial period 
end;
//////or 

 if FIsPurchased then
  begin
    ShowMessage('La version professionnelle est déjà activée');
  end
  else
  begin
    // User is not registered yet or trial period has expired, proceed with purchase
    if Purchase(NoAdsId) then
    begin
      // Purchase successful
      ShowMessage('La version professionnelle est activée.....');
    end;
  end;
 

 

Edited by toufik

Share this post


Link to post
4 minutes ago, toufik said:

i don't know what I'm missing i keep thinking that the new library is the problem (because its come with new change to how to implement purchase) 

It's supposed to be backward compatible. You should use the OnError event of InAppPurchase1 to find out what the failure is.

 

  • Like 1

Share this post


Link to post
4 hours ago, Dave Nottage said:

It's supposed to be backward compatible. You should use the OnError event of InAppPurchase1 to find out what the failure is.

 

after i add the code below no error nothing just like the first submit any idea ?
 

 types
 procedure InAppPurchase1Error(Sender: TObject; ErrorKind: TFailureKind;
      const ErrorMessage: string);


procedure TFormMain.FormCreate(Sender: TObject);
begin
// the code before then ....this 
     InAppPurchase1.OnError := InAppPurchase1Error;
     end;
     

 procedure TFormMain.InAppPurchase1Error(Sender: TObject;
  ErrorKind: TFailureKind; const ErrorMessage: string);
begin
 ShowMessage('Une erreur est survenue pendant l''achat : ' + ErrorMessage);
end;

 

Share this post


Link to post
3 minutes ago, toufik said:

after i add the code below no error nothing just like the first submit any idea ?

Just noticed your code does not call SetupInAppPurchase, so it's no wonder it does not even fire OnError.

 

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

×