Skip to content

Commit 0d686d6

Browse files
Erik Bylundkirre-bylund
authored andcommitted
Add support for redeeming purchases made towards Apple and Google
1 parent 0e5599b commit 0d686d6

File tree

3 files changed

+152
-0
lines changed

3 files changed

+152
-0
lines changed

Runtime/Client/LootLockerEndPoints.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,10 @@ public class LootLockerEndPoints
193193
public static EndPointClass androidPurchaseVerification = new EndPointClass("v1/purchase", LootLockerHTTPMethod.POST);
194194
public static EndPointClass pollingOrderStatus = new EndPointClass("v1/purchase/{0}", LootLockerHTTPMethod.GET);
195195
public static EndPointClass activatingARentalAsset = new EndPointClass("v1/asset/instance/{0}/activate", LootLockerHTTPMethod.POST);
196+
196197
public static EndPointClass purchaseCatalogItem = new EndPointClass("purchase", LootLockerHTTPMethod.POST);
198+
public static EndPointClass redeemAppleAppStorePurchase = new EndPointClass("redeem/store/apple", LootLockerHTTPMethod.POST);
199+
public static EndPointClass redeemGooglePlayStorePurchase = new EndPointClass("redeem/store/google", LootLockerHTTPMethod.POST);
197200

198201
// EventTrigger
199202
[Header("EventTrigger")]

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4281,6 +4281,94 @@ public static void LootLockerPurchaseCatalogItems(string walletId, LootLockerCat
42814281
LootLockerServerRequest.CallAPI(LootLockerEndPoints.purchaseCatalogItem.endPoint, LootLockerEndPoints.purchaseCatalogItem.httpMethod, body, onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); });
42824282
}
42834283

4284+
/// <summary>
4285+
/// Redeem a purchase that was made successfully towards the Apple App Store for the current player
4286+
/// </summary>
4287+
/// <param name="transactionId">The id of the transaction successfully made towards the Apple App Store</param>
4288+
/// <param name="onComplete">onComplete Action for handling the response</param>
4289+
public static void RedeemAppleAppStorePurchaseForPlayer(string transactionId, Action<LootLockerResponse> onComplete)
4290+
{
4291+
if (!CheckInitialized())
4292+
{
4293+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerResponse>());
4294+
return;
4295+
}
4296+
var body = LootLockerJson.SerializeObject(new LootLockerRedeemAppleAppStorePurchaseForPlayerRequest()
4297+
{
4298+
transaction_id = transactionId
4299+
});
4300+
4301+
LootLockerServerRequest.CallAPI(LootLockerEndPoints.redeemAppleAppStorePurchase.endPoint, LootLockerEndPoints.redeemAppleAppStorePurchase.httpMethod, body, onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); });
4302+
}
4303+
4304+
/// <summary>
4305+
/// Redeem a purchase that was made successfully towards the Apple App Store for a character that the current player owns
4306+
/// </summary>
4307+
/// <param name="transactionId">The id of the transaction successfully made towards the Apple App Store</param>
4308+
/// <param name="characterId">The id of the character to redeem this transaction for</param>
4309+
/// <param name="onComplete">onComplete Action for handling the response</param>
4310+
public static void RedeemAppleAppStorePurchaseForCharacter(string transactionId, int characterId, Action<LootLockerResponse> onComplete)
4311+
{
4312+
if (!CheckInitialized())
4313+
{
4314+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerResponse>());
4315+
return;
4316+
}
4317+
var body = LootLockerJson.SerializeObject(new LootLockerRedeemAppleAppStorePurchaseForCharacterRequest()
4318+
{
4319+
transaction_id = transactionId,
4320+
character_id = characterId
4321+
});
4322+
4323+
LootLockerServerRequest.CallAPI(LootLockerEndPoints.redeemAppleAppStorePurchase.endPoint, LootLockerEndPoints.redeemAppleAppStorePurchase.httpMethod, body, onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); });
4324+
}
4325+
4326+
/// <summary>
4327+
/// Redeem a purchase that was made successfully towards the Google Play Store for the current player
4328+
/// </summary>
4329+
/// <param name="productId">The id of the product that this redemption refers to</param>
4330+
/// <param name="purchaseToken">The token from the purchase successfully made towards the Google Play Store</param>
4331+
/// <param name="onComplete">onComplete Action for handling the response</param>
4332+
public static void RedeemGooglePlayStorePurchaseForPlayer(string productId, string purchaseToken, Action<LootLockerResponse> onComplete)
4333+
{
4334+
if (!CheckInitialized())
4335+
{
4336+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerResponse>());
4337+
return;
4338+
}
4339+
var body = LootLockerJson.SerializeObject(new LootLockerRedeemGooglePlayStorePurchaseForPlayerRequest()
4340+
{
4341+
product_id = productId,
4342+
purchase_token = purchaseToken
4343+
});
4344+
4345+
LootLockerServerRequest.CallAPI(LootLockerEndPoints.redeemGooglePlayStorePurchase.endPoint, LootLockerEndPoints.redeemGooglePlayStorePurchase.httpMethod, body, onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); });
4346+
}
4347+
4348+
/// <summary>
4349+
/// Redeem a purchase that was made successfully towards the Google Play Store for a character that the current player owns
4350+
/// </summary>
4351+
/// <param name="productId">The id of the product that this redemption refers to</param>
4352+
/// <param name="purchaseToken">The token from the purchase successfully made towards the Google Play Store</param>
4353+
/// <param name="characterId">The id of the character to redeem this purchase for</param>
4354+
/// <param name="onComplete">onComplete Action for handling the response</param>
4355+
public static void RedeemGooglePlayStorePurchaseForCharacter(string productId, string purchaseToken, int characterId, Action<LootLockerResponse> onComplete)
4356+
{
4357+
if (!CheckInitialized())
4358+
{
4359+
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerResponse>());
4360+
return;
4361+
}
4362+
var body = LootLockerJson.SerializeObject(new LootLockerRedeemGooglePlayStorePurchaseForCharacterRequest()
4363+
{
4364+
product_id = productId,
4365+
purchase_token = purchaseToken,
4366+
character_id = characterId
4367+
});
4368+
4369+
LootLockerServerRequest.CallAPI(LootLockerEndPoints.redeemGooglePlayStorePurchase.endPoint, LootLockerEndPoints.redeemGooglePlayStorePurchase.httpMethod, body, onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); });
4370+
}
4371+
42844372
#endregion
42854373

