Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="orderId">Unique identifier of the order.</param>
        /// <param name="responseFields">Filtering syntax appended to an API call to increase or decrease the amount of data returned inside a JSON object. This parameter should only be used to retrieve data. Attempting to update data using this parameter may cause data loss.</param>
        /// <param name="updateMode">Specifies whether to update the original order, update the order in draft mode, or update the order in draft mode and then commit the changes to the original. Draft mode enables users to make incremental order changes before committing the changes to the original order. Valid values are "ApplyToOriginal," "ApplyToDraft," or "ApplyAndCommit."</param>
        /// <param name="version">Determines whether or not to check versioning of items for concurrency purposes.</param>
        /// <param name="billingInfo">Properties of the billing information entered for an order during checkout.</param>
        /// <returns>
        /// <see cref="Mozu.Api.Contracts.CommerceRuntime.Payments.BillingInfo"/>
        /// </returns>
        /// <example>
        /// <code>
        ///   var billinginfo = new BillingInfo();
        ///   var billingInfo = await billinginfo.SetBillingInfoAsync( billingInfo,  orderId,  updateMode,  version,  responseFields);
        /// </code>
        /// </example>
        public virtual async Task <Mozu.Api.Contracts.CommerceRuntime.Payments.BillingInfo> SetBillingInfoAsync(Mozu.Api.Contracts.CommerceRuntime.Payments.BillingInfo billingInfo, string orderId, string updateMode = null, string version = null, string responseFields = null, CancellationToken ct = default(CancellationToken))
        {
            MozuClient <Mozu.Api.Contracts.CommerceRuntime.Payments.BillingInfo> response;
            var client = Mozu.Api.Clients.Commerce.Orders.BillingInfoClient.SetBillingInfoClient(billingInfo, orderId, updateMode, version, responseFields);

            client.WithContext(_apiContext);
            response = await client.ExecuteAsync(ct).ConfigureAwait(false);

            return(await response.ResultAsync());
        }
        public void Exercise_14_2_Auth_Capture_Order_Payment()
        {
            var orderNumber = 11;

            //Create an Order resource. This resource is used to get, create, update orders
            var orderResource   = new Mozu.Api.Resources.Commerce.OrderResource(_apiContext);
            var paymentResource = new Mozu.Api.Resources.Commerce.Orders.PaymentResource(_apiContext);

            var existingOrder = (orderResource.GetOrdersAsync(filter: "OrderNumber eq '" + orderNumber + "'").Result).Items[0];

            Mozu.Api.Contracts.CommerceRuntime.Payments.Payment authorizedPayment = null;
            Mozu.Api.Contracts.CommerceRuntime.Payments.Payment pendingPayment    = null;

            #region Add BillingInfo from Customer Object
            var customerResource = new Mozu.Api.Resources.Commerce.Customer.CustomerAccountResource(_apiContext);
            var customerAccount  = customerResource.GetAccountAsync(1002).Result;

            var contactInfo = new Mozu.Api.Contracts.Core.Contact();

            foreach (var contact in customerAccount.Contacts)
            {
                foreach (var type in contact.Types)
                {
                    if (type.IsPrimary)
                    {
                        contactInfo.Address = contact.Address;
                        contactInfo.CompanyOrOrganization = contact.CompanyOrOrganization;
                        contactInfo.Email               = contact.Email;
                        contactInfo.FirstName           = contact.FirstName;
                        contactInfo.LastNameOrSurname   = contact.LastNameOrSurname;
                        contactInfo.MiddleNameOrInitial = contact.MiddleNameOrInitial;
                        contactInfo.PhoneNumbers        = contact.PhoneNumbers;
                    }
                }
            }

            var billingInfo = new Mozu.Api.Contracts.CommerceRuntime.Payments.BillingInfo()
            {
                BillingContact = contactInfo,
                IsSameBillingShippingAddress = true,
                PaymentType = "Check",
            };
            #endregion

            var action = new Mozu.Api.Contracts.CommerceRuntime.Payments.PaymentAction()
            {
                Amount                   = existingOrder.Total,
                CurrencyCode             = "USD",
                InteractionDate          = DateTime.Now,
                NewBillingInfo           = billingInfo,
                ActionName               = "CreatePayment",
                ReferenceSourcePaymentId = null,
                CheckNumber              = "1234"
            };

            try
            {
                authorizedPayment = existingOrder.Payments.FirstOrDefault(d => d.Status == "Authorized");
                pendingPayment    = existingOrder.Payments.FirstOrDefault(d => d.Status == "Pending");
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
            }

            if (authorizedPayment != null)
            {
                action.ActionName = "CapturePayment";
                var capturedPayment = paymentResource.PerformPaymentActionAsync(action, existingOrder.Id, authorizedPayment.Id).Result;
            }
            else if (pendingPayment != null)
            {
                action.ActionName = "CapturePayment";
                var capturedPayment = paymentResource.PerformPaymentActionAsync(action, existingOrder.Id, pendingPayment.Id).Result;
            }
            else
            {
                var authPayment = paymentResource.CreatePaymentActionAsync(action, existingOrder.Id).Result;
            }
        }
        public void Exercise_14_2_Auth_Capture_Order_Payment()
        {
            var orderNumber = 12;

            //Create an Order resource. This resource is used to get, create, update orders
            var orderResource = new Mozu.Api.Resources.Commerce.OrderResource(_apiContext);
            var paymentResource = new Mozu.Api.Resources.Commerce.Orders.PaymentResource(_apiContext);

            var existingOrder = (orderResource.GetOrdersAsync(filter: "OrderNumber eq '" + orderNumber + "'").Result).Items[0];
            Mozu.Api.Contracts.CommerceRuntime.Payments.Payment authorizedPayment = null;
            Mozu.Api.Contracts.CommerceRuntime.Payments.Payment pendingPayment = null;

            #region Add BillingInfo from Customer Object
            var customerResource = new Mozu.Api.Resources.Commerce.Customer.CustomerAccountResource(_apiContext);
            var customerAccount = customerResource.GetAccountAsync(1002).Result;

            var contactInfo = new Mozu.Api.Contracts.Core.Contact();

            foreach (var contact in customerAccount.Contacts)
            {
                foreach (var type in contact.Types)
                {
                    if (type.IsPrimary)
                    {
                        contactInfo.Address = contact.Address;
                        contactInfo.CompanyOrOrganization = contact.CompanyOrOrganization;
                        contactInfo.Email = contact.Email;
                        contactInfo.FirstName = contact.FirstName;
                        contactInfo.LastNameOrSurname = contact.LastNameOrSurname;
                        contactInfo.MiddleNameOrInitial = contact.MiddleNameOrInitial;
                        contactInfo.PhoneNumbers = contact.PhoneNumbers;
                    }
                }
            }

            var billingInfo = new Mozu.Api.Contracts.CommerceRuntime.Payments.BillingInfo()
            {
                BillingContact = contactInfo,
                IsSameBillingShippingAddress = true,
                PaymentType = "Check",
            };
            #endregion

            var action = new Mozu.Api.Contracts.CommerceRuntime.Payments.PaymentAction()
            {
                    Amount = existingOrder.Total,
                    CurrencyCode = "USD",
                    InteractionDate = DateTime.Now,
                    NewBillingInfo = billingInfo,
                    ActionName = "CreatePayment",
                    ReferenceSourcePaymentId = null,
                    CheckNumber = "1234"
            };

            try
            {
                authorizedPayment = existingOrder.Payments.FirstOrDefault(d => d.Status == "Authorized");
                pendingPayment = existingOrder.Payments.FirstOrDefault(d => d.Status == "Pending");
            }
            catch(Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
            }

            if(authorizedPayment != null)
            {
                action.ActionName = "CapturePayment";
                var capturedPayment = paymentResource.PerformPaymentActionAsync(action, existingOrder.Id, authorizedPayment.Id).Result;
            }
            else if(pendingPayment != null)
            {
                action.ActionName = "CapturePayment";
                var capturedPayment = paymentResource.PerformPaymentActionAsync(action, existingOrder.Id, pendingPayment.Id).Result;
            }
            else
            {
                var authPayment = paymentResource.CreatePaymentActionAsync(action, existingOrder.Id).Result;

            }
        }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="orderId">Unique identifier of the order.</param>
        /// <param name="responseFields">Filtering syntax appended to an API call to increase or decrease the amount of data returned inside a JSON object. This parameter should only be used to retrieve data. Attempting to update data using this parameter may cause data loss.</param>
        /// <param name="updateMode">Specifies whether to update the original order, update the order in draft mode, or update the order in draft mode and then commit the changes to the original. Draft mode enables users to make incremental order changes before committing the changes to the original order. Valid values are "ApplyToOriginal," "ApplyToDraft," or "ApplyAndCommit."</param>
        /// <param name="version">Determines whether or not to check versioning of items for concurrency purposes.</param>
        /// <param name="billingInfo">Properties of the billing information entered for an order during checkout.</param>
        /// <returns>
        ///  <see cref="Mozu.Api.MozuClient" />{<see cref="Mozu.Api.Contracts.CommerceRuntime.Payments.BillingInfo"/>}
        /// </returns>
        /// <example>
        /// <code>
        ///   var mozuClient=SetBillingInfo( billingInfo,  orderId,  updateMode,  version,  responseFields);
        ///   var billingInfoClient = mozuClient.WithBaseAddress(url).Execute().Result();
        /// </code>
        /// </example>
        public static MozuClient <Mozu.Api.Contracts.CommerceRuntime.Payments.BillingInfo> SetBillingInfoClient(Mozu.Api.Contracts.CommerceRuntime.Payments.BillingInfo billingInfo, string orderId, string updateMode = null, string version = null, string responseFields = null)
        {
            var          url        = Mozu.Api.Urls.Commerce.Orders.BillingInfoUrl.SetBillingInfoUrl(orderId, updateMode, version, responseFields);
            const string verb       = "PUT";
            var          mozuClient = new MozuClient <Mozu.Api.Contracts.CommerceRuntime.Payments.BillingInfo>()
                                      .WithVerb(verb).WithResourceUrl(url)
                                      .WithBody <Mozu.Api.Contracts.CommerceRuntime.Payments.BillingInfo>(billingInfo);

            return(mozuClient);
        }
Exemple #5
0
        /// <summary>
        /// Updates the billing information supplied for an order.
        /// <example>
        ///  <code>
        /// var result = BillingInfoFactory.SetBillingInfo(handler : handler,  billingInfo :  billingInfo,  orderId :  orderId,  updateMode :  updateMode,  version :  version,  responseFields :  responseFields,  expectedCode: expectedCode, successCode: successCode);
        /// var optionalCasting = ConvertClass<BillingInfo/>(result);
        /// return optionalCasting;
        ///  </code>
        /// </example>
        /// </summary>
        public static Mozu.Api.Contracts.CommerceRuntime.Payments.BillingInfo SetBillingInfo(ServiceClientMessageHandler handler,
                                                                                             Mozu.Api.Contracts.CommerceRuntime.Payments.BillingInfo billingInfo, string orderId, string updateMode = null, string version = null, string responseFields = null,
                                                                                             HttpStatusCode expectedCode = HttpStatusCode.OK, HttpStatusCode successCode = HttpStatusCode.OK)
        {
            SetSdKparameters();
            var currentClassName  = System.Reflection.MethodInfo.GetCurrentMethod().DeclaringType.Name;
            var currentMethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            Debug.WriteLine(currentMethodName + '.' + currentMethodName);
            var apiClient = Mozu.Api.Clients.Commerce.Orders.BillingInfoClient.SetBillingInfoClient(
                billingInfo:  billingInfo, orderId:  orderId, updateMode:  updateMode, version:  version, responseFields:  responseFields);

            try
            {
                apiClient.WithContext(handler.ApiContext).Execute();
            }
            catch (ApiException ex)
            {
                // Custom error handling for test cases can be placed here
                Exception customException = TestFailException.GetCustomTestException(ex, currentClassName, currentMethodName, expectedCode);
                if (customException != null)
                {
                    throw customException;
                }
                return(null);
            }
            return(ResponseMessageFactory.CheckResponseCodes(apiClient.HttpResponse.StatusCode, expectedCode, successCode)
                                         ? (apiClient.Result())
                                         : null);
        }
        public virtual Mozu.Api.Contracts.CommerceRuntime.Payments.BillingInfo SetBillingInfo(Mozu.Api.Contracts.CommerceRuntime.Payments.BillingInfo billingInfo, string orderId, string updateMode = null, string version = null, string responseFields = null)
        {
            MozuClient <Mozu.Api.Contracts.CommerceRuntime.Payments.BillingInfo> response;
            var client = Mozu.Api.Clients.Commerce.Orders.BillingInfoClient.SetBillingInfoClient(billingInfo, orderId, updateMode, version, responseFields);

            client.WithContext(_apiContext);
            response = client.Execute();
            return(response.Result());
        }