line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Braintree::CustomerGateway; |
2
|
|
|
|
|
|
|
$WebService::Braintree::CustomerGateway::VERSION = '0.93'; |
3
|
1
|
|
|
1
|
|
8
|
use Moose; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
4
|
|
|
|
|
|
|
with 'WebService::Braintree::Role::MakeRequest'; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
8791
|
use Carp qw(confess); |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
116
|
|
7
|
1
|
|
|
1
|
|
11
|
use WebService::Braintree::Validations qw(verify_params customer_signature); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
88
|
|
8
|
1
|
|
|
1
|
|
12
|
use WebService::Braintree::Util qw(validate_id); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
61
|
|
9
|
1
|
|
|
1
|
|
10
|
use WebService::Braintree::Result; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
35
|
|
10
|
1
|
|
|
1
|
|
6
|
use WebService::Braintree::Util; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
629
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'gateway' => (is => 'ro'); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub create { |
15
|
0
|
|
|
0
|
0
|
|
my ($self, $params) = @_; |
16
|
0
|
0
|
|
|
|
|
confess "ArgumentError" unless verify_params($params, customer_signature); |
17
|
0
|
|
|
|
|
|
$self->_make_request("/customers/", 'post', { customer => $params }); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub find { |
21
|
0
|
|
|
0
|
0
|
|
my ($self, $id) = @_; |
22
|
0
|
0
|
|
|
|
|
confess "NotFoundError" unless validate_id($id); |
23
|
0
|
|
|
|
|
|
$self->_make_request("/customers/$id", 'get', undef)->customer; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub delete { |
27
|
0
|
|
|
0
|
0
|
|
my ($self, $id) = @_; |
28
|
0
|
|
|
|
|
|
$self->_make_request("/customers/$id", "delete", undef); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub update { |
32
|
0
|
|
|
0
|
0
|
|
my ($self, $id, $params) = @_; |
33
|
0
|
0
|
|
|
|
|
confess "ArgumentError" unless verify_params($params, customer_signature); |
34
|
0
|
|
|
|
|
|
$self->_make_request("/customers/$id", 'put', {customer => $params}); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub search { |
38
|
0
|
|
|
0
|
0
|
|
my ($self, $block) = @_; |
39
|
0
|
|
|
|
|
|
my $search = WebService::Braintree::CustomerSearch->new; |
40
|
0
|
|
|
|
|
|
my $params = $block->($search)->to_hash; |
41
|
0
|
|
|
|
|
|
my $response = $self->gateway->http->post("/customers/advanced_search_ids", {search => $params}); |
42
|
|
|
|
|
|
|
return WebService::Braintree::ResourceCollection->new()->init($response, sub { |
43
|
0
|
|
|
0
|
|
|
$self->fetch_customers($search, shift); |
44
|
0
|
|
|
|
|
|
}); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub all { |
48
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
49
|
0
|
|
|
|
|
|
my $response = $self->gateway->http->post("/customers/advanced_search_ids"); |
50
|
|
|
|
|
|
|
return WebService::Braintree::ResourceCollection->new()->init($response, sub { |
51
|
0
|
|
|
0
|
|
|
$self->fetch_customers(WebService::Braintree::CustomerSearch->new, shift); |
52
|
0
|
|
|
|
|
|
}); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub fetch_customers { |
56
|
0
|
|
|
0
|
0
|
|
my ($self, $search, $ids) = @_; |
57
|
0
|
|
|
|
|
|
$search->ids->in($ids); |
58
|
0
|
|
|
|
|
|
my @result = (); |
59
|
0
|
0
|
|
|
|
|
return [] if scalar @{$ids} == 0; |
|
0
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $response = $self->gateway->http->post( "/customers/advanced_search/", {search => $search->to_hash}); |
61
|
0
|
|
|
|
|
|
my $attrs = $response->{'customers'}->{'customer'}; |
62
|
0
|
|
|
|
|
|
return to_instance_array($attrs, "WebService::Braintree::Customer"); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|