Add Payment Information

Current version: 8.2

Developer tasks for using service method AddPaymentInformation.

AddPaymentInformation is used to add payment information to an existing cart.

At your Visual Studio solution setup:

  1. Reference the Sitecore.Commerce.Connect.CommerceServer and Sitecore.Commerce.dll.

  2. Pick the class in your solution where want to use this service method.

  3. Paste in the code below to use the service method.

    RequestResponse
    
    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 = "[email protected]",                
    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);
    

Do you have some feedback for us?

If you have suggestions for improving this article,