lib/WebService/Braintree/TransparentRedirectGateway.pm

filter: Statementstmt 94.4% 68 / 72 Branchbran 75.0% 6 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 20 / 20 Podpod 0.0% 0 / 12 totaltotal 81.2% 95 / 117 CC 7 SCAR 6.4
CC
7
Cov
90%
requires_type
4.8
requires
3.0
create_credit_card_data
2.0
CRAP 1.9
« blib/lib/WebService/Braintree/Transaction/PaymentInstrumentType.pm ↑ Summary lib/WebService/Braintree/Configuration.pm »
1 # vim: sw=4 ts=4 ft=perl
2  
3 package # hide from pause
4 WebService::Braintree::TransparentRedirectGateway;
5  
6 22 ▶use 5.010_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 22 ▶use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 22 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 22 with 'WebService::Braintree::Role::MakeRequest';
11  
12 22 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 22 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 22 ▶use WebService::Braintree::Util qw(hash_to_query_string);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 22 ▶use WebService::Braintree::Digest qw(hexdigest);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 22 ▶use WebService::Braintree::TransparentRedirect::QueryString;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 ▶sub confirm {
Subroutine confirm: called CC=1 SCAR=0.6
Pod undocumented
20 1 my ($self, $query_string) = @_;
21 1 my $qs = WebService::Braintree::TransparentRedirect::QueryString->new(config => $self->gateway->config);
22 1 $qs->validate($query_string);
23 0 my $params = $qs->parse($query_string);
24 0 $self->_make_request("/transparent_redirect_requests/". $params->{id} . "/confirm", "post", undef);
25 }
26  
27 3 ▶sub transaction_data {
Subroutine transaction_data: called CC=1 SCAR=0.6
Pod undocumented
28 3 my ($self, $params) = @_;
29 3 $self->requires($params, qw(redirect_url transaction));
30 1 $self->requires_type($params);
31 0 $params->{'kind'} = 'create_transaction';
32 0 return $self->data_string($params);
33 }
34  
35 2 ▶sub create_customer_data {
Subroutine create_customer_data: called CC=1 SCAR=0.0
Pod undocumented
36 2 my ($self, $params) = @_;
37 2 $self->requires($params, qw(redirect_url));
38 1 $params->{'kind'} = 'create_customer';
39 1 return $self->data_string($params);
40 }
41  
42 3 ▶sub update_customer_data {
Subroutine update_customer_data: called CC=1 SCAR=0.0
Pod undocumented
43 3 my ($self, $params) = @_;
44 3 $self->requires($params, qw(redirect_url customer_id));
45 1 $params->{'kind'} = 'update_customer';
46 1 return $self->data_string($params);
47 }
48  
49 4 ▶sub create_credit_card_data {
Subroutine create_credit_card_data: called CC=2 SCAR=6.9
Pod undocumented
50 4 my ($self, $params) = @_;
51 4 $self->requires($params, qw(redirect_url credit_card));
52 2 ▶ confess "ArgumentError: credit card must be associated with a customer" unless $params->{'credit_card'}->{'customer_id'};
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{"credit_card"}{"customer_id"} 1 1 2
53 1 $params->{'kind'} = 'create_payment_method';
54 1 return $self->data_string($params);
55 }
56  
57 3 ▶sub update_credit_card_data {
Subroutine update_credit_card_data: called CC=1 SCAR=0.0
Pod undocumented
58 3 my ($self, $params) = @_;
59 3 $self->requires($params, qw(redirect_url payment_method_token));
60 1 $params->{'kind'} = 'update_payment_method';
61 1 return $self->data_string($params);
62 }
63  
64 1 ▶sub url {
Subroutine url: called CC=1 SCAR=0.0
Pod undocumented
65 1 return shift->gateway->config->base_merchant_url . "/transparent_redirect_requests";
66 }
67  
68 15 ▶sub requires {
Subroutine requires: called CC=3 SCAR=11.0
Pod undocumented
69 15 my ($self, $params, @required) = @_;
70 15 foreach my $field (@required) {
71 24 ▶ confess "ArgumentError: $field is required" unless $params->{$field}
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{$field} 9 15 24
72 }
73 }
74  
75 1 ▶sub requires_type {
Subroutine requires_type: called CC=4 SCAR=15.6
Pod undocumented
76 1 my ($self, $params) = @_;
77 1 ▶ confess "ArgumentError: Transaction type is required" unless $params->{'transaction'}->{'type'} ;
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{"transaction"}{"type"} 0 1 1
78 1 ▶ if ($params->{'transaction'}->{'type'} ne 'sale' &&
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"transaction"}{"type"} ne "sale" and $params->{"transaction"}{"type"} ne "credit") 1 0 1
Condition33%1/3
$params->{"transaction"}{"type"} ne "sale" and $params->{"transaction"}{"type"} ne "credit"
!ll&&!rl&&r
001
MC/DC0%0/2
$params->{"transaction"}{"type"} ne "sale" and $params->{"transaction"}{"type"} ne "credit"
$params->{"transaction"}{"type"} ne "sale" $params->{"transaction"}{"type"} ne "credit"
Truth table33%1/3
A and B
A= $params->{"transaction"}{"type"} ne "sale"B= $params->{"transaction"}{"type"} ne "credit"
ABresult
0X0
100
111
79 $params->{'transaction'}->{'type'} ne 'credit') {
80 1 confess "ArgumentError: Transaction type must be credit or sale";
81 }
82 }
83  
84 4 ▶sub time_string {
Subroutine time_string: called CC=1 SCAR=0.0
Pod undocumented
85 4 my $dt = DateTime->now;
86 4 return $dt->strftime("%Y%m%d%H%M%S");
87 }
88  
89 4 ▶sub data_string {
Subroutine data_string: called CC=1 SCAR=0.0
Pod undocumented
90 4 my ($self, $params) = @_;
91 4 $params->{'api_version'} = $self->gateway->config->api_version;
92 4 $params->{'time'} = time_string;
93 4 $params->{'public_key'} = $self->gateway->config->public_key;
94 4 return $self->build_tr_data($params);
95 }
96  
97 4 ▶sub build_tr_data {
Subroutine build_tr_data: called CC=1 SCAR=0.0
Pod undocumented
98 4 my ($self, $params) = @_;
99 4 my $query = hash_to_query_string($params);
100 4 my $tr_hash = hexdigest($self->gateway->config->private_key, $query);
101 4 return "$tr_hash|$query";
102 }
103  
104 22 __PACKAGE__->meta->make_immutable;
105  
106 22 1;
107 __END__
« blib/lib/WebService/Braintree/Transaction/PaymentInstrumentType.pm ↑ Summary lib/WebService/Braintree/Configuration.pm »