/// <summary>
        /// Updates the given <see cref="Customer"/>.
        /// </summary>
        /// <param name="customerId">Id of the object being updated.</param>
        /// <param name="customer">The <see cref="Customer"/> to update.</param>
        /// <param name="options">Options for updating the customer.</param>
        /// <returns>The updated <see cref="Customer"/>.</returns>
        public virtual async Task <Customer> UpdateAsync(long customerId, Customer customer, CustomerUpdateOptions options = null)
        {
            var req  = PrepareRequest($"customers/{customerId}.json");
            var body = customer.ToDictionary();

            if (options != null)
            {
                foreach (var keyValuePair in options.ToDictionary())
                {
                    body.Add(keyValuePair);
                }
            }

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

            return(await ExecuteRequestAsync <Customer>(req, HttpMethod.Put, content, "customer"));
        }
示例#2
0
        /// <summary>
        /// Creates a new <see cref="Customer"/> on the store.
        /// </summary>
        /// <param name="customer">A new <see cref="Customer"/>. Id should be set to null.</param>
        /// <param name="options">Options for creating the customer.</param>
        /// <param name="cancellationToken">Cancellation Token</param>
        /// <returns>The new <see cref="Customer"/>.</returns>
        public virtual async Task <Customer> CreateAsync(Customer customer, CustomerCreateOptions options = null, CancellationToken cancellationToken = default)
        {
            var req  = PrepareRequest("customers.json");
            var body = customer.ToDictionary();

            if (options != null)
            {
                foreach (var keyValuePair in options.ToDictionary())
                {
                    body.Add(keyValuePair);
                }
            }

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

            var response = await ExecuteRequestAsync <Customer>(req, HttpMethod.Post, cancellationToken, content, "customer");

            return(response.Result);
        }