CartRequest

public class CartRequest: MoltinRequest

An entry point to make API calls relating to Cart

  • The API endpoint for this resource.

    Declaration

    Swift

    public var endpoint: String = "/carts"
  • A typealias which allows automatic casting of a collection to [CartItem].

    Declaration

    Swift

    public typealias DefaultCollectionRequestHandler = CollectionRequestHandler<[CartItem]>
  • Return instance of type Cart by id

    Author

    Craig Tweedy

    • forID: The ID of the object
    • completionHandler: The handler to be called on success or failure

    Declaration

    Swift

    public func get(forID id: String,
                    completionHandler: @escaping ObjectRequestHandler<Cart>) -> MoltinRequest

    Parameters

    forID

    The ID of the object

    completionHandler

    The handler to be called on success or failure

    Return Value

    A instance of MoltinRequest which encapsulates the request.

  • Returns an array of CartItem for a requested Cart

    Author

    Craig Tweedy

    Declaration

    Swift

    public func items(forCartID id: String,
                      completionHandler: @escaping DefaultCollectionRequestHandler) -> MoltinRequest

    Parameters

    forCartID

    The ID of the object

    completionHandler

    The handler to be called on success or failure

    Return Value

    A instance of MoltinRequest which encapsulates the request.

  • Adds an amount of products with productID to a specified Cart with toCart

    Author

    Craig Tweedy

    Declaration

    Swift

    public func addProduct(withID productID: String,
                           ofQuantity quantity: Int,
                           toCart cart: String,
                           completionHandler: @escaping ObjectRequestHandler<Cart>) -> MoltinRequest

    Parameters

    withID

    The ID of the product

    ofQuantity

    The amount of this product to add to the cart

    toCart

    The cart ID to add this product to

    completionHandler

    The handler to be called on success or failure

    Return Value

    A instance of MoltinRequest which encapsulates the request.

  • Adds a custom cart item to a cart

    Author

    Craig Tweedy

    Declaration

    Swift

    public func addCustomItem(_ customItem: CustomCartItem,
                              toCart cart: String,
                              completionHandler: @escaping ObjectRequestHandler<Cart>) -> MoltinRequest

    Parameters

    customItem

    The custom cart item to add to this cart

    toCart

    The cart ID to add this item to

    completionHandler

    The handler to be called on success or failure

    Return Value

    A instance of MoltinRequest which encapsulates the request.

  • Adds a promotion to a cart

    Author

    Craig Tweedy

    Declaration

    Swift

    public func addPromotion(_ promotion: String,
                             toCart cart: String,
                             completionHandler: @escaping ObjectRequestHandler<Cart>) -> MoltinRequest

    Parameters

    promotion

    The promotion code

    toCart

    The cart ID to add this promo to

    completionHandler

    The handler to be called on success or failure

    Return Value

    A instance of MoltinRequest which encapsulates the request.

  • Removes an item from the cart

    Author

    Craig Tweedy

    Declaration

    Swift

    public func removeItem(_ itemID: String,
                           fromCart cart: String,
                           completionHandler: @escaping ObjectRequestHandler<Cart>) -> MoltinRequest

    Parameters

    itemID

    The cart item ID to remove

    fromCart

    The cart ID to remove this item from

    completionHandler

    The handler to be called on success or failure

    Return Value

    A instance of MoltinRequest which encapsulates the request.

  • Updates an item in the cart

    Author

    Craig Tweedy

    Declaration

    Swift

    public func updateItem(_ itemID: String,
                           withQuantity quantity: Int,
                           inCart cart: String,
                           completionHandler: @escaping ObjectRequestHandler<Cart>) -> MoltinRequest

    Parameters

    itemID

    The item ID to update

    withQuantity

    The amount of this item ID to update too.

    inCart

    The cart ID to update this item in

    completionHandler

    The handler to be called on success or failure

    Return Value

    A instance of MoltinRequest which encapsulates the request.

  • Begins the checkout process for this cart

    Author

    Craig Tweedy

    Declaration

    Swift

    public func checkout(cart: String,
                         withCustomer customer: Customer,
                         withBillingAddress billingAddress: Address,
                         withShippingAddress shippingAddress: Address?,
                         completionHandler: @escaping ObjectRequestHandler<Order>) -> MoltinRequest

    Return Value

    A instance of MoltinRequest which encapsulates the request.

  • Pay for an order

    Author

    Craig Tweedy

  • forOrderID: The order to pay for

  • withPaymentMethod: The payment method to pay with

  • completionHandler: The handler to be called on success or failure

  • Declaration

    Swift

    public func pay(forOrderID order: String,
                    withPaymentMethod paymentMethod: PaymentMethod,
                    completionHandler: @escaping ObjectRequestHandler<Order>) -> MoltinRequest

    Return Value

    A instance of MoltinRequest which encapsulates the request.

  • Delete a cart

    Author

    Craig Tweedy

    Declaration

    Swift

    public func deleteCart(_ cart: String,
                           completionHandler: @escaping ObjectRequestHandler<Cart>) -> MoltinRequest

    Parameters

    cart

    The cart ID to delete

    completionHandler

    The handler to be called on success or failure

    Return Value

    A instance of MoltinRequest which encapsulates the request.