NAME

Handel::Checkout - Checkout Pipeline Process

SYNOPSIS

use Handel::Checkout;

my $checkout = Handel::Checkout->new({
    cart    => '122345678-9098-7654-3212-345678909876',
    phases  => [CHECKOUT_PHASE_INITIALIZE, CHECKOUT_PHASE_VALIDATE]
});

if ($checkout->process == CHECKOUT_STATUS_OK) {
    print 'Your order number is ', $checkout->order->number;
} else {
    ...
};

DESCRIPTION

Handel::Checkout is a basic pipeline processor that uses plugins at various phases to perform any work necessary from credit card authorization to order delivery. Handel does not try to be all things to all people needing to place online orders. Instead, it provides a basic plugin mechanism allowing the checkout process to be customized for many different needs.

CONSTRUCTOR

new([\%options])

Creates a new checkout pipeline process and loads all available plugins. new accepts the following options in an optional HASH reference:

cart

A HASH reference, Handel::Cart object, or a cart id. This will be loaded into a new Handel::Order object and associated with the new checkout process.

See cart below for further details about the various values allowed to be passed.

order

A HASH reference, Handel::Order object, or an order id. This will be loaded and associated with the new checkout process.

See order below for further details about the various values allowed to be passed.

plugins

An array reference containing the various namespaces of plugins to be loaded.

my $checkout = Handel::Checkout->new({
    plugins => [MyNamespace::Plugins, Other::Plugin]
});
phases

An array reference containing the various phases to be executed.

my $checkout = Handel::Checkout->new({
    phases => [CHECKOUT_PHASE_VALIDATION,
               CHECKOUT_PHASE_AUTHORIZATION]
});

METHODS

add_handler($phase, \&coderef)

Registers a code reference with the checkout phase specified. This is usually called within register on the current checkout context:

sub register {
    my ($self, $ctx) = @_;

    $ctx->add_handler(CHECKOUT_PHASE_DELIVER, \&myhandler);
};

sub myhandler {
    ...
};

cart

Creates a new Handel::Order object from the specified cart and associates that order with the current checkout process. This is typeically only needed the first time you want to run checkout for a specific cart. From then on, you only need to load the already created order using order below.

cart can accept one of three possible parameter values:

cart(\%filter)

When you pass a HASH reference, cart will attempt to load all available carts using Handel::Cart::load(\%filter). If multiple carts are found, only the first one will be used.

$checkout->cart({
    shopper => '12345678-9098-7654-3212-345678909876',
    type => CART_TYPE_TEMP
});
cart(Handel::Cart)

You can also pass in an already existing Handel::Cart object. It will then be loaded into a new order object ans associated with the current checkout process.

my $cart = Handel::Cart->load({
    id => '12345678-9098-7654-3212-345678909876'
});

$checkout->cart($cart);
cart($cartid)

Finally, you can pass a valid cart/uuid into cart. The matching cart will be loaded into a new Handel::Order object and associated with the current checkout process.

$checkout->cart('12345678-9098-7654-3212-345678909876');

order

Gets/Sets an existing Handel::Order object with the existing checkout process.

order can accept one of three possible parameter values:

order(\%filter)

When you pass a HASH reference, order will attempt to load all available order using Handel::Order::load(\%filter). If multiple order are found, only the first one will be used.

$checkout->order({
    shopper => '12345678-9098-7654-3212-345678909876',
    id => '11111111-2222-3333-4444-5555666677778888'
});
order(Handel::Order)

You can also pass in an already existing Handel::Order object. It will then be associated with the current checkout process.

my $order = Handel::Order->load({
    id => '12345678-9098-7654-3212-345678909876'
});

$checkout->order($order);
order($orderid)

Finally, you can pass a valid order/uuid into order. The matching order will be loaded and associated with the current checkout process.

$checkout->order('12345678-9098-7654-3212-345678909876');

phases(\@phases)

Get/Set the phases active for the current checkout process.

$checkout->phases([
    CHECKOUT_PHASE_INITIALIZE,
    CHECKOUT_PHASE_VALIDATION
]);

process([\@phases])

Executes the current checkout process pipeline and returns CHECKOUT_STATUS_*.

SEE ALSO

Handel::Constants, Handel::Checkout::Plugin, Handel::Order

AUTHOR

Christopher H. Laco
CPAN ID: CLACO
claco@chrislaco.com
http://today.icantfocus.com/blog/