com.xd.sdk.payment 0.0.1 → 0.0.10-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/Plugins/Android/libs/XDGPaymentUPPay_7.0.0.aar +0 -0
  2. package/Plugins/Android/libs/{XDGPayment_6.21.1.aar.meta → XDGPaymentUPPay_7.0.0.aar.meta} +2 -2
  3. package/Plugins/Android/libs/XDGPayment_7.0.0.aar +0 -0
  4. package/Plugins/Android/libs/XDGPayment_7.0.0.aar.meta +32 -0
  5. package/Plugins/Android/libs.meta +1 -1
  6. package/Plugins/Android.meta +1 -1
  7. package/Plugins/iOS/XDPaymentSDK.framework/Headers/XDGOrderInfo.h +9 -9
  8. package/Plugins/iOS/XDPaymentSDK.framework/Headers/XDGOrderInfo.h.meta +1 -1
  9. package/Plugins/iOS/XDPaymentSDK.framework/Headers/XDGPayment.h +12 -57
  10. package/Plugins/iOS/XDPaymentSDK.framework/Headers/XDGPayment.h.meta +1 -1
  11. package/Plugins/iOS/XDPaymentSDK.framework/Headers/XDGPaymentDefines.h +49 -0
  12. package/{README.md.meta → Plugins/iOS/XDPaymentSDK.framework/Headers/XDGPaymentDefines.h.meta} +2 -2
  13. package/Plugins/iOS/XDPaymentSDK.framework/Headers/XDGPaymentParams.h +43 -0
  14. package/Plugins/iOS/XDPaymentSDK.framework/Headers/XDGPaymentParams.h.meta +7 -0
  15. package/Plugins/iOS/XDPaymentSDK.framework/Headers/XDGPaymentService.h +11 -8
  16. package/Plugins/iOS/XDPaymentSDK.framework/Headers/XDGPaymentService.h.meta +1 -1
  17. package/Plugins/iOS/XDPaymentSDK.framework/Headers/XDGPaymentVersion.h +3 -2
  18. package/Plugins/iOS/XDPaymentSDK.framework/Headers/XDGPaymentVersion.h.meta +1 -1
  19. package/Plugins/iOS/XDPaymentSDK.framework/Headers/XDGPendingPurchase.h +18 -0
  20. package/Plugins/iOS/XDPaymentSDK.framework/Headers/XDGPendingPurchase.h.meta +7 -0
  21. package/Plugins/iOS/XDPaymentSDK.framework/Headers/XDGProductInfo.h +29 -2
  22. package/Plugins/iOS/XDPaymentSDK.framework/Headers/XDGProductInfo.h.meta +1 -1
  23. package/Plugins/iOS/XDPaymentSDK.framework/Headers/XDGTransactionInfo.h +7 -3
  24. package/Plugins/iOS/XDPaymentSDK.framework/Headers/XDGTransactionInfo.h.meta +1 -1
  25. package/Plugins/iOS/XDPaymentSDK.framework/Headers/XDPaymentSDK.h +2 -1
  26. package/Plugins/iOS/XDPaymentSDK.framework/Headers/XDPaymentSDK.h.meta +1 -1
  27. package/Plugins/iOS/XDPaymentSDK.framework/Headers.meta +1 -1
  28. package/Plugins/iOS/XDPaymentSDK.framework/Info.plist +0 -0
  29. package/Plugins/iOS/XDPaymentSDK.framework/Info.plist.meta +1 -1
  30. package/Plugins/iOS/XDPaymentSDK.framework/Modules/module.modulemap.meta +1 -1
  31. package/Plugins/iOS/XDPaymentSDK.framework/Modules.meta +1 -1
  32. package/Plugins/iOS/XDPaymentSDK.framework/XDPaymentSDK +0 -0
  33. package/Plugins/iOS/XDPaymentSDK.framework/XDPaymentSDK.meta +1 -1
  34. package/Plugins/iOS/XDPaymentSDK.framework.meta +56 -3
  35. package/Plugins/iOS.meta +1 -1
  36. package/Plugins.meta +1 -1
  37. package/{Mobile → Runtime/Internal/Mobile}/PaymentConstants.cs +5 -8
  38. package/{Mobile/Editor/XDPaymentMobileProcessBuild.cs.meta → Runtime/Internal/Mobile/PaymentConstants.cs.meta} +1 -1
  39. package/Runtime/Internal/Mobile/PaymentFeaturesImpl.cs +185 -0
  40. package/{Editor/XDGAndroidPaymentProcessor.cs.meta → Runtime/Internal/Mobile/PaymentFeaturesImpl.cs.meta} +1 -1
  41. package/Runtime/Internal/Mobile/XDGRestoredPurchasesWrapper.cs +23 -0
  42. package/{Mobile → Runtime/Internal/Mobile}/XDGRestoredPurchasesWrapper.cs.meta +1 -1
  43. package/{Mobile.meta → Runtime/Internal/Mobile.meta} +1 -1
  44. package/Runtime/Internal/Standalone/AliyunTrack.Payment.cs +156 -0
  45. package/{Mobile/XDGDataBean.cs.meta → Runtime/Internal/Standalone/AliyunTrack.Payment.cs.meta} +1 -1
  46. package/Runtime/Internal/Standalone/Bean/PayCheckResponse.cs +19 -0
  47. package/{Editor/XDPaymentProcessBuild.cs.meta → Runtime/Internal/Standalone/Bean/PayCheckResponse.cs.meta} +1 -1
  48. package/Runtime/Internal/Standalone/Bean/PayInfo.cs +31 -0
  49. package/Runtime/Internal/Standalone/Bean/PayInfo.cs.meta +11 -0
  50. package/Runtime/Internal/Standalone/Bean/QueryProductsResponse.cs +46 -0
  51. package/Runtime/Internal/Standalone/Bean/QueryProductsResponse.cs.meta +11 -0
  52. package/Runtime/Internal/Standalone/Bean/XDGRefundResultWrapper.cs +19 -0
  53. package/Runtime/Internal/Standalone/Bean/XDGRefundResultWrapper.cs.meta +11 -0
  54. package/{Editor/XD.SDK.Payment.Editor.asmdef.meta → Runtime/Internal/Standalone/Bean.meta} +3 -2
  55. package/Runtime/Internal/Standalone/PayListener.cs +83 -0
  56. package/Runtime/Internal/Standalone/PayListener.cs.meta +11 -0
  57. package/Runtime/Internal/Standalone/PayModule.cs +261 -0
  58. package/Runtime/Internal/Standalone/PayModule.cs.meta +11 -0
  59. package/Runtime/Internal/Standalone/PaymentAlert.cs +112 -0
  60. package/Runtime/Internal/Standalone/PaymentAlert.cs.meta +11 -0
  61. package/Runtime/Internal/Standalone/PaymentFeaturesImpl.cs +238 -0
  62. package/Runtime/Internal/Standalone/PaymentFeaturesImpl.cs.meta +11 -0
  63. package/{Mobile/Editor.meta → Runtime/Internal/Standalone.meta} +1 -1
  64. package/Runtime/Internal/XDGPaymentInternal.cs +46 -0
  65. package/Runtime/Internal/XDGPaymentInternal.cs.meta +11 -0
  66. package/Runtime/{XDGRefundDetails.cs → Internal/XDGRefundDetails.cs} +3 -5
  67. package/Runtime/Internal/XDGRefundDetails.cs.meta +11 -0
  68. package/Runtime/{XDGRefundResultWrapper.cs → Internal/XDGRefundResultWrapper.cs} +1 -1
  69. package/Runtime/Internal/XDGRefundResultWrapper.cs.meta +11 -0
  70. package/{Editor.meta → Runtime/Internal.meta} +1 -1
  71. package/Runtime/Public/XDGPayment.Deprecated.cs +231 -0
  72. package/Runtime/Public/XDGPayment.Deprecated.cs.meta +11 -0
  73. package/Runtime/Public/XDGPayment.cs +97 -0
  74. package/Runtime/Public/XDGPayment.cs.meta +11 -0
  75. package/Runtime/Public/XDGPaymentEventHandler.cs +34 -0
  76. package/Runtime/Public/XDGPaymentEventHandler.cs.meta +3 -0
  77. package/Runtime/Public.meta +8 -0
  78. package/Runtime/XD.SDK.Payment.asmdef +5 -2
  79. package/Runtime/XD.SDK.Payment.asmdef.meta +6 -2
  80. package/Runtime.meta +7 -2
  81. package/package.json +5 -5
  82. package/package.json.meta +2 -2
  83. package/Editor/XD.SDK.Payment.Editor.asmdef +0 -19
  84. package/Editor/XDGAndroidPaymentProcessor.cs +0 -44
  85. package/Editor/XDPaymentProcessBuild.cs +0 -18
  86. package/Mobile/Editor/XD.SDK.Payment.Mobile.Editor.asmdef +0 -20
  87. package/Mobile/Editor/XD.SDK.Payment.Mobile.Editor.asmdef.meta +0 -7
  88. package/Mobile/Editor/XDPaymentMobileProcessBuild.cs +0 -20
  89. package/Mobile/PaymentConstants.cs.meta +0 -3
  90. package/Mobile/XD.SDK.Payment.Mobile.asmdef +0 -22
  91. package/Mobile/XD.SDK.Payment.Mobile.asmdef.meta +0 -7
  92. package/Mobile/XDGDataBean.cs +0 -242
  93. package/Mobile/XDGPaymentDetailsParam.cs +0 -127
  94. package/Mobile/XDGPaymentDetailsParam.cs.meta +0 -3
  95. package/Mobile/XDGPaymentMobile.cs +0 -132
  96. package/Mobile/XDGPaymentMobile.cs.meta +0 -11
  97. package/Mobile/XDGPaymentMobileImpl.cs +0 -331
  98. package/Mobile/XDGPaymentMobileImpl.cs.meta +0 -11
  99. package/Mobile/XDGRestoredPurchasesWrapper.cs +0 -42
  100. package/Plugins/Android/libs/XDGPayment_6.21.1.aar +0 -0
  101. package/README.md +0 -0
  102. package/Runtime/IXDGPayment.cs +0 -38
  103. package/Runtime/IXDGPayment.cs.meta +0 -3
  104. package/Runtime/WebPayResultType.cs +0 -8
  105. package/Runtime/WebPayResultType.cs.meta +0 -3
  106. package/Runtime/XDGPayType.cs +0 -8
  107. package/Runtime/XDGPayType.cs.meta +0 -3
  108. package/Runtime/XDGPayment.cs +0 -101
  109. package/Runtime/XDGPayment.cs.meta +0 -3
  110. package/Runtime/XDGRefundDetails.cs.meta +0 -3
  111. package/Runtime/XDGRefundResultWrapper.cs.meta +0 -3
  112. package/Runtime/XDGSkuDetailInfo.cs +0 -252
  113. package/Runtime/XDGSkuDetailInfo.cs.meta +0 -3
