GetOrders - Ebay API to get all orders for developer (php version)

  • Posted on: 18 October 2016
  • By: jmu

In the past few weeks, I was working on Ebay API. Before that, I have never touched anything about calling Ebay API. In this blog, I will share some of my experience about calling GetOrders Method in Ebay API. This is a very useful method for sellers to link their own website with their ebay selling account. By using GetOrders API method, we can get all the order information and easily to show these information on our website. OK, LET'S DO IT NOW!!!

We need to do some preparation before we calling the Ebay API.

      1. Go to Ebay Developer page and register an account.

ebay Developer setting

      2. Generate keyset and token for later using

generate ID sample

Code coming (zip file, click here for downloading)~~~~

I found this code from ebaydts.com. The code works like charming. But I will share some hints here:

  1. Ebay provide a new feature: SKU.
    • If your item doesn't have variation, you will use:
              $transactions = $order->TransactionArray;
              foreach ($transactions->Transaction as $transaction) {
      
                  $SKU = $transaction->Item->SKU;
                  $Title = $transaction->Item->Title;
                  $ItemID = $transaction->Item->ItemID;
               }
    • If your item include some variations, you will need to use:
              $transactions = $order->TransactionArray;
              foreach ($transactions->Transaction as $transaction) {
      
                  $SKU = $transaction->Item->SKU;
                  $Title = $transaction->Item->Title;
                  $ItemID = $transaction->Item->ItemID;
                  $Variation = $transaction->Variation;
                  if ($Variation) {
                      if ($Variation != null) {
                          $SKU = $Variation->SKU;
                          $Title = $Variation->VariationTitle;
                      }
                  }
               }
  2. Ebay provide international shipping, we can use OrderArray.Order.IsMultiLegShipping to check if the order is an international order.3.
    • Ebay will help seller to handle those international orders. Ebay will provide a shipping address, which is domestic, but they will also give a reference number, which we have to print it right after the buyer name. (You can find the number by calling OrderArray. Order. MultiLegShippingDetails. SellerShipmentToLogisticsProvider. ShipToAddress. ReferenceID)
    • Here is my sample code:
              $orderIsMultiLegShipping = $order->IsMultiLegShipping;
              if($orderIsMultiLegShipping == 'true'){
                  $orderShipToAddress = $order->MultiLegShippingDetails->SellerShipmentToLogisticsProvider->ShipToAddress;
                  $orderCountry = $orderShipToAddress->Country;
                  $orderCountryName = $orderShipToAddress->CountryName;
                  $orderCityName = $orderShipToAddress->CityName;
                  $orderStateOrProvince = $orderShipToAddress->StateOrProvince;
                  $orderStreet1 = $orderShipToAddress->Street1;
                  $orderStreet2 = $orderShipToAddress->Street2;
                  $orderPostalCode = $orderShipToAddress->PostalCode;
                  $orderCompany = 'Reference #'.$orderShipToAddress->ReferenceID; // Sellers must include this value on the package immediately above the street address of the international shipping provider. Example: "Reference #1234567890123456"
                  $orderInternational = 1;
              }else{
                  $orderCountry = $order->ShippingAddress->Country;
                  $orderCountryName = $order->ShippingAddress->CountryName;
                  $orderCityName = $order->ShippingAddress->CityName;
                  $orderStateOrProvince = $order->ShippingAddress->StateOrProvince;
                  $orderStreet1 = $order->ShippingAddress->Street1;
                  $orderStreet2 = $order->ShippingAddress->Street2;
                  $orderPostalCode = $order->ShippingAddress->PostalCode;
                  $orderCompany = '';
                  $orderInternational = 0;
              }
              $EbayPostalCode = explode("-",$orderPostalCode); //just need first 5 digits of postal code
              $postalCode = $EbayPostalCode[0] 
  3. All the price will be returned as string.
    • Here is what I am using for convert string to float and format the price.
      $itemPrice = number_format((float)$transaction->TransactionPrice,2,'.','');

References:

  1. Some test seller for the sandbox
  2. The origin code explaination

Feel free to leave comment to share your experience.

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.