Braintree/CustomerGateway.pm

filter: Statementstmt 37.7% 20 / 53 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 37.5% 6 / 16 Podpod 0.0% 0 / 7 totaltotal 30.9% 26 / 84 CC 5 SCAR 11.9
CC
5
Cov
33%
create
6.0
find
6.0
update
6.0
CRAP 3.3
« Braintree/TransactionGateway.pm ↑ Summary Braintree/CreditCardVerificationGateway.pm »
1 package Net::Braintree::CustomerGateway;
2 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Net::Braintree::Validations qw(verify_params customer_signature);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Net::Braintree::Util qw(validate_id);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Net::Braintree::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Net::Braintree::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 has 'gateway' => (is => 'ro');
10  
11 0 ▶sub create {
Subroutine create: not called CC=2 SCAR=17.9
Pod undocumented
12 0 my ($self, $params) = @_;
13 0 ▶ confess "ArgumentError" unless verify_params($params, customer_signature);
Branch: 1 branch
BranchTrueFalseTotal
unless verify_params($params, customer_signature()) 0 0 0
14 0 $self->_make_request("/customers/", 'post', { customer => $params });
15 }
16  
17 0 ▶sub find {
Subroutine find: not called CC=2 SCAR=17.9
Pod undocumented
18 0 my ($self, $id) = @_;
19 0 ▶ confess "NotFoundError" unless validate_id($id);
Branch: 1 branch
BranchTrueFalseTotal
unless validate_id($id) 0 0 0
20 0 $self->_make_request("/customers/$id", 'get', undef)->customer;
21 }
22  
23 0 ▶sub delete {
Subroutine delete: not called CC=1 SCAR=6.9
Pod undocumented
24 0 my ($self, $id) = @_;
25 0 $self->_make_request("/customers/$id", "delete", undef);
26 }
27  
28 0 ▶sub update {
Subroutine update: not called CC=2 SCAR=17.9
Pod undocumented
29 0 my ($self, $id, $params) = @_;
30 0 ▶ confess "ArgumentError" unless verify_params($params, customer_signature);
Branch: 1 branch
BranchTrueFalseTotal
unless verify_params($params, customer_signature()) 0 0 0
31 0 $self->_make_request("/customers/$id", 'put', {customer => $params});
32 }
33  
34 0 ▶sub search {
Subroutine search: not called CC=1 SCAR=6.9
Pod undocumented
35 0 my ($self, $block) = @_;
36 0 my $search = Net::Braintree::CustomerSearch->new;
37 0 my $params = $block->($search)->to_hash;
38 0 my $response = $self->gateway->http->post("/customers/advanced_search_ids", {search => $params});
39 0 ▶ return Net::Braintree::ResourceCollection->new()->init($response, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
40 0 $self->fetch_customers($search, shift);
41 0 });
42 }
43  
44 0 ▶sub all {
Subroutine all: not called CC=1 SCAR=6.9
Pod undocumented
45 0 my $self = shift;
46 0 my $response = $self->gateway->http->post("/customers/advanced_search_ids");
47 0 ▶ return Net::Braintree::ResourceCollection->new()->init($response, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 0 $self->fetch_customers(Net::Braintree::CustomerSearch->new, shift);
49 0 });
50 }
51  
52 0 ▶sub _make_request {
Subroutine _make_request: not called CC=1 SCAR=6.9
53 0 my($self, $path, $verb, $params) = @_;
54 0 my $response = $self->gateway->http->$verb($path, $params);
55 0 my $result = Net::Braintree::Result->new(response => $response);
56 0 return $result;
57 }
58  
59 0 ▶sub fetch_customers {
Subroutine fetch_customers: not called CC=2 SCAR=17.9
Pod undocumented
60 0 my ($self, $search, $ids) = @_;
61 0 $search->ids->in($ids);
62 0 my @result = ();
63 0 ▶ return [] if scalar @{$ids} == 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$ids;} == 0 0 0 0
64 0 my $response = $self->gateway->http->post( "/customers/advanced_search/", {search => $search->to_hash});
65 0 my $attrs = $response->{'customers'}->{'customer'};
66 0 return to_instance_array($attrs, "Net::Braintree::Customer");
67 }
68  
69  
70 1 1;
71  
« Braintree/TransactionGateway.pm ↑ Summary Braintree/CreditCardVerificationGateway.pm »