File Coverage

lib/WebService/Braintree/Subscription.pm
Criterion Covered Total %
statement 14 33 42.4
branch n/a
condition n/a
subroutine 5 14 35.7
pod 7 9 77.7
total 26 56 46.4


line stmt bran cond sub pod time code
1             package WebService::Braintree::Subscription;
2             $WebService::Braintree::Subscription::VERSION = '0.94';
3 20     20   341 use 5.010_001;
  20         64  
4 20     20   99 use strictures 1;
  20         115  
  20         699  
5              
6             =head1 NAME
7              
8             WebService::Braintree::Subscription
9              
10             =head1 PURPOSE
11              
12             This class creates, finds, updates, cancels, retries charges on, searches for,
13             and lists all subscriptions.
14              
15             =cut
16              
17 20     20   6901 use WebService::Braintree::SubscriptionGateway;
  20         55  
  20         740  
18 20     20   6246 use WebService::Braintree::Subscription::Status;
  20         46  
  20         485  
19              
20 20     20   106 use Moose;
  20         37  
  20         114  
21             extends 'WebService::Braintree::ResultObject';
22              
23             =head1 CLASS METHODS
24              
25             =head2 create()
26              
27             This takes a hashref of parameters and returns the subscription created.
28              
29             =cut
30              
31             sub create {
32 0     0 1   my ($class, $params) = @_;
33 0           $class->gateway->subscription->create($params);
34             }
35              
36             =head2 find()
37              
38             This takes a subscription_id and returns the subscription (if it exists).
39              
40             =cut
41              
42             sub find {
43 0     0 1   my ($class, $id) = @_;
44 0           $class->gateway->subscription->find($id);
45             }
46              
47             =head2 update()
48              
49             This takes a subcsription_id and a hashref of parameters. It will update the
50             corresponding subscription (if found) and returns the updated subscription.
51              
52             =cut
53              
54             sub update {
55 0     0 1   my ($class, $id, $params) = @_;
56 0           $class->gateway->subscription->update($id, $params);
57             }
58              
59             =head2 cancel()
60              
61             This takes a subscription_id and cancels (aka, deletes) the corresponding
62             subscription (if found).
63              
64             =cut
65              
66             sub cancel {
67 0     0 1   my ($class, $id) = @_;
68 0           $class->gateway->subscription->cancel($id);
69             }
70              
71             =head2 retry_charge()
72              
73             This takes a subscription_id and an amount and attempts to retry a charge for
74             that amount to that subscription (if found).
75              
76             =cut
77              
78             sub retry_charge {
79 0     0 1   my ($class, $subscription_id, $amount) = @_;
80 0           $class->gateway->transaction->retry_subscription_charge($subscription_id, $amount);
81             }
82              
83             =head2 search()
84              
85             This takes a subref which is used to set the search parameters and returns a
86             subscription object.
87              
88             Please see L<Searching|WebService::Braintree/SEARCHING> for more information on
89             the subref and how it works.
90              
91             =cut
92              
93             sub search {
94 0     0 1   my($class, $block) = @_;
95 0           $class->gateway->subscription->search($block);
96             }
97              
98             =head2 all()
99              
100             This returns all the subscriptions.
101              
102             =cut
103              
104             sub all {
105 0     0 1   my $class = shift;
106 0           $class->gateway->subscription->all;
107             }
108              
109             sub gateway {
110 0     0 0   return WebService::Braintree->configuration->gateway;
111             }
112              
113             =head1 OBJECT METHODS
114              
115             In addition to the methods provided by the keys returned from Braintree, this
116             class provides the following methods:
117              
118             =head2 transactions()
119              
120             This returns a list of all transactions that have been made against this
121             subscription. This is a list of L<WebService::Braintree::Transaction> objects.
122              
123             =cut
124              
125             sub BUILD {
126 0     0 0   my ($self, $attributes) = @_;
127 0           my $sub_objects = {
128             transactions => 'WebService::Braintree::Transaction',
129             };
130 0           $self->setup_sub_objects($self, $attributes, $sub_objects);
131 0           $self->set_attributes_from_hash($self, $attributes);
132             }
133              
134             __PACKAGE__->meta->make_immutable;
135              
136             1;
137             __END__
138              
139             =head1 TODO
140              
141             =over 4
142              
143             =item Need to document the keys and values that are returned
144              
145             =item Need to document the required and optional input parameters
146              
147             =item Need to document the possible errors/exceptions
148              
149             =back
150              
151             =cut