예제 #1
0
        /// <summary>
        /// Removes user attributes.
        /// </summary>
        /// <remarks> Swagger method name:<c>Update User's Attributes from Client</c>.</remarks>
        /// <see cref="https://developers.xsolla.com/login-api/attributes/update-users-attributes-from-client"/>
        /// <param name="token">JWT from Xsolla Login.</param>
        /// <param name="projectId">Project ID from your Publisher Account.</param>
        /// <param name="attributeKeys">Attributes names list.</param>
        /// <param name="onSuccess">Success operation callback.</param>
        /// <param name="onError">Failed operation callback.</param>
        /// <seealso cref="GetUserAttributes"/>
        /// <seealso cref="UpdateUserAttributes"/>
        public void RemoveUserAttributes(string token, string projectId, List <string> attributeKeys, Action onSuccess, Action <Error> onError)
        {
            var removeAttributesRequestBody = new ModifyAttributesJson(null, projectId, attributeKeys);
            var headers = new List <WebRequestHeader>()
            {
                WebRequestHeader.AuthHeader(token), WebRequestHeader.ContentTypeHeader()
            };

            WebRequestHelper.Instance.PostRequest(SdkType.Login, URL_USER_UPDATE_ATTRIBUTES, removeAttributesRequestBody, headers, onSuccess, onError);
        }
        public void ConsumeInventoryItem(string projectId, ConsumeItem item, [CanBeNull] Action onSuccess, [CanBeNull] Action <Error> onError)
        {
            var urlBuilder = new StringBuilder(string.Format(URL_INVENTORY_ITEM_CONSUME, projectId)).Append(AdditionalUrlParams);

            var headers = new List <WebRequestHeader>()
            {
                WebRequestHeader.AuthHeader(Token), WebRequestHeader.ContentTypeHeader()
            };

            WebRequestHelper.Instance.PostRequest(urlBuilder.ToString(), item, headers, onSuccess, onError, Error.ConsumeItemErrors);
        }
예제 #3
0
        /// <summary>
        /// Redeems a coupon code.
        /// </summary>
        /// <remarks> Swagger method name:<c>Redeem coupon code</c>.</remarks>
        /// <see cref="https://developers.xsolla.com/store-api/promotions/coupons/redeem-coupon/"/>
        /// <param name="projectId">Project ID from your Publisher Account.</param>
        /// <param name="couponCode">Unique coupon code. Contains letters and numbers.</param>
        /// <param name="onSuccess">Success operation callback.</param>
        /// <param name="onError">Failed operation callback.</param>
        public void RedeemCouponCode(string projectId, CouponCode couponCode, [NotNull] Action <CouponRedeemedItems> onSuccess, [CanBeNull] Action <Error> onError)
        {
            var url           = string.Format(URL_INVENTORY_REDEEM_COUPON, projectId);
            var platformParam = GetPlatformUrlParam();

            url = ConcatUrlAndParams(url, platformParam);

            var headers = new List <WebRequestHeader>()
            {
                WebRequestHeader.AuthHeader(Token.Instance), WebRequestHeader.ContentTypeHeader()
            };

            WebRequestHelper.Instance.PostRequest(SdkType.Store, url, couponCode, headers, onSuccess, onError, Error.CouponErrors);
        }
예제 #4
0
        /// <summary>
        /// Consumes item from inventory.
        /// </summary>
        /// <remarks> Swagger method name:<c>Consume item</c>.</remarks>
        /// <see cref="https://developers.xsolla.com/store-api/inventory-client/consume-item"/>
        /// <param name="projectId">Project ID from your Publisher Account.</param>
        /// <param name="item">Contains consume parameters.</param>
        /// <param name="onSuccess">Successful operation callback.</param>
        /// <param name="onError">Failed operation callback.</param>
        public void ConsumeInventoryItem(string projectId, ConsumeItem item, [CanBeNull] Action onSuccess, [CanBeNull] Action <Error> onError)
        {
            var url           = string.Format(URL_INVENTORY_ITEM_CONSUME, projectId);
            var platformParam = GetPlatformUrlParam();

            url = ConcatUrlAndParams(url, platformParam);

            var headers = new List <WebRequestHeader>()
            {
                WebRequestHeader.AuthHeader(Token.Instance), WebRequestHeader.ContentTypeHeader()
            };

            WebRequestHelper.Instance.PostRequest(SdkType.Store, url, item, headers, onSuccess, onError, Error.ConsumeItemErrors);
        }
예제 #5
0
        /// <summary>
        /// Gets coupons rewards by its code. Can be used to allow users to choose one of many items as a bonus.
        /// The usual case is choosing a DRM if the coupon contains a game as a bonus (type=unit).
        /// </summary>
        /// <remarks> Swagger method name:<c>Get coupon rewards</c>.</remarks>
        /// <see cref="https://developers.xsolla.com/store-api/promotions/coupons/get-coupon-rewards-by-code/"/>
        /// <param name="projectId">Project ID from your Publisher Account.</param>
        /// <param name="couponCode">Unique case sensitive code. Contains letters and numbers.</param>
        /// <param name="onSuccess">Success operation callback.</param>
        /// <param name="onError">Failed operation callback.</param>
        public void GetCouponRewards(string projectId, string couponCode, [NotNull] Action <CouponReward> onSuccess, [CanBeNull] Action <Error> onError, [CanBeNull] string locale = null)
        {
            var url           = string.Format(URL_INVENTORY_GET_COUPON_REWARDS, projectId, couponCode);
            var localeParam   = GetLocaleUrlParam(locale);
            var platformParam = GetPlatformUrlParam();

            url = ConcatUrlAndParams(url, localeParam, platformParam);

            var headers = new List <WebRequestHeader>()
            {
                WebRequestHeader.AuthHeader(Token.Instance), WebRequestHeader.ContentTypeHeader()
            };

            WebRequestHelper.Instance.GetRequest(SdkType.Store, url, headers, onSuccess, onError, Error.CouponErrors);
        }
예제 #6
0
        void RequestToken([NotNull] Action <Token> onSuccess, [CanBeNull] Action <Error> onError)
        {
            var urlBuilder = new StringBuilder(string.Format("https://api.xsolla.com/merchant/v2/merchants/{0}/token", XsollaSettings.MerchantId));

            var headers = new List <WebRequestHeader>()
            {
                WebRequestHeader.ContentTypeHeader(), WebRequestHeader.AuthBasic("API KEY")
            };

            var jsonData = JsonUtility.ToJson(GenerateTestToken());

            print(jsonData);

            WebRequestHelper.Instance.PostRequest(urlBuilder.ToString(), jsonData, new WWWForm(), headers, onSuccess, onError);
        }
예제 #7
0
        /// <summary>
        /// Returns user attributes.
        /// </summary>
        /// <remarks> Swagger method name:<c>Get User's Attributes from Client</c>.</remarks>
        /// <see cref="https://developers.xsolla.com/login-api/attributes/get-user-attributes-from-client"/>
        /// <param name="token">JWT from Xsolla Login.</param>
        /// <param name="projectId">Project ID from your Publisher Account.</param>
        /// <param name="attributeKeys">Attributes names list filter</param>
        /// <param name="userId">Login user ID. Can be null, because this info exist in the token.</param>
        /// <param name="attributeType">User attribute type to get</param>
        /// <param name="onSuccess">Successful operation callback.</param>
        /// <param name="onError">Failed operation callback.</param>
        /// <seealso cref="UpdateUserAttributes"/>
        /// <seealso cref="RemoveUserAttributes"/>
        public void GetUserAttributes(string token, string projectId, UserAttributeType attributeType, [CanBeNull] List <string> attributeKeys, [CanBeNull] string userId, [NotNull] Action <List <UserAttribute> > onSuccess, [CanBeNull] Action <Error> onError)
        {
            var getAttributesRequestBody = new GetAttributesJson(attributeKeys, projectId, userId);
            var headers = new List <WebRequestHeader> {
                WebRequestHeader.AuthHeader(token), WebRequestHeader.ContentTypeHeader()
            };

            string url = default(string);

            switch (attributeType)
            {
            case UserAttributeType.CUSTOM:
                url = URL_USER_GET_ATTRIBUTES;
                break;

            case UserAttributeType.READONLY:
                url = URL_USER_GET_READONLY_ATTRIBUTES;
                break;
            }

            WebRequestHelper.Instance.PostRequest(SdkType.Login, url, getAttributesRequestBody, headers, onSuccess, onError);
        }
예제 #8
0
        public void AddItemToCart(string projectId, string cartId, string itemSku, int quantity, [CanBeNull] Action onSuccess, [CanBeNull] Action <Error> onError)
        {
            var urlBuilder = new StringBuilder(string.Format(URL_CART_ITEM_ADD, projectId, cartId, itemSku)).Append(AdditionalUrlParams);

            string jsonData = JsonConvert.SerializeObject(new Quantity {
                quantity = quantity
            });

            WebRequestHelper.Instance.PutRequest(urlBuilder.ToString(), jsonData, WebRequestHeader.AuthHeader(Token), WebRequestHeader.ContentTypeHeader(), onSuccess, onError, Error.AddToCartCartErrors);
        }