| 1 | package Business::CPI::Gateway::Base; | ||||||||||||
| 2 | # ABSTRACT: Father of all gateways | ||||||||||||
| 3 | 6 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 6 | ▶ | use Locale::Currency (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 6 | ▶ | use Data::Dumper; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 6 | ▶ | use Carp qw/croak/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 6 | ▶ | use Business::CPI::Util::Types qw/UserAgent HTTPResponse/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 6 | ▶ | use Types::Standard qw/Maybe/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 6 | ▶ | use LWP::UserAgent; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 6 | with 'Business::CPI::Role::Gateway::Base'; | |||||||||||
| 12 | |||||||||||||
| 13 | 6 | our $VERSION = '0.924'; # VERSION | |||||||||||
| 14 | |||||||||||||
| 15 | 6 | has receiver_id => ( | |||||||||||
| 16 | is => 'ro', | ||||||||||||
| 17 | ); | ||||||||||||
| 18 | |||||||||||||
| 19 | 6 | has checkout_url => ( | |||||||||||
| 20 | is => 'rw', | ||||||||||||
| 21 | ); | ||||||||||||
| 22 | |||||||||||||
| 23 | has checkout_with_token => ( | ||||||||||||
| 24 | is => 'ro', | ||||||||||||
| 25 | 8 | ▶ | default => sub { 0 }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 26 | 6 | ); | |||||||||||
| 27 | |||||||||||||
| 28 | has currency => ( | ||||||||||||
| 29 | 4 | ▶ | isa => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||
| 30 | 4 | my $curr = uc($_[0]); | |||||||||||
| 31 | |||||||||||||
| 32 | 4 | for (Locale::Currency::all_currency_codes()) { | |||||||||||
| 33 | 76 | ▶ | return 1 if $curr eq uc($_); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 34 | } | ||||||||||||
| 35 | |||||||||||||
| 36 | 0 | die "Must be a valid currency code"; | |||||||||||
| 37 | }, | ||||||||||||
| 38 | 4 | ▶ | coerce => sub { uc $_[0] }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 39 | 6 | is => 'ro', | |||||||||||
| 40 | ); | ||||||||||||
| 41 | |||||||||||||
| 42 | 6 | has user_agent => ( | |||||||||||
| 43 | is => 'rwp', | ||||||||||||
| 44 | isa => UserAgent, | ||||||||||||
| 45 | lazy => 1, | ||||||||||||
| 46 | builder => '_build_user_agent', | ||||||||||||
| 47 | ); | ||||||||||||
| 48 | |||||||||||||
| 49 | 6 | has most_recent_request => ( | |||||||||||
| 50 | is => 'rwp', | ||||||||||||
| 51 | isa => Maybe[HTTPResponse], | ||||||||||||
| 52 | ); | ||||||||||||
| 53 | |||||||||||||
| 54 | 6 | has error => ( is => 'rwp' ); | |||||||||||
| 55 | |||||||||||||
| 56 | 1 | ▶ | sub new_account { | ||||||||||
|
Subroutine
new_account: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 57 | 1 | my ($self, $account) = @_; | |||||||||||
| 58 | |||||||||||||
| 59 | 1 | return $self->account_class->new( | |||||||||||
| 60 | _gateway => $self, | ||||||||||||
| 61 | %$account | ||||||||||||
| 62 | ); | ||||||||||||
| 63 | } | ||||||||||||
| 64 | |||||||||||||
| 65 | 6 | ▶ | sub new_cart { | ||||||||||
|
Subroutine
new_cart: called CC=7 SCAR=19.7
Pod
documented
| |||||||||||||
| 66 | 6 | my ( $self, $info ) = @_; | |||||||||||
| 67 | |||||||||||||
| 68 | 6 | ▶ | if ($self->log->is_debug) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 69 | 0 | $self->log->debug("Building a cart with: " . Dumper($info)); | |||||||||||
| 70 | } | ||||||||||||
| 71 | |||||||||||||
| 72 | 6 | ▶ | my @items = @{ delete $info->{items} || [] }; | ||||||||||
|
Condition100%2/2
delete $info->{'items'} || []
MC/DC100%1/1
delete $info->{'items'} || []
delete $info->{'items'}
Truth table100%2/2
A
A= delete $info->{'items'}
| |||||||||||||
| 73 | 6 | ▶ | my @receivers = @{ delete $info->{receivers} || [] }; | ||||||||||
|
Condition100%2/2
delete $info->{'receivers'} || []
MC/DC100%1/1
delete $info->{'receivers'} || []
delete $info->{'receivers'}
Truth table100%2/2
A
A= delete $info->{'receivers'}
| |||||||||||||
| 74 | |||||||||||||
| 75 | 6 | my $buyer_class = $self->buyer_class; | |||||||||||
| 76 | 6 | my $cart_class = $self->cart_class; | |||||||||||
| 77 | |||||||||||||
| 78 | # We might be using a more generic Account class | ||||||||||||
| 79 | 6 | ▶ | if ($buyer_class->does('Business::CPI::Role::Account')) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 80 | 0 | $info->{buyer}{_gateway} = $self; | |||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | $self->log->debug( | ||||||||||||
| 84 | 6 | "Loaded buyer class $buyer_class and cart class $cart_class." | |||||||||||
| 85 | ); | ||||||||||||
| 86 | |||||||||||||
| 87 | 6 | my $buyer = $buyer_class->new( delete $info->{buyer} ); | |||||||||||
| 88 | |||||||||||||
| 89 | 6 | $self->log->info("Built cart for buyer " . $buyer->email); | |||||||||||
| 90 | |||||||||||||
| 91 | 6 | my $cart = $cart_class->new( | |||||||||||
| 92 | _gateway => $self, | ||||||||||||
| 93 | buyer => $buyer, | ||||||||||||
| 94 | %$info, | ||||||||||||
| 95 | ); | ||||||||||||
| 96 | |||||||||||||
| 97 | 6 | for (@items) { | |||||||||||
| 98 | 6 | $cart->add_item($_); | |||||||||||
| 99 | } | ||||||||||||
| 100 | |||||||||||||
| 101 | 6 | for (@receivers) { | |||||||||||
| 102 | 2 | $cart->add_receiver($_); | |||||||||||
| 103 | } | ||||||||||||
| 104 | |||||||||||||
| 105 | 6 | return $cart; | |||||||||||
| 106 | } | ||||||||||||
| 107 | |||||||||||||
| 108 | 0 | ▶ | sub map_object { | ||||||||||
|
Subroutine
map_object: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 109 | 0 | my ($self, $map, $obj) = @_; | |||||||||||
| 110 | |||||||||||||
| 111 | 0 | my @result; | |||||||||||
| 112 | |||||||||||||
| 113 | 0 | ▶ | while (my ($bcpi_key, $gtw_key) = each %$map) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 114 | 0 | my $value = $obj->$bcpi_key; | |||||||||||
| 115 | 0 | ▶ | next unless $value; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 116 | |||||||||||||
| 117 | 0 | my $name = $gtw_key; | |||||||||||
| 118 | |||||||||||||
| 119 | 0 | ▶ | if (ref $gtw_key) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 120 | 0 | $name = $gtw_key->{name}; | |||||||||||
| 121 | 0 | $value = $gtw_key->{coerce}->($name); | |||||||||||
| 122 | } | ||||||||||||
| 123 | |||||||||||||
| 124 | 0 | push @result, ( $name, $value ); | |||||||||||
| 125 | } | ||||||||||||
| 126 | |||||||||||||
| 127 | 0 | return @result; | |||||||||||
| 128 | } | ||||||||||||
| 129 | |||||||||||||
| 130 | 0 | ▶ | sub get_notification_details { shift->_unimplemented } | ||||||||||
|
Subroutine
get_notification_details: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 131 | |||||||||||||
| 132 | 0 | ▶ | sub query_transactions { shift->_unimplemented } | ||||||||||
|
Subroutine
query_transactions: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 133 | |||||||||||||
| 134 | 0 | ▶ | sub get_transaction_details { shift->_unimplemented } | ||||||||||
|
Subroutine
get_transaction_details: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 135 | |||||||||||||
| 136 | 0 | ▶ | sub notify { shift->_unimplemented } | ||||||||||
|
Subroutine
notify: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 137 | |||||||||||||
| 138 | 0 | ▶ | sub get_checkout_code { shift->_unimplemented } | ||||||||||
|
Subroutine
get_checkout_code: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 139 | |||||||||||||
| 140 | 0 | ▶ | sub _unimplemented { | ||||||||||
|
Subroutine
_unimplemented: not called CC=1 SCAR=6.9
| |||||||||||||
| 141 | 0 | my $self = shift; | |||||||||||
| 142 | 0 | die "Not implemented."; | |||||||||||
| 143 | } | ||||||||||||
| 144 | |||||||||||||
| 145 | 0 | ▶ | sub _build_user_agent { | ||||||||||
|
Subroutine
_build_user_agent: not called CC=2 SCAR=17.9
| |||||||||||||
| 146 | 0 | my ($self) = @_; | |||||||||||
| 147 | |||||||||||||
| 148 | 0 | my $class_name = ref $self; | |||||||||||
| 149 | 0 | ▶ | my $version = eval { $self->VERSION } || 'devel'; | ||||||||||
|
Condition0%0/2
eval {
do {
$self->VERSION
}
} || 'devel'
MC/DC0%0/1
eval {
do {
$self->VERSION
}
} || 'devel'
eval {
do {
$self->VERSION
}
}
Truth table0%0/2
A
A= eval {
do {
$self->VERSION
}
}
| |||||||||||||
| 150 | |||||||||||||
| 151 | 0 | return LWP::UserAgent->new(agent => "$class_name/$version"); | |||||||||||
| 152 | } | ||||||||||||
| 153 | |||||||||||||
| 154 | 8 | ▶ | around BUILDARGS => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||
| 155 | 8 | my $orig = shift; | |||||||||||
| 156 | 8 | my $self = shift; | |||||||||||
| 157 | 8 | my $args = $self->$orig(@_); | |||||||||||
| 158 | |||||||||||||
| 159 | 8 | ▶ | if ($args->{receiver_email}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 160 | 0 | croak 'receiver_email attribute has been removed - use receiver_id instead'; | |||||||||||
| 161 | } | ||||||||||||
| 162 | |||||||||||||
| 163 | 8 | return $args; | |||||||||||
| 164 | 6 | }; | |||||||||||
| 165 | |||||||||||||
| 166 | 6 | 1; | |||||||||||
| 167 | |||||||||||||
| 168 | __END__ | ||||||||||||