File Coverage

blib/lib/WWW/PayPal/Subscription.pm
Criterion Covered Total %
statement 23 44 52.2
branch 4 8 50.0
condition 1 3 33.3
subroutine 12 23 52.1
pod 20 20 100.0
total 60 98 61.2


line stmt bran cond sub pod time code
1             package WWW::PayPal::Subscription;
2              
3             # ABSTRACT: PayPal Billing Subscription entity
4              
5 2     2   16 use Moo;
  2         4  
  2         13  
6 2     2   926 use namespace::clean;
  2         4  
  2         16  
7              
8             our $VERSION = '0.002';
9              
10              
11             has _client => (
12             is => 'ro',
13             required => 1,
14             weak_ref => 1,
15             init_arg => 'client',
16             );
17              
18             has data => ( is => 'rw', required => 1 );
19              
20              
21 1     1 1 1674 sub id { $_[0]->data->{id} }
22 1     1 1 9 sub status { $_[0]->data->{status} }
23 0     0 1 0 sub plan_id { $_[0]->data->{plan_id} }
24 0     0 1 0 sub custom_id { $_[0]->data->{custom_id} }
25 0     0 1 0 sub start_time { $_[0]->data->{start_time} }
26 0     0 1 0 sub create_time { $_[0]->data->{create_time} }
27 0     0 1 0 sub update_time { $_[0]->data->{update_time} }
28              
29              
30 1 50   1   9 sub _links { $_[0]->data->{links} || [] }
31              
32             sub link_for {
33 1     1 1 4 my ($self, $rel) = @_;
34 1         3 for my $l (@{ $self->_links }) {
  1         4  
35 1 50 33     14 return $l->{href} if $l->{rel} && $l->{rel} eq $rel;
36             }
37 0         0 return;
38             }
39              
40              
41             sub approve_url {
42 1     1 1 3 my ($self) = @_;
43 1         4 return $self->link_for('approve');
44             }
45              
46              
47             sub subscriber_email {
48 1     1 1 10 $_[0]->data->{subscriber}{email_address};
49             }
50              
51             sub subscriber_name {
52 1     1 1 4 my ($self) = @_;
53 1 50       7 my $n = $self->data->{subscriber}{name} or return;
54 1 50       5 return join(' ', grep { defined && length } $n->{given_name}, $n->{surname});
  2         17  
55             }
56              
57             sub subscriber_payer_id {
58 0     0 1 0 $_[0]->data->{subscriber}{payer_id};
59             }
60              
61              
62             sub next_billing_time {
63 1     1 1 27 $_[0]->data->{billing_info}{next_billing_time};
64             }
65              
66             sub last_payment_amount {
67 1     1 1 10 $_[0]->data->{billing_info}{last_payment}{amount}{value};
68             }
69              
70             sub last_payment_currency {
71 1     1 1 9 $_[0]->data->{billing_info}{last_payment}{amount}{currency_code};
72             }
73              
74             sub cycle_executions {
75 0     0 1   $_[0]->data->{billing_info}{cycle_executions};
76             }
77              
78              
79             sub refresh {
80 0     0 1   my ($self) = @_;
81 0           my $fresh = $self->_client->subscriptions->get($self->id);
82 0           $self->data($fresh->data);
83 0           return $self;
84             }
85              
86 0     0 1   sub suspend { my $s = shift; $s->_client->subscriptions->suspend($s->id, @_); $s->refresh }
  0            
  0            
87 0     0 1   sub activate { my $s = shift; $s->_client->subscriptions->activate($s->id, @_); $s->refresh }
  0            
  0            
88 0     0 1   sub cancel { my $s = shift; $s->_client->subscriptions->cancel($s->id, @_); $s->refresh }
  0            
  0            
89              
90              
91              
92             1;
93              
94             __END__