Stripe Basket Controller

The StripeBasketController is a preconfigured Umbraco Surface Controller which interacts with the BasketService.

It can be found within the namespace UmbCheckout.Stripe.Controllers.Surface

It has a number of methods available as a starting point to allow UmbCheckout to be consumed without the need to write C# code.

Add

Adds an item to the Basket, the example below would typically be used on the Product page

Example add form
@using (Html.BeginUmbracoForm<StripeBasketController>(nameof(StripeBasketController.Add), FormMethod.Post))
{
    <label for="quantity">Quantity:</label>
    <input type="number" name="quantity" value="1" min="1" /> <br />
    <input type="hidden" name="key" value="@Model.Key" />
    <input type="hidden" name="currencyCode" value="GBP" />
    <button type="submit">Buy</button>
}

This method sets the following TempData

KeyValue

UmbCheckout_Added_To_Basket

Key of the LineItem added to the Basket

Increase

Increases the specified item quantity, the example below would typically be used on the Basket page

@using (Html.BeginUmbracoForm<StripeBasketController>(nameof(StripeBasketController.Add), FormMethod.Post))
{
    <input type="hidden" name="key" value="@lineItem.Key" />
    <button type="submit">+</button>
}

This method sets the following TempData

KeyValue

UmbCheckout_Added_To_Basket

Key of the LineItem increased in the Basket

Reduce

Reduces the specified item quantity, the example below would typically be used on the Basket page

Example reduce item
@using (Html.BeginUmbracoForm<StripeBasketController>(nameof(StripeBasketController.Reduce), FormMethod.Post))
{
    <input type="hidden" name="key" value="@lineItem.Key" />
    <button type="submit">-</button>
}

This method sets the following TempData

KeyValue

UmbCheckout_Basket_Reduced

Key of the LineItem reduced in the Basket

Remove

Removes the specified item, the example below would typically be used on the Basket page

Example remove item
@using (Html.BeginUmbracoForm<StripeBasketController>(nameof(StripeBasketController.Remove), FormMethod.Post))
{
    <input type="hidden" name="key" value="@lineItem.Id" />
    <button type="submit">Remove</button>
}

This method sets the following TempData

KeyValue

UmbCheckout_Basket_Removed

Key of the LineItem removed from the Basket

Checkout

Starts the Stripe Checkout process, the example below would typically be used on the Basket page

@using (Html.BeginUmbracoForm<StripeBasketController>(nameof(StripeBasketController.Checkout), FormMethod.Post))
{
    <button type="submit">Checkout</button>
}

This method sets the following TempData

KeyValue

UmbCheckout_EmptyBasket

Returns true if there are 0 LineItems in the Basket

Change return page

If you would like to change the page which the user is redirected to after carrying out one of the above actions you simply need to pass in the page Guid

<input type="hidden" name="redirectGuid" value="4a1f4198-e143-48ba-a0f5-1a7ef2df23aa" />

The example below shows how to do this with the Add method

@using (Html.BeginUmbracoForm<StripeBasketController>(nameof(StripeBasketController.Add), FormMethod.Post))
{
    <label for="quantity">Quantity:</label>
    <input type="number" name="quantity" value="1" min="1" /> <br />
    <input type="hidden" name="key" value="@Model.Key" />
    <input type="hidden" name="currencyCode" value="GBP" />
    <input type="hidden" name="redirectGuid" value="4a1f4198-e143-48ba-a0f5-1a7ef2df23aa" />
    <button type="submit">Buy</button>
}

Last updated