Documentation

Ucommerce includes full API reference documentation and lots of helpful articles to help you build your e-commerce site as effortlessly as possible.

Topics Payment Providers
v7.18

Checkout Step by Step

Add to basket

    
    
    // First load the current catalog (URLs will contain this information)
    int catalogId = 0;
    string catalogName = "";
    ProductCatalog catalog;
    if (int.TryParse(SiteContext.Current.CatalogContext.GetCurrentCatalogName, out catalogId)
    {
        catalog = ProductCatalog.Get(catalogId);
    }
    else
    {
        catalog = ProductCatalog.SingleOrDefault(x => x.Name == catalogName);
    }
    
    // Then load the product to add
    Product product = Product.All().Single(x => x.Sku == "mySku" && x.VariantSku == "myVariantSku");
    
    PurchaseOrder order = SiteContext.Current.OrderContext.GetBasket();
    
    order.AddProduct(catalog, product);
    
    // Exec basket pipeline to update totals
    Library.ExecuteBasketPipeline();
    
    

Update address info

    
    
    /* BILLING */
    var billingAddress = order.BillingAddress ?? new OrderAddress();
    address.AddressName = "Billing";
    address.FirstName = "firstName";
    address.LastName = "lastName";
    address.EmailAddress = "emailAddress";
    address.PhoneNumber = "phoneNumber";
    address.MobilePhoneNumber = "mobilePhoneNumber";
    address.CompanyName = "company";
    address.Line1 = "line1";
    address.Line2 = "line2";
    address.PostalCode = "postCode";
    address.City = "city";
    address.State = "state";
    address.Attention = "attention";
    address.Country = Country.Get(countryId);
    address.PurchaseOrder = order;
    
    order.BillingAddress = billingAddress;
    
    order.Save(); // Saves cascade to children, so the address is saved as well
    
    

Create shipment

    
    
    /* SHIPPING */
    // First we'll need a shipping method using the name as defined in the backend, e.g. Ground or Air
    var shippingMethod = ShippingMethod.SingleOrDefault(x => x.Name = "Ground");
    var shipment = order.CreateShipment(shippingMethod, billingAddress);
    
    // Add all order lines to shipment using a handy extension mehod in UCommerce.Extensions called ForEach
    order.OrderLines.ForEach(x => shipment.AddOrderLine(x));
    
    // Execute basket pipeline to make sure totals are up to date
    // Also save order and new shipment
    PipelineFactory.Create<PurhcaseOrder>("basket").Execute(order);
    
    

Payment

    
    
    /* PAYMENT */
    // As with shipping grab the payment method to use by name as defined in the backend
    var paymentMethod = PaymentMethod.SingleOrDefault(x => x.Name == "Account");
    
    // Use the library to create the payment and request it from the gateway
    Library.CreatePayment(paymentMethod.Id);
    
    // Alternatively you can use to defer the request if you
    // need to display an confirm page before handing it over
    // to the gateway. The false value indicates that the request
    // should be deferred.
    // You can then use Library.RequestPayments()
    // to trigger the gateway
    Library.CreatePayment(paymentMethod.Id, -1, false, true);