File Coverage

blib/lib/WebService/Braintree/Subscription.pm
Criterion Covered Total %
statement 9 28 32.1
branch n/a
condition n/a
subroutine 3 12 25.0
pod 7 9 77.7
total 19 49 38.7


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