• Articles
  • Api Documentation

    Show / Hide Table of Contents
    • Yort.Laybuy.InStore
      • CancelOrderRequest
      • CancelOrderResponse
      • CreateOrderRequest
      • CreateOrderResponse
      • ILaybuyClient
      • LaybuyApiException
      • LaybuyApiResponseBase
      • LaybuyClient
      • LaybuyClientConfiguration
      • LaybuyCredentials
      • LaybuyCustomerAddress
      • LaybuyCustomerBase
      • LaybuyEnvironment
      • LaybuyItem
      • LaybuyOrderRefund
      • LaybuyOrderStatus
      • LaybuyRequestBase
      • LaybuyStatus
      • OrderRequest
      • OrderResponse
      • OrderStatusRequest
      • OrderStatusResponse
      • RefundRequest
      • RefundResponse
      • RequestLaybuyCustomer
      • ResponseLaybuyCustomer
      • StandardOriginData

    Class LaybuyClient

    Provides access to the REST endpoints exposed by Laybuy API using an idiomatic .Net, object-oriented model.

    Inheritance
    Object
    LaybuyClient
    Implements
    ILaybuyClient
    IDisposable
    Inherited Members
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Object.ReferenceEquals(Object, Object)
    Object.ToString()
    Namespace: Yort.Laybuy.InStore
    Assembly: Yort.Laybuy.InStore.dll
    Syntax
    public sealed class LaybuyClient : ILaybuyClient, IDisposable
    Remarks

    Instances of this class are thread-safe if that you can send requests through the same instance from multiple threads for different orders (MerchantReferences). Sending different requests for the same merchant reference simulatenously should be thread-safe in terms of this library code, but will be prone to potential race conditons on the API back end. Sending a cancel request for a client reference that is still being polled for on another thread is allowed, as the polling mechansim should repeat until the Laybuy API returns a cancelled status and no race condition should be present.

    Instances of this class should be kept and reused as this allows HTTP connection pooling and improves performance. Instances should only be disposed when you no longer intend to use the instance again, such as on process shutdown or if changing the configuration of the client.

    LaybuyClientConfiguration instances should not be modified after being passed into the construtor of an instance of this class.

    Constructors

    | Improve this Doc View Source

    LaybuyClient(LaybuyClientConfiguration)

    Full constructor.

    Declaration
    public LaybuyClient(LaybuyClientConfiguration settings)
    Parameters
    Type Name Description
    LaybuyClientConfiguration settings

    A LaybuyClientConfiguration instance containing configuration details.

    Methods

    | Improve this Doc View Source

    Cancel(CancelOrderRequest)

    Cancels a Laybuy previously created via the Create(CreateOrderRequest) method.

    Declaration
    public Task<CancelOrderResponse> Cancel(CancelOrderRequest request)
    Parameters
    Type Name Description
    CancelOrderRequest request

    A CancelOrderRequest instance containing details of the Laybuy to cancel.

    Returns
    Type Description
    Task<CancelOrderResponse>

    A CancelOrderResponse indicating success if the Laybuy was cancelled ok, otherwise error details.

    Remarks

    An error will be returned if the Laybuy is already confirmed.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown if Token is null.

    ArgumentException

    Thrown if Token is an empty string or only whitespace.

    TaskCanceledException

    May be thrown in the event of a timeout calling the Laybuy API.

    TimeoutException

    May be thrown in the event of a timeout calling the Laybuy API.

    HttpRequestException

    Thrown if the call to the Laybuy API returns an error response code. The Laybuy API does not use HTTP response codes for 'business level errors', such as 'order not found' or 'declined', so this type of exception typically represents a problem such as bad credentials, a bad gateway/DNS, server unavailable etc.

    See Also
    Create(CreateOrderRequest)
    | Improve this Doc View Source

    Create(CreateOrderRequest)

    Creates a new order at Laybuy.

    Declaration
    public Task<CreateOrderResponse> Create(CreateOrderRequest request)
    Parameters
    Type Name Description
    CreateOrderRequest request

    A CreateOrderRequest with details of the order to create.

    Returns
    Type Description
    Task<CreateOrderResponse>

    A CreateOrderResponse indicating the outcome of the request.

    Remarks

    If DefaultBranch is non empty in the settings object used to construct this client then a new StandardOriginData instance is automatically created with appropriate values and applied to the request. If no default value can be applied then ArgumentNullException is thrown.

    See the Laybuy documenation at: https://integrations.laybuy.com/reference#post_order-create-1

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown if request, Origin, OriginData, Customer or MerchantReference is null.

    ArgumentException

    Thrown if request, Origin, OriginData, MerchantReference or Phone is an empty string or only whitespace..

    ArgumentOutOfRangeException

    Thrown if Amount is zero or negative.

    TaskCanceledException

    May be thrown in the event of a timeout calling the Laybuy API.

    TimeoutException

    May be thrown in the event of a timeout calling the Laybuy API.

    HttpRequestException

    Thrown if the call to the Laybuy API returns an error response code. The Laybuy API does not use HTTP response codes for 'business level errors', such as 'order not found' or 'declined', so this type of exception typically represents a problem such as bad credentials, a bad gateway/DNS, server unavailable etc.

    | Improve this Doc View Source

    Dispose()

    Disposes this instance and all internal resources.

    Declaration
    public void Dispose()
    | Improve this Doc View Source

    GetOrder(OrderRequest)

    Gets the details of a (completed) Laybuy order previously created via Create(CreateOrderRequest).

    Declaration
    public Task<OrderResponse> GetOrder(OrderRequest request)
    Parameters
    Type Name Description
    OrderRequest request

    A OrderRequest with details of the Laybuy order to retrieve the status of.

    Returns
    Type Description
    Task<OrderResponse>

    A OrderResponse indicating the outcome of the request.

    Exceptions
    Type Condition
    ArgumentException

    Thrown if MerchantReference and OrderId are both null, empty or whitespace. Also thrown if OrderId is zero or negative.

    TaskCanceledException

    May be thrown in the event of a timeout calling the Laybuy API.

    TimeoutException

    May be thrown in the event of a timeout calling the Laybuy API.

    HttpRequestException

    Thrown if the call to the Laybuy API returns an error response code. The Laybuy API does not use HTTP response codes for 'business level errors', such as 'order not found' or 'declined', so this type of exception typically represents a problem such as bad credentials, a bad gateway/DNS, server unavailable etc.

    | Improve this Doc View Source

    GetOrderStatus(OrderStatusRequest)

    Gets the current status of a Laybuy order previously created via Create(CreateOrderRequest).

    Declaration
    public Task<OrderStatusResponse> GetOrderStatus(OrderStatusRequest request)
    Parameters
    Type Name Description
    OrderStatusRequest request

    A OrderStatusRequest with details of the Laybuy order to retrieve the status of.

    Returns
    Type Description
    Task<OrderStatusResponse>

    A OrderStatusResponse indicating the outcome of the request.

    Exceptions
    Type Condition
    ArgumentException

    Thrown if MerchantReference is null, empty or whitespace.

    TaskCanceledException

    May be thrown in the event of a timeout calling the Laybuy API.

    TimeoutException

    May be thrown in the event of a timeout calling the Laybuy API.

    HttpRequestException

    Thrown if the call to the Laybuy API returns an error response code. The Laybuy API does not use HTTP response codes for 'business level errors', such as 'order not found' or 'declined', so this type of exception typically represents a problem such as bad credentials, a bad gateway/DNS, server unavailable etc.

    | Improve this Doc View Source

    Refund(RefundRequest)

    Refunds an amount of money against a Laybuy previously created via Create(CreateOrderRequest).

    Declaration
    public Task<RefundResponse> Refund(RefundRequest request)
    Parameters
    Type Name Description
    RefundRequest request

    A RefundRequest with details of the refund to make.

    Returns
    Type Description
    Task<RefundResponse>

    A RefundResponse indicating the outcome of the request.

    Remarks

    If you need to retry a refund due to a transient error or interruption (power failure/crash) ensure the same *RefundReference* is used on each retry attempt. This should ensure idempotency and prevent multiple refunds being issued by mistake.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown if RefundMerchantReference is null.

    ArgumentException

    Thrown if OrderId or Amount are zero or negative. Also thrown if RefundMerchantReference is empty or whitespace.

    TaskCanceledException

    May be thrown in the event of a timeout calling the Laybuy API.

    TimeoutException

    May be thrown in the event of a timeout calling the Laybuy API.

    HttpRequestException

    Thrown if the call to the Laybuy API returns an error response code. The Laybuy API does not use HTTP response codes for 'business level errors', such as 'order not found' or 'declined', so this type of exception typically represents a problem such as bad credentials, a bad gateway/DNS, server unavailable etc.

    Implements

    ILaybuyClient
    System.IDisposable
    • Improve this Doc
    • View Source
    Back to top Copyright (c) 2020 Troy Willmot