42864374
#region Collectables

Runtime/Game/Requests/PurchaseRequest.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
namespace LootLocker.Requests
55
{
6+
#region Legacy Purchasing
7+
//TODO: Deprecate legacy purchasing
8+
69
public class LootLockerPurchaseRequests
710
{
811
}
@@ -47,6 +50,7 @@ public class LootLockerPurchaseOrderStatus : LootLockerResponse
4750
{
4851
public string status { get; set; }
4952
}
53+
#endregion
5054

5155
/// <summary>
5256
///
@@ -77,12 +81,68 @@ public class LootLockerPurchaseCatalogItemRequest
7781
/// </summary>
7882
public LootLockerCatalogItemAndQuantityPair[] items { get; set; }
7983
}
84+
85+
/// <summary>
86+
///
87+
/// </summary>
88+
public class LootLockerRedeemAppleAppStorePurchaseForPlayerRequest
89+
{
90+
#if LOOTLOCKER_SANDBOX_APPLE_APP_STORE
91+
/// <summary>
92+
/// Whether or not to use the app store sandbox for this redemption
93+
/// </summary>
94+
public string sandboxed { get; set; } = true;
95+
#endif
96+
/// <summary>
97+
/// The id of the transaction successfully made towards the Apple App Store
98+
/// </summary>
99+
public string transaction_id { get; set; }
100+
}
101+
102+
/// <summary>
103+
///
104+
/// </summary>
105+
public class LootLockerRedeemAppleAppStorePurchaseForCharacterRequest : LootLockerRedeemAppleAppStorePurchaseForPlayerRequest
106+
{
107+
/// <summary>
108+
/// The id of the character to redeem this transaction for
109+
/// </summary>
110+
public int character_id { get; set; }
111+
}
112+
113+
/// <summary>
114+
///
115+
/// </summary>
116+
public class LootLockerRedeemGooglePlayStorePurchaseForPlayerRequest
117+
{
118+
/// <summary>
119+
/// The id of the product that this redemption refers to
120+
/// </summary>
121+
public string product_id { get; set; }
122+
/// <summary>
123+
/// The token from the purchase successfully made towards the Google Play Store
124+
/// </summary>
125+
public string purchase_token { get; set; }
126+
}
127+
128+
/// <summary>
129+
///
130+
/// </summary>
131+
public class LootLockerRedeemGooglePlayStorePurchaseForCharacterRequest : LootLockerRedeemGooglePlayStorePurchaseForPlayerRequest
132+
{
133+
/// <summary>
134+
/// The id of the character to redeem this purchase for
135+
/// </summary>
136+
public int character_id { get; set; }
137+
}
80138
}
81139

82140
namespace LootLocker
83141
{
84142
public partial class LootLockerAPIManager
85143
{
144+
#region Legacy Purchasing
145+
// TODO: Deprecate legacy purchasing
86146
public static void NormalPurchaseCall(LootLockerNormalPurchaseRequest[] data, Action<LootLockerPurchaseResponse> onComplete)
87147
{
88148
if(data == null)
@@ -160,5 +220,6 @@ public static void ActivateRentalAsset(LootLockerGetRequest lootLockerGetRequest
160220

161221
LootLockerServerRequest.CallAPI(getVariable, endPoint.httpMethod, "", (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); });
162222
}
223+
#endregion
163224
}
164225
}

0 commit comments

Comments
 (0)