| 1 | package Business::CPI::Role::Account; | ||||||||||||||||||||
| 2 | # ABSTRACT: Manage accounts in the gateway | ||||||||||||||||||||
| 3 | 2 | ▶ | use Moo::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use Business::CPI::Util::Types qw/PhoneNumber DateTime/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 2 | ▶ | use Type::EmailAddress qw/EmailAddress/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 2 | ▶ | use Types::Standard qw/Bool/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 2 | our $VERSION = '0.924'; # VERSION | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | # TODO: Validate this? URI.pm seems to accept anything | ||||||||||||||||||||
| 12 | # actually... does this really belong here??? | ||||||||||||||||||||
| 13 | 2 | has return_url => ( is => 'rw' ); | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 2 | has _gateway => ( is => 'ro', required => 1 ); | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 2 | has id => ( is => 'rw' ); | |||||||||||||||||||
| 18 | 2 | has gateway_id => ( is => 'rw' ); | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | # Some gateways use the Full Name, others use the first and last separately. | ||||||||||||||||||||
| 21 | # You can set both and let the driver decide what to send. | ||||||||||||||||||||
| 22 | 2 | has full_name => ( is => 'lazy' ); | |||||||||||||||||||
| 23 | 2 | has first_name => ( is => 'rw' ); | |||||||||||||||||||
| 24 | 2 | has last_name => ( is => 'rw' ); | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 2 | has phone => ( | |||||||||||||||||||
| 27 | is => 'rw', | ||||||||||||||||||||
| 28 | isa => PhoneNumber, | ||||||||||||||||||||
| 29 | coerce => PhoneNumber->coercion, | ||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 2 | has login => ( is => 'rw' ); | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 2 | has email => ( | |||||||||||||||||||
| 35 | is => 'rw', | ||||||||||||||||||||
| 36 | isa => EmailAddress, | ||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 2 | has birthdate => ( | |||||||||||||||||||
| 40 | is => 'rw', | ||||||||||||||||||||
| 41 | isa => DateTime, | ||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 2 | has registration_date => ( | |||||||||||||||||||
| 45 | is => 'rw', | ||||||||||||||||||||
| 46 | isa => DateTime, | ||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 2 | has is_business_account => ( is => 'rw', isa => Bool ); | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 2 | has address => ( is => 'rw' ); | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 2 | has business => ( is => 'rw' ); | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 2 | ▶ | around address => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.4
| |||||||||||||||||||||
| 56 | 2 | my $orig = shift; | |||||||||||||||||||
| 57 | 2 | my $self = shift; | |||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 2 | ▶ | if (my $new_address = shift) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 0 | return $self->$orig( $self->_inflate_address($new_address) ); | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 2 | return $self->$orig(); | |||||||||||||||||||
| 64 | 2 | }; | |||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 3 | ▶ | around business => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.4
| |||||||||||||||||||||
| 67 | 3 | my $orig = shift; | |||||||||||||||||||
| 68 | 3 | my $self = shift; | |||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 3 | ▶ | if (my $new_business = shift) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 71 | 0 | return $self->$orig( $self->_inflate_business($new_business) ); | |||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 3 | return $self->$orig(); | |||||||||||||||||||
| 75 | 2 | }; | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 11 | ▶ | around BUILDARGS => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||
| 78 | 11 | my $orig = shift; | |||||||||||||||||||
| 79 | 11 | my $class = shift; | |||||||||||||||||||
| 80 | 11 | my $args = $class->$orig(@_); | |||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 11 | ▶ | return $args if !$args->{_gateway}; # let it die elsewhere | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 10 | ▶ | if (exists $args->{business}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 85 | 1 | $args->{business} = $class->_inflate_business($args->{business}, $args->{_gateway}); | |||||||||||||||||||
| 86 | } | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 10 | ▶ | if (exists $args->{address}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 89 | 1 | $args->{address} = $class->_inflate_address($args->{address}, $args->{_gateway}); | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 10 | return $args; | |||||||||||||||||||
| 93 | 2 | }; | |||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 1 | ▶ | sub _build_full_name { | ||||||||||||||||||
|
Subroutine
_build_full_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 96 | 1 | my $self = shift; | |||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 1 | return $self->first_name . ' ' . $self->last_name; | |||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 1 | ▶ | sub _inflate_address { | ||||||||||||||||||
|
Subroutine
_inflate_address: called CC=2 SCAR=7.4
| |||||||||||||||||||||
| 102 | 1 | my ($self, $comp, $gateway) = @_; | |||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 1 | ▶ | $gateway ||= $self->_gateway; | ||||||||||||||||||
|
Condition33%1/3
$gateway ||= $self->_gateway
MC/DC0%0/2
$gateway ||= $self->_gateway
$gateway
$self->_gateway
Truth table33%1/3
A ||= B
A= $gatewayB= $self->_gateway
| |||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 1 | $comp->{_gateway} = $gateway; | |||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 1 | return $gateway->account_address_class->new($comp); | |||||||||||||||||||
| 109 | } | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | 1 | ▶ | sub _inflate_business { | ||||||||||||||||||
|
Subroutine
_inflate_business: called CC=2 SCAR=7.4
| |||||||||||||||||||||
| 112 | 1 | my ($self, $comp, $gateway) = @_; | |||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | 1 | ▶ | $gateway ||= $self->_gateway; | ||||||||||||||||||
|
Condition33%1/3
$gateway ||= $self->_gateway
MC/DC0%0/2
$gateway ||= $self->_gateway
$gateway
$self->_gateway
Truth table33%1/3
A ||= B
A= $gatewayB= $self->_gateway
| |||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | 1 | $comp->{_gateway} = $gateway; | |||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 1 | return $gateway->account_business_class->new($comp); | |||||||||||||||||||
| 119 | } | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | 2 | 1; | |||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | __END__ | ||||||||||||||||||||