Skip to content

Commit 55c7164

Browse files
authored
Merge pull request #114 from android/feature/reward-update
Update reward rate card flow and BillingClient logic
2 parents e6c8450 + 808cfd0 commit 55c7164

5 files changed

Lines changed: 54 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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ void UTrivialKartGameInstance::Init()
4747
FOnReadUserFileCompleteDelegate::CreateUObject(this, &UTrivialKartGameInstance::OnCloudWriteComplete));
4848
}
4949
InitiateAutoLogin();
50+
// Check unacknowledged purchases on start or foreground
51+
FCoreDelegates::ApplicationHasEnteredForegroundDelegate.AddUObject(this, &UTrivialKartGameInstance::CheckPendingPurchases);
5052
}
5153

5254
void UTrivialKartGameInstance::Shutdown()
@@ -60,6 +62,8 @@ void UTrivialKartGameInstance::Shutdown()
6062
CloudInterface->ClearOnReadUserFileCompleteDelegate_Handle(ReadSaveHandle);
6163
CloudInterface->ClearOnWriteUserFileCompleteDelegate_Handle(WriteSaveHandle);
6264
}
65+
FCoreDelegates::ApplicationHasEnteredForegroundDelegate.RemoveAll(this);
66+
Super::Shutdown();
6367
}
6468

6569
void UTrivialKartGameInstance::InitiateAutoLogin()
@@ -161,6 +165,45 @@ void UTrivialKartGameInstance::StartPurchasing(const FUniqueOfferId& OfferID, co
161165
}
162166
}
163167

168+
void UTrivialKartGameInstance::CheckPendingPurchases()
169+
{
170+
if (const IOnlineSubsystem* Subsystem = Online::GetSubsystem(GetWorld()))
171+
{
172+
if (const IOnlineIdentityPtr IdentityInterface = Online::GetIdentityInterface(GetWorld()))
173+
{
174+
if (const TSharedPtr<const FUniqueNetId> UserId = IdentityInterface->GetUniquePlayerId(0); UserId.IsValid())
175+
{
176+
if (const IOnlinePurchasePtr PurchaseInterface = Online::GetPurchaseInterface(GetWorld()); PurchaseInterface.IsValid())
177+
{
178+
PurchaseInterface->QueryReceipts(*UserId, true,
179+
FOnQueryReceiptsComplete::CreateWeakLambda(this,
180+
[this, PurchaseInterface, UserId](const FOnlineError& OnlineError)
181+
{
182+
if (!OnlineError.WasSuccessful())
183+
return;
184+
185+
TArray<FPurchaseReceipt> Receipts;
186+
PurchaseInterface->GetReceipts(*UserId, Receipts);
187+
188+
for (const FPurchaseReceipt& Receipt : Receipts)
189+
{
190+
for (const FPurchaseReceipt::FReceiptOfferEntry& Offer : Receipt.ReceiptOffers)
191+
{
192+
if (OnPurchaseReceived.IsBound())
193+
{
194+
OnPurchaseReceived.Broadcast(Offer.OfferId, 1);
195+
FPlatformMisc::LowLevelOutputDebugStringf(TEXT(" Pending purchase restored - Offer ID:: %s"), *Offer.OfferId);
196+
}
197+
// The Purchase Token is passed as the ReceiptId to tell the platform which purchase to finalize (consume/acknowledge).
198+
PurchaseInterface->FinalizePurchase(*UserId, Receipt.TransactionId);
199+
}
200+
}
201+
}));
202+
}
203+
}
204+
}
205+
}
206+
}
164207
UTrivialKartSaveGame* UTrivialKartGameInstance::LoadGame()
165208
{
166209
#if WITH_EDITOR
@@ -230,6 +273,8 @@ void UTrivialKartGameInstance::OnLoginCompleted(int32 LocalUserNum, bool bWasSuc
230273
CloudInterface->ReadUserFile(*IdentityInterface->GetUniquePlayerId(0), "TrivialKartCloudSave");
231274
}
232275
}
276+
// Check unacknowledged purchases on start or foreground
277+
CheckPendingPurchases();
233278
}
234279
}
235280

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)