Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Develop

See merge request sdk_group/store-unity-sdk!366
  • Loading branch information
DenisRakhimovXsolla committed Jan 16, 2025
2 parents eddc761 + fe6a9c1 commit 38781ac
Show file tree
Hide file tree
Showing 509 changed files with 276 additions and 1,623 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
!xsolla-unity-sdk-latest.unitypackage

[Ll]ibrary/
[Tt]emp/
[Oo]bj/
Expand Down
6 changes: 3 additions & 3 deletions Assets/Plugins/Android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.unity3d.player" xmlns:tools="http://schemas.android.com/tools">
<application>
<activity android:name="com.xsolla.sdk.unity.Example.androidProxies.XsollaWidgetAuthProxyActivity" android:exported="true" android:configChanges="orientation|screenSize|keyboardHidden" />
<activity android:name="com.xsolla.sdk.unity.Example.androidProxies.SocialAuthProxyActivity" android:exported="true" android:configChanges="orientation|screenSize|keyboardHidden" />
<activity android:name="com.xsolla.sdk.unity.Example.androidProxies.PaymentsProxyActivity" android:exported="true" android:configChanges="orientation|screenSize|keyboardHidden" />
<activity android:name="com.xsolla.sdk.unity.Example.androidProxies.XsollaWidgetAuthProxyActivity" android:exported="true" android:configChanges="orientation|screenSize|keyboardHidden" android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity android:name="com.xsolla.sdk.unity.Example.androidProxies.SocialAuthProxyActivity" android:exported="true" android:configChanges="orientation|screenSize|keyboardHidden" android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity android:name="com.xsolla.sdk.unity.Example.androidProxies.PaymentsProxyActivity" android:exported="true" android:configChanges="orientation|screenSize|keyboardHidden" android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:theme="@style/UnityThemeSelector" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
16 changes: 8 additions & 8 deletions Assets/Tests/Auth/SocialAuthTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public IEnumerator GetLinksForSocialAuth_deDE_Locale_Success()
yield return GetLinksForSocialAuth("de_DE");
}

[UnityTest]
public IEnumerator GetLinksForSocialAuth_InvalidToken_SuccessAndTokenRefreshed()
{
yield return SetOldAccessToken();
var oldToken = XsollaToken.AccessToken;
yield return GetLinksForSocialAuth();
Assert.AreNotEqual(oldToken, XsollaToken.AccessToken);
}
// [UnityTest]
// public IEnumerator GetLinksForSocialAuth_InvalidToken_SuccessAndTokenRefreshed()
// {
// yield return SetOldAccessToken();
// var oldToken = XsollaToken.AccessToken;
// yield return GetLinksForSocialAuth();
// Assert.AreNotEqual(oldToken, XsollaToken.AccessToken);
// }

