Amazon-MWS

 view release on metacpan or  search on metacpan

t/order-reports.t  view on Meta::CPAN

          <TaxableAmounts>
            <District currency="USD">0.00</District>
            <City currency="USD">0.00</City>
            <County currency="USD">0.00</County>
            <State currency="USD">0.00</State>
          </TaxableAmounts>
          <NonTaxableAmounts>
            <District currency="USD">0.00</District>
            <City currency="USD">0.00</City>
            <County currency="USD">63.99</County>
            <State currency="USD">63.99</State>
          </NonTaxableAmounts>
          <ZeroRatedAmounts>
            <District currency="USD">63.99</District>
            <City currency="USD">63.99</City>
            <County currency="USD">0.00</County>
            <State currency="USD">0.00</State>
          </ZeroRatedAmounts>
          <TaxCollectedAmounts>
            <District currency="USD">0.00</District>
            <City currency="USD">0.00</City>
            <County currency="USD">0.00</County>
            <State currency="USD">0.00</State>
          </TaxCollectedAmounts>
          <TaxRates>
            <District>0.0000</District>
            <City>0.0000</City>
            <County>0.0000</County>
            <State>0.0000</State>
          </TaxRates>
        </ItemTaxData>
        <Promotion>
          <PromotionClaimCode>_SITE_WIDE_</PromotionClaimCode>
          <MerchantPromotionID>FREESHIPPINGOVER25</MerchantPromotionID>
          <Component>
            <Type>Principal</Type>
            <Amount currency="USD">0.00</Amount>
          </Component>
          <Component>
            <Type>Shipping</Type>
            <Amount currency="USD">0.00</Amount>
          </Component>
        </Promotion>
      </Item>
    </OrderReport>
  </Message>
</AmazonEnvelope>
AMAZONXML

my @orders = ($uploader->_parse_order_reports_xml($xml), $uploader->_parse_order_reports_xml($xml_doc));

ok(@orders == 2, "Got the orders");
my $count = 0;
foreach my $order (@orders) {
    $count++;
    ok ($order, "object ok");
    ok ($order->amazon_order_number, "Got order number")  and diag $order->amazon_order_number;
    ok ($order->struct, "struct ok");

    my $order_date = $order->order_date;
    ok($order_date->isa('DateTime'), "datetime object returned");
    foreach my $method (qw/name city zip country address_line region/) {
        ok ($order->shipping_address->$method, "shipping $method ok")
          and diag $order->shipping_address->$method;
        # only our example have a billing address
        if ($count == 1) {
            ok ($order->billing_address->$method, "billing $method ok")
              and diag $order->billing_address->$method;
        }
        else {
            ok (!$order->billing_address);
        }
    }
    ok ($order->shipping_address->phone, "phone ok");

    # test only the first order for exact match for now
    if ($count == 1) {
        is $order->email, 'asdfalklkasdfdh@marketplace.amazon.de';
        is $order->amazon_order_number, '028-1111111-1111111';
        is $order->order_date->ymd, '2015-03-24';
        is ($order->billing_address->phone, '07777777777', 'phone matches')
          or diag Dumper($order->billing_address->phone);
        is $order->currency, 'EUR';
    }
    my @items = $order->items;
    foreach my $item (@items) {
        $item->merchant_order_item('dummy');
        foreach my $method (qw/price shipping subtotal total_price shipping
                               shipping_netto
                               price_netto item_tax shipping_tax item_tax
                               sku quantity name subtotal
                               as_ack_orderline_item_hashref
                               merchant_order_item amazon_order_item
                               currency
                              /) {
            ok($item->$method, "$method ok") and diag $item->$method;
        }
        if ($count == 1) {
            is $item->currency, 'EUR';
            is $item->total_price, '17.55';
            is $item->subtotal, '17.55';
            is ($item->amazon_fee, '-2.11');
        }
        else {
            is $item->currency, 'USD';
            is $item->total_price, '63.99';
            is $item->subtotal, '63.99';
            is ($item->amazon_fee, '-9.60');
        }
    }
    $order->order_number('testme');
    ok $order->as_ack_order_hashref, "Hashref ok";
    ok $order->can_be_imported;
    ok $order->order_status;
    diag Dumper($order->as_ack_order_hashref);
    ok($order->currency, "currency ok");
    ok $order->shipping_cost;
    ok $order->subtotal;
    ok $order->total_amazon_fee;
    ok $order->total_cost;
    is $order->number_of_items, 1, "Only one item";



( run in 0.569 second using v1.01-cache-2.11-cpan-39bf76dae61 )