public void Exercise_13_1_Get_Customers() { //Create a Customer Account resource var customerAccountResource = new Mozu.Api.Resources.Commerce.Customer.CustomerAccountResource(_apiContext); //Retrieve an Account by id var account = customerAccountResource.GetAccountAsync(1001).Result; //Write the Account email System.Diagnostics.Debug.WriteLine("Account Email[{0}]: {1}", account.Id, account.EmailAddress); //You can also filter the Accounts Get call by email var accountByEmail = customerAccountResource.GetAccountsAsync(filter: "EmailAddress eq '*****@*****.**'").Result; //write account email System.Diagnostics.Debug.WriteLine("Account Email[{0}]: {1}", account.EmailAddress, account.Id); //Now, create a Customer Contact resource var customerContactResource = new Mozu.Api.Resources.Commerce.Customer.Accounts.CustomerContactResource(_apiContext); var customerContactCollection = new Mozu.Api.Contracts.Customer.CustomerContactCollection(); if (accountByEmail.TotalCount > 0) { customerContactCollection = customerContactResource.GetAccountContactsAsync(accountByEmail.Items[0].Id).Result; } else { System.Diagnostics.Debug.WriteLine("No contact information -- Customer does not exist"); } if (customerContactCollection.TotalCount > 0) { foreach (var contact in customerContactCollection.Items) { System.Diagnostics.Debug.WriteLine("Name:"); System.Diagnostics.Debug.WriteLine(contact.FirstName); System.Diagnostics.Debug.WriteLine(contact.MiddleNameOrInitial); System.Diagnostics.Debug.WriteLine(contact.LastNameOrSurname); System.Diagnostics.Debug.WriteLine("Address:"); System.Diagnostics.Debug.WriteLine(contact.Address.Address1); System.Diagnostics.Debug.WriteLine(contact.Address.Address2); System.Diagnostics.Debug.WriteLine(contact.Address.Address3); System.Diagnostics.Debug.WriteLine(contact.Address.Address4); System.Diagnostics.Debug.WriteLine(contact.Address.CityOrTown); System.Diagnostics.Debug.WriteLine(contact.Address.StateOrProvince); System.Diagnostics.Debug.WriteLine(contact.Address.PostalOrZipCode); System.Diagnostics.Debug.WriteLine(contact.Address.CountryCode); System.Diagnostics.Debug.WriteLine(String.Format("Is a validated address? {0}", contact.Address.IsValidated)); } } //Create a Customer Credit resource var creditResource = new Mozu.Api.Resources.Commerce.Customer.CreditResource(_apiContext); //Get credits by customer account id var customerCredits = creditResource.GetCreditsAsync(filter: "CustomerId eq '1001'").Result; foreach (var customerCredit in customerCredits.Items) { System.Diagnostics.Debug.WriteLine(string.Format("Customer Credit[{0}]: Code({1})Balance ({2})", customerCredit.CustomerId, customerCredit.Code, customerCredit.CurrentBalance)); } }
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; } }
public void Exercise_13_1_Get_Customers() { //Create a Customer Account resource var customerAccountResource = new Mozu.Api.Resources.Commerce.Customer.CustomerAccountResource(_apiContext); //Retrieve an Account by id var account = customerAccountResource.GetAccountAsync(1001).Result; //Write the Account email System.Diagnostics.Debug.WriteLine("Account Email[{0}]: {1}", account.Id, account.EmailAddress); //You can also filter the Accounts Get call by email var accountByEmail = customerAccountResource.GetAccountsAsync(filter: "EmailAddress eq '*****@*****.**'").Result; //write account email System.Diagnostics.Debug.WriteLine("Account Email[{0}]: {1}", account.EmailAddress, account.Id); //Now, create a Customer Contact resource var customerContactResource = new Mozu.Api.Resources.Commerce.Customer.Accounts.CustomerContactResource(_apiContext); var customerContactCollection = new Mozu.Api.Contracts.Customer.CustomerContactCollection(); if (accountByEmail.TotalCount > 0) { customerContactCollection = customerContactResource.GetAccountContactsAsync(accountByEmail.Items[0].Id).Result; } else { System.Diagnostics.Debug.WriteLine("No contact information -- Customer does not exist"); } if (customerContactCollection.TotalCount > 0) { foreach (var contact in customerContactCollection.Items) { System.Diagnostics.Debug.WriteLine("Name:"); System.Diagnostics.Debug.WriteLine(contact.FirstName); System.Diagnostics.Debug.WriteLine(contact.MiddleNameOrInitial); System.Diagnostics.Debug.WriteLine(contact.LastNameOrSurname); System.Diagnostics.Debug.WriteLine("Address:"); System.Diagnostics.Debug.WriteLine(contact.Address.Address1); System.Diagnostics.Debug.WriteLine(contact.Address.Address2); System.Diagnostics.Debug.WriteLine(contact.Address.Address3); System.Diagnostics.Debug.WriteLine(contact.Address.Address4); System.Diagnostics.Debug.WriteLine(contact.Address.CityOrTown); System.Diagnostics.Debug.WriteLine(contact.Address.StateOrProvince); System.Diagnostics.Debug.WriteLine(contact.Address.PostalOrZipCode); System.Diagnostics.Debug.WriteLine(contact.Address.CountryCode); System.Diagnostics.Debug.WriteLine(String.Format("Is a validated address? {0}", contact.Address.IsValidated)); } } //Create a Customer Credit resource var creditResource = new Mozu.Api.Resources.Commerce.Customer.CreditResource(_apiContext); //Get credits by customer account id var customerCredits = creditResource.GetCreditsAsync(filter: "CustomerId eq '1001'").Result; foreach (var customerCredit in customerCredits.Items) { System.Diagnostics.Debug.WriteLine(string.Format("Customer Credit[{0}]: Code({1})Balance ({2})", customerCredit.CustomerId, customerCredit.Code, customerCredit.CurrentBalance)); } }