Skip to content

Commit

Permalink
Add launcher checkout.
Browse files Browse the repository at this point in the history
  • Loading branch information
oliexe committed Oct 16, 2024
1 parent 2180ccf commit 82414f3
Show file tree
Hide file tree
Showing 17 changed files with 235 additions and 40 deletions.
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"visualstudiotoolsforunity.vstuc"
]
}
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Unity",
"type": "vstuc",
"request": "attach"
}
]
}
60 changes: 60 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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"
}
1 change: 0 additions & 1 deletion Assets/Stash.Sample/Scenes/StashSample.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 10 additions & 1 deletion Assets/Stash.Sample/Scripts/DeeplinkExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
7 changes: 0 additions & 7 deletions Assets/Stash/Scripts/Core/StashAnalytics.cs

This file was deleted.

3 changes: 0 additions & 3 deletions Assets/Stash/Scripts/Core/StashAnalytics.cs.meta

This file was deleted.

4 changes: 3 additions & 1 deletion Assets/Stash/Scripts/Core/StashConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
57 changes: 57 additions & 0 deletions Assets/Stash/Scripts/Core/StashLauncher.cs
Original file line number Diff line number Diff line change
@@ -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<CheckoutResponse> 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<RequestHeader> { authorizationHeader });

if (result.StatusCode == 200)
{
try
{
CheckoutResponse resultResponse = JsonUtility.FromJson<CheckoutResponse>(result.Data);
return resultResponse;
}
catch
{
throw new StashParseError(result.Data);
}
}

throw new StashRequestError(result.StatusCode, result.Data);
}

}
}
11 changes: 11 additions & 0 deletions Assets/Stash/Scripts/Core/StashLauncher.cs.meta

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

23 changes: 23 additions & 0 deletions Assets/Stash/Scripts/Models/CheckoutBody.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
11 changes: 11 additions & 0 deletions Assets/Stash/Scripts/Models/CheckoutBody.cs.meta

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

7 changes: 7 additions & 0 deletions Assets/Stash/Scripts/Models/CheckoutResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Stash.Models
{
public class CheckoutResponse
{
public string url { get; set; }
}
}
11 changes: 11 additions & 0 deletions Assets/Stash/Scripts/Models/CheckoutResponse.cs.meta

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

8 changes: 4 additions & 4 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading

0 comments on commit 82414f3

Please sign in to comment.