Simplify/Coupon.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::Coupon;
2  
3 =head1 NAME
4  
5 Net::Simplify::Coupon - A Simplify Commerce Coupon 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 Coupon.
16 my $coupon = Net::Simplify::Coupon->create{ {...});
17  
18 # Retrieve a Coupon given its ID.
19 my $coupon = Net::Simplify::Coupon->find('a7e41');
20  
21 # Update existing Coupon.
22 my $coupon = Net::Simplify::Coupon->find('a7e41');
23 $coupon->{PROPERTY} = "NEW VALUE";
24 $coupon->update();
25  
26 # Delete
27 my $coupon = Net::Simplify::Coupon->find('a7e41');
28 $coupon->delete();
29  
30 # Retrieve a list of objects
31 my $coupons = Net::Simplify::Coupon->list({max => 10});
32 foreach my $v ($coupons->list) {
33 # ...
34 }
35  
36 =head1 DESCRIPTION
37  
38 =head2 METHODS
39  
40 =head3 create(%params, $auth)
41  
42 Creates a C<Net::Simplify::Coupon> 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 amountOff
53  
54 Amount off of the price of the product in the smallest units of the currency of the merchant. While this field is optional, you must provide either amountOff or percentOff for a coupon. Example: 100 = $1.00 [min value: 1]
55  
56 =item couponCode
57  
58 Code that identifies the coupon to be used. [min length: 2] (B<required>)
59  
60 =item description
61  
62 A brief section that describes the coupon.
63  
64 =item durationInMonths
65  
66 DEPRECATED - Duration in months that the coupon will be applied after it has first been selected. [min value: 1, max value: 9999]
67  
68 =item endDate
69  
70 Last date of the coupon in UTC millis that the coupon can be applied to a subscription. This ends at 23:59:59 of the merchant timezone.
71  
72 =item maxRedemptions
73  
74 Maximum number of redemptions allowed for the coupon. A redemption is defined as when the coupon is applied to the subscription for the first time. [min value: 1]
75  
76 =item numTimesApplied
77  
78 The number of times a coupon will be applied on a customer's subscription. [min value: 1, max value: 9999]
79  
80 =item percentOff
81  
82 Percentage off of the price of the product. While this field is optional, you must provide either amountOff or percentOff for a coupon. The percent off is a whole number. [min value: 1, max value: 100]
83  
84 =item startDate
85  
86 First date of the coupon in UTC millis that the coupon can be applied to a subscription. This starts at midnight of the merchant timezone. (B<required>)
87  
88  
89 =back
90  
91 =item C<$auth>
92  
93 Authentication object for accessing the API. If no value is passed the global keys
94 C<$Net::Simplify::public_key> and C<$Net::Simplify::private_key> are used.
95  
96 =back
97  
98  
99  
100  
101 =head3 delete()
102  
103 Deletes the C<Net::Simplify::Coupon> object. Authentication is done using the same credentials used when the AccessToken was created.
104  
105  
106  
107 =head3 list(%criteria, $auth)
108  
109 Retrieve a list of C<Net::Simplify::Coupon> objects. The parameters are:
110  
111 =over 4
112  
113 =item C<%criteria>
114  
115 Hash map representing the criteria to limit the results of the list operation. Valid keys are:
116  
117 =over 4
118  
119 =item C<filter>
120  
121 <table class="filter_list"><tr><td>filter.id</td><td>Filter by the coupon Id</td></tr><tr><td>filter.text</td><td>Filter by the coupon code</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.startDateMin</td><td>Filter by the minimum coupon start date you are searching for - Date in UTC millis</td></tr><tr><td>filter.startDateMax</td><td>Filter by the maximum coupon start date you are searching for - Date in UTC millis</td></tr><tr><td>filter.endDateMin</td><td>Filter by the minimum coupon end date you are searching for - Date in UTC millis</td></tr><tr><td>filter.endDateMax</td><td>Filter by the maximum coupon end date you are searching for - Date in UTC millis</td></tr></table><br><sup>*</sup>Use dateCreatedMin with dateCreatedMax in the same filter if you want to search between two created dates
122  
123  
124  
125 =item C<max>
126  
127 Allows up to a max of 50 list items to return. [min value: 0, max value: 50, default: 20]
128  
129  
130  
131 =item C<offset>
132  
133 Used in paging of the list. This is the start offset of the page. [min value: 0, default: 0]
134  
135  
136  
137 =item C<sorting>
138  
139 Allows for ascending or descending sorting of the list.
140 The value maps properties to the sort direction (either C<asc> for ascending or C<desc> for descending). Sortable properties are:
141  
142 =over 4
143  
144 =item C<dateCreated>
145  
146 =item C<maxRedemptions>
147  
148 =item C<timesRedeemed>
149  
150 =item C<id>
151  
152 =item C<startDate>
153  
154 =item C<endDate>
155  
156 =item C<percentOff>
157  
158 =item C<couponCode>
159  
160 =item C<durationInMonths>
161  
162 =item C<numTimesApplied>
163  
164 =item C<amountOff>
165  
166  
167 =back
168  
169  
170  
171  
172 =back
173  
174 =back
175  
176  
177  
178 =head3 find($id, $auth)
179  
180 Retrieve a C<Net::Simplify::Coupon> object from the API. Parameters are:
181  
182 =over 4
183  
184 =item C<$id>
185  
186 Identifier of the object to retrieve.
187  
188 =item C<$auth>
189  
190 Authentication object for accessing the API. If no value is passed the global keys
191 C<$Net::Simplify::public_key> and C<$Net::Simplify::private_key> are used.
192  
193 =back
194  
195  
196  
197  
198 =head3 update()
199  
200 Update C<Net::Simplify::Coupon> object.
201 The properties that can be updated are:
202  
203 =over 4
204  
205  
206 =item C<endDate>
207  
208 The ending date in UTC millis for the coupon. This must be after the starting date of the coupon.
209  
210  
211 =item C<maxRedemptions>
212  
213 Maximum number of redemptions allowed for the coupon. A redemption is defined as when the coupon is applied to the subscription for the first time. [min value: 1]
214  
215 Authentication is done using the same credentials used when the AccessToken was created.
216  
217 =back
218  
219  
220  
221  
222 =head1 SEE ALSO
223  
224 L<Net::Simplify>,
225 L<Net::Simplify::Domain>,
226 L<Net::Simplify::DomainList>,
227 L<Net::Simplify::Authentication>,
228 L<Net::Simplify::ApiException>,
229 L<http://www.simplify.com>
230  
231 =head1 VERSION
232  
233 1.6.0
234  
235 =head1 LICENSE
236  
237 Copyright (c) 2013 - 2022 MasterCard International Incorporated
238 All rights reserved.
239  
240 Redistribution and use in source and binary forms, with or without modification, are
241 permitted provided that the following conditions are met:
242  
243 Redistributions of source code must retain the above copyright notice, this list of
244 conditions and the following disclaimer.
245 Redistributions in binary form must reproduce the above copyright notice, this list of
246 conditions and the following disclaimer in the documentation and/or other materials
247 provided with the distribution.
248 Neither the name of the MasterCard International Incorporated nor the names of its
249 contributors may be used to endorse or promote products derived from this software
250 without specific prior written permission.
251 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
252 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
253 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
254 SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
255 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
256 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
257 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
258 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
259 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
260 SUCH DAMAGE.
261  
262 =head1 SEE ALSO
263  
264 =cut
265  
266 use 5.006;
267 use strict;
268 use warnings FATAL => 'all';
269  
270 use Net::Simplify::Domain;
271 use Net::Simplify::DomainList;
272  
273 our @ISA = qw(Net::Simplify::Domain);
274  
275 sub create {
276  
277 my ($class, $params, $auth) = @_;
278
279 $auth = Net::Simplify::SimplifyApi->get_authentication($auth);
280 my $result = Net::Simplify::SimplifyApi->send_api_request("coupon", 'create', $params, $auth);
281  
282 $class->SUPER::new($result, $auth);
283 }
284  
285 sub delete {
286  
287 my ($self) = @_;
288  
289 my $auth = Net::Simplify::SimplifyApi->get_authentication($self->{_authentication});
290  
291 my $id = $self->{id};
292 $self->merge(Net::Simplify::SimplifyApi->send_api_request("coupon", 'delete', {id => $id}, $auth));
293 }
294  
295 sub list {
296 my ($class, $criteria, $auth) = @_;
297
298 $auth = Net::Simplify::SimplifyApi->get_authentication($auth);
299 my $result = Net::Simplify::SimplifyApi->send_api_request("coupon", 'list', $criteria, $auth);
300  
301 Net::Simplify::DomainList->new($result, $class, $auth);
302 }
303  
304 sub find {
305 my ($class, $id, $auth) = @_;
306  
307 $auth = Net::Simplify::SimplifyApi->get_authentication($auth);
308 my $result = Net::Simplify::SimplifyApi->send_api_request("coupon", 'find', { id => $id }, $auth);
309  
310 $class->SUPER::new($result, $auth);
311 }
312  
313 sub update {
314  
315 my ($self) = @_;
316  
317 my $auth = Net::Simplify::SimplifyApi->get_authentication($self->{_authentication});
318 my $params = { %$self };
319 delete $params->{_authentication};
320  
321 $self->merge(Net::Simplify::SimplifyApi->send_api_request("coupon", 'update', $params, $auth));
322 }
323  
324  
325 1;