From 82414f30a46635df6e6eed1cf697ea4831be7ca6 Mon Sep 17 00:00:00 2001 From: Ondrej Rehacek Date: Wed, 16 Oct 2024 22:42:28 +0200 Subject: [PATCH] Add launcher checkout. --- .vscode/extensions.json | 5 ++ .vscode/launch.json | 10 ++++ .vscode/settings.json | 60 +++++++++++++++++++ Assets/Stash.Sample/Scenes/StashSample.unity | 1 - .../Stash.Sample/Scripts/DeeplinkExample.cs | 11 +++- Assets/Stash/Scripts/Core/StashAnalytics.cs | 7 --- .../Stash/Scripts/Core/StashAnalytics.cs.meta | 3 - Assets/Stash/Scripts/Core/StashConstants.cs | 4 +- Assets/Stash/Scripts/Core/StashLauncher.cs | 57 ++++++++++++++++++ .../Stash/Scripts/Core/StashLauncher.cs.meta | 11 ++++ Assets/Stash/Scripts/Models/CheckoutBody.cs | 23 +++++++ .../Stash/Scripts/Models/CheckoutBody.cs.meta | 11 ++++ .../Stash/Scripts/Models/CheckoutResponse.cs | 7 +++ .../Scripts/Models/CheckoutResponse.cs.meta | 11 ++++ Packages/manifest.json | 8 +-- Packages/packages-lock.json | 42 ++++++------- ProjectSettings/ProjectVersion.txt | 4 +- 17 files changed, 235 insertions(+), 40 deletions(-) create mode 100644 .vscode/extensions.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json delete mode 100644 Assets/Stash/Scripts/Core/StashAnalytics.cs delete mode 100644 Assets/Stash/Scripts/Core/StashAnalytics.cs.meta create mode 100644 Assets/Stash/Scripts/Core/StashLauncher.cs create mode 100644 Assets/Stash/Scripts/Core/StashLauncher.cs.meta create mode 100644 Assets/Stash/Scripts/Models/CheckoutBody.cs create mode 100644 Assets/Stash/Scripts/Models/CheckoutBody.cs.meta create mode 100644 Assets/Stash/Scripts/Models/CheckoutResponse.cs create mode 100644 Assets/Stash/Scripts/Models/CheckoutResponse.cs.meta diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..ddb6ff8 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "visualstudiotoolsforunity.vstuc" + ] +} diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..da60e25 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,10 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Attach to Unity", + "type": "vstuc", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..81ae2ef --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,60 @@ +{ + "files.exclude": { + "**/.DS_Store": true, + "**/.git": true, + "**/.vs": true, + "**/.gitmodules": true, + "**/.vsconfig": true, + "**/*.booproj": true, + "**/*.pidb": true, + "**/*.suo": true, + "**/*.user": true, + "**/*.userprefs": true, + "**/*.unityproj": true, + "**/*.dll": true, + "**/*.exe": true, + "**/*.pdf": true, + "**/*.mid": true, + "**/*.midi": true, + "**/*.wav": true, + "**/*.gif": true, + "**/*.ico": true, + "**/*.jpg": true, + "**/*.jpeg": true, + "**/*.png": true, + "**/*.psd": true, + "**/*.tga": true, + "**/*.tif": true, + "**/*.tiff": true, + "**/*.3ds": true, + "**/*.3DS": true, + "**/*.fbx": true, + "**/*.FBX": true, + "**/*.lxo": true, + "**/*.LXO": true, + "**/*.ma": true, + "**/*.MA": true, + "**/*.obj": true, + "**/*.OBJ": true, + "**/*.asset": true, + "**/*.cubemap": true, + "**/*.flare": true, + "**/*.mat": true, + "**/*.meta": true, + "**/*.prefab": true, + "**/*.unity": true, + "build/": true, + "Build/": true, + "Library/": true, + "library/": true, + "obj/": true, + "Obj/": true, + "Logs/": true, + "logs/": true, + "ProjectSettings/": true, + "UserSettings/": true, + "temp/": true, + "Temp/": true + }, + "dotnet.defaultSolution": "stash-unity.sln" +} \ No newline at end of file diff --git a/Assets/Stash.Sample/Scenes/StashSample.unity b/Assets/Stash.Sample/Scenes/StashSample.unity index 0f6d953..02e863b 100644 --- a/Assets/Stash.Sample/Scenes/StashSample.unity +++ b/Assets/Stash.Sample/Scenes/StashSample.unity @@ -38,7 +38,6 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.3710032, g: 0.3785125, b: 0.35738343, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: diff --git a/Assets/Stash.Sample/Scripts/DeeplinkExample.cs b/Assets/Stash.Sample/Scripts/DeeplinkExample.cs index dc0ac79..ee11804 100644 --- a/Assets/Stash.Sample/Scripts/DeeplinkExample.cs +++ b/Assets/Stash.Sample/Scripts/DeeplinkExample.cs @@ -17,8 +17,17 @@ public class DeeplinkExample : MonoBehaviour private string _stashChallenge; private const string InternalPlayerId = "TEST_PLAYER_ID"; - private void Awake() + private async void Awake() { + try{ + CheckoutResponse response = await StashLauncher.Checkout("ITEM_ID", "ID_PLAYER", "ID_TOKEN", StashEnvironment.Test); + } + catch (StashRequestError e) + { + Console.WriteLine(e); + throw; + } + //Event handler "OnDeepLinkActivated" is invoked every time the game is launched or resumed via the Stash’s deep link. if (Instance == null) { diff --git a/Assets/Stash/Scripts/Core/StashAnalytics.cs b/Assets/Stash/Scripts/Core/StashAnalytics.cs deleted file mode 100644 index c5020fd..0000000 --- a/Assets/Stash/Scripts/Core/StashAnalytics.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Stash.Scripts.Core -{ - public class StashAnalytics - { - - } -} \ No newline at end of file diff --git a/Assets/Stash/Scripts/Core/StashAnalytics.cs.meta b/Assets/Stash/Scripts/Core/StashAnalytics.cs.meta deleted file mode 100644 index c8a1c94..0000000 --- a/Assets/Stash/Scripts/Core/StashAnalytics.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 93c2ff26d5c348c8bf8a637b068f50a7 -timeCreated: 1724778744 \ No newline at end of file diff --git a/Assets/Stash/Scripts/Core/StashConstants.cs b/Assets/Stash/Scripts/Core/StashConstants.cs index 6c4676c..3553b12 100644 --- a/Assets/Stash/Scripts/Core/StashConstants.cs +++ b/Assets/Stash/Scripts/Core/StashConstants.cs @@ -19,6 +19,8 @@ public class StashConstants public const string LoginAppleGameCenter = "/sdk/custom_login/approve_apple_game_center"; public const string LoginGooglePlayGames = "/sdk/custom_login/google_play"; public const string LoginFacebook = "/sdk/custom_login/facebook_auth"; - + + //Launcher + public const string LauncherCheckout = "/sdk/launcher/payment/generate_add_to_cart_url"; } } diff --git a/Assets/Stash/Scripts/Core/StashLauncher.cs b/Assets/Stash/Scripts/Core/StashLauncher.cs new file mode 100644 index 0000000..3d7187d --- /dev/null +++ b/Assets/Stash/Scripts/Core/StashLauncher.cs @@ -0,0 +1,57 @@ +using System.Collections; +using System.Collections.Generic; +using System.Threading.Tasks; +using UnityEngine; +using Stash.Core.Exceptions; +using Stash.Models; +using Stash.Scripts.Core; + +namespace Stash.Core +{ + public static class StashLauncher + { + public static async Task Checkout(string itemId, + string playerId, + string idToken, + StashEnvironment environment = StashEnvironment.Test) + { + // Create the authorization header with the access token + RequestHeader authorizationHeader = new() + { + Key = "Authorization", + Value = "Bearer " + idToken + }; + + var requestBody = new CheckoutBody + { + item = new CheckoutBody.Item + { + id = itemId + }, + user = new CheckoutBody.User + { + id = playerId + } + }; + + string requestUrl = environment.GetRootUrl() + StashConstants.LauncherCheckout; + Response result = await RestClient.Post(requestUrl, JsonUtility.ToJson(requestBody), new List { authorizationHeader }); + + if (result.StatusCode == 200) + { + try + { + CheckoutResponse resultResponse = JsonUtility.FromJson(result.Data); + return resultResponse; + } + catch + { + throw new StashParseError(result.Data); + } + } + + throw new StashRequestError(result.StatusCode, result.Data); + } + + } +} \ No newline at end of file diff --git a/Assets/Stash/Scripts/Core/StashLauncher.cs.meta b/Assets/Stash/Scripts/Core/StashLauncher.cs.meta new file mode 100644 index 0000000..34a02cd --- /dev/null +++ b/Assets/Stash/Scripts/Core/StashLauncher.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a2710a03b1db549c19ea416d4d61c1f6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Stash/Scripts/Models/CheckoutBody.cs b/Assets/Stash/Scripts/Models/CheckoutBody.cs new file mode 100644 index 0000000..62ac8b3 --- /dev/null +++ b/Assets/Stash/Scripts/Models/CheckoutBody.cs @@ -0,0 +1,23 @@ +using System; + +namespace Stash.Models +{ + [Serializable] + public class CheckoutBody + { + public Item item; + public User user; + + [Serializable] + public class Item + { + public string id; + } + + [Serializable] + public class User + { + public string id; + } + } +} \ No newline at end of file diff --git a/Assets/Stash/Scripts/Models/CheckoutBody.cs.meta b/Assets/Stash/Scripts/Models/CheckoutBody.cs.meta new file mode 100644 index 0000000..0fb374e --- /dev/null +++ b/Assets/Stash/Scripts/Models/CheckoutBody.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8e85ec9c98ec948669a56eddcd43cba9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Stash/Scripts/Models/CheckoutResponse.cs b/Assets/Stash/Scripts/Models/CheckoutResponse.cs new file mode 100644 index 0000000..83c9731 --- /dev/null +++ b/Assets/Stash/Scripts/Models/CheckoutResponse.cs @@ -0,0 +1,7 @@ +namespace Stash.Models +{ + public class CheckoutResponse + { + public string url { get; set; } + } +} \ No newline at end of file diff --git a/Assets/Stash/Scripts/Models/CheckoutResponse.cs.meta b/Assets/Stash/Scripts/Models/CheckoutResponse.cs.meta new file mode 100644 index 0000000..e4a391c --- /dev/null +++ b/Assets/Stash/Scripts/Models/CheckoutResponse.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 870d0608735cd4db893cd65c6ed9eeba +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/manifest.json b/Packages/manifest.json index 3023dd0..1ad949d 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -5,19 +5,19 @@ "com.unity.ads": "4.4.2", "com.unity.ai.navigation": "1.1.5", "com.unity.analytics": "3.8.1", - "com.unity.collab-proxy": "2.3.1", + "com.unity.collab-proxy": "2.4.4", "com.unity.feature.development": "1.0.1", - "com.unity.ide.rider": "3.0.26", + "com.unity.ide.rider": "3.0.31", "com.unity.ide.visualstudio": "2.0.22", "com.unity.ide.vscode": "1.2.5", - "com.unity.mobile.android-logcat": "1.4.0", + "com.unity.mobile.android-logcat": "1.4.2", "com.unity.purchasing": "4.11.0", "com.unity.services.authentication": "3.3.0", "com.unity.test-framework": "1.1.33", "com.unity.textmeshpro": "3.0.6", "com.unity.timeline": "1.7.6", "com.unity.ugui": "1.0.0", - "com.unity.visualscripting": "1.9.1", + "com.unity.visualscripting": "1.9.4", "com.unity.xr.legacyinputhelpers": "2.1.10", "com.unity.modules.ai": "1.0.0", "com.unity.modules.androidjni": "1.0.0", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 89dc920..d9945e7 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -38,13 +38,13 @@ "depth": 0, "source": "registry", "dependencies": { - "com.unity.services.analytics": "1.0.4", - "com.unity.ugui": "1.0.0" + "com.unity.ugui": "1.0.0", + "com.unity.services.analytics": "1.0.4" }, "url": "https://packages.unity.com" }, "com.unity.collab-proxy": { - "version": "2.3.1", + "version": "2.4.4", "depth": 0, "source": "registry", "dependencies": {}, @@ -70,16 +70,16 @@ "source": "builtin", "dependencies": { "com.unity.ide.visualstudio": "2.0.22", - "com.unity.ide.rider": "3.0.26", + "com.unity.ide.rider": "3.0.31", "com.unity.ide.vscode": "1.2.5", "com.unity.editorcoroutines": "1.0.0", "com.unity.performance.profile-analyzer": "1.2.2", "com.unity.test-framework": "1.1.33", - "com.unity.testtools.codecoverage": "1.2.4" + "com.unity.testtools.codecoverage": "1.2.6" } }, "com.unity.ide.rider": { - "version": "3.0.26", + "version": "3.0.31", "depth": 0, "source": "registry", "dependencies": { @@ -104,7 +104,7 @@ "url": "https://packages.unity.com" }, "com.unity.mobile.android-logcat": { - "version": "1.4.0", + "version": "1.4.2", "depth": 0, "source": "registry", "dependencies": {}, @@ -130,10 +130,10 @@ "source": "registry", "dependencies": { "com.unity.ugui": "1.0.0", - "com.unity.modules.unitywebrequest": "1.0.0", - "com.unity.modules.jsonserialize": "1.0.0", + "com.unity.services.core": "1.8.2", "com.unity.modules.androidjni": "1.0.0", - "com.unity.services.core": "1.8.2" + "com.unity.modules.jsonserialize": "1.0.0", + "com.unity.modules.unitywebrequest": "1.0.0" }, "url": "https://packages.unity.com" }, @@ -143,8 +143,8 @@ "source": "registry", "dependencies": { "com.unity.ugui": "1.0.0", - "com.unity.modules.jsonserialize": "1.0.0", - "com.unity.services.core": "1.10.1" + "com.unity.services.core": "1.10.1", + "com.unity.modules.jsonserialize": "1.0.0" }, "url": "https://packages.unity.com" }, @@ -153,21 +153,21 @@ "depth": 0, "source": "registry", "dependencies": { - "com.unity.nuget.newtonsoft-json": "3.2.1", + "com.unity.ugui": "1.0.0", "com.unity.services.core": "1.12.2", - "com.unity.modules.unitywebrequest": "1.0.0", - "com.unity.ugui": "1.0.0" + "com.unity.nuget.newtonsoft-json": "3.2.1", + "com.unity.modules.unitywebrequest": "1.0.0" }, "url": "https://packages.unity.com" }, "com.unity.services.core": { - "version": "1.12.2", + "version": "1.12.5", "depth": 1, "source": "registry", "dependencies": { - "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.modules.androidjni": "1.0.0", "com.unity.nuget.newtonsoft-json": "3.2.1", - "com.unity.modules.androidjni": "1.0.0" + "com.unity.modules.unitywebrequest": "1.0.0" }, "url": "https://packages.unity.com" }, @@ -190,7 +190,7 @@ "url": "https://packages.unity.com" }, "com.unity.testtools.codecoverage": { - "version": "1.2.4", + "version": "1.2.6", "depth": 1, "source": "registry", "dependencies": { @@ -213,9 +213,9 @@ "depth": 0, "source": "registry", "dependencies": { + "com.unity.modules.audio": "1.0.0", "com.unity.modules.director": "1.0.0", "com.unity.modules.animation": "1.0.0", - "com.unity.modules.audio": "1.0.0", "com.unity.modules.particlesystem": "1.0.0" }, "url": "https://packages.unity.com" @@ -230,7 +230,7 @@ } }, "com.unity.visualscripting": { - "version": "1.9.1", + "version": "1.9.4", "depth": 0, "source": "registry", "dependencies": { diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index 2e7bb8a..1e3d799 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2022.3.15f1 -m_EditorVersionWithRevision: 2022.3.15f1 (b58023a2b463) +m_EditorVersion: 2022.3.46f1 +m_EditorVersionWithRevision: 2022.3.46f1 (8e9b8558c41a)