Catalyst::Model::CPI - Business::CPI models for Catalyst
version 0.03
In the config:
<model Payments> <gateway PayPal> api_username ... api_password ... signature ... receiver_email seller@test.com sandbox 1 </gateway> <gateway X> ... </gateway> <gateway Y> ... </gateway> </model>
In the controller:
# It should be configured in PayPal's IPN, for example, the notify_url as: # http://myserver/api/store/notification/PayPal # Other gateways are similar. sub gtw_notification : Chained('/api/store') PathPart('notification') Args(1) { my ($self, $ctx, $gateway_name) = @_; my $model = $ctx->model('Payments'); if ( !$model->exists($gateway_name) ) { my $gtw_list = join ", ", $model->available_gateways; die "$gateway_name is not available.\n" . "Available gateways are: $gtw_list."; } my $notification = $model->get($gateway_name)->notify; my $purchase = $ctx->model('DB::Purchase')->find( $notification->{payment_id} ); $purchase->update({ payment_status => $notification->{status} }); ... } sub checkout : Chained('/website/cart') PathPart Args(0) { my ($self, $ctx) = @_; my $model = $ctx->model('Payments'); my $cart = $ctx->session->{cart}; # create a form for each available gateway my @forms = map { $model->get($_)->new_cart($cart)->get_form_to_pay("${_}_form") } $model->available_gateways; $ctx->stash->{checkout_forms} = \@forms; }
This module connects CPI gateways to a Catalyst application. It automatically loads the configuration from Catalyst and uses it to instantiate the gateways when requested through this model.
List all the class names for the installed CPI gateways.
my @gateways = $ctx->model('Payments')->available_gateways;
Returns a new instance of the gateway, with all the configuration passed as arguments to the constructor.
my $cart = $ctx->model('Payments')->get('PayPal')->new_cart(...);
Check whether the provided gateway is really installed.
if ($model->exists($gateway)) { ... }
Saves the request, so that $gateway->notify can receive it automatically. See the Catalyst docs for details.
$gateway->notify
<model Payments> <gateway PayPal> api_username ... api_password ... signature ... receiver_email seller@test.com sandbox 1 </gateway> <gateway PagSeguro> receiver_email seller@test.com ... </gateway> <gateway Custom> foo bar </gateway> </model>
André Walker <andre@andrewalker.net>
This software is copyright (c) 2013 by André Walker.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Catalyst::Model::CPI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::Model::CPI
CPAN shell
perl -MCPAN -e shell install Catalyst::Model::CPI
For more information on module installation, please visit the detailed CPAN module installation guide.