Commerce Connect Integration Fundamentals / Commerce Connect Cart Management |
Developer tasks for using service method AddPaymentInformation.
At your visual studio solution setup:
CartServiceProvider provider = new CartServiceProvider(); // You should get a real user id. string userId = Guid.NewGuid().ToString("B"); string anonymousUserId = Guid.NewGuid().ToString("B"); var loadRequest = new LoadCartByNameRequest("Website", "MyBasket",userId); var loadResult = provider.LoadCart(loadRequest); CommerceCart cart = loadResult.Cart as CommerceCart; // Add the party (address)information. CommerceParty party = new CommerceParty() { ExternalId =Guid.NewGuid().ToString("B"), Name = "MyFirstAddress", Address1 = "Address 1 field", Address2 = "Address 2 field", City = "City field", Company = "Company field", Country = "Country field", CountryCode = "CND", Email = "a@b.com", EveningPhoneNumber = "111 111-1111", FaxNumber = "222 222-2222", FirstName = "First name field", LastName = "Last name field", PhoneNumber = "333 333-3333", RegionCode = "01", RegionName = "Region field", State = "State field", ZipPostalCode = "HOH OHO" }; AddPartiesRequest request = new AddPartiesRequest(cart, new List<Party> { party }); var result = provider.AddParties(request); party = result.Parties.ElementAt(0) as CommerceParty; // Get the payment methods CommerceOrderServiceProvider orderProvider = new CommerceOrderServiceProvider(); GetPaymentMethodsRequest paymentMethodsRequest = new GetPaymentMethodsRequest("en-US"); var paymentMethodsResult = orderProvider.GetPaymentMethods(paymentMethodsRequest); CommercePaymentMethod paymentMethod = paymentMethodsResult.PaymentMethods.ElementAt(0) as CommercePaymentMethod; CommerceCreditCardPaymentInfo payment = new CommerceCreditCardPaymentInfo(); payment.CreditCardNumber = "1111111111111111"; payment.Amount = 72.70M; payment.CreditCardIdentifier = "111"; payment.CustomerNameOnPayment = "John Smith"; payment.PartyID = party.ExternalId; payment.PaymentMethodID = paymentMethod.ExternalId; payment.ExpirationMonth =10; payment.ExpirationYear = 2020; var paymentRequest = new AddPaymentInfoRequest(cart, new List<PaymentInfo> { payment }); provider.AddPaymentInfo(paymentRequest);