File Coverage

blib/lib/Business/cXML/Amount.pm
Criterion Covered Total %
statement 48 48 100.0
branch 24 24 100.0
condition 12 12 100.0
subroutine 10 10 100.0
pod 2 2 100.0
total 96 96 100.0


line stmt bran cond sub pod time code
1             =encoding utf-8
2              
3             =head1 NAME
4              
5             Business::cXML::Amount - cXML amounts
6              
7             =head1 SYNOPSIS
8              
9             use Business::cXML::Amount;
10             my $charge = new Business::cXML::Amount 'Charge' {
11             currency => 'CAD',
12             amount => '17.99',
13             };
14              
15             =head1 DESCRIPTION
16              
17             Object representation of the common cXML amounts:
18              
19             =over
20              
21             C<AdditionalCost>
22             C<AvailablePrice>
23             C<Charge>
24             C<DeductedPrice>
25             C<DeductionAmount>
26             C<DepositAmount>
27             C<DiscountAmount>
28             C<DiscountBasis>
29             C<DueAmount>
30             C<ExactAmount>
31             C<ExpectedLimit>
32             C<Fee>
33             C<FeeAmount>
34             C<FixedAmount>
35             C<GoodsAndServiceAmount>
36             C<GrossAmount>
37             C<GrossProgressPaymentAmount>
38             C<InformationalAmount>
39             C<InformationalPrice>
40             C<InformationalPriceExclTax>
41             C<MaxAmount>
42             C<MaxReleaseAmount>
43             C<MinAmount>
44             C<MinReleaseAMount>
45             C<NetAmount>
46             C<OriginalPrice>
47             C<OverallLimit>
48             C<PartialAmount>
49             C<Penalty>
50             C<Shipping>
51             C<ShippingAmount>
52             C<SpecialHandlingAmount>
53             C<SubtotalAmount>
54             C<Tax>
55             C<TaxableAmount>
56             C<TaxAdjustment>
57             C<TaxAdjustmentDetail>
58             C<TaxAmount>
59             C<TotalAllowances>
60             C<TotalAmountInBillingCurrency>
61             C<TotalAmountInPostedCurrency>
62             C<TotalAmountWithoutTax>
63             C<TotalCharges>
64             C<TotalRetailAmount>
65             C<TotalReturnableItemsDepositAmount>
66             C<UnitGrossPrice>
67             C<UnitNetPriceCorrection>
68              
69             =back
70              
71             Not all variations allow the same attributes, but since they overwhelmingly
72             share the same basic function and structure, they were grouped into a single
73             object.
74              
75             Specifically B<NOT> implemented are:
76              
77             =over
78              
79             =item * C<Distribution> sub-section
80              
81             =item * C<Modifications> sub-section
82              
83             =item * C<PriceBasisQuantity> sub-section
84              
85             =item * C<AdditionalCost> with a C<Percentage> sub-section (only its C<Money> is implemented)
86              
87             =back
88              
89             =head1 METHODS
90              
91             See L<Business::cXML::Object/COMMON METHODS>.
92              
93             =head1 PROPERTY METHODS
94              
95             See L<Business::cXML::Object/PROPERTY METHODS> for how the following operate.
96              
97             =over
98              
99             =cut
100              
101 3     3   158984 use 5.014;
  3         24  
102 3     3   17 use strict;
  3         5  
  3         97  
103              
104             use base qw(Business::cXML::Object);
105 3     3   13  
  3         5  
  3         541  
106             use Business::cXML::Amount::TaxDetail;
107 3     3   1309 use XML::LibXML::Ferry;
  3         13  
  3         71  
108 3     3   16  
  3         5  
  3         52  
109             use constant NODENAME => 'Amount';
110 3     3   11 use constant PROPERTIES => (
  3         6  
  3         191  
111 3         191 currency => 'USD',
112             amount => '0.00',
113             description => undef,
114             type => undef,
115             fees => [],
116             tracking_domain => undef,
117             tracking_id => undef,
118             tax_details => [],
119             taxadj_details => [],
120             category => '',
121             region => undef,
122             );
123 3     3   13 use constant OBJ_PROPERTIES => (
  3         6  
124 3         1624 fees => [ 'Business::cXML::Amount', 'Fee' ],
125             tax_details => 'Business::cXML::Amount::TaxDetail',
126             taxadj_details => [ 'Business::cXML::Amount', 'TaxAdjustmentDetail' ],
127             description => 'Business::cXML::Description',
128             );
129 3     3   15  
  3         7  
