| 1 | package Net::Braintree::SubscriptionGateway; | ||||||||||
| 2 | 1 | ▶ | use Net::Braintree::Util qw(to_instance_array validate_id); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | has 'gateway' => (is => 'ro'); | |||||||||
| 7 | |||||||||||
| 8 | 0 | ▶ | sub create { | ||||||||
|
Subroutine
create: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 9 | 0 | my ($self, $params) = @_; | |||||||||
| 10 | 0 | my $result = $self->_make_request("/subscriptions/", "post", {subscription => $params}); | |||||||||
| 11 | 0 | return $result; | |||||||||
| 12 | } | ||||||||||
| 13 | |||||||||||
| 14 | 0 | ▶ | sub find { | ||||||||
|
Subroutine
find: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 15 | 0 | my ($self, $id) = @_; | |||||||||
| 16 | 0 | ▶ | confess "NotFoundError" unless validate_id($id); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 0 | my $result = $self->_make_request("/subscriptions/$id", "get", undef)->subscription; | |||||||||
| 18 | } | ||||||||||
| 19 | |||||||||||
| 20 | 0 | ▶ | sub update { | ||||||||
|
Subroutine
update: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 21 | 0 | my ($self, $id, $params) = @_; | |||||||||
| 22 | 0 | my $result = $self->_make_request("/subscriptions/$id", "put", {subscription => $params}); | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 0 | ▶ | sub cancel { | ||||||||
|
Subroutine
cancel: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 26 | 0 | my ($self, $id) = @_; | |||||||||
| 27 | 0 | my $result = $self->_make_request("/subscriptions/$id/cancel", "put", undef); | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 0 | ▶ | sub _make_request { | ||||||||
|
Subroutine
_make_request: not called CC=1 SCAR=6.9
| |||||||||||
| 31 | 0 | my($self, $path, $verb, $params) = @_; | |||||||||
| 32 | 0 | my $response = $self->gateway->http->$verb($path, $params); | |||||||||
| 33 | 0 | my $result = Net::Braintree::Result->new(response => $response); | |||||||||
| 34 | 0 | return $result; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 0 | ▶ | sub search { | ||||||||
|
Subroutine
search: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 38 | 0 | my ($self, $block) = @_; | |||||||||
| 39 | 0 | my $search = Net::Braintree::SubscriptionSearch->new; | |||||||||
| 40 | 0 | my $params = $block->($search)->to_hash; | |||||||||
| 41 | 0 | my $response = $self->gateway->http->post("/subscriptions/advanced_search_ids", {search => $params}); | |||||||||
| 42 | 0 | ▶ | return Net::Braintree::ResourceCollection->new()->init($response, sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 43 | 0 | $self->fetch_subscriptions($search, shift); | |||||||||
| 44 | 0 | }); | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 0 | ▶ | sub all { | ||||||||
|
Subroutine
all: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 48 | 0 | my $self = shift; | |||||||||
| 49 | 0 | my $response = $self->gateway->http->post("/subscriptions/advanced_search_ids"); | |||||||||
| 50 | 0 | ▶ | return Net::Braintree::ResourceCollection->new()->init($response, sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 51 | 0 | $self->fetch_subscriptions(Net::Braintree::SubscriptionSearch->new, shift); | |||||||||
| 52 | 0 | }); | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 0 | ▶ | sub fetch_subscriptions { | ||||||||
|
Subroutine
fetch_subscriptions: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 56 | 0 | my ($self, $search, $ids) = @_; | |||||||||
| 57 | 0 | $search->ids->in($ids); | |||||||||
| 58 | 0 | ▶ | return [] if scalar @{$ids} == 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 0 | my $response = $self->gateway->http->post("/subscriptions/advanced_search/", {search => $search->to_hash}); | |||||||||
| 60 | 0 | my $attrs = $response->{'subscriptions'}->{'subscription'}; | |||||||||
| 61 | 0 | return to_instance_array($attrs, "Net::Braintree::Subscription"); | |||||||||
| 62 | } | ||||||||||
| 63 | 1 | 1; | |||||||||