Exemplo n.º 1
0
        /// <summary>
        /// Creates a new payment for a return that results in a refund to the customer.
        /// </summary>
        /// <param name="responseFields">Use this field to include those fields which are not included by default.</param>
        /// <param name="returnId">Unique identifier of the return whose items you want to get.</param>
        /// <param name="action">Properties of the payment action performed for an order.</param>
        /// <returns>
        ///  <see cref="Mozu.Api.MozuClient" />{<see cref="Mozu.Api.Contracts.CommerceRuntime.Returns.Return"/>}
        /// </returns>
        /// <example>
        /// <code>
        ///   var mozuClient=CreatePaymentActionForReturn( action,  returnId,  responseFields);
        ///   var returnClient = mozuClient.WithBaseAddress(url).Execute().Result();
        /// </code>
        /// </example>
        public static MozuClient <Mozu.Api.Contracts.CommerceRuntime.Returns.Return> CreatePaymentActionForReturnClient(Mozu.Api.Contracts.CommerceRuntime.Payments.PaymentAction action, string returnId, string responseFields = null)
        {
            var          url        = Mozu.Api.Urls.Commerce.ReturnUrl.CreatePaymentActionForReturnUrl(returnId, responseFields);
            const string verb       = "POST";
            var          mozuClient = new MozuClient <Mozu.Api.Contracts.CommerceRuntime.Returns.Return>()
                                      .WithVerb(verb).WithResourceUrl(url)
                                      .WithBody <Mozu.Api.Contracts.CommerceRuntime.Payments.PaymentAction>(action);

            return(mozuClient);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// <example>
        ///  <code>
        /// var result = ReturnFactory.CreatePaymentActionForReturn(handler : handler,  action :  action,  returnId :  returnId,  responseFields :  responseFields,  expectedCode: expectedCode, successCode: successCode);
        /// var optionalCasting = ConvertClass<Return/>(result);
        /// return optionalCasting;
        ///  </code>
        /// </example>
        /// </summary>
        public static Mozu.Api.Contracts.CommerceRuntime.Returns.Return CreatePaymentActionForReturn(ServiceClientMessageHandler handler,
                                                                                                     Mozu.Api.Contracts.CommerceRuntime.Payments.PaymentAction action, string returnId, string responseFields = null,
                                                                                                     HttpStatusCode expectedCode = HttpStatusCode.Created, HttpStatusCode successCode = HttpStatusCode.Created)
        {
            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.ReturnClient.CreatePaymentActionForReturnClient(
                action:  action, returnId:  returnId, responseFields:  responseFields);

            try
            {
                apiClient.WithContext(handler.ApiContext).ExecuteAsync(default(CancellationToken)).Wait();
            }
            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 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;

            }
        }
        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;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Performs the specified action for an individual order payment transaction.
        /// </summary>
        /// <param name="orderId">Unique identifier of the order.</param>
        /// <param name="paymentId">Unique identifier of the payment for which to perform the action.</param>
        /// <param name="responseFields">Use this field to include those fields which are not included by default.</param>
        /// <param name="action">Properties of the payment action performed for an order.</param>
        /// <returns>
        ///  <see cref="Mozu.Api.MozuClient" />{<see cref="Mozu.Api.Contracts.CommerceRuntime.Orders.Order"/>}
        /// </returns>
        /// <example>
        /// <code>
        ///   var mozuClient=PerformPaymentAction( action,  orderId,  paymentId,  responseFields);
        ///   var orderClient = mozuClient.WithBaseAddress(url).Execute().Result();
        /// </code>
        /// </example>
        public static MozuClient <Mozu.Api.Contracts.CommerceRuntime.Orders.Order> PerformPaymentActionClient(Mozu.Api.Contracts.CommerceRuntime.Payments.PaymentAction action, string orderId, string paymentId, string responseFields = null)
        {
            var          url        = Mozu.Api.Urls.Commerce.Orders.PaymentUrl.PerformPaymentActionUrl(orderId, paymentId, responseFields);
            const string verb       = "POST";
            var          mozuClient = new MozuClient <Mozu.Api.Contracts.CommerceRuntime.Orders.Order>()
                                      .WithVerb(verb).WithResourceUrl(url)
                                      .WithBody <Mozu.Api.Contracts.CommerceRuntime.Payments.PaymentAction>(action);

            return(mozuClient);
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <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="returnId">Unique identifier of the return whose items you want to get.</param>
        /// <param name="action">Properties of the payment action performed for an order.</param>
        /// <returns>
        /// <see cref="Mozu.Api.Contracts.CommerceRuntime.Returns.Return"/>
        /// </returns>
        /// <example>
        /// <code>
        ///   var return = new Return();
        ///   var return = await return.CreatePaymentActionForReturnAsync( action,  returnId,  responseFields);
        /// </code>
        /// </example>
        public virtual async Task <Mozu.Api.Contracts.CommerceRuntime.Returns.Return> CreatePaymentActionForReturnAsync(Mozu.Api.Contracts.CommerceRuntime.Payments.PaymentAction action, string returnId, string responseFields = null, CancellationToken ct = default(CancellationToken))
        {
            MozuClient <Mozu.Api.Contracts.CommerceRuntime.Returns.Return> response;
            var client = Mozu.Api.Clients.Commerce.ReturnClient.CreatePaymentActionForReturnClient(action, returnId, responseFields);

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

            return(await response.ResultAsync());
        }
Exemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="orderId">Unique identifier of the order.</param>
        /// <param name="paymentId">Unique identifier of the payment for which to perform the action.</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="action">Properties of the payment action performed for an order.</param>
        /// <returns>
        /// <see cref="Mozu.Api.Contracts.CommerceRuntime.Orders.Order"/>
        /// </returns>
        /// <example>
        /// <code>
        ///   var payment = new Payment();
        ///   var order = await payment.PerformPaymentActionAsync( action,  orderId,  paymentId,  responseFields);
        /// </code>
        /// </example>
        public virtual async Task <Mozu.Api.Contracts.CommerceRuntime.Orders.Order> PerformPaymentActionAsync(Mozu.Api.Contracts.CommerceRuntime.Payments.PaymentAction action, string orderId, string paymentId, string responseFields = null, CancellationToken ct = default(CancellationToken))
        {
            MozuClient <Mozu.Api.Contracts.CommerceRuntime.Orders.Order> response;
            var client = Mozu.Api.Clients.Commerce.Orders.PaymentClient.PerformPaymentActionClient(action, orderId, paymentId, responseFields);

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

            return(await response.ResultAsync());
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a new payment transaction for the specified order and performs the specified action.
        /// </summary>
        /// <param name="orderId">Unique identifier of the order.</param>
        /// <param name="responseFields">Use this field to include those fields which are not included by default.</param>
        /// <param name="action">Properties of the payment action performed for an order.</param>
        /// <returns>
        /// <see cref="Mozu.Api.Contracts.CommerceRuntime.Orders.Order"/>
        /// </returns>
        /// <example>
        /// <code>
        ///   var payment = new Payment();
        ///   var order = await payment.CreatePaymentActionAsync( action,  orderId,  responseFields);
        /// </code>
        /// </example>
        public virtual async Task <Mozu.Api.Contracts.CommerceRuntime.Orders.Order> CreatePaymentActionAsync(Mozu.Api.Contracts.CommerceRuntime.Payments.PaymentAction action, string orderId, string responseFields = null)
        {
            MozuClient <Mozu.Api.Contracts.CommerceRuntime.Orders.Order> response;
            var client = Mozu.Api.Clients.Commerce.Orders.PaymentClient.CreatePaymentActionClient(action, orderId, responseFields);

            client.WithContext(_apiContext);
            response = await client.ExecuteAsync();

            return(await response.ResultAsync());
        }
Exemplo n.º 9
0
        public virtual Mozu.Api.Contracts.CommerceRuntime.Orders.Order PerformPaymentAction(Mozu.Api.Contracts.CommerceRuntime.Payments.PaymentAction action, string orderId, string paymentId, string responseFields = null)
        {
            MozuClient <Mozu.Api.Contracts.CommerceRuntime.Orders.Order> response;
            var client = Mozu.Api.Clients.Commerce.Orders.PaymentClient.PerformPaymentActionClient(action, orderId, paymentId, responseFields);

            client.WithContext(_apiContext);
            response = client.Execute();
            return(response.Result());
        }
Exemplo n.º 10
0
        public virtual Mozu.Api.Contracts.CommerceRuntime.Returns.Return CreatePaymentActionForReturn(Mozu.Api.Contracts.CommerceRuntime.Payments.PaymentAction action, string returnId, string responseFields = null)
        {
            MozuClient <Mozu.Api.Contracts.CommerceRuntime.Returns.Return> response;
            var client = Mozu.Api.Clients.Commerce.ReturnClient.CreatePaymentActionForReturnClient(action, returnId, responseFields);

            client.WithContext(_apiContext);
            response = client.Execute();
            return(response.Result());
        }
Exemplo n.º 11
0
        /// <summary>
        /// Updates a refund payment associated with a customer return by performing the specified action.
        /// </summary>
        /// <param name="paymentId">Unique identifier of the payment for which to perform the action.</param>
        /// <param name="responseFields">Use this field to include those fields which are not included by default.</param>
        /// <param name="returnId">Unique identifier of the return whose items you want to get.</param>
        /// <param name="action">Properties of the payment action performed for an order.</param>
        /// <returns>
        /// <see cref="Mozu.Api.Contracts.CommerceRuntime.Returns.Return"/>
        /// </returns>
        /// <example>
        /// <code>
        ///   var return = new Return();
        ///   var return = await return.PerformPaymentActionForReturnAsync( action,  returnId,  paymentId,  responseFields);
        /// </code>
        /// </example>
        public virtual async Task <Mozu.Api.Contracts.CommerceRuntime.Returns.Return> PerformPaymentActionForReturnAsync(Mozu.Api.Contracts.CommerceRuntime.Payments.PaymentAction action, string returnId, string paymentId, string responseFields = null)
        {
            MozuClient <Mozu.Api.Contracts.CommerceRuntime.Returns.Return> response;
            var client = Mozu.Api.Clients.Commerce.ReturnClient.PerformPaymentActionForReturnClient(action, returnId, paymentId, responseFields);

            client.WithContext(_apiContext);
            response = await client.ExecuteAsync();

            return(await response.ResultAsync());
        }