@@ -0,0 +1,83 @@
1
+ #if UNITY_EDITOR || UNITY_STANDALONE
2
+
3
+ using System;
4
+ using System.Net;
5
+ using System.Threading.Tasks;
6
+ using UnityEngine;
7
+ using XD.SDK.Common;
8
+ using XD.SDK.Common.Internal.Standalone;
9
+
10
+ namespace XD.SDK.Payment.Internal.Standalone
11
+ {
12
+ internal class PayListener
13
+ {
14
+ private const float TIMEOUT = 0.25f;
15
+ private float _timeLeft = 0;
16
+
17
+ internal async Task Start(string url)
18
+ {
19
+ string redirectUri = $"http://{IPAddress.Loopback}:{LocalServerUtils.GetRandomUnusedPort()}";
20
+ string state = LocalServerUtils.GenerateRandomDataBase64url(32);
21
+ string payRequest = $"{url}&redirect_uri={redirectUri}&state={state}";
22
+
23
+ XDGLogger.Debug($"pay: {payRequest}");
24
+ _timeLeft = TIMEOUT;
25
+ UIManager.ShowLoading(true);
26
+ Application.OpenURL(Uri.EscapeUriString(payRequest));
27
+ AliyunTrack.PaymentCallPage();
28
+ // 启动监听
29
+ HttpListener server = new HttpListener();
30
+ server.Prefixes.Add($"{redirectUri}/");
31
+ server.Start();
32
+
33
+ while (true)
34
+ {
35
+ UIManager.Instance.DelayAction(TIMEOUT, () => { CloseLoading(); });
36
+ HttpListenerContext context = await server.GetContextAsync();
37
+
38
+ Debug.Log($"Request method: {context.Request.HttpMethod}");
39
+
40
+ context.Response.StatusCode = 200;
41
+ context.Response.Close();
42
+
43
+ if (context.Request.HttpMethod == "OPTIONS")
44
+ {
45
+ continue;
46
+ }
47
+
48
+ server.Stop();
49
+
50
+ XDGLogger.Debug($"pay callback: {context.Request.RawUrl}");
51
+
52
+ WindowUtils.BringToFront();
53
+
54
+ string result = context.Request.QueryString["pay_result"];
55
+ if (result == "success")
56
+ {
57
+ CloseLoading();
58
+ AliyunTrack.PaymentDone();
59
+ return;
60
+ }
61
+ else if (result == "fail")
62
+ {
63
+ CloseLoading();
64
+ AliyunTrack.PaymentFailed("fail");
65
+ throw new Exception("pay failed");
66
+ }
67
+ else if (result == "cancel")
68
+ {
69
+ CloseLoading();
70
+ AliyunTrack.PaymentFailed("user_cancel");
71
+ throw new TaskCanceledException();
72
+ }
73
+ }
74
+ }
75
+
76
+ private void CloseLoading()
77
+ {
78
+ UIManager.DismissLoading();
79
+ _timeLeft = 0;
80
+ }
81
+ }
82
+ }
83
+ #endif
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 954cf4692da64a3ab9a1212d9ddab1b9
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,261 @@
1
+ #if UNITY_EDITOR || UNITY_STANDALONE
2
+
3
+ using System;
4
+ using System.Threading.Tasks;
5
+ using System.Collections.Generic;
6
+ using System.Security.Cryptography;
7
+ using System.Text;
8
+ using System.Threading;
9
+ using UnityEngine;
10
+ using XD.SDK.Account;
11
+ using XD.SDK.Common;
12
+ using XD.SDK.Common.Internal;
13
+ using XD.SDK.Common.Internal.Standalone;
14
+ using CommonAliyunTrack = XD.SDK.Common.Internal.Standalone.AliyunTrack;
15
+ using XDHttpClient = XD.SDK.Common.Internal.Standalone.XDHttpClient;
16
+
17
+ namespace XD.SDK.Payment.Internal.Standalone
18
+ {
19
+ public class PayModule
20
+ {
21
+ // 查询补款订单信息
22
+ private readonly static string XDG_PAYBACK_LIST = "order/v1/user/repayOrders";
23
+
24
+ // 创建订单
25
+ private readonly static string XDG_CREATE_ORDER = "trade/v1/client/createOrder";
26
+
27
+ // 上报订单
28
+ private readonly static string XDG_REPORT_ORDER = "callback/v1/client/pay/notify";
29
+
30
+ // 查询商品
31
+ private readonly static string XDG_QUERY_PRODUCTS = "payment/product/v1/query/game/skus";
32
+ // 查询 silent 商品价格
33
+ private readonly static string XDG_QUERY_PRODUCTS_V2 = "payment/product/v2/query/game/skus";
34
+
35
+ internal readonly static int PAY_DONE = 0;
36
+
37
+ internal readonly static int PAY_CANCEL = -1;
38
+
39
+ internal readonly static string PAY_FRAGMENT_SUCCESS = "#success";
40
+
41
+ internal readonly static string PAY_FRAGMENT_FAILURE = "#fail";
42
+
43
+ internal readonly static string PAY_FRAGMENT_CANCEL = "#cancel";
44
+
45
+ private readonly static int STEAM_CHANNEL_TYPE = 17;
46
+
47
+ private readonly static int STEAM_PAYMENT_TYPE = 0;
48
+
49
+ private readonly static int STEAM_PAY_ORDER_TYPE = 0;
50
+
51
+ public static string GetPayUrl(string serverId, string roleId, string productId,
52
+ string orderId = null,
53
+ string productName = null,
54
+ double payAmount = 0,
55
+ string extras = null)
56
+ {
57
+ Dictionary<string, object> queryParmas = new Dictionary<string, object>
58
+ {
59
+ { "appId", ConfigModule.AppId },
60
+ { "serverId", serverId },
61
+ { "roleId", roleId },
62
+ { "productSkuCode", productId },
63
+ { "lang", XDLocalization.GetLanguageKey() },
64
+ { "platform", XDUtility.GetPlatform() },
65
+ { "sign", Sign(serverId, roleId, productId, ConfigModule.ClientId) },
66
+ { "eventSessionId", AliyunTrack.PaymentEventSessionId },
67
+ { "account", XDGAccount.GetCurrentUser()?.UserId },
68
+ { "loginType", XDGAccount.GetCurrentUser()?.LoginType },
69
+ { "userLoginType", XDGAccount.GetCurrentUser()?.LoginType },
70
+ { "deviceId", SystemInfo.deviceUniqueIdentifier },
71
+ { "xdClientId", ConfigModule.ClientId },
72
+ { "sessionUUID", CommonAliyunTrack.CurrentSessionUUId },
73
+ { "sdkVer", XDGConstants.SDK_VERSION },
74
+ { "os", CommonAliyunTrack.GetPlatform() },
75
+ { "os_version", SystemInfo.operatingSystem }
76
+ };
77
+ if (!string.IsNullOrEmpty(ConfigModule.TargetCountryOrRegion))
78
+ {
79
+ queryParmas.Add("region", ConfigModule.TargetCountryOrRegion);
80
+ }
81
+
82
+ if (!string.IsNullOrEmpty(orderId))
83
+ {
84
+ queryParmas.Add("orderId", orderId);
85
+ }
86
+
87
+ if (!string.IsNullOrEmpty(productName))
88
+ {
89
+ queryParmas.Add("productName", productName);
90
+ }
91
+
92
+ if (Math.Abs(payAmount) > float.Epsilon)
93
+ {
94
+ queryParmas.Add("payAmount", payAmount);
95
+ }
96
+
97
+ if (!string.IsNullOrEmpty(extras))
98
+ {
99
+ queryParmas.Add("extras", extras);
100
+ }
101
+
102
+ return $"{ConfigModule.WebPayUrlForPC}?{XDUrlUtils.ToQueryString(queryParmas)}";
103
+ }
104
+
105
+ public static async Task<List<PayInfo>> CheckPay(CancellationToken cancellationToken = default)
106
+ {
107
+ var user = XDGAccount.GetCurrentUser();
108
+
109
+ Dictionary<string, object> param = new Dictionary<string, object>()
110
+ {
111
+ { "userId", user.UserId },
112
+ };
113
+ PayCheckResponse response = await XDHttpClient.Client.GetAsync<PayCheckResponse>(XDG_PAYBACK_LIST,
114
+ queryParams: param,
115
+ cancellationToken: cancellationToken);
116
+ return response.Result.List;
117
+ }
118
+
119
+ public static async Task PayWithSteam(string productId, string serverId, string roldId, string orderId, string ext)
120
+ {
121
+ // 开始支付
122
+ AliyunTrack.PaymentStart(productId, AliyunTrack.PAY_PLATFORM_STEAM, AliyunTrack.PAY_TYPE_STEAM, AliyunTrack.PAY_CHANNEL_STEAM);
123
+ string xdOrderId = null;
124
+ try
125
+ {
126
+ CreateOrderResult createOrderResult = await CreateSteamOrder(productId, serverId, roldId, orderId, ext);
127
+
128
+ string microTxn = await SteamUtils.Instance.GetMicroTxn(createOrderResult.TradeNo);
129
+ AliyunTrack.ReceiveSteamOrder(createOrderResult.TradeNo.ToString());
130
+ await ReportSteamOrder(productId, createOrderResult.TradeNo, microTxn);
131
+ }
132
+ catch (XDGError e)
133
+ {
134
+ // 支付失败
135
+ AliyunTrack.PayFailure(xdOrderId, e.Code, e.ErrorMsg);
136
+ throw e;
137
+ }
138
+ }
139
+
140
+ private static async Task<CreateOrderResult> CreateSteamOrder(string productId, string serverId, string roldId, string orderId, string ext)
141
+ {
142
+ // 创建订单
143
+ AliyunTrack.CreateOrder();
144
+ try
145
+ {
146
+ string steamId = SteamUtils.Instance.GetSteamId();
147
+ string steamLanguage = SteamUtils.Instance.GetSteamLanguage();
148
+ Dictionary<string, object> data = new Dictionary<string, object>
149
+ {
150
+ { "productId", productId },
151
+ { "appServerId", serverId },
152
+ { "appRoleId", roldId },
153
+ { "outTradeNo", orderId },
154
+ { "channelType", STEAM_CHANNEL_TYPE },
155
+ { "paymentType", STEAM_PAYMENT_TYPE },
156
+ { "orderType", STEAM_PAY_ORDER_TYPE },
157
+ { "steamId", steamId },
158
+ { "steamLanguage", steamLanguage },
159
+ };
160
+ if (string.IsNullOrEmpty(ext))
161
+ {
162
+ data["remark"] = ext;
163
+ }
164
+
165
+ CreateOrderResponse response = await XDHttpClient.Client.PostAsync<CreateOrderResponse>(XDG_CREATE_ORDER, data: data);
166
+ // 创建订单成功
167
+ AliyunTrack.CreateOrderSuccess();
168
+ return response.Result;
169
+ }
170
+ catch (XDGError e)
171
+ {
172
+ // 创建订单失败
173
+ AliyunTrack.CreateOrderFailure(e.Code);
174
+ if (e.Code == 40023 || e.Code == 42902)
175
+ {
176
+ // 防沉迷错误
177
+ TaskCompletionSource<CreateOrderResult> tcs = new TaskCompletionSource<CreateOrderResult>();
178
+ LocalizableString localizable = XDLocalization.GetCurrentLocalizableString();
179
+ Dictionary<string, object> config = new Dictionary<string, object>
180
+ {
181
+ { Dialog.TITLE_KEY, e.ExtraData["title"] },
182
+ { Dialog.CONTENT_KEY, e.ExtraData["content"] },
183
+ { Dialog.PRIMARY_TEXT_KEY, localizable.Confirm2 }
184
+ };
185
+ UIManager.ShowUI<Dialog>("Dialog", config, (code, data) =>
186
+ {
187
+ UIManager.Dismiss();
188
+ tcs.TrySetException(e);
189
+ });
190
+ return await tcs.Task;
191
+ }
192
+
193
+ throw e;
194
+ }
195
+ }
196
+
197
+ private static async Task<ReportOrderResult> ReportSteamOrder(string productId, ulong tradeNo, string microTxn)
198
+ {
199
+ // 上报票据
200
+ AliyunTrack.ReportOrder(tradeNo.ToString());
201
+ try
202
+ {
203
+ Dictionary<string, object> data = new Dictionary<string, object>
204
+ {
205
+ { "productId", productId },
206
+ { "tradeNo", tradeNo },
207
+ { "rawCallback", microTxn },
208
+ { "channelType", STEAM_CHANNEL_TYPE },
209
+ { "paymentType", STEAM_PAYMENT_TYPE },
210
+ { "orderType", STEAM_PAY_ORDER_TYPE },
211
+ };
212
+ ReportOrderResponse response = await XDHttpClient.Client.PostAsync<ReportOrderResponse>(XDG_REPORT_ORDER, data: data);
213
+ // 上报票据成功
214
+ AliyunTrack.ReportOrderSuccess(tradeNo.ToString());
215
+ return response.Result;
216
+ }
217
+ catch (XDGError e)
218
+ {
219
+ // 上报票据失败
220
+ AliyunTrack.ReportOrderFailure(tradeNo.ToString(), e.Code, e.ErrorMsg);
221
+ throw e;
222
+ }
223
+ }
224
+
225
+ public static async Task<List<SkuDetailBean>> QueryProducts(string[] productIds)
226
+ {
227
+ if (productIds == null || productIds.Length == 0)
228
+ {
229
+ return new List<SkuDetailBean>();
230
+ }
231
+
232
+ var queryParams = new Dictionary<string, object>
233
+ {
234
+ { "skus", string.Join(",", productIds) }
235
+ };
236
+ var url = XDG_QUERY_PRODUCTS_V2;
237
+ #if XD_STEAM_SUPPORT
238
+ queryParams.Add("steamId", SteamUtils.Instance.GetSteamId());
239
+ url = XDG_QUERY_PRODUCTS;
240
+ #endif
241
+ var response = await XDHttpClient.Client.GetAsync<QueryProductsResponse>(XDG_QUERY_PRODUCTS,
242
+ queryParams: queryParams);
243
+ return response.Products;
244
+ }
245
+
246
+ static string Sign(string serverId, string roleId, string productId, string clientId)
247
+ {
248
+ MD5 md5 = MD5.Create();
249
+ long timestamp = ServerTime.GetTimestamp();
250
+ byte[] data = md5.ComputeHash(Encoding.UTF8.GetBytes($"{productId}{roleId}{serverId}{timestamp}{clientId}"));
251
+ StringBuilder sb = new StringBuilder();
252
+ for (int i = 0; i < data.Length; i++)
253
+ {
254
+ sb.Append(data[i].ToString("x2"));
255
+ }
256
+
257
+ return $"{sb},{timestamp}";
258
+ }
259
+ }
260
+ }
261
+ #endif
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: f7cb11f46e0f4b5da019a1a6afe6ce5d
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,112 @@
1
+ #if UNITY_EDITOR || UNITY_STANDALONE
2
+ using System;
3
+ using UnityEngine;
4
+ using UnityEngine.UI;
5
+ using Vuplex.WebView;
6
+ using XD.SDK.Common.Internal.Standalone;
7
+
8
+ namespace XD.SDK.Payment.Internal.Standalone
9
+ {
10
+ public class PaymentAlert : UIElement
11
+ {
12
+ CanvasWebViewPrefab canvasWebViewPrefab;
13
+ Button closeButton;
14
+
15
+ GameObject loadFailedGO;
16
+ Text loadFailedTipsText;
17
+ Button loadFaieldRetryButton;
18
+
19
+ private void Awake()
20
+ {
21
+ GameObject webviewGO = Instantiate(Resources.Load("CanvasWebViewPrefab")) as GameObject;
22
+ canvasWebViewPrefab = webviewGO.GetComponent<CanvasWebViewPrefab>();
23
+ canvasWebViewPrefab.Resolution = 2;
24
+
25
+ webviewGO.transform.SetParent(transform.Find("WebViewContainer"));
26
+ RectTransform rectTransform = webviewGO.GetComponent<RectTransform>();
27
+ rectTransform.offsetMin = Vector2.zero;
28
+ rectTransform.offsetMax = Vector2.zero;
29
+ canvasWebViewPrefab = webviewGO.GetComponent<CanvasWebViewPrefab>();
30
+
31
+ closeButton = GameObject.Find("CloseButton").GetComponent<Button>();
32
+ closeButton.onClick.AddListener(OnCloseButtonClicked);
33
+
34
+ loadFailedGO = GameObject.Find("PayLoadFailedView");
35
+ loadFailedTipsText = loadFailedGO.transform.Find("TipsText").GetComponent<Text>();
36
+ loadFaieldRetryButton = loadFailedGO.transform.Find("RetryButton").GetComponent<Button>();
37
+ loadFaieldRetryButton.onClick.AddListener(OnRetryButtonClicked);
38
+
39
+ Text retryText = loadFaieldRetryButton.transform.Find("Container/Text").GetComponent<Text>();
40
+ retryText.text = XDLocalization.GetCurrentLocalizableString().Retry;
41
+
42
+ loadFailedGO.SetActive(false);
43
+ }
44
+
45
+ private async void Start()
46
+ {
47
+ await canvasWebViewPrefab.WaitUntilInitialized();
48
+
49
+ canvasWebViewPrefab.WebView.UrlChanged += OnUrlChanged;
50
+ canvasWebViewPrefab.WebView.PageLoadFailed += OnPageLoadFailed;
51
+
52
+ LoadPaymentPage();
53
+ }
54
+
55
+ void LoadPaymentPage()
56
+ {
57
+ if (Application.internetReachability == NetworkReachability.NotReachable)
58
+ {
59
+ // 没网
60
+ ShowError(XDLocalization.GetCurrentLocalizableString().NetError);
61
+ }
62
+ else
63
+ {
64
+ string url = Extra["url"] as string;
65
+ canvasWebViewPrefab.WebView.LoadUrl(url);
66
+ }
67
+ }
68
+
69
+ private void OnDestroy()
70
+ {
71
+ canvasWebViewPrefab.WebView.UrlChanged -= OnUrlChanged;
72
+ canvasWebViewPrefab.WebView.PageLoadFailed -= OnPageLoadFailed;
73
+ }
74
+
75
+ void OnUrlChanged(object sender, UrlChangedEventArgs eventArgs)
76
+ {
77
+ string url = eventArgs.Url;
78
+ Uri uri = new Uri(url);
79
+ string fragment = uri.Fragment;
80
+ if (!string.IsNullOrEmpty(fragment))
81
+ {
82
+ // 只有返回 fragment 才认为是完成
83
+ UIManager.Dismiss();
84
+ OnCallback(PayModule.PAY_DONE, fragment);
85
+ }
86
+ }
87
+
88
+ void OnPageLoadFailed(object sender, EventArgs eventArgs)
89
+ {
90
+ ShowError(XDLocalization.GetCurrentLocalizableString().LoadError);
91
+ }
92
+
93
+ void OnCloseButtonClicked()
94
+ {
95
+ UIManager.Dismiss();
96
+ OnCallback(PayModule.PAY_CANCEL, null);
97
+ }
98
+
99
+ void OnRetryButtonClicked()
100
+ {
101
+ loadFailedGO.SetActive(false);
102
+ LoadPaymentPage();
103
+ }
104
+
105
+ void ShowError(string message)
106
+ {
107
+ loadFailedTipsText.text = message;
108
+ loadFailedGO.SetActive(true);
109
+ }
110
+ }
111
+ }
112
+ #endif
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 19d49608cbbe428e8bffffb00c20cdd2
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant: