Beispiel #1
0
        /// <summary>
        /// Creates a new discount code.
        /// </summary>
        /// <param name="priceRuleId">Id of an existing price rule.</param>
        public virtual async Task <PriceRuleDiscountCode> CreateAsync(long priceRuleId, PriceRuleDiscountCode code)
        {
            var req  = PrepareRequest($"price_rules/{priceRuleId}/discount_codes.json");
            var body = code.ToDictionary();

            var content = new JsonContent(new
            {
                discount_code = body
            });

            return(await ExecuteRequestAsync <PriceRuleDiscountCode>(req, HttpMethod.Post, content, "discount_code"));
        }
Beispiel #2
0
        /// <summary>
        /// Updates the given object.
        /// </summary>
        /// <param name="priceRuleId">The Id of the Price Rule being updated.</param>
        /// <param name="code">The code being updated.</param>
        public virtual async Task <PriceRuleDiscountCode> UpdateAsync(long priceRuleId, PriceRuleDiscountCode code)
        {
            var req     = PrepareRequest($"price_rules/{priceRuleId}/discount_codes/{code.Id.Value}.json");
            var content = new JsonContent(new
            {
                discount_code = code
            });

            return(await ExecuteRequestAsync <PriceRuleDiscountCode>(req, HttpMethod.Put, content, "discount_code"));
        }
        /// <summary>
        /// Updates the given object.
        /// </summary>
        /// <param name="priceRuleId">The Id of the Price Rule being updated.</param>
        /// <param name="code">The code being updated.</param>
        /// <param name="cancellationToken">Cancellation Token</param>
        public virtual async Task <PriceRuleDiscountCode> UpdateAsync(long priceRuleId, PriceRuleDiscountCode code, CancellationToken cancellationToken = default)
        {
            var req     = PrepareRequest($"price_rules/{priceRuleId}/discount_codes/{code.Id.Value}.json");
            var content = new JsonContent(new
            {
                discount_code = code
            });

            var response = await ExecuteRequestAsync <PriceRuleDiscountCode>(req, HttpMethod.Put, cancellationToken, content, "discount_code");

            return(response.Result);
        }