private static IEnumerator GetLinksForSocialAuth(string locale = null)
{
Expand Down
8 changes: 3 additions & 5 deletions Assets/Xsolla.Demo/Login/Scripts/Login/Auth/SavedTokenAuth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ public class SavedTokenAuth : LoginAuthorization
{
public override void TryAuth(object[] _, Action onSuccess, Action<Error> onError)
{
var success = XsollaAuth.AuthViaSavedToken();
if (success)
onSuccess?.Invoke();
else
onError?.Invoke(null);
XsollaAuth.AuthBySavedToken(
() => onSuccess?.Invoke(),
error => onError?.Invoke(null));
}
}
}
62 changes: 57 additions & 5 deletions Assets/Xsolla/Auth/XsollaAuth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static void SignIn(string username, string password, Action onSuccess, Ac
requestData,
response =>
{
XsollaToken.Create(response.access_token, response.refresh_token);
XsollaToken.Create(response.access_token, response.refresh_token, response.expires_in);
onSuccess?.Invoke();
},
onError,
Expand Down Expand Up @@ -374,11 +374,63 @@ public static void AuthWithSocialNetworkAccessToken(string accessToken, string a
}

/// <summary>
/// Authenticates the user by saved token. Returns `true` if the token is loaded successfully and the user is authenticated
/// [Obsolete. Use AuthBySavedToken instead.] Authenticates the user by saved token. Returns `true` if the token is loaded successfully and the user is authenticated
/// </summary>
[Obsolete("Use AuthBySavedToken instead")]
public static bool AuthViaSavedToken()
{
return XsollaToken.TryLoadInstance();
var isTokenLoaded = XsollaToken.TryLoadInstance();
if (!isTokenLoaded)
{
XDebug.Log("Failed to auth via saved token");
return false;
}

var expirationTime = XsollaToken.ExpirationTime;
if (expirationTime <= 0)
{
XDebug.Log("XsollaToken has no expiration time");
return true;
}

if (expirationTime >= DateTimeOffset.UtcNow.ToUnixTimeSeconds())
return true;

XDebug.Log("XsollaToken is expired. Trying to refresh it");
RefreshToken(() => { }, _ => { });
return true;
}

/// <summary>
/// Authenticates user with the saved token.
/// <param name="onSuccess">Called after successful authentication.</param>
/// <param name="onError">Called after the request resulted with an error.</param>
/// </summary>
public static void AuthBySavedToken(Action onSuccess, Action<Error> onError)
{
if (!XsollaToken.TryLoadInstance())
{
XDebug.Log("Failed to auth via saved token");
onError?.Invoke(new Error(errorMessage: "Failed to auth via saved token"));
return;
}

var expirationTime = XsollaToken.ExpirationTime;
if (expirationTime <= 0)
{
XDebug.Log("XsollaToken has no expiration time, trying to refresh it");
RefreshToken(onSuccess, onError);
return;
}

if (expirationTime < DateTimeOffset.UtcNow.ToUnixTimeSeconds())
{
XDebug.Log("XsollaToken is expired, trying to refresh it");
RefreshToken(() => onSuccess?.Invoke(), e => onError?.Invoke(e));
return;
}

onSuccess?.Invoke();
}

/// <summary>
Expand Down Expand Up @@ -685,7 +737,7 @@ public static void RefreshToken(Action onSuccess, Action<Error> onError, string
requestData,
response =>
{
XsollaToken.Create(response.access_token, response.refresh_token);
XsollaToken.Create(response.access_token, response.refresh_token, response.expires_in);
onSuccess?.Invoke();
},
error => onError?.Invoke(error));
Expand Down Expand Up @@ -716,7 +768,7 @@ public static void ExchangeCodeToToken(string code, Action onSuccess, Action<Err
requestData,
response =>
{
XsollaToken.Create(response.access_token, response.refresh_token);
XsollaToken.Create(response.access_token, response.refresh_token, response.expires_in);
onSuccess?.Invoke();
},
error => onError?.Invoke(error));
Expand Down
16 changes: 15 additions & 1 deletion Assets/Xsolla/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## [2.5.2] - 2025-01-14
### Added
- `XsollaAuth.AuthBySavedToken` SDK method for user authentication with a saved token
- `XsollaToken.ExpirationTime` property for getting the token expiration time in seconds since the Unix epoch

### Changed
- `XsollaAuth.AuthViaSavedToken` SDK method marked as obsolete. Use `XsollaAuth.AuthBySavedToken` instead
- `XsollaCatalog.GetCatalog` SDK method marked as obsolete. Use `GetItems` instead
- The Android build process no longer affects SDK source files (proxy activities, etc.)
- Default built-in browser resolution for desktop platforms is now 1024 x 800 px

### Fixed
- `Different serialization layout when loading` error

## [2.5.1] - 2024-12-12
### Changed
- Minimum supported Unity version updated to 2021.3.45f1
Expand Down Expand Up @@ -59,7 +73,7 @@
- Added `google_pay_quick_payment_button` parameter, that brings the Google Pay button to the top of the payment methods list

### Fixed:
- Malformed URL error when requesting a catalog on some iOS devices
- `Malformed URL` error when requesting a catalog on some iOS devices

## [2.4.0] - 2024-04-17
### Added
Expand Down
2 changes: 1 addition & 1 deletion Assets/Xsolla/Catalog/XsollaCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ public static void PurchaseFreeItem(string itemSku, Action<OrderStatus> onSucces
}

/// <summary>
/// [Obsolete. Use GetItems instead] Returns a list of virtual items according to pagination settings. //TEXTREVIEW
/// [Obsolete. Use GetItems instead.] Returns a list of virtual items according to pagination settings.
/// The list includes items for which display in the store is enabled in the settings. For each virtual item, complete data is returned.
/// If used after user authentication, the method returns items that match the personalization rules for the current user.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Xsolla.XsollaBrowser
{
public class XsollaBrowserPackPostprocessor : IPostprocessBuildWithReport
public class BrowserPackingProcessor : IPostprocessBuildWithReport
{
public int callbackOrder { get; }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System.IO;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;

namespace Xsolla.XsollaBrowser
{
public class BrowserPrefabProcessor : IPreprocessBuildWithReport, IPostprocessBuildWithReport
{
public int callbackOrder { get; }

private static string SavedOriginPrefabPath;

public void OnPreprocessBuild(BuildReport report)
{
SavedOriginPrefabPath = null;

if (report.summary.platformGroup == BuildTargetGroup.Standalone)
return;

var originPrefabPath = GetOriginPrefabPath();
var tempPrefabPath = GetTempPrefabPath();

var error = AssetDatabase.MoveAsset(originPrefabPath, tempPrefabPath);
if (!string.IsNullOrEmpty(error))
{
Debug.LogError($"Can't move {originPrefabPath} to {tempPrefabPath}: {error}");
return;
}

AssetDatabase.Refresh();
SavedOriginPrefabPath = originPrefabPath;
}

public void OnPostprocessBuild(BuildReport report)
{
if (report.summary.platformGroup == BuildTargetGroup.Standalone)
return;

if (SavedOriginPrefabPath == null)
return;

var originPrefabPath = SavedOriginPrefabPath;
var tempPrefabPath = GetTempPrefabPath();

var error = AssetDatabase.MoveAsset(tempPrefabPath, originPrefabPath);
if (!string.IsNullOrEmpty(error))
Debug.LogError($"Can't move {tempPrefabPath} to {originPrefabPath}: {error}");

AssetDatabase.Refresh();
SavedOriginPrefabPath = null;
}

private static string GetOriginPrefabPath()
{
var guids = AssetDatabase.FindAssets("t:Prefab XsollaWebBrowser");
if (guids.Length == 0)
throw new FileNotFoundException($"Can't find {nameof(BrowserPrefabProcessor)} script");

if (guids.Length > 1)
throw new FileNotFoundException($"Found more than one {nameof(BrowserPrefabProcessor)} script");

return AssetDatabase.GUIDToAssetPath(guids[0]);
}

private static string GetTempPrefabPath()
{
return Path.Combine("Assets", "XsollaWebBrowser.prefab");
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Xsolla.XsollaBrowser
{
public class XsollaBrowserPreprocessor : IPreprocessBuildWithReport
public class ScriptingBackendProcessor : IPreprocessBuildWithReport
{
public int callbackOrder { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Xsolla.XsollaBrowser
{
public static class BrowserSettings
{
public static Vector2Int LaunchViewportSize { get; set; } = new Vector2Int(1280, 1024);
public static Vector2Int LaunchViewportSize { get; set; } = new Vector2Int(1024, 800);

public static bool Headless { get; set; } = true;
public static bool DevTools { get; set; } = false;
Expand Down
5 changes: 2 additions & 3 deletions Assets/Xsolla/Core/Browser/XsollaWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static void OpenPurchaseUI(string paymentToken, bool forcePlatformBrowser
};

Screen.fullScreen = false;
OpenPaystationWidget(paymentToken, XsollaSettings.IsSandbox);
OpenPaystationWidget(paymentToken, XsollaSettings.IsSandbox, Application.unityVersion, Constants.SDK_VERSION);
return;
}
#endif
Expand All @@ -100,7 +100,6 @@ public static void OpenPurchaseUI(string paymentToken, bool forcePlatformBrowser
#if UNITY_STANDALONE || UNITY_EDITOR
if (InAppBrowser != null && !forcePlatformBrowser)
{
InAppBrowser.AddInitHandler(() => InAppBrowser.UpdateSize(740, 760));
InAppBrowser.CloseEvent += onBrowserClosed;
}
#endif
Expand Down Expand Up @@ -136,7 +135,7 @@ public static void Close(float delay = 0)

#if UNITY_WEBGL
[DllImport("__Internal")]
private static extern void OpenPaystationWidget(string token, bool sandbox);
private static extern void OpenPaystationWidget(string token, bool sandbox, string engineVersion, string sdkVersion);

[DllImport("__Internal")]
private static extern void ClosePaystationWidget();
Expand Down
4 changes: 2 additions & 2 deletions Assets/Xsolla/Core/Editor/AndroidManifestPreprocess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ private static string GetTargetFilePath(string fileName)

private static string GetTemplateFilePath()
{
var guids = AssetDatabase.FindAssets($"t:Script {nameof(AndroidScriptsPreprocess)}");
var guids = AssetDatabase.FindAssets($"t:Script {nameof(AndroidManifestPreprocess)}");
if (guids.Length == 0)
throw new FileNotFoundException($"Can't find {nameof(AndroidScriptsPreprocess)} script");
throw new FileNotFoundException($"Can't find {nameof(AndroidManifestPreprocess)} script");

var path = AssetDatabase.GUIDToAssetPath(guids[0]);
path = path.Replace("Assets", Application.dataPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Xsolla.Core.Editor
{
public class AndroidScriptsPreprocess : IPreprocessBuildWithReport
public class AndroidScriptsProcessor : IPreprocessBuildWithReport, IPostprocessBuildWithReport
{
public int callbackOrder => 2000;

Expand All @@ -18,13 +18,24 @@ public void OnPreprocessBuild(BuildReport report)
return;

XDebug.Log("Xsolla SDK is now processing android activities", true);
SetupActivity("PaymentsProxyActivity", true, "androidProxies");
SetupActivity("SocialAuthProxyActivity", true, "androidProxies");
SetupActivity("XsollaWidgetAuthProxyActivity", true, "androidProxies");
SetupActivity("WXEntryActivity", !string.IsNullOrEmpty(XsollaSettings.WeChatAppId), "wxapi");
SetupActivities(Application.identifier);
}

private static void SetupActivity(string activityName, bool enableCondition, string packageSuffix)
public void OnPostprocessBuild(BuildReport report)
{
if (report.summary.platform == BuildTarget.Android)
SetupActivities("com.xsolla.sdk.unity.Example");
}

private void SetupActivities(string appId)
{
SetupActivity("PaymentsProxyActivity", true, appId, "androidProxies");
SetupActivity("SocialAuthProxyActivity", true, appId, "androidProxies");
SetupActivity("XsollaWidgetAuthProxyActivity", true, appId, "androidProxies");
SetupActivity("WXEntryActivity", !string.IsNullOrEmpty(XsollaSettings.WeChatAppId), appId, "wxapi");
}

private static void SetupActivity(string activityName, bool enableCondition, string appId, string packageSuffix)
{
var assetPath = GetAssetPath(activityName);
var activityAsset = AssetImporter.GetAtPath(assetPath) as PluginImporter;
Expand All @@ -36,7 +47,7 @@ private static void SetupActivity(string activityName, bool enableCondition, str

var filePath = GetFilePath(activityName);
var scriptContent = File.ReadAllText(filePath);
var packageLineText = $"package {Application.identifier}.{packageSuffix};";
var packageLineText = $"package {appId}.{packageSuffix};";
scriptContent = Regex.Replace(scriptContent, "package.+;", packageLineText);

File.WriteAllText(filePath, scriptContent);
Expand All @@ -51,9 +62,9 @@ private static string GetAssetPath(string fileName)

private static string GetFilePath(string fileName)
{
var guids = AssetDatabase.FindAssets($"t:Script {nameof(AndroidScriptsPreprocess)}");
var guids = AssetDatabase.FindAssets($"t:Script {nameof(AndroidScriptsProcessor)}");
if (guids.Length == 0)
throw new FileNotFoundException($"Can't find {nameof(AndroidScriptsPreprocess)} script");
throw new FileNotFoundException($"Can't find {nameof(AndroidScriptsProcessor)} script");

var path = AssetDatabase.GUIDToAssetPath(guids[0]);
path = path.Replace("Assets", Application.dataPath);
Expand Down
Loading

0 comments on commit 38781ac

Please sign in to comment.