MWS/XML/Response/OrderReport.pm

filter: Statementstmt 42.4% 45 / 106 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 39.2% 11 / 28 Podpod 100% 7 / 7 totaltotal 37.5% 63 / 168 CC 18 SCAR 21.7
CC
18
Cov
34%
_build_currency
30.0
_build_shipping_address
12.0
_build_billing_address
12.0
CRAP 8.7
« MWS/XML/ShippedOrder.pm ↑ Summary MWS/XML/GenericFeed.pm »
1 package Amazon::MWS::XML::Response::OrderReport;
2  
3 6 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use DateTime::Format::ISO8601;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Amazon::MWS::XML::Response::OrderReport::Item;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use Amazon::MWS::XML::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use MooX::Types::MooseLike::Base qw(HashRef ArrayRef Str Int);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 =head1 NAME
16  
17 Amazon::MWS::XML::Response::OrderReport
18  
19 =head1 DESCRIPTION
20  
21 Class to handle the xml structures returned by the C<GetReport> with type
22 C<OrderReport>.
23  
24 The constructor is meant to be called by L<Amazon::MWS::Uploader> when
25 C<get_order_reports> is called. A list of objects of this class will be
26 returned.
27  
28 =head1 SYNOPSIS
29  
30 my $order = Amazon::MWS::XML::Response::OrderReport->new(struct => $struct);
31 my @items = $order->items;
32  
33 =head1 ACCESSORS
34  
35 =head2 struct
36  
37 Mandatory. Must be an hashref.
38  
39 =head2 order_number
40  
41 Our order ID. Read-write.
42  
43 =head2 shipping_address
44  
45 An L<Amazon::MWS::XML::Address> instance, lazily built.
46  
47 =head2 billing_address
48  
49 An L<Amazon::MWS::XML::Address> instance, lazily built.
50  
51 =cut
52  
53 6 has struct => (is => 'ro', isa => HashRef, required => 1);
54 6 has order_number => (is => 'rw');
55 6 has shipping_address => (is => 'lazy');
56 6 has billing_address => (is => 'lazy');
57  
58 0 ▶sub _build_shipping_address {
Subroutine _build_shipping_address: not called CC=3 SCAR=24.8
59 0 my $self = shift;
60 0 ▶ if (my $data = $self->struct->{FulfillmentData}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = $self->struct->{"FulfillmentData"}) 0 0 0
61 # unclear if we want to check the FulfillmentMethod
62 0 ▶ if (my $address = $data->{Address}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $address = $data->{"Address"}) 0 0 0
63 0 return Amazon::MWS::XML::Address->new(%$address);
64 }
65 }
66 0 return undef;
67 }
68  
69 0 ▶sub _build_billing_address {
Subroutine _build_billing_address: not called CC=3 SCAR=24.8
70 0 my $self = shift;
71 0 ▶ if (my $data = $self->struct->{BillingData}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = $self->struct->{"BillingData"}) 0 0 0
72 0 ▶ if (my $address = $data->{Address}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $address = $data->{"Address"}) 0 0 0
73 0 return Amazon::MWS::XML::Address->new(%$address);
74 }
75 }
76 0 return undef;
77 }
78  
79 6 has _items_ref => (is => 'lazy');
80  
81 0 ▶sub _build__items_ref {
Subroutine _build__items_ref: not called CC=3 SCAR=24.8
82 0 my $self = shift;
83 0 my @items;
84 0 ▶ if (my $list = $self->struct->{Item}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $list = $self->struct->{"Item"}) 0 0 0
85 0 foreach my $item (@$list) {
86 0 my $obj = Amazon::MWS::XML::Response::OrderReport::Item->new(%$item);
87 0 push @items, $obj;
88 }
89 }
90 0 return \@items;
91 }
92  
93 =head1 METHODS
94  
95 =head2 amazon_order_number
96  
97 =head2 email
98  
99 The buyer email.
100  
101 =head2 order_date
102  
103 The date when the order processing was complete or when the order was
104 placed as a L<DateTime> object.
105  
106 =head2 items
107  
108 Return a list of L<Amazon::MWS::XML::Response::OrderReport::Item>,
109 which acts (more or less) like L<Amazon::MWS::XML::OrderlineItem>.
110  
111 =cut
112  
113 0 ▶sub amazon_order_number {
Subroutine amazon_order_number: not called CC=1 SCAR=6.9
Pod documented
114 0 return shift->struct->{AmazonOrderID};
115 }
116  
117 0 ▶sub email {
Subroutine email: not called CC=3 SCAR=24.8
Pod documented
118 0 my $self = shift;
119 0 ▶ if (my $billing = $self->struct->{BillingData}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $billing = $self->struct->{"BillingData"}) 0 0 0
120 0 ▶ if (exists $billing->{BuyerEmailAddress}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $billing->{"BuyerEmailAddress"}) 0 0 0
121 0 return $billing->{BuyerEmailAddress};
122 }
123 };
124 0 return;
125 }
126  
127  
128 # OrderDate The date the order was placed
129 # OrderPostedDate The date the buyer's credit card was charged and order processing was completed
130  
131 0 ▶sub order_date {
Subroutine order_date: not called CC=2 SCAR=17.9
Pod documented
132 0 my $self = shift;
133 0 my $struct = $self->struct;
134 # maybe this would need a different method, but we don't know what
135 # to do with it anyway.
136 0 ▶ my $date = $struct->{OrderPostedDate} || $struct->{OrderDate};
Condition0%0/3
$struct->{'OrderPostedDate'} || $struct->{'OrderDate'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$struct->{'OrderPostedDate'} || $struct->{'OrderDate'}
$struct->{'OrderPostedDate'} $struct->{'OrderDate'}
Truth table0%0/3
A || B
A= $struct->{'OrderPostedDate'}B= $struct->{'OrderDate'}
ABresult
1X1
011
000
137 0 return DateTime::Format::ISO8601->parse_datetime($date);
138 }
139  
140 0 ▶sub items {
Subroutine items: not called CC=1 SCAR=6.9
Pod documented
141 0 return @{ shift->_items_ref };
142 }
143  
144 =head2 as_ack_order_hashref
145  
146 Return a structure suitable create an the acknowledge feed.
147  
148 =cut
149  
150 0 ▶sub as_ack_order_hashref {
Subroutine as_ack_order_hashref: not called CC=2 SCAR=17.9
Pod documented
151 0 my $self = shift;
152 0 my @items;
153 0 foreach my $item ($self->items) {
154 0 push @items, $item->as_ack_orderline_item_hashref;
155 }
156 return {
157 0 AmazonOrderID => $self->amazon_order_number,
158 MerchantOrderID => $self->order_number,
159 Item => \@items,
160 };
161 }
162  
163 =head2 can_be_imported
164  
165 Compatibility method with L<Amazon::MWS::XML::Order>. Given that this
166 is a report, the order can be imported right away without checking.
167 LFW.
168  
169 =head2 order_status
170  
171 Compatibility method.
172  
173 =cut
174  
175 0 ▶sub can_be_imported {
Subroutine can_be_imported: not called CC=1 SCAR=6.9
Pod documented
176 # why not?
177 0 return 1;
178 }
179  
180 0 ▶sub order_status {
Subroutine order_status: not called CC=1 SCAR=6.9
Pod documented
181 0 return 'Report';
182 }
183  
184 =head2 currency
185  
186 We check the items currency.
187  
188 =head2 shipping_cost
189  
190 The sum of the shipping of all the items (including taxes from the
191 Amazon point of view).
192  
193 =head2 subtotal
194  
195 The sum of the items' subtotal
196  
197 =head2 total_cost
198  
199 The grand total
200  
201 =head2 total_amazon_fee
202  
203 The total of the amazon fees.
204  
205 =head2 number_of_items
206  
207 Total number of items.
208  
209 =cut
210  
211 6 has currency => (is => 'lazy', isa => Str);
212  
213 0 ▶sub _build_currency {
Subroutine _build_currency: not called CC=5 SCAR=34.0
214 0 my $self = shift;
215 0 my $currency;
216 0 foreach my $item ($self->items) {
217 0 my $item_currency = $item->currency;
218 0 ▶ die "Missign currency on item?" . Dumper($item) unless $item_currency;
Branch: 1 branch
BranchTrueFalseTotal
unless $item_currency 0 0 0
219 0 ▶ if ($currency) {
Branch: 1 branch
BranchTrueFalseTotal
if ($currency) { } 0 0 0
220 0 ▶ if ($currency ne $item_currency) {
Branch: 1 branch
BranchTrueFalseTotal
if ($currency ne $item_currency) 0 0 0
221 0 die "Currency mismatch in the same order, should happen" . Dumper($self);
222 }
223 }
224 else {
225 0 $currency = $item_currency;
226 }
227 }
228 0 return $currency;
229 }
230  
231 6 has shipping_cost => (is => 'lazy', isa => Str);
232  
233 0 ▶sub _build_shipping_cost {
Subroutine _build_shipping_cost: not called CC=1 SCAR=6.9
234 0 return shift->_calc_sum_item_method('shipping');
235 }
236  
237 6 has subtotal => (is => 'lazy', isa => Str);
238  
239 0 ▶sub _build_subtotal {
Subroutine _build_subtotal: not called CC=1 SCAR=6.9
240 0 return shift->_calc_sum_item_method('subtotal');
241 }
242  
243 6 has total_cost => (is => 'lazy', isa => Str);
244  
245 0 ▶sub _build_total_cost {
Subroutine _build_total_cost: not called CC=1 SCAR=6.9
246 0 return shift->_calc_sum_item_method('total_price');
247 }
248  
249 6 has total_amazon_fee => (is => 'lazy', isa => Str);
250  
251 0 ▶sub _build_total_amazon_fee {
Subroutine _build_total_amazon_fee: not called CC=1 SCAR=6.9
252 0 return shift->_calc_sum_item_method('amazon_fee');
253 }
254  
255 0 ▶sub _calc_sum_item_method {
Subroutine _calc_sum_item_method: not called CC=3 SCAR=24.8
256 0 my ($self, $method) = @_;
257 0 ▶ die unless $method;
Branch: 1 branch
BranchTrueFalseTotal
unless $method 0 0 0
258 0 my $cost = 0;
259 0 foreach my $item ($self->items) {
260 0 $cost += $item->$method;
261 }
262 0 return sprintf ('%.2f', $cost);
263 }
264  
265 6 has number_of_items => (is => 'lazy', isa => Int);
266  
267 0 ▶sub _build_number_of_items {
Subroutine _build_number_of_items: not called CC=2 SCAR=17.9
268 0 my $self = shift;
269 0 my $count = 0;
270 0 foreach my $item ($self->items) {
271 0 $count += $item->quantity;
272 }
273 0 return $count;
274 }
275  
276 6 1;
« MWS/XML/ShippedOrder.pm ↑ Summary MWS/XML/GenericFeed.pm »