line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Braintree::CustomerGateway; |
2
|
1
|
|
|
1
|
|
5
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
3
|
1
|
|
|
1
|
|
5307
|
use Carp qw(confess); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
56
|
|
4
|
1
|
|
|
1
|
|
5
|
use Net::Braintree::Validations qw(verify_params customer_signature); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
82
|
|
5
|
1
|
|
|
1
|
|
6
|
use Net::Braintree::Util qw(validate_id); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
6
|
1
|
|
|
1
|
|
5
|
use Net::Braintree::Result; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
7
|
1
|
|
|
1
|
|
3
|
use Net::Braintree::Util; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
590
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has 'gateway' => (is => 'ro'); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub create { |
12
|
0
|
|
|
0
|
0
|
|
my ($self, $params) = @_; |
13
|
0
|
0
|
|
|
|
|
confess "ArgumentError" unless verify_params($params, customer_signature); |
14
|
0
|
|
|
|
|
|
$self->_make_request("/customers/", 'post', { customer => $params }); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub find { |
18
|
0
|
|
|
0
|
0
|
|
my ($self, $id) = @_; |
19
|
0
|
0
|
|
|
|
|
confess "NotFoundError" unless validate_id($id); |
20
|
0
|
|
|
|
|
|
$self->_make_request("/customers/$id", 'get', undef)->customer; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub delete { |
24
|
0
|
|
|
0
|
0
|
|
my ($self, $id) = @_; |
25
|
0
|
|
|
|
|
|
$self->_make_request("/customers/$id", "delete", undef); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub update { |
29
|
0
|
|
|
0
|
0
|
|
my ($self, $id, $params) = @_; |
30
|
0
|
0
|
|
|
|
|
confess "ArgumentError" unless verify_params($params, customer_signature); |
31
|
0
|
|
|
|
|
|
$self->_make_request("/customers/$id", 'put', {customer => $params}); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub search { |
35
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
return Net::Braintree::ResourceCollection->new()->init($response, sub { |
40
|
0
|
|
|
0
|
|
|
$self->fetch_customers($search, shift); |
41
|
0
|
|
|
|
|
|
}); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub all { |
45
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
46
|
0
|
|
|
|
|
|
my $response = $self->gateway->http->post("/customers/advanced_search_ids"); |
47
|
|
|
|
|
|
|
return Net::Braintree::ResourceCollection->new()->init($response, sub { |
48
|
0
|
|
|
0
|
|
|
$self->fetch_customers(Net::Braintree::CustomerSearch->new, shift); |
49
|
0
|
|
|
|
|
|
}); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _make_request { |
53
|
0
|
|
|
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
|
|
|
|
|
|
|
sub fetch_customers { |
60
|
0
|
|
|
0
|
0
|
|
my ($self, $search, $ids) = @_; |
61
|
0
|
|
|
|
|
|
$search->ids->in($ids); |
62
|
0
|
|
|
|
|
|
my @result = (); |
63
|
0
|
0
|
|
|
|
|
return [] if scalar @{$ids} == 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; |
71
|
|
|
|
|
|
|
|