Skip to content

Commit f8f1fed

Browse files
committed
feat: add user cancel purchase UI response
1 parent 57702cd commit f8f1fed

9 files changed

Lines changed: 49 additions & 41 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
poolakeyunitysdk-unity/.utmp

poolakeyunitysdk-unity/Assets/Bazaar/Poolakey/Demo/ScriptableObjects/UiManagerData.asset

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ MonoBehaviour:
2020
\u0645\u0648\u0641\u0642\u06CC\u062A \u0627\u0646\u062C\u0627\u0645 \u0634\u062F!"
2121
<OnConsumptionFailedMessage>k__BackingField: "\u0645\u0635\u0631\u0641 \u0628\u0627
2222
\u062E\u0637\u0627 \u0627\u0646\u062C\u0627\u0645 \u0634\u062F!"
23+
<OnUserCancelledPurchase>k__BackingField: "\u062E\u0631\u06CC\u062F \u0644\u063A\u0648
24+
\u0634\u062F!"

poolakeyunitysdk-unity/Assets/Bazaar/Poolakey/Demo/Scripts/IapManager.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public class IapManager : MonoBehaviour
1515
private Payment _payment;
1616

1717
private Func<string, Task> _onPurchaseSuccess = null;
18-
private Action _onPurchaseFailure = null;
19-
18+
private Action<bool> _onPurchaseFailure = null;
19+
private bool _userCancelled = false;
2020
private void Awake()
2121
{
2222
var securityCheck = SecurityCheck.Enable(Data.RsaKey);
@@ -42,7 +42,9 @@ private void OnPaymentConnectSuccess(Result<bool> result)
4242
public async Task Purchase(string productId, Action<bool> onComplete)
4343
{
4444
Debug.Log($"Purchasing product: {productId}");
45+
_userCancelled = true;
4546
var result = await _payment.Purchase(productId);
47+
_userCancelled = false;
4648
Debug.Log($"purchase result: {result.message}, status: {result.status},{result.data.purchaseState}");
4749
if (result.status == Status.Success)
4850
{
@@ -57,20 +59,24 @@ public async Task Purchase(string productId, Action<bool> onComplete)
5759
}
5860

5961
public async Task PurchaseWithCallBack(string productId, Func<string, Task> onSuccess = null,
60-
Action onFailure = null)
62+
Action<bool> onFailure = null)
6163
{
6264
Debug.Log($"Purchasing product: {productId}");
6365
_onPurchaseFailure = onFailure;
6466
_onPurchaseSuccess = onSuccess;
67+
_userCancelled = true;
6568
var result = await _payment.Purchase(productId, onComplete: OnComplete);
69+
_userCancelled = false;
6670
Debug.Log($"purchase result: {result.message}, status: {result.status},{result.data.purchaseState}");
6771
}
6872

6973
private void OnComplete(Result<PurchaseInfo> result)
7074
{
7175
if (result.status != Status.Success)
7276
{
73-
_onPurchaseFailure?.Invoke();
77+
78+
_onPurchaseFailure?.Invoke(_userCancelled);
79+
_userCancelled = false;
7480
_onPurchaseFailure = null;
7581
_onPurchaseSuccess = null;
7682
return;
@@ -115,5 +121,8 @@ public async Task ConsumePurchase(string productId, Action<bool> onComplete = nu
115121

116122
onComplete?.Invoke(false);
117123
}
124+
125+
126+
118127
}
119128
}

poolakeyunitysdk-unity/Assets/Bazaar/Poolakey/Demo/Scripts/UIManager.cs

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,25 @@
11
using System;
22
using System.Threading.Tasks;
33
using RTLTMPro;
4-
using TMPro;
54
using UnityEngine;
65

76
namespace PoolakeyDemo
87
{
98
public class UIManager : MonoBehaviour
109
{
1110
[SerializeField] private IapManager _iapManager;
12-
[SerializeField] private PoolakiData _poolakiData;
11+
[SerializeField] private PoolakiData _poolakiData;
1312
[SerializeField] private UiManagerData _uiManagerData;
1413
[SerializeField] MessageBoxPanel _messageBoxPanel;
1514
[SerializeField] ResourceManager _resourceManager;
1615
[SerializeField] private RTLTextMeshPro _text_starCount;
1716
[SerializeField] private RTLTextMeshPro _text_remainingJellyTime;
18-
private bool _isPurchasing = false;
19-
private bool _isConsuming = false;
20-
private bool _isGettingPurchaseData = false;
2117

2218
private void Awake()
2319
{
2420
_resourceManager.OnStarCountChange += OnStarCountChane;
2521
_resourceManager.OnRemainingTimeChange += OnJellyTimeUpdate;
26-
2722
}
28-
2923
private void OnDestroy()
3024
{
3125
_resourceManager.OnStarCountChange -= OnStarCountChane;
@@ -54,17 +48,16 @@ public void OnPurchaseSubscriptionClick()
5448

5549
private async Task PurchaseAndConsume(int index)
5650
{
57-
if (_isPurchasing)
58-
return;
59-
_isPurchasing = true;
6051
await _iapManager.PurchaseWithCallBack(_poolakiData.Items[index].ItemSKU, ConsumeOnPurchaseSuccess,
6152
OnPurchaseFailure);
62-
_isPurchasing = false;
6353
}
6454

65-
private void OnPurchaseFailure()
55+
private void OnPurchaseFailure(bool userCancelled)
6656
{
67-
_messageBoxPanel.Show(_uiManagerData.OnPurchaseFailedMessage);
57+
var message = userCancelled
58+
? _uiManagerData.OnUserCancelledPurchase
59+
: _uiManagerData.OnPurchaseFailedMessage;
60+
_messageBoxPanel.Show(message);
6861
}
6962

7063
private async Task ConsumeOnPurchaseSuccess(string itemSKU)
@@ -74,25 +67,21 @@ private async Task ConsumeOnPurchaseSuccess(string itemSKU)
7467

7568
private async Task Purchase(int itemIndex)
7669
{
77-
if (_isPurchasing)
78-
return;
79-
_isPurchasing = true;
8070
Action<bool> onComplete = itemIndex == 1 ? OnSubscriptionPurchaseComplete : OnPurchaseComplete;
81-
await _iapManager.Purchase(_poolakiData.Items[itemIndex].ItemSKU,onComplete);
82-
_isPurchasing = false;
71+
await _iapManager.Purchase(_poolakiData.Items[itemIndex].ItemSKU, onComplete);
8372
}
8473

8574
private void OnSubscriptionPurchaseComplete(bool isSucceeded)
8675
{
87-
#if UNITY_EDITOR
76+
#if UNITY_EDITOR
8877
_messageBoxPanel.Show(_uiManagerData.OnPurchaseSuccessMessage);
89-
_resourceManager.AddJellyEndTime(new TimeSpan(0,5,0));
78+
_resourceManager.AddJellyEndTime(new TimeSpan(0, 5, 0));
9079
return;
91-
#endif
80+
#endif
9281
if (isSucceeded)
9382
{
9483
_messageBoxPanel.Show(_uiManagerData.OnPurchaseSuccessMessage);
95-
_resourceManager.AddJellyEndTime(new TimeSpan(0,5,0));
84+
_resourceManager.AddJellyEndTime(new TimeSpan(0, 5, 0));
9685
return;
9786
}
9887

@@ -112,20 +101,16 @@ private void OnPurchaseComplete(bool isSucceeded)
112101

113102
private async Task Consume(int itemIndex)
114103
{
115-
if (_isConsuming)
116-
return;
117-
_isConsuming = true;
104+
// if (_isConsuming)
105+
// return;
106+
// _isConsuming = true;
118107
await _iapManager.ConsumePurchase(_poolakiData.Items[itemIndex].ItemSKU, OnConsumeComplete);
119-
_isConsuming = false;
108+
// _isConsuming = false;
120109
}
121110

122111
public async Task GetPurchaseData()
123112
{
124-
if (_isGettingPurchaseData)
125-
return;
126-
_isGettingPurchaseData = true;
127113
await _iapManager.GetPurchases();
128-
_isGettingPurchaseData = false;
129114
}
130115

131116
private void OnConsumeComplete(bool isSucceeded)
@@ -136,18 +121,19 @@ private void OnConsumeComplete(bool isSucceeded)
136121
_resourceManager.AddStar(100);
137122
return;
138123
}
124+
139125
_messageBoxPanel.Show(_uiManagerData.OnConsumptionFailedMessage);
140126
}
141127

142128
private void OnStarCountChane(int starCount)
143129
{
144-
_text_starCount.Farsi=true;
130+
_text_starCount.Farsi = true;
145131
_text_starCount.text = $"{starCount:N0}";
146132
}
147133

148134
private void OnJellyTimeUpdate(string jellyTime)
149135
{
150-
_text_remainingJellyTime.Farsi=true;
136+
_text_remainingJellyTime.Farsi = true;
151137
_text_remainingJellyTime.text = jellyTime;
152138
}
153139
}

poolakeyunitysdk-unity/Assets/Bazaar/Poolakey/Demo/Scripts/UiManagerData.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class UiManagerData : ScriptableObject
88
[field: SerializeField] public string OnPurchaseFailedMessage { get; private set; }
99
[field: SerializeField] public string OnConsumptionSuccessMessage { get; private set; }
1010
[field: SerializeField] public string OnConsumptionFailedMessage { get; private set; }
11+
[field: SerializeField] public string OnUserCancelledPurchase { get; private set; }
1112

1213
}
1314
}
Binary file not shown.

