Simplify/Plan.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 53 CC 1 SCAR 6.9
CC
1
Cov
0%
create
2.0
delete
2.0
list
2.0
CRAP 2.0
1 package Net::Simplify::Plan;
2  
3 =head1 NAME
4  
5 Net::Simplify::Plan - A Simplify Commerce Plan object
6  
7 =head1 SYNOPSIS
8  
9 use Net::Simplify;
10  
11  
12 $Net::Simplify::public_key = 'YOUR PUBLIC KEY';
13 $Net::Simplify::private_key = 'YOUR PRIVATE KEY';
14  
15 # Create a new Plan.
16 my $plan = Net::Simplify::Plan->create{ {...});
17  
18 # Retrieve a Plan given its ID.
19 my $plan = Net::Simplify::Plan->find('a7e41');
20  
21 # Update existing Plan.
22 my $plan = Net::Simplify::Plan->find('a7e41');
23 $plan->{PROPERTY} = "NEW VALUE";
24 $plan->update();
25  
26 # Delete
27 my $plan = Net::Simplify::Plan->find('a7e41');
28 $plan->delete();
29  
30 # Retrieve a list of objects
31 my $plans = Net::Simplify::Plan->list({max => 10});
32 foreach my $v ($plans->list) {
33 # ...
34 }
35  
36 =head1 DESCRIPTION
37  
38 =head2 METHODS
39  
40 =head3 create(%params, $auth)
41  
42 Creates a C<Net::Simplify::Plan> object. The parameters are:
43  
44 =over 4
45  
46 =item C<%params>
47  
48 Hash map containing initial values for the object. Valid keys are:
49  
50 =over 4
51  
52 =item amount
53  
54 Amount of payment for the plan in the smallest unit of your currency. Example: 100 = $1.00 (B<required>)
55  
56 =item billingCycle
57  
58 How the plan is billed to the customer. Values must be AUTO (indefinitely until the customer cancels) or FIXED (a fixed number of billing cycles). [default: AUTO]
59  
60 =item billingCycleLimit
61  
62 The number of fixed billing cycles for a plan. Only used if the billingCycle parameter is set to FIXED. Example: 4
63  
64 =item currency
65  
66 Currency code (ISO-4217) for the plan. Must match the currency associated with your account. [default: USD] (B<required>)
67  
68 =item frequency
69  
70 Frequency of payment for the plan. Used in conjunction with frequencyPeriod. Valid values are "DAILY", "WEEKLY", "MONTHLY" and "YEARLY". [default: MONTHLY] (B<required>)
71  
72 =item frequencyPeriod
73  
74 Period of frequency of payment for the plan. Example: if the frequency is weekly, and periodFrequency is 2, then the subscription is billed bi-weekly. [min value: 1, default: 1] (B<required>)
75  
76 =item name
77  
78 Name of the plan [max length: 50, min length: 2] (B<required>)
79  
80 =item renewalReminderLeadDays
81  
82 If set, how many days before the next billing cycle that a renewal reminder is sent to the customer. If null, then no emails are sent. Minimum value is 7 if set.
83  
84 =item trialPeriod
85  
86 Plan free trial period selection. Must be Days, Weeks, or Month [default: NONE] (B<required>)
87  
88 =item trialPeriodQuantity
89  
90 Quantity of the trial period. Must be greater than 0 and a whole number. [min value: 1]
91  
92  
93 =back
94  
95 =item C<$auth>
96  
97 Authentication object for accessing the API. If no value is passed the global keys
98 C<$Net::Simplify::public_key> and C<$Net::Simplify::private_key> are used.
99  
100 =back
101  
102  
103  
104  
105 =head3 delete()
106  
107 Deletes the C<Net::Simplify::Plan> object. Authentication is done using the same credentials used when the AccessToken was created.
108  
109  
110  
111 =head3 list(%criteria, $auth)
112  
113 Retrieve a list of C<Net::Simplify::Plan> objects. The parameters are:
114  
115 =over 4
116  
117 =item C<%criteria>
118  
119 Hash map representing the criteria to limit the results of the list operation. Valid keys are:
120  
121 =over 4
122  
123 =item C<filter>
124  
125 <table class="filter_list"><tr><td>filter.id</td><td>Filter by the plan Id</td></tr><tr><td>filter.text</td><td>Filter by the name of the plan</td></tr><tr><td>filter.frequency</td><td>Filter by the frequency of the plan</td></tr><tr><td>filter.amountMin & filter.amountMax</td><td>The filter amountMin must be used with amountMax to find plans with plan values between the min and max figures</td></tr><tr><td>filter.dateCreatedMin<sup>*</sup></td><td>Filter by the minimum created date you are searching for - Date in UTC millis</td></tr><tr><td>filter.dateCreatedMax<sup>*</sup></td><td>Filter by the maximum created date you are searching for - Date in UTC millis</td></tr><tr><td>filter.q</td><td>You can use this to filter by the Id, the name or the amount of the plan</td></tr></table><br><sup>*</sup>Use dateCreatedMin with dateCreatedMax in the same filter if you want to search between two created dates
126  
127  
128  
129 =item C<max>
130  
131 Allows up to a max of 50 list items to return. [min value: 0, max value: 50, default: 20]
132  
133  
134  
135 =item C<offset>
136  
137 Used in paging of the list. This is the start offset of the page. [min value: 0, default: 0]
138  
139  
140  
141 =item C<sorting>
142  
143 Allows for ascending or descending sorting of the list.
144 The value maps properties to the sort direction (either C<asc> for ascending or C<desc> for descending). Sortable properties are:
145  
146 =over 4
147  
148 =item C<dateCreated>
149  
150 =item C<amount>
151  
152 =item C<frequency>
153  
154 =item C<name>
155  
156 =item C<id>
157  
158  
159 =back
160  
161  
162  
163  
164 =back
165  
166 =back
167  
168  
169  
170 =head3 find($id, $auth)
171  
172 Retrieve a C<Net::Simplify::Plan> object from the API. Parameters are:
173  
174 =over 4
175  
176 =item C<$id>
177  
178 Identifier of the object to retrieve.
179  
180 =item C<$auth>
181  
182 Authentication object for accessing the API. If no value is passed the global keys
183 C<$Net::Simplify::public_key> and C<$Net::Simplify::private_key> are used.
184  
185 =back
186  
187  
188  
189  
190 =head3 update()
191  
192 Update C<Net::Simplify::Plan> object.
193 The properties that can be updated are:
194  
195 =over 4
196  
197  
198  
199 =item C<name>
200  
201 Name of the plan. [min length: 2] (B<required>)
202  
203 Authentication is done using the same credentials used when the AccessToken was created.
204  
205 =back
206  
207  
208  
209  
210 =head1 SEE ALSO
211  
212 L<Net::Simplify>,
213 L<Net::Simplify::Domain>,
214 L<Net::Simplify::DomainList>,
215 L<Net::Simplify::Authentication>,
216 L<Net::Simplify::ApiException>,
217 L<http://www.simplify.com>
218  
219 =head1 VERSION
220  
221 1.6.0
222  
223 =head1 LICENSE
224  
225 Copyright (c) 2013 - 2022 MasterCard International Incorporated
226 All rights reserved.
227  
228 Redistribution and use in source and binary forms, with or without modification, are
229 permitted provided that the following conditions are met:
230  
231 Redistributions of source code must retain the above copyright notice, this list of
232 conditions and the following disclaimer.
233 Redistributions in binary form must reproduce the above copyright notice, this list of
234 conditions and the following disclaimer in the documentation and/or other materials
235 provided with the distribution.
236 Neither the name of the MasterCard International Incorporated nor the names of its
237 contributors may be used to endorse or promote products derived from this software
238 without specific prior written permission.
239 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
240 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
241 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
242 SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
243 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
244 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
245 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
246 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
247 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
248 SUCH DAMAGE.
249  
250 =head1 SEE ALSO
251  
252 =cut
253  
254 use 5.006;
255 use strict;
256 use warnings FATAL => 'all';
257  
258 use Net::Simplify::Domain;
259 use Net::Simplify::DomainList;
260  
261 our @ISA = qw(Net::Simplify::Domain);
262  
263 sub create {
264  
265 my ($class, $params, $auth) = @_;
266
267 $auth = Net::Simplify::SimplifyApi->get_authentication($auth);
268 my $result = Net::Simplify::SimplifyApi->send_api_request("plan", 'create', $params, $auth);
269  
270 $class->SUPER::new($result, $auth);
271 }
272  
273 sub delete {
274  
275 my ($self) = @_;
276  
277 my $auth = Net::Simplify::SimplifyApi->get_authentication($self->{_authentication});
278  
279 my $id = $self->{id};
280 $self->merge(Net::Simplify::SimplifyApi->send_api_request("plan", 'delete', {id => $id}, $auth));
281 }
282  
283 sub list {
284 my ($class, $criteria, $auth) = @_;
285
286 $auth = Net::Simplify::SimplifyApi->get_authentication($auth);
287 my $result = Net::Simplify::SimplifyApi->send_api_request("plan", 'list', $criteria, $auth);
288  
289 Net::Simplify::DomainList->new($result, $class, $auth);
290 }
291  
292 sub find {
293 my ($class, $id, $auth) = @_;
294  
295 $auth = Net::Simplify::SimplifyApi->get_authentication($auth);
296 my $result = Net::Simplify::SimplifyApi->send_api_request("plan", 'find', { id => $id }, $auth);
297  
298 $class->SUPER::new($result, $auth);
299 }
300  
301 sub update {
302  
303 my ($self) = @_;
304  
305 my $auth = Net::Simplify::SimplifyApi->get_authentication($self->{_authentication});
306 my $params = { %$self };
307 delete $params->{_authentication};
308  
309 $self->merge(Net::Simplify::SimplifyApi->send_api_request("plan", 'update', $params, $auth));
310 }
311  
312  
313 1;