Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Git LFS file not shown
Git LFS file not shown
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ void UTrivialKartGameInstance::Init()
FOnReadUserFileCompleteDelegate::CreateUObject(this, &UTrivialKartGameInstance::OnCloudWriteComplete));
}
InitiateAutoLogin();
// Check unacknowledged purchases on start or foreground
FCoreDelegates::ApplicationHasEnteredForegroundDelegate.AddUObject(this, &UTrivialKartGameInstance::CheckPendingPurchases);
Comment thread
jsyjbaba marked this conversation as resolved.
}

void UTrivialKartGameInstance::Shutdown()
Expand All @@ -60,6 +62,8 @@ void UTrivialKartGameInstance::Shutdown()
CloudInterface->ClearOnReadUserFileCompleteDelegate_Handle(ReadSaveHandle);
CloudInterface->ClearOnWriteUserFileCompleteDelegate_Handle(WriteSaveHandle);
}
FCoreDelegates::ApplicationHasEnteredForegroundDelegate.RemoveAll(this);
Super::Shutdown();
}

void UTrivialKartGameInstance::InitiateAutoLogin()
Expand Down Expand Up @@ -161,6 +165,45 @@ void UTrivialKartGameInstance::StartPurchasing(const FUniqueOfferId& OfferID, co
}
}

void UTrivialKartGameInstance::CheckPendingPurchases()
{
if (const IOnlineSubsystem* Subsystem = Online::GetSubsystem(GetWorld()))
{
if (const IOnlineIdentityPtr IdentityInterface = Online::GetIdentityInterface(GetWorld()))
{
if (const TSharedPtr<const FUniqueNetId> UserId = IdentityInterface->GetUniquePlayerId(0); UserId.IsValid())
{
if (const IOnlinePurchasePtr PurchaseInterface = Online::GetPurchaseInterface(GetWorld()); PurchaseInterface.IsValid())
{
PurchaseInterface->QueryReceipts(*UserId, true,
FOnQueryReceiptsComplete::CreateWeakLambda(this,
[this, PurchaseInterface, UserId](const FOnlineError& OnlineError)
{
if (!OnlineError.WasSuccessful())
return;

TArray<FPurchaseReceipt> Receipts;
PurchaseInterface->GetReceipts(*UserId, Receipts);

for (const FPurchaseReceipt& Receipt : Receipts)
{
for (const FPurchaseReceipt::FReceiptOfferEntry& Offer : Receipt.ReceiptOffers)
{
if (OnPurchaseReceived.IsBound())
{
OnPurchaseReceived.Broadcast(Offer.OfferId, 1);
FPlatformMisc::LowLevelOutputDebugStringf(TEXT(" Pending purchase restored - Offer ID:: %s"), *Offer.OfferId);
}
// The Purchase Token is passed as the ReceiptId to tell the platform which purchase to finalize (consume/acknowledge).
PurchaseInterface->FinalizePurchase(*UserId, Receipt.TransactionId);
}
}
Comment thread
RKS13D marked this conversation as resolved.
}));
}
}
}
}
}
UTrivialKartSaveGame* UTrivialKartGameInstance::LoadGame()
{
#if WITH_EDITOR
Expand Down Expand Up @@ -230,6 +273,8 @@ void UTrivialKartGameInstance::OnLoginCompleted(int32 LocalUserNum, bool bWasSuc
CloudInterface->ReadUserFile(*IdentityInterface->GetUniquePlayerId(0), "TrivialKartCloudSave");
}
}
// Check unacknowledged purchases on start or foreground
CheckPendingPurchases();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class TRIVIALKART_UNREAL_API UTrivialKartGameInstance : public UPlatformGameInst

void AddAchievementProgress(const float Progress, const FString& AchievementName);
void StartPurchasing(const FUniqueOfferId& OfferID, const int32 Quantity, bool bIsConsumable);

void CheckPendingPurchases();
UTrivialKartSaveGame* LoadGame();
void SaveGame(UTrivialKartSaveGame* SaveData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ public TrivialKart_Unreal(ReadOnlyTargetRules Target) : base(Target)

PrivateDependencyModuleNames.AddRange(new string[] {
"OnlineSubsystem",
"OnlineSubsystemUtils"
});
"OnlineSubsystemUtils",
"Json",
"JsonUtilities"
});

if (Target.Platform == UnrealTargetPlatform.Android)
{
DynamicallyLoadedModuleNames.Add("OnlineSubsystemGooglePlay");
DynamicallyLoadedModuleNames.Add("OnlineSubsystemGooglePlayExtension");
}
}
}