poolakeyunitysdk-unity/Packages/manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"com.unity.collab-proxy": "2.5.2",
66
"com.unity.ide.rider": "3.0.34",
77
"com.unity.ide.visualstudio": "2.0.22",
8+
"com.unity.mobile.android-logcat": "1.4.3",
89
"com.unity.multiplayer.center": "1.0.0",
910
"com.unity.test-framework": "1.4.5",
1011
"com.unity.timeline": "1.8.7",

poolakeyunitysdk-unity/Packages/packages-lock.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@
4747
},
4848
"url": "https://packages.unity.com"
4949
},
50+
"com.unity.mobile.android-logcat": {
51+
"version": "1.4.3",
52+
"depth": 0,
53+
"source": "registry",
54+
"dependencies": {},
55+
"url": "https://packages.unity.com"
56+
},
5057
"com.unity.multiplayer.center": {
5158
"version": "1.0.0",
5259
"depth": 0,

poolakeyunitysdk-unity/ProjectSettings/ProjectSettings.asset

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ PlayerSettings:
140140
loadStoreDebugModeEnabled: 0
141141
visionOSBundleVersion: 1.0
142142
tvOSBundleVersion: 1.0
143-
bundleVersion: 0.3
143+
bundleVersion: 0.4
144144
preloadedAssets: []
145145
metroInputSource: 0
146146
wsaTransparentSwapchain: 0
@@ -170,9 +170,9 @@ PlayerSettings:
170170
iPhone: 0
171171
tvOS: 0
172172
overrideDefaultApplicationIdentifier: 0
173-
AndroidBundleVersionCode: 3
173+
AndroidBundleVersionCode: 4
174174
AndroidMinSdkVersion: 23
175-
AndroidTargetSdkVersion: 35
175+
AndroidTargetSdkVersion: 33
176176
AndroidPreferredInstallLocation: 1
177177
aotOptions:
178178
stripEngineCode: 1
@@ -253,7 +253,7 @@ PlayerSettings:
253253
clonedFromGUID: c0afd0d1d80e3634a9dac47e8a0426ea
254254
templatePackageId: com.unity.template.3d@5.0.4
255255
templateDefaultScene: Assets/Scenes/SampleScene.unity
256-
useCustomMainManifest: 0
256+
useCustomMainManifest: 1
257257
useCustomLauncherManifest: 0
258258
useCustomMainGradleTemplate: 1
259259
useCustomLauncherGradleManifest: 0
@@ -831,7 +831,8 @@ PlayerSettings:
831831
scriptingDefineSymbols: {}
832832
additionalCompilerArguments: {}
833833
platformArchitecture: {}
834-
scriptingBackend: {}
834+
scriptingBackend:
835+
Android: 0
835836
il2cppCompilerConfiguration: {}
836837
il2cppCodeGeneration: {}
837838
il2cppStacktraceInformation: {}

0 commit comments

Comments
 (0)