has
order
=> (
is
=>
'rw'
,
required
=> 1,
isa
=> HashRef);
has
orderline
=> (
is
=>
'lazy'
,
isa
=> ArrayRef);
has
retrieve_orderline_sub
=> (
is
=>
'ro'
,
isa
=> CodeRef);
sub
_build_orderline {
my
$self
=
shift
;
my
$sub
=
$self
->retrieve_orderline_sub;
die
"Missing retrieve_orderline_sub"
unless
$sub
;
return
$sub
->();
}
has
order_number
=> (
is
=>
'rw'
);
sub
amazon_order_number {
return
shift
->order->{AmazonOrderId};
}
sub
remote_shop_order_id {
return
shift
->amazon_order_number;
}
sub
email {
return
shift
->order->{BuyerEmail};
}
has
shipping_address
=> (
is
=>
'lazy'
);
sub
_build_shipping_address {
my
$self
=
shift
;
my
$address
=
$self
->order->{ShippingAddress};
return
Amazon::MWS::XML::Address->new(
%$address
);
}
has
first_name
=> (
is
=>
'lazy'
);
sub
_build_first_name {
my
$self
=
shift
;
my
(
$first
,
$last
) =
$self
->_get_first_last_name;
return
$first
||
''
;
}
has
last_name
=> (
is
=>
'lazy'
);
sub
_build_last_name {
my
$self
=
shift
;
my
(
$first
,
$last
) =
$self
->_get_first_last_name;
return
$last
||
''
;
}
sub
_get_first_last_name {
my
$self
=
shift
;
my
$address
=
$self
->shipping_address;
die
"Missing name in shipping address"
unless
$address
->name;
my
(
$first_name
,
$last_name
) =
split
(/\s+/,
$address
->name, 2);
return
(
$first_name
,
$last_name
);
}
has
items_ref
=> (
is
=>
'lazy'
);
sub
_build_items_ref {
my
(
$self
) =
@_
;
my
$orderline
=
$self
->orderline;
my
@items
;
foreach
my
$item
(
@$orderline
) {
push
@items
, Amazon::MWS::XML::OrderlineItem->new(
%$item
);
}
return
\
@items
;
}
sub
items {
my
$self
=
shift
;
return
@{
$self
->items_ref };
}
sub
order_date {
my
(
$self
) =
@_
;
return
$self
->_get_dt(
$self
->order->{PurchaseDate});
}
sub
_get_dt {
my
(
$self
,
$date
) =
@_
;
return
DateTime::Format::ISO8601->parse_datetime(
$date
);
}
sub
shipping_cost {
my
$self
=
shift
;
my
@items
=
$self
->items;
my
$shipping
= 0;
foreach
my
$i
(
@items
) {
$shipping
+=
$i
->shipping;
}
return
sprintf
(
'%.2f'
,
$shipping
);
}
sub
subtotal {
my
$self
=
shift
;
my
@items
=
$self
->items;
my
$total
= 0;
foreach
my
$i
(
@items
) {
$total
+=
$i
->subtotal;
}
return
sprintf
(
'%.2f'
,
$total
);
}
sub
number_of_items {
my
$self
=
shift
;
my
@items
=
$self
->items;
my
$total
= 0;
foreach
my
$i
(
@items
) {
$total
+=
$i
->quantity;
}
return
$total
;
}
sub
total_cost {
my
$self
=
shift
;
my
$total_cost
=
sprintf
(
'%.2f'
,
$self
->order->{OrderTotal}->{Amount});
die
"Couldn't retrieve the OrderTotal/Amount "
. Dumper(
$self
->order)
unless
defined
$total_cost
;
my
$subtotal
=
$self
->subtotal;
my
$shipping
=
$self
->shipping_cost;
if
(_kinda_equal(
$subtotal
+
$shipping
,
$total_cost
)) {
return
$total_cost
;
}
else
{
die
"subtotal $subtotal + shipping $shipping is not $total_cost\n"
;
}
}
sub
currency {
my
$self
=
shift
;
my
$currency
=
$self
->order->{OrderTotal}->{CurrencyCode};
die
"Couldn't find OrderTotal/Currency "
. Dumper(
$self
->order)
unless
$currency
;
return
$currency
;
}
sub
as_ack_order_hashref {
my
$self
=
shift
;
my
@items
;
foreach
my
$item
(
$self
->items) {
push
@items
,
$item
->as_ack_orderline_item_hashref;
}
return
{
AmazonOrderID
=>
$self
->amazon_order_number,
MerchantOrderID
=>
$self
->order_number,
Item
=> \
@items
,
};
}
sub
_kinda_equal {
return
abs
(
$_
[0] -
$_
[1]) < 0.01;
}
sub
reported_order_number {
return
shift
->order->{SellerOrderId};
}
sub
order_is_shipped {
my
$self
=
shift
;
my
$status
=
$self
->order_status;
$status
eq
'Shipped'
?
return
1 :
return
;
}
sub
order_status {
return
shift
->order->{OrderStatus};
}
sub
can_be_imported {
my
$self
=
shift
;
my
$status
=
$self
->order_status;
if
(
$status
eq
'Pending'
or
$status
eq
'Canceled'
) {
return
;
}
else
{
return
1;
}
}
sub
shop_type {
return
'amazon'
;
}
sub
comments {
return
''
;
}
sub
payment_method {
return
'Amazon'
;
}
sub
shipping_method {
return
''
;
}
1;