Simplify/Invoice.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::Invoice;
2  
3 =head1 NAME
4  
5 Net::Simplify::Invoice - A Simplify Commerce Invoice 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 Invoice.
16 my $invoice = Net::Simplify::Invoice->create{ {...});
17  
18 # Retrieve a Invoice given its ID.
19 my $invoice = Net::Simplify::Invoice->find('a7e41');
20  
21 # Update existing Invoice.
22 my $invoice = Net::Simplify::Invoice->find('a7e41');
23 $invoice->{PROPERTY} = "NEW VALUE";
24 $invoice->update();
25  
26 # Delete
27 my $invoice = Net::Simplify::Invoice->find('a7e41');
28 $invoice->delete();
29  
30 # Retrieve a list of objects
31 my $invoices = Net::Simplify::Invoice->list({max => 10});
32 foreach my $v ($invoices->list) {
33 # ...
34 }
35  
36 =head1 DESCRIPTION
37  
38 =head2 METHODS
39  
40 =head3 create(%params, $auth)
41  
42 Creates a C<Net::Simplify::Invoice> 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  
53  
54 =item billingAddress.city
55  
56 Billing address city of the location where the goods or services were supplied. [max length: 255, min length: 2]
57  
58 =item billingAddress.country
59  
60 Billing address country of the location where the goods or services were supplied. [max length: 2, min length: 2]
61  
62 =item billingAddress.line1
63  
64 Billing address line 1 of the location where the goods or services were supplied. [max length: 255]
65  
66 =item billingAddress.line2
67  
68 Billing address line 2 of the location where the goods or services were supplied. [max length: 255]
69  
70 =item billingAddress.name
71  
72 Billing address name of the location where the goods or services were supplied. Will use the customer name if not provided. [max length: 255]
73  
74 =item billingAddress.state
75  
76 Billing address state of the location where the goods or services were supplied. [max length: 255]
77  
78 =item billingAddress.zip
79  
80 Billing address zip of the location where the goods or services were supplied. [max length: 32]
81  
82  
83  
84 =item businessAddress.city
85  
86 Address city of the business that is sending the invoice. [max length: 255, min length: 2]
87  
88 =item businessAddress.country
89  
90 Address country of the business that is sending the invoice. [max length: 2, min length: 2]
91  
92 =item businessAddress.line1
93  
94 Address line 1 of the business that is sending the invoice. [max length: 255]
95  
96 =item businessAddress.line2
97  
98 Address line 2 of the business that is sending the invoice. [max length: 255]
99  
100 =item businessAddress.name
101  
102 The name of the business that is sending the invoice. [max length: 255]
103  
104 =item businessAddress.state
105  
106 Address state of the business that is sending the invoice. [max length: 255]
107  
108 =item businessAddress.zip
109  
110 Address zip of the business that is sending the invoice. [max length: 32]
111  
112 =item currency
113  
114 Currency code (ISO-4217). Must match the currency associated with your account. [max length: 3, min length: 3]
115  
116 =item customer
117  
118 The customer ID of the customer we are invoicing. This is optional if invoiceToCopy or a name and email are provided
119  
120 =item customerTaxNo
121  
122 The tax number or VAT id of the person to whom the goods or services were supplied. [max length: 255]
123  
124 =item discountRate
125  
126 The discount percent as a decimal e.g. 12.5. This is used to calculate the discount amount which is subtracted from the total amount due before any tax is applied. [max length: 6]
127  
128 =item dueDate
129  
130 The date invoice payment is due. If a late fee is provided this will be added to the invoice total is the due date has past.
131  
132 =item email
133  
134 The email of the customer we are invoicing. This is optional if customer or invoiceToCopy is provided. A new customer will be created using the the name and email.
135  
136 =item invoiceId
137  
138 User defined invoice id. If not provided the system will generate a numeric id. [max length: 255]
139  
140 =item invoiceLanguage
141  
142 The language in which invoice will be displayed. [max length: 5, min length: 5]
143  
144 =item invoiceToCopy
145  
146 The id of an existing invoice to be copied. This is optional if customer or a name and email are provided
147  
148  
149  
150 =item items.amount
151  
152 Amount of the invoice item (the smallest unit of your currency). Example: 100 = $1.00 (B<required>)
153  
154 =item items.description
155  
156 The description of the invoice item. [max length: 1024]
157  
158 =item items.invoice
159  
160 The ID of the invoice this item belongs to.
161  
162 =item items.product
163  
164 The product this invoice item refers to.
165  
166 =item items.quantity
167  
168 Quantity of the item. This total amount of the invoice item is the amount * quantity. [min value: 1, max value: 999999, default: 1]
169  
170 =item items.reference
171  
172 User defined reference field. [max length: 255]
173  
174 =item items.tax
175  
176 The tax ID of the tax charge in the invoice item.
177  
178 =item lateFee
179  
180 The late fee amount that will be added to the invoice total is the due date is past due. Value provided must be in the smallest unit of your currency. Example: 100 = $1.00
181  
182 =item memo
183  
184 A memo that is displayed to the customer on the invoice payment screen. [max length: 4000]
185  
186 =item name
187  
188 The name of the customer we are invoicing. This is optional if customer or invoiceToCopy is provided. A new customer will be created using the the name and email. [max length: 50, min length: 2]
189  
190 =item note
191  
192 This field can be used to store a note that is not displayed to the customer. [max length: 4000]
193  
194 =item reference
195  
196 User defined reference field. [max length: 255]
197  
198  
199  
200 =item shippingAddress.city
201  
202 Address city of the location where the goods or services were supplied. [max length: 255, min length: 2]
203  
204 =item shippingAddress.country
205  
206 Address country of the location where the goods or services were supplied. [max length: 2, min length: 2]
207  
208 =item shippingAddress.line1
209  
210 Address line 1 of the location where the goods or services were supplied. [max length: 255]
211  
212 =item shippingAddress.line2
213  
214 Address line 2 of the location where the goods or services were supplied. [max length: 255]
215  
216 =item shippingAddress.name
217  
218 Address name of the location where the goods or services were supplied. [max length: 255]
219  
220 =item shippingAddress.state
221  
222 Address state of the location where the goods or services were supplied. [max length: 255]
223  
224 =item shippingAddress.zip
225  
226 Address zip of the location where the goods or services were supplied. [max length: 32]
227  
228 =item suppliedDate
229  
230 The date on which the goods or services were supplied.
231  
232 =item taxNo
233  
234 The tax number or VAT id of the person who supplied the goods or services. [max length: 255]
235  
236 =item type
237  
238 The type of invoice. One of WEB or MOBILE. [valid values: WEB, MOBILE, default: WEB]
239  
240  
241 =back
242  
243 =item C<$auth>
244  
245 Authentication object for accessing the API. If no value is passed the global keys
246 C<$Net::Simplify::public_key> and C<$Net::Simplify::private_key> are used.
247  
248 =back
249  
250  
251  
252  
253 =head3 delete()
254  
255 Deletes the C<Net::Simplify::Invoice> object. Authentication is done using the same credentials used when the AccessToken was created.
256  
257  
258  
259 =head3 list(%criteria, $auth)
260  
261 Retrieve a list of C<Net::Simplify::Invoice> objects. The parameters are:
262  
263 =over 4
264  
265 =item C<%criteria>
266  
267 Hash map representing the criteria to limit the results of the list operation. Valid keys are:
268  
269 =over 4
270  
271 =item C<filter>
272  
273 <table class="filter_list"><tr><td>filter.id</td><td>Filter by the invoice Id</td></tr><tr><td>filter.amount</td><td>Filter by the invoice amount (in the smallest unit of your currency)</td></tr><tr><td>filter.text</td><td>Filter by the name of the invoice</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.datePaidMin<sup>*</sup></td><td>Filter by the minimum invoice paid date you are searching for - Date in UTC millis</td></tr><tr><td>filter.datePaidMax<sup>*</sup></td><td>Filter by the maximum invoice paid date you are searching for - Date in UTC millis</td></tr><tr><td>filter.status</td><td>Filter by the status of the invoice</td></tr><tr><td>filter.statuses</td><td>Filter by multiple statuses of different invoices</td></tr><tr><td>filter.customer</td><td>Filter using the Id of the customer linked to the invoice</td></tr><tr><td>filter.type</td><td>Filter by the invoice type</td></tr><tr><td>filter.types</td><td>Filter by multiple invoice types</td></tr><tr><td>filter.invoiceId</td><td>Filter by the user defined invoice id</td></tr><tr><td>filter.reference</td><td>Filter by the invoice reference text</td></tr></table><br><sup>*</sup>The filters datePaidMin and datePaidMax can be used in the same filter if you want to search between the two dates. The same is for dateCreatedMin/dateCreatedMax.
274  
275  
276  
277 =item C<max>
278  
279 Allows up to a max of 50 list items to return. [min value: 0, max value: 50, default: 20]
280  
281  
282  
283 =item C<offset>
284  
285 Used in paging of the list. This is the start offset of the page. [min value: 0, default: 0]
286  
287  
288  
289 =item C<sorting>
290  
291 Allows for ascending or descending sorting of the list.
292 The value maps properties to the sort direction (either C<asc> for ascending or C<desc> for descending). Sortable properties are:
293  
294 =over 4
295  
296 =item C<id>
297  
298 =item C<invoiceDate>
299  
300 =item C<dueDate>
301  
302 =item C<datePaid>
303  
304 =item C<customer>
305  
306 =item C<status>
307  
308 =item C<dateCreated>
309  
310  
311 =back
312  
313  
314  
315  
316 =back
317  
318 =back
319  
320  
321  
322 =head3 find($id, $auth)
323  
324 Retrieve a C<Net::Simplify::Invoice> object from the API. Parameters are:
325  
326 =over 4
327  
328 =item C<$id>
329  
330 Identifier of the object to retrieve.
331  
332 =item C<$auth>
333  
334 Authentication object for accessing the API. If no value is passed the global keys
335 C<$Net::Simplify::public_key> and C<$Net::Simplify::private_key> are used.
336  
337 =back
338  
339  
340  
341  
342 =head3 update()
343  
344 Update C<Net::Simplify::Invoice> object.
345 The properties that can be updated are:
346  
347 =over 4
348  
349  
350 =item C<billingAddress.city>
351  
352 Billing address city of the location where the goods or services were supplied. [max length: 255, min length: 2]
353  
354 =item C<billingAddress.country>
355  
356 Billing address country of the location where the goods or services were supplied. [max length: 2, min length: 2]
357  
358 =item C<billingAddress.line1>
359  
360 Billing address line 1 of the location where the goods or services were supplied. [max length: 255]
361  
362 =item C<billingAddress.line2>
363  
364 Billing address line 2 of the location where the goods or services were supplied. [max length: 255]
365  
366 =item C<billingAddress.name>
367  
368 Billing address name of the location where the goods or services were supplied. [max length: 255]
369  
370 =item C<billingAddress.state>
371  
372 Billing address state of the location where the goods or services were supplied. [max length: 255]
373  
374 =item C<billingAddress.zip>
375  
376 Billing address zip of the location where the goods or services were supplied. [max length: 32]
377  
378 =item C<businessAddress.city>
379  
380 Business address city of the business that is sending the invoice. [max length: 255, min length: 2]
381  
382 =item C<businessAddress.country>
383  
384 Business address country of the business that is sending the invoice. [max length: 2, min length: 2]
385  
386 =item C<businessAddress.line1>
387  
388 Business address line 1 of the business that is sending the invoice. [max length: 255]
389  
390 =item C<businessAddress.line2>
391  
392 Business address line 2 of the business that is sending the invoice. [max length: 255]
393  
394 =item C<businessAddress.name>
395  
396 Business address name of the business that is sending the invoice. [max length: 255]
397  
398 =item C<businessAddress.state>
399  
400 Business address state of the business that is sending the invoice. [max length: 255]
401  
402 =item C<businessAddress.zip>
403  
404 Business address zip of the business that is sending the invoice. [max length: 32]
405  
406 =item C<currency>
407  
408 Currency code (ISO-4217). Must match the currency associated with your account. [max length: 3, min length: 3]
409  
410 =item C<customerTaxNo>
411  
412 The tax number or VAT id of the person to whom the goods or services were supplied. [max length: 255]
413  
414 =item C<datePaid>
415  
416 This is the date the invoice was PAID in UTC millis.
417  
418 =item C<discountRate>
419  
420 The discount percent as a decimal e.g. 12.5. This is used to calculate the discount amount which is subtracted from the total amount due before any tax is applied. [max length: 6]
421  
422 =item C<dueDate>
423  
424 The date invoice payment is due. If a late fee is provided this will be added to the invoice total is the due date has past.
425  
426 =item C<email>
427  
428 The email of the customer we are invoicing. This is optional if customer or invoiceToCopy is provided. A new customer will be created using the the name and email.
429  
430  
431 =item C<invoiceId>
432  
433 User defined invoice id. If not provided the system will generate a numeric id. [max length: 255]
434  
435 =item C<invoiceLanguage>
436  
437 The language in which invoice will be displayed. [max length: 5, min length: 5]
438  
439 =item C<items.amount>
440  
441 Amount of the invoice item in the smallest unit of your currency. Example: 100 = $1.00 (B<required>)
442  
443 =item C<items.description>
444  
445 The description of the invoice item. [max length: 1024]
446  
447 =item C<items.invoice>
448  
449 The ID of the invoice this item belongs to.
450  
451 =item C<items.product>
452  
453 The Id of the product this item refers to.
454  
455 =item C<items.quantity>
456  
457 Quantity of the item. This total amount of the invoice item is the amount * quantity. [min value: 1, max value: 999999, default: 1]
458  
459 =item C<items.reference>
460  
461 User defined reference field. [max length: 255]
462  
463 =item C<items.tax>
464  
465 The tax ID of the tax charge in the invoice item.
466  
467 =item C<lateFee>
468  
469 The late fee amount that will be added to the invoice total is the due date is past due. Value provided must be in the smallest unit of your currency. Example: 100 = $1.00
470  
471 =item C<memo>
472  
473 A memo that is displayed to the customer on the invoice payment screen. [max length: 4000]
474  
475 =item C<name>
476  
477 The name of the customer we are invoicing. This is optional if customer or invoiceToCopy is provided. A new customer will be created using the the name and email. [max length: 50, min length: 2]
478  
479 =item C<note>
480  
481 This field can be used to store a note that is not displayed to the customer. [max length: 4000]
482  
483 =item C<payment>
484  
485 The ID of the payment. Use this ID to query the /payment API. [max length: 255]
486  
487 =item C<reference>
488  
489 User defined reference field. [max length: 255]
490  
491 =item C<sendMail>
492  
493 Boolean flag. If true the invoice will be sent to the customer if the invoice is in an OPEN state. [default: false] (B<required>)
494  
495 =item C<shippingAddress.city>
496  
497 Address city of the location where the goods or services were supplied. [max length: 255, min length: 2]
498  
499 =item C<shippingAddress.country>
500  
501 Address country of the location where the goods or services were supplied. [max length: 2, min length: 2]
502  
503 =item C<shippingAddress.line1>
504  
505 Address line 1 of the location where the goods or services were supplied. [max length: 255]
506  
507 =item C<shippingAddress.line2>
508  
509 Address line 2 of the location where the goods or services were supplied. [max length: 255]
510  
511 =item C<shippingAddress.name>
512  
513 Address name of the location where the goods or services were supplied. [max length: 255]
514  
515 =item C<shippingAddress.state>
516  
517 Address state of the location where the goods or services were supplied. [max length: 255]
518  
519 =item C<shippingAddress.zip>
520  
521 Address zip of the location where the goods or services were supplied. [max length: 32]
522  
523 =item C<status>
524  
525 New status of the invoice.
526  
527 =item C<suppliedDate>
528  
529 The date on which the goods or services were supplied.
530  
531 =item C<taxNo>
532  
533 The tax number or VAT id of the person who supplied the goods or services. [max length: 255]
534  
535 Authentication is done using the same credentials used when the AccessToken was created.
536  
537 =back
538  
539  
540  
541  
542 =head1 SEE ALSO
543  
544 L<Net::Simplify>,
545 L<Net::Simplify::Domain>,
546 L<Net::Simplify::DomainList>,
547 L<Net::Simplify::Authentication>,
548 L<Net::Simplify::ApiException>,
549 L<http://www.simplify.com>
550  
551 =head1 VERSION
552  
553 1.6.0
554  
555 =head1 LICENSE
556  
557 Copyright (c) 2013 - 2022 MasterCard International Incorporated
558 All rights reserved.
559  
560 Redistribution and use in source and binary forms, with or without modification, are
561 permitted provided that the following conditions are met:
562  
563 Redistributions of source code must retain the above copyright notice, this list of
564 conditions and the following disclaimer.
565 Redistributions in binary form must reproduce the above copyright notice, this list of
566 conditions and the following disclaimer in the documentation and/or other materials
567 provided with the distribution.
568 Neither the name of the MasterCard International Incorporated nor the names of its
569 contributors may be used to endorse or promote products derived from this software
570 without specific prior written permission.
571 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
572 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
573 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
574 SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
575 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
576 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
577 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
578 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
579 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
580 SUCH DAMAGE.
581  
582 =head1 SEE ALSO
583  
584 =cut
585  
586 use 5.006;
587 use strict;
588 use warnings FATAL => 'all';
589  
590 use Net::Simplify::Domain;
591 use Net::Simplify::DomainList;
592  
593 our @ISA = qw(Net::Simplify::Domain);
594  
595 sub create {
596  
597 my ($class, $params, $auth) = @_;
598
599 $auth = Net::Simplify::SimplifyApi->get_authentication($auth);
600 my $result = Net::Simplify::SimplifyApi->send_api_request("invoice", 'create', $params, $auth);
601  
602 $class->SUPER::new($result, $auth);
603 }
604  
605 sub delete {
606  
607 my ($self) = @_;
608  
609 my $auth = Net::Simplify::SimplifyApi->get_authentication($self->{_authentication});
610  
611 my $id = $self->{id};
612 $self->merge(Net::Simplify::SimplifyApi->send_api_request("invoice", 'delete', {id => $id}, $auth));
613 }
614  
615 sub list {
616 my ($class, $criteria, $auth) = @_;
617
618 $auth = Net::Simplify::SimplifyApi->get_authentication($auth);
619 my $result = Net::Simplify::SimplifyApi->send_api_request("invoice", 'list', $criteria, $auth);
620  
621 Net::Simplify::DomainList->new($result, $class, $auth);
622 }
623  
624 sub find {
625 my ($class, $id, $auth) = @_;
626  
627 $auth = Net::Simplify::SimplifyApi->get_authentication($auth);
628 my $result = Net::Simplify::SimplifyApi->send_api_request("invoice", 'find', { id => $id }, $auth);
629  
630 $class->SUPER::new($result, $auth);
631 }
632  
633 sub update {
634  
635 my ($self) = @_;
636  
637 my $auth = Net::Simplify::SimplifyApi->get_authentication($self->{_authentication});
638 my $params = { %$self };
639 delete $params->{_authentication};
640  
641 $self->merge(Net::Simplify::SimplifyApi->send_api_request("invoice", 'update', $params, $auth));
642 }
643  
644  
645 1;