Skip to content

Commit 5dd80d4

Browse files
author
Junesig Kong
committed
Update reward rate card flow and BillingClient logic
1 parent e6c8450 commit 5dd80d4

5 files changed

Lines changed: 53 additions & 8 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:2dd643244fe507e5e7b58d4d6d6754a43df1b8fd9ee09fa6549ca697578431ca
3-
size 6232
2+
oid sha256:6cd514997ea43a57197cb88bfe9e8c813e565b0c1e0fb3f7e8f70ce24568f1ab
3+
size 6249
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:9a3649d582676e91ab81ec283d13b03d7677c15ad088946dd7124866fb8292f5
3-
size 260559
2+
oid sha256:23f18ee2816b929883fa17ea67c97380b13981df62f594cd5fd21097c9ad2038
3+
size 265608

trivialkart/trivialkart_unreal/Source/TrivialKart_Unreal/Private/GameInstances/TrivialKartGameInstance.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ void UTrivialKartGameInstance::Init()
4747
FOnReadUserFileCompleteDelegate::CreateUObject(this, &UTrivialKartGameInstance::OnCloudWriteComplete));
4848
}
4949
InitiateAutoLogin();
50+
// Check unacknowledged purchases on start or foreground
51+
CheckPendingPurchases();
52+
FCoreDelegates::ApplicationHasEnteredForegroundDelegate.AddUObject(this, &UTrivialKartGameInstance::CheckPendingPurchases);
5053
}
5154

5255
void UTrivialKartGameInstance::Shutdown()
@@ -60,6 +63,8 @@ void UTrivialKartGameInstance::Shutdown()
6063
CloudInterface->ClearOnReadUserFileCompleteDelegate_Handle(ReadSaveHandle);
6164
CloudInterface->ClearOnWriteUserFileCompleteDelegate_Handle(WriteSaveHandle);
6265
}
66+
FCoreDelegates::ApplicationHasEnteredForegroundDelegate.RemoveAll(this);
67+
Super::Shutdown();
6368
}
6469

6570
void UTrivialKartGameInstance::InitiateAutoLogin()
@@ -161,6 +166,45 @@ void UTrivialKartGameInstance::StartPurchasing(const FUniqueOfferId& OfferID, co
161166
}
162167
}
163168

169+
void UTrivialKartGameInstance::CheckPendingPurchases()
170+
{
171+
if (const IOnlineSubsystem* Subsystem = Online::GetSubsystem(GetWorld()))
172+
{
173+
if (const IOnlineIdentityPtr IdentityInterface = Online::GetIdentityInterface(GetWorld()))
174+
{
175+
if (const TSharedPtr<const FUniqueNetId> UserId = IdentityInterface->GetUniquePlayerId(0); UserId.IsValid())
176+
{
177+
if (const IOnlinePurchasePtr PurchaseInterface = Online::GetPurchaseInterface(GetWorld()); PurchaseInterface.IsValid())
178+
{
179+
PurchaseInterface->QueryReceipts(*UserId, true,
180+
FOnQueryReceiptsComplete::CreateWeakLambda(this,
181+
[this, PurchaseInterface, UserId](const FOnlineError& OnlineError)
182+
{
183+
if (!OnlineError.WasSuccessful())
184+
return;
185+
186+
TArray<FPurchaseReceipt> Receipts;
187+
PurchaseInterface->GetReceipts(*UserId, Receipts);
188+
189+
for (const FPurchaseReceipt& Receipt : Receipts)
190+
{
191+
for (const FPurchaseReceipt::FReceiptOfferEntry& Offer : Receipt.ReceiptOffers)
192+
{
193+
if (OnPurchaseReceived.IsBound())
194+
{
195+
OnPurchaseReceived.Broadcast(Offer.OfferId, 1);
196+
FPlatformMisc::LowLevelOutputDebugStringf(TEXT(" Pending purchase restored - Offer ID:: %s"), *Offer.OfferId);
197+
}
198+
// The Purchase Token is passed as the ReceiptId to tell the platform which purchase to finalize (consume/acknowledge).
199+
PurchaseInterface->FinalizePurchase(*UserId, Receipt.TransactionId);
200+
}
201+
}
202+
}));
203+
}
204+
}
205+
}
206+
}
207+
}
164208
UTrivialKartSaveGame* UTrivialKartGameInstance::LoadGame()
165209
{
166210
#if WITH_EDITOR

trivialkart/trivialkart_unreal/Source/TrivialKart_Unreal/Public/GameInstances/TrivialKartGameInstance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class TRIVIALKART_UNREAL_API UTrivialKartGameInstance : public UPlatformGameInst
5454

5555
void AddAchievementProgress(const float Progress, const FString& AchievementName);
5656
void StartPurchasing(const FUniqueOfferId& OfferID, const int32 Quantity, bool bIsConsumable);
57-
57+
void CheckPendingPurchases();
5858
UTrivialKartSaveGame* LoadGame();
5959
void SaveGame(UTrivialKartSaveGame* SaveData);
6060

trivialkart/trivialkart_unreal/Source/TrivialKart_Unreal/TrivialKart_Unreal.Build.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ public TrivialKart_Unreal(ReadOnlyTargetRules Target) : base(Target)
3737

3838
PrivateDependencyModuleNames.AddRange(new string[] {
3939
"OnlineSubsystem",
40-
"OnlineSubsystemUtils"
41-
});
40+
"OnlineSubsystemUtils",
41+
"Json",
42+
"JsonUtilities"
43+
});
4244

4345
if (Target.Platform == UnrealTargetPlatform.Android)
4446
{
4547
DynamicallyLoadedModuleNames.Add("OnlineSubsystemGooglePlay");
46-
DynamicallyLoadedModuleNames.Add("OnlineSubsystemGooglePlayExtension");
4748
}
4849
}
4950
}

0 commit comments

Comments
 (0)