Remove Payment Information

Developer tasks for using service method RemovePaymentInformation.

RemovePaymentInformation is used to remove payment information from 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.
    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 });             
    var paymentResult = provider.AddPaymentInfo(paymentRequest);             
    cart = paymentResult.Cart as CommerceCart;             
    CommerceCreditCardPaymentInfo currentPayment = cart.Payment.ElementAt(0) as CommerceCreditCardPaymentInfo;             
    var removePaymentRequest = new RemovePaymentInfoRequest(cart, new List<PaymentInfo>() { currentPayment});           
    provider.RemovePaymentInfo(removePaymentRequest);