Skip to content

Commit eaf0eb3

Browse files
Erik Bylundkirre-bylund
authored andcommitted
Add auto creation of wallets when missing
1 parent 04c38ce commit eaf0eb3

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

Runtime/Client/LootLockerEndPoints.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ public class LootLockerEndPoints
247247
public static EndPointClass getWalletByHolderId = new EndPointClass("wallet/holder/{0}", LootLockerHTTPMethod.GET);
248248
public static EndPointClass creditBalanceToWallet = new EndPointClass("balances/credit", LootLockerHTTPMethod.POST);
249249
public static EndPointClass debitBalanceToWallet = new EndPointClass("balances/debit", LootLockerHTTPMethod.POST);
250+
public static EndPointClass createWallet = new EndPointClass("wallet", LootLockerHTTPMethod.POST);
250251

251252
// Catalogs
252253
[Header("Catalogs")]

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5058,18 +5058,52 @@ public static void GetWalletByWalletId(string walletId, Action<LootLockerGetWall
50585058
/// <summary>
50595059
/// Get information about a wallet for a specified holder
50605060
/// </summary>
5061-
/// <param name="holderId">Ulid of the holder of the wallet you want to get information for</param>
5061+
/// <param name="holderUlid">ULID of the holder of the wallet you want to get information for</param>
5062+
/// <param name="holderType">The type of the holder to get the wallet for</param>
50625063
/// <param name="onComplete">onComplete Action for handling the response</param>
5063-
public static void GetWalletByHolderId(string holderId, Action<LootLockerGetWalletResponse> onComplete)
5064+
public static void GetWalletByHolderId(string holderUlid, LootLockerWalletHolderTypes holderType, Action<LootLockerGetWalletResponse> onComplete)
50645065
{
50655066
if (!CheckInitialized())
50665067
{
50675068
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerGetWalletResponse>());
50685069
return;
50695070
}
5070-
var endpoint = string.Format(LootLockerEndPoints.getWalletByHolderId.endPoint, holderId);
5071+
var endpoint = string.Format(LootLockerEndPoints.getWalletByHolderId.endPoint, holderUlid);
50715072

5072-
LootLockerServerRequest.CallAPI(endpoint, LootLockerEndPoints.getWalletByHolderId.httpMethod, onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); });
5073+
LootLockerServerRequest.CallAPI(endpoint, LootLockerEndPoints.getWalletByHolderId.httpMethod, onComplete:
5074+
(serverResponse) =>
5075+
{
5076+
var parsedResponse = LootLockerResponse.Deserialize<LootLockerGetWalletResponse>(serverResponse);
5077+
if (!parsedResponse.success && parsedResponse.statusCode == 404)
5078+
{
5079+
LootLockerCreateWalletRequest request = new LootLockerCreateWalletRequest()
5080+
{
5081+
holder_id = holderUlid,
5082+
holder_type = holderType
5083+
};
5084+
LootLockerServerRequest.CallAPI(LootLockerEndPoints.createWallet.endPoint,
5085+
LootLockerEndPoints.createWallet.httpMethod, LootLockerJson.SerializeObject(request),
5086+
createWalletResponse =>
5087+
{
5088+
if (createWalletResponse.success)
5089+
{
5090+
LootLockerServerRequest.CallAPI(endpoint,
5091+
LootLockerEndPoints.getWalletByHolderId.httpMethod, null,
5092+
secondResponse =>
5093+
{
5094+
LootLockerResponse.Deserialize(onComplete, secondResponse);
5095+
});
5096+
return;
5097+
}
5098+
5099+
onComplete?.Invoke(parsedResponse);
5100+
});
5101+
return;
5102+
}
5103+
5104+
onComplete?.Invoke(parsedResponse);
5105+
}
5106+
);
50735107
}
50745108

50755109
/// <summary>

Runtime/Game/Requests/BalanceRequests.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,27 @@ public class LootLockerBalance
4242
//==================================================
4343
// Request Definitions
4444
//==================================================
45+
46+
/// <summary>
47+
/// </summary>
48+
public class LootLockerCreateWalletRequest
49+
{
50+
/// <summary>
51+
/// ULID of the holder you want to create a wallet for
52+
/// </summary>
53+
public string holder_id { get; set; }
54+
/// <summary>
55+
/// The type of holder that this holder id refers to
56+
/// </summary>
57+
public LootLockerWalletHolderTypes holder_type { get; set; }
58+
};
4559

4660
/// <summary>
4761
/// </summary>
4862
public class LootLockerCreditRequest
4963
{
50-
/// <summary> Amount of the given currency to debit/credit to/from the given wallet
64+
/// <summary>
65+
/// Amount of the given currency to debit/credit to/from the given wallet
5166
/// </summary>
5267
public string amount { get; set; }
5368
/// <summary>
@@ -63,7 +78,8 @@ public class LootLockerCreditRequest
6378
/// </summary>
6479
public class LootLockerDebitRequest
6580
{
66-
/// <summary> Amount of the given currency to debit/credit to/from the given wallet
81+
/// <summary>
82+
/// Amount of the given currency to debit/credit to/from the given wallet
6783
/// </summary>
6884
public string amount { get; set; }
6985
/// <summary>

0 commit comments

Comments
 (0)