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 sub create {
12 0 ▶ my ($self, $params) = @_;
Subroutine create: not called CC=2 SCAR=17.9
Pod undocumented
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 sub find {
18 0 ▶ my ($self, $id) = @_;
Subroutine find: not called CC=2 SCAR=17.9
Pod undocumented
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 sub delete {
24 0 ▶ my ($self, $id) = @_;
Subroutine delete: not called CC=1 SCAR=6.9
Pod undocumented
25 0 $self->_make_request("/customers/$id", "delete", undef);
26 }
27  
28 sub update {
29 0 ▶ my ($self, $id, $params) = @_;
Subroutine update: not called CC=2 SCAR=17.9
Pod undocumented
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 sub search {
35 0 ▶ my ($self, $block) = @_;
Subroutine search: not called CC=1 SCAR=6.9
Pod undocumented
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 return Net::Braintree::ResourceCollection->new()->init($response, sub {
40 0 ▶ $self->fetch_customers($search, shift);
Subroutine __ANON__: not called CC=1 SCAR=6.9
41 0 });
42 }
43  
44 sub all {
45 0 ▶ my $self = shift;
Subroutine all: not called CC=1 SCAR=6.9
Pod undocumented
46 0 my $response = $self->gateway->http->post("/customers/advanced_search_ids");
47 return Net::Braintree::ResourceCollection->new()->init($response, sub {
48 0 ▶ $self->fetch_customers(Net::Braintree::CustomerSearch->new, shift);
Subroutine __ANON__: not called CC=1 SCAR=6.9
49 0 });
50 }
51  
52 sub _make_request {
53 0 ▶ my($self, $path, $verb, $params) = @_;
Subroutine _make_request: not called CC=1 SCAR=6.9
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 sub fetch_customers {
60 0 ▶ my ($self, $search, $ids) = @_;
Subroutine fetch_customers: not called CC=2 SCAR=17.9
Pod undocumented
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 »