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