130             my ($self, $el) = @_;
131              
132 28     28 1 75 $el->ferry($self, {
133             trackingDomain => 'tracking_domain',
134 28         381 trackingId => 'tracking_id',
135             tracking => '__OBSOLETE',
136             Money => { __text => 'amount' },
137             Fee => [ 'fees', 'Business::cXML::Amount'],
138             Percentage => '__UNIMPLEMENTED',
139             PriceBasisQuantity => '__UNIMPLEMENTED',
140             TaxDetail => [ 'tax_details', 'Business::cXML::Amount::TaxDetail' ],
141             TaxAdjustmentDetail => [ 'taxadj_details', 'Business::cXML::Amount' ],
142             Description => [ 'description', 'Business::cXML::Description' ],
143             Distribution => '__UNIMPLEMENTED',
144             Modifications => '__UNIMPLEMENTED',
145             });
146             }
147              
148             my ($self, $doc) = @_;
149             my $node = $doc->create($self->{_nodeName});
150              
151 42     42 1 132 $self->{type} = 'other' if $self->{_nodeName} eq 'AvailablePrice' && !defined $self->{type};
152 42         165 $node->{type} = $self->{type} if defined $self->{type} && $self->{_nodeName} =~ /^(AvailablePrice|Fee|OriginalPrice)$/;
153             if ($self->{_nodeName} eq 'TaxAdjustmentDetail') {
154 42 100 100     661 $node->{category} = $self->{category};
155 42 100 100     150 $node->{region} = $self->{region} if defined $self->{region};
156 42 100       227 };
157 2         7  
158 2 100       113 if ($self->{_nodeName} eq 'Shipping') {
159             $node->{trackingDomain} = $self->{tracking_domain} if defined $self->{tracking_domain};
160             $node->{trackingId} = $self->{tracking_id} if defined $self->{tracking_id};
161 42 100       134 };
162 4 100       15  
163 4 100       79 $node->add('Money', $self->{amount}, currency => $self->{currency});
164              
165             if ($self->{_nodeName} eq 'FeeAmount') {
166 42         180 $node->add($_->to_node($node)) foreach (@{ $self->{fees} });
167             };
168 42 100       2397  
169 1         2 $self->description({}) if !defined($self->{description}) && $self->{_nodeName} =~ /^(Penalty|Shipping|Tax)$/;
  1         4  
170             $node->add($self->{description}->to_node($node))
171             if defined $self->{description}
172 42 100 100     266 && $self->{_nodeName} =~ /^(AvailablePrice|Penalty|Shipping|SpecialHandlingAmount|Tax)$/
173             ;
174              
175 42 100 100     229 if ($self->{_nodeName} eq 'Tax') {
176             $node->add($_->to_node($node)) foreach (@{ $self->{tax_details} });
177             };
178 42 100       268 if ($self->{_nodeName} eq 'TaxAdjustment') {
179 5         53 $node->add($_->to_node($node)) foreach (@{ $self->{taxadj_details} });
  5         22  
180             };
181 42 100       194  
182 2         8 return $node;
  2         9  
183             }
184              
185 42         199 =item C<B<currency>>
186              
187             Mandatory, i.e. C<USD> (default)
188              
189             =item C<B<amount>>
190              
191             Mandatory, i.e C<0.0> (default). Use a string if you want control over formatting.
192              
193             =back
194              
195             =head3 C<AvailablePrice>, C<Penalty>, C<Shipping>, C<SpecialHandlingAmount>, C<Tax> add:
196              
197             =over
198              
199             =item C<B<description>>
200              
201             Optional, L<Business::cXML::Description> object
202              
203             =back
204              
205             =head3 C<AvailablePrice>, C<Fee>, C<OriginalPrice> add:
206              
207             =over
208              
209             =item C<B<type>>
210              
211             Optional. For C<AvailablePrice>, it is expected to be one of: C<lowest>,
212             C<lowestCompliant>, C<highestCompliant>, C<highest>, C<other> (default)
213              
214             =back
215              
216             =head3 C<FeeAmount> adds:
217              
218             =over
219              
220             =item C<B<fees>[]>
221              
222             Optional, L<Business::cXML::Amount> objects of C<Fee> type
223              
224             =back
225              
226             =head3 C<Shipping> adds:
227              
228             =over
229              
230             =item C<B<tracking_domain>>
231              
232             Optional, logistics supplier, i.e. C<FedEx>, C<UPS>
233              
234             =item C<B<tracking_id>>
235              
236             Optional, logistics supplier tracking number
237              
238             =back
239              
240             =head3 C<Tax> adds:
241              
242             =over
243              
244             =item C<B<tax_details>[]>
245              
246             Optional, L</Business::cXML::Amount::TaxDetail> objects
247              
248             =back
249              
250             =head3 C<TaxAdjustment> adds:
251              
252             =over
253              
254             =item C<B<taxadj_details>[]>
255              
256             Optional, L<Business::cXML::Amount> objects named C<TaxAdjustmentDetail>
257              
258             =back
259              
260             =head3 C<TaxAdjustmentDetail> adds:
261              
262             =over
263              
264             =item C<B<category>>
265              
266             Mandatory
267              
268             =item C<B<region>>
269              
270             Optional
271              
272             =back
273              
274             =head1 AUTHOR
275              
276             Stéphane Lavergne L<https://github.com/vphantom>
277              
278             =head1 ACKNOWLEDGEMENTS
279              
280             Graph X Design Inc. L<https://www.gxd.ca/> sponsored this project.
281              
282             =head1 COPYRIGHT & LICENSE
283              
284             Copyright (c) 2017-2018 Stéphane Lavergne L<https://github.com/vphantom>
285              
286             Permission is hereby granted, free of charge, to any person obtaining a copy
287             of this software and associated documentation files (the "Software"), to deal
288             in the Software without restriction, including without limitation the rights
289             to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
290             copies of the Software, and to permit persons to whom the Software is
291             furnished to do so, subject to the following conditions:
292              
293             The above copyright notice and this permission notice shall be included in all
294             copies or substantial portions of the Software.
295              
296             THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
297             IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
298             FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
299             AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
300             LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
301             OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
302             SOFTWARE.
303              
304             =cut
305              
306             1;