I try to add In-app purchase in my app for the first time.
I use XE7. I’ve created test alpha-project in google play and some consumable products.
When I test purchase after “success payment” my app “doesn’t answer” and terminated (InAppPurchaseCompleted doesn’t start to work).
When I start my app again, google play say that “this client already has this product”. But I can’t consume it, or ever check using IsProductPurchased (it’s always false).
Maybe someone can give workable example of code.
My code is here:
type
TShopForm = class(TForm)
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure InAppPurchaseError (Sender: TObject;
ErrorKind: TFailureKind; const ErrorMessage: string);
procedure InAppPurchaseCompleted(Sender: TObject;
const ProductID: string; NewTransaction: Boolean);
procedure InAppProductsRequestResponse(Sender: TObject;
const Products: TIAPProductList; const InvalidProductIDs: TStrings);
procedure InAppPurchaseSetupComplete(Sender: TObject);
private
FInAppPurchase: TInAppPurchase;
{ Private declarations }
public
{ Public declarations }
end;
var
ShopForm: TShopForm;
implementation
const testp=’test13′;
procedure mlog(s: string);
begin
ShopForm.Memo1.Lines.Add(s);
end;
procedure TShopForm.Button1Click(Sender: TObject);
begin
FInAppPurchase.PurchaseProduct(testp);
end;
procedure TShopForm.InAppPurchaseSetupComplete(Sender: TObject);
begin
mlog(‘setup complete’);
end;
procedure TShopForm.InAppProductsRequestResponse(Sender: TObject;
const Products: TIAPProductList; const InvalidProductIDs: TStrings);
begin
mlog(‘ProductsRequestResponse’);
end;
procedure TShopForm.InAppPurchaseError(Sender: TObject;
ErrorKind: TFailureKind; const ErrorMessage: string);
begin
mlog(‘error ‘+ErrorMessage);
end;
procedure TShopForm.InAppPurchaseCompleted(Sender: TObject;
const ProductID: string; NewTransaction: Boolean);
begin
mlog(‘Purchase ‘+ProductID);
end;
procedure InAppConsumeCompleted(Sender: TObject; const ProductID:string);
begin
mlog(‘!consume ‘+ProductID);
end;
procedure TShopForm.FormCreate(Sender: TObject);
begin
FInAppPurchase:=TInAppPurchase.Create(self);
FInAppPurchase.ApplicationLicenseKey:=’MI….’;
FInAppPurchase.ProductIDs.Add(testp);
FInAppPurchase.OnSetupComplete:=InAppPurchaseSetupComplete;
FInAppPurchase.OnProductsRequestResponse:=InAppProductsRequestResponse;
FInAppPurchase.OnError:=InAppPurchaseError;
FInAppPurchase.OnPurchaseCompleted:=InAppPurchaseCompleted;
FInAppPurchase.SetupInAppPurchase;
end;