|
6 | 6 | using LootLocker.LootLockerEnums;
|
7 | 7 | using System.Linq;
|
8 | 8 | using System.Security.Cryptography;
|
| 9 | +#if LOOTLOCKER_USE_NEWTONSOFTJSON |
| 10 | +using Newtonsoft.Json; |
| 11 | +using Newtonsoft.Json.Linq; |
| 12 | +#else |
| 13 | +using LLlibs.ZeroDepJson; |
| 14 | +#endif |
9 | 15 | #if UNITY_EDITOR
|
10 | 16 | using UnityEditor;
|
11 | 17 | #endif
|
@@ -4394,7 +4400,7 @@ public static void PollOrderStatus(int assetId, Action<LootLockerPurchaseOrderSt
|
4394 | 4400 | /// <summary>
|
4395 | 4401 | /// Activate a rental asset. This will grant the asset to the player and start the rental timer on the server.
|
4396 | 4402 | /// </summary>
|
4397 |
| - /// <param name="assetId">The asset instance ID of the asset to activate</param> |
| 4403 | + /// <param name="assetInstanceID">The asset instance ID of the asset to activate</param> |
4398 | 4404 | /// <param name="onComplete">onComplete Action for handling the response of type LootLockerActivateARentalAssetResponse</param>
|
4399 | 4405 | public static void ActivateRentalAsset(int assetInstanceID, Action<LootLockerActivateRentalAssetResponse> onComplete)
|
4400 | 4406 | {
|
@@ -4522,7 +4528,210 @@ public static void RedeemGooglePlayStorePurchaseForClass(string productId, strin
|
4522 | 4528 | LootLockerServerRequest.CallAPI(LootLockerEndPoints.redeemGooglePlayStorePurchase.endPoint, LootLockerEndPoints.redeemGooglePlayStorePurchase.httpMethod, body, onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); });
|
4523 | 4529 | }
|
4524 | 4530 |
|
4525 |
| - #endregion |
| 4531 | + /// <summary> |
| 4532 | + /// Begin a Steam purchase with the given settings that when finalized will redeem the specified catalog item |
| 4533 | + /// |
| 4534 | + /// Steam in-app purchases need to be configured for this to work |
| 4535 | + /// Steam in-app purchases works slightly different from other platforms, you begin a purchase with this call which initiates it in Steams backend |
| 4536 | + /// While your app is waiting for the user to finalize that purchase you can use QuerySteamPurchaseRedemptionStatus to get the status, when that tells you that the purchase is Approved you can finalize the purchase using FinalizeSteamPurchaseRedemption |
| 4537 | + /// </summary> |
| 4538 | + /// <param name="steamId">Id of the Steam User that is making the purchase</param> |
| 4539 | + /// <param name="currency">The currency to use for the purchase</param> |
| 4540 | + /// <param name="language">The language to use for the purchase</param> |
| 4541 | + /// <param name="catalogItemId">The LootLocker Catalog Item Id for the item you wish to purchase</param> |
| 4542 | + /// <param name="onComplete">onComplete Action for handling the response</param> |
| 4543 | + public static void BeginSteamPurchaseRedemption(string steamId, string currency, string language, string catalogItemId, Action<LootLockerBeginSteamPurchaseRedemptionResponse> onComplete) |
| 4544 | + { |
| 4545 | + if (!CheckInitialized()) |
| 4546 | + { |
| 4547 | + onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerBeginSteamPurchaseRedemptionResponse>()); |
| 4548 | + return; |
| 4549 | + } |
| 4550 | + var body = LootLockerJson.SerializeObject(new LootLockerBeginSteamPurchaseRedemptionRequest() |
| 4551 | + { |
| 4552 | + steam_id = steamId, |
| 4553 | + currency = currency, |
| 4554 | + language = language, |
| 4555 | + catalog_item_id = catalogItemId |
| 4556 | + }); |
| 4557 | + |
| 4558 | + LootLockerServerRequest.CallAPI(LootLockerEndPoints.beginSteamPurchaseRedemption.endPoint, LootLockerEndPoints.beginSteamPurchaseRedemption.httpMethod, body, onComplete: |
| 4559 | + (serverResponse) => |
| 4560 | + { |
| 4561 | + var parsedResponse = LootLockerResponse.Deserialize<LootLockerBeginSteamPurchaseRedemptionResponse>(serverResponse); |
| 4562 | + if (!parsedResponse.success) |
| 4563 | + { |
| 4564 | + onComplete?.Invoke(parsedResponse); |
| 4565 | + return; |
| 4566 | + } |
| 4567 | + |
| 4568 | +#if LOOTLOCKER_USE_NEWTONSOFTJSON |
| 4569 | + JObject jsonObject; |
| 4570 | + try |
| 4571 | + { |
| 4572 | + jsonObject = JObject.Parse(serverResponse.text); |
| 4573 | + } |
| 4574 | + catch (JsonReaderException) |
| 4575 | + { |
| 4576 | + onComplete?.Invoke(parsedResponse); |
| 4577 | + return; |
| 4578 | + } |
| 4579 | + if (jsonObject != null && jsonObject.TryGetValue("success", StringComparison.OrdinalIgnoreCase, out var successObj)) |
| 4580 | + { |
| 4581 | + if (successObj.ToObject(typeof(bool)) is bool isSuccess) |
| 4582 | + { |
| 4583 | + parsedResponse.isSuccess = isSuccess; |
| 4584 | + } |
| 4585 | + } |
| 4586 | +#else |
| 4587 | + Dictionary<string, object> jsonObject = null; |
| 4588 | + try |
| 4589 | + { |
| 4590 | + jsonObject = Json.Deserialize(serverResponse.text) as Dictionary<string, object>; |
| 4591 | + } |
| 4592 | + catch (JsonException) |
| 4593 | + { |
| 4594 | + onComplete?.Invoke(parsedResponse); |
| 4595 | + return; |
| 4596 | + } |
| 4597 | + if (jsonObject != null && jsonObject.TryGetValue("success", out var successObj)) |
| 4598 | + { |
| 4599 | + if (successObj is bool isSuccess) |
| 4600 | + { |
| 4601 | + parsedResponse.isSuccess = isSuccess; |
| 4602 | + } |
| 4603 | + } |
| 4604 | +#endif |
| 4605 | + onComplete?.Invoke(parsedResponse); |
| 4606 | + }); |
| 4607 | + } |
| 4608 | + |
| 4609 | + /// <summary> |
| 4610 | + /// Begin a Steam purchase with the given settings that when finalized will redeem the specified catalog item for the specified class |
| 4611 | + /// |
| 4612 | + /// Steam in-app purchases need to be configured for this to work |
| 4613 | + /// Steam in-app purchases works slightly different from other platforms, you begin a purchase with this call which initiates it in Steams backend |
| 4614 | + /// While your app is waiting for the user to finalize that purchase you can use QuerySteamPurchaseRedemptionStatus to get the status, when that tells you that the purchase is Approved you can finalize the purchase using FinalizeSteamPurchaseRedemption |
| 4615 | + /// </summary> |
| 4616 | + /// <param name="classId">Id of the class to make the purchase for</param> |
| 4617 | + /// <param name="steamId">Id of the Steam User that is making the purchase</param> |
| 4618 | + /// <param name="currency">The currency to use for the purchase</param> |
| 4619 | + /// <param name="language">The language to use for the purchase</param> |
| 4620 | + /// <param name="catalogItemId">The LootLocker Catalog Item Id for the item you wish to purchase</param> |
| 4621 | + /// <param name="onComplete">onComplete Action for handling the response</param> |
| 4622 | + public static void BeginSteamPurchaseRedemptionForClass(int classId, string steamId, string currency, string language, string catalogItemId, Action<LootLockerBeginSteamPurchaseRedemptionResponse> onComplete) |
| 4623 | + { |
| 4624 | + if (!CheckInitialized()) |
| 4625 | + { |
| 4626 | + onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerBeginSteamPurchaseRedemptionResponse>()); |
| 4627 | + return; |
| 4628 | + } |
| 4629 | + var body = LootLockerJson.SerializeObject(new LootLockerBeginSteamPurchaseRedemptionForClassRequest() |
| 4630 | + { |
| 4631 | + class_id = classId, |
| 4632 | + steam_id = steamId, |
| 4633 | + currency = currency, |
| 4634 | + language = language, |
| 4635 | + catalog_item_id = catalogItemId |
| 4636 | + }); |
| 4637 | + |
| 4638 | + LootLockerServerRequest.CallAPI(LootLockerEndPoints.beginSteamPurchaseRedemption.endPoint, LootLockerEndPoints.beginSteamPurchaseRedemption.httpMethod, body, onComplete: |
| 4639 | + (serverResponse) => |
| 4640 | + { |
| 4641 | + var parsedResponse = LootLockerResponse.Deserialize<LootLockerBeginSteamPurchaseRedemptionResponse>(serverResponse); |
| 4642 | + if (!parsedResponse.success) |
| 4643 | + { |
| 4644 | + onComplete?.Invoke(parsedResponse); |
| 4645 | + return; |
| 4646 | + } |
| 4647 | + |
| 4648 | +#if LOOTLOCKER_USE_NEWTONSOFTJSON |
| 4649 | + JObject jsonObject; |
| 4650 | + try |
| 4651 | + { |
| 4652 | + jsonObject = JObject.Parse(serverResponse.text); |
| 4653 | + } |
| 4654 | + catch (JsonReaderException) |
| 4655 | + { |
| 4656 | + onComplete?.Invoke(parsedResponse); |
| 4657 | + return; |
| 4658 | + } |
| 4659 | + if (jsonObject != null && jsonObject.TryGetValue("success", StringComparison.OrdinalIgnoreCase, out var successObj)) |
| 4660 | + { |
| 4661 | + if (successObj.ToObject(typeof(bool)) is bool isSuccess) |
| 4662 | + { |
| 4663 | + parsedResponse.isSuccess = isSuccess; |
| 4664 | + } |
| 4665 | + } |
| 4666 | +#else |
| 4667 | + Dictionary<string, object> jsonObject = null; |
| 4668 | + try |
| 4669 | + { |
| 4670 | + jsonObject = Json.Deserialize(serverResponse.text) as Dictionary<string, object>; |
| 4671 | + } |
| 4672 | + catch (JsonException) |
| 4673 | + { |
| 4674 | + onComplete?.Invoke(parsedResponse); |
| 4675 | + return; |
| 4676 | + } |
| 4677 | + if (jsonObject != null && jsonObject.TryGetValue("success", out var successObj)) |
| 4678 | + { |
| 4679 | + if (successObj is bool isSuccess) |
| 4680 | + { |
| 4681 | + parsedResponse.isSuccess = isSuccess; |
| 4682 | + } |
| 4683 | + } |
| 4684 | +#endif |
| 4685 | + onComplete?.Invoke(parsedResponse); |
| 4686 | + }); |
| 4687 | + } |
| 4688 | + |
| 4689 | + /// <summary> |
| 4690 | + /// Check the Steam Purchase status for a given entitlement |
| 4691 | + /// |
| 4692 | + /// Use this to check the status of an ongoing purchase to know when it's ready to finalize or has been aborted |
| 4693 | + /// or use this to get information for a completed purchase |
| 4694 | + /// </summary> |
| 4695 | + /// <param name="entitlementId">The id of the entitlement to check the status for</param> |
| 4696 | + /// <param name="onComplete">onComplete Action for handling the response</param> |
| 4697 | + public static void BeginSteamPurchaseRedemption(string entitlementId, Action<LootLockerQuerySteamPurchaseRedemptionStatusResponse> onComplete) |
| 4698 | + { |
| 4699 | + if (!CheckInitialized()) |
| 4700 | + { |
| 4701 | + onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerQuerySteamPurchaseRedemptionStatusResponse>()); |
| 4702 | + return; |
| 4703 | + } |
| 4704 | + var body = LootLockerJson.SerializeObject(new LootLockerQuerySteamPurchaseRedemptionStatusRequest() |
| 4705 | + { |
| 4706 | + entitlement_id = entitlementId |
| 4707 | + }); |
| 4708 | + |
| 4709 | + LootLockerServerRequest.CallAPI(LootLockerEndPoints.querySteamPurchaseRedemptionStatus.endPoint, LootLockerEndPoints.querySteamPurchaseRedemptionStatus.httpMethod, body, onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); }); |
| 4710 | + } |
| 4711 | + |
| 4712 | + /// <summary> |
| 4713 | + /// Finalize a started Steam Purchase and subsequently redeem the catalog items that the entitlement refers to |
| 4714 | + /// |
| 4715 | + /// The steam purchase needs to be in status Approved for this call to work |
| 4716 | + /// </summary> |
| 4717 | + /// <param name="entitlementId">The id of the entitlement to finalize the purchase for</param> |
| 4718 | + /// <param name="onComplete">onComplete Action for handling the response</param> |
| 4719 | + public static void FinalizeSteamPurchaseRedemption(string entitlementId, Action<LootLockerResponse> onComplete) |
| 4720 | + { |
| 4721 | + if (!CheckInitialized()) |
| 4722 | + { |
| 4723 | + onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerResponse>()); |
| 4724 | + return; |
| 4725 | + } |
| 4726 | + var body = LootLockerJson.SerializeObject(new LootLockerFinalizeSteamPurchaseRedemptionRequest() |
| 4727 | + { |
| 4728 | + entitlement_id = entitlementId |
| 4729 | + }); |
| 4730 | + |
| 4731 | + LootLockerServerRequest.CallAPI(LootLockerEndPoints.finalizeSteamPurchaseRedemption.endPoint, LootLockerEndPoints.finalizeSteamPurchaseRedemption.httpMethod, body, onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); }); |
| 4732 | + } |
| 4733 | + |
| 4734 | +#endregion |
4526 | 4735 |
|
4527 | 4736 | #region Collectables
|
4528 | 4737 | /// <summary>
|
|
0 commit comments