-
Notifications
You must be signed in to change notification settings - Fork 1
/
GetOrders.php
173 lines (142 loc) · 7.26 KB
/
GetOrders.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
/* © 2013 eBay Inc., All Rights Reserved */
/* Licensed under CDDL 1.0 - http://opensource.org/licenses/cddl1.php */
require('config.php');
require('functions.php');
//Time with respect to GMT
//by default retreive orders in last 30 minutes
$CreateTimeFrom = gmdate("Y-m-d\TH:i:s",time()-1153200); //current time minus 30 minutes
//echo $CreateTimeFrom;
$CreateTimeTo = gmdate("Y-m-d\TH:i:s", time());
//If you want to hard code From and To timings, Follow the below format in "GMT".
//$CreateTimeFrom = YYYY-MM-DDTHH:MM:SS; //GMT
//$CreateTimeTo = YYYY-MM-DDTHH:MM:SS; //GMT
///Build the request Xml string
$requestXmlBody = '<?xml version="1.0" encoding="utf-8" ?>';
$requestXmlBody .= '<GetOrdersRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
$requestXmlBody .= '<DetailLevel>ReturnAll</DetailLevel>';
$requestXmlBody .= "<NumberOfDays>1</NumberOfDays>";
$requestXmlBody .= '<OrderRole>Seller</OrderRole><OrderStatus>Completed</OrderStatus>';
$requestXmlBody .= "<RequesterCredentials><eBayAuthToken>$userToken</eBayAuthToken></RequesterCredentials>";
$requestXmlBody .= '</GetOrdersRequest>';
//Create a new eBay session with all details pulled in from included keys.php
$session = new eBaySession($userToken, $devID, $appID, $certID, $serverUrl, $compatabilityLevel, $siteID, 'GetOrders');
//send the request and get response
$responseXml = $session->sendHttpRequest($requestXmlBody);
if (stristr($responseXml, 'HTTP 404') || $responseXml == '')
die('Error sending request');
//Xml string is parsed and creates a DOM Document object
$responseDoc = new DomDocument();
$responseDoc->loadXML($responseXml);
//get any error nodes
$errors = $responseDoc->getElementsByTagName('Errors');
$response = simplexml_import_dom($responseDoc);
$entries = $response->PaginationResult->TotalNumberOfEntries;
//if there are error nodes
if ($errors->length > 0) {
echo '<P><B>eBay returned the following error(s):</B>';
//display each error
//Get error code, ShortMesaage and LongMessage
$code = $errors->item(0)->getElementsByTagName('ErrorCode');
$shortMsg = $errors->item(0)->getElementsByTagName('ShortMessage');
$longMsg = $errors->item(0)->getElementsByTagName('LongMessage');
//Display code and shortmessage
echo '<P>', $code->item(0)->nodeValue, ' : ', str_replace(">", ">", str_replace("<", "<", $shortMsg->item(0)->nodeValue));
//if there is a long message (ie ErrorLevel=1), display it
if (count($longMsg) > 0)
echo '<BR>', str_replace(">", ">", str_replace("<", "<", $longMsg->item(0)->nodeValue));
}else { //If there are no errors, continue
if(isset($_GET['debug']))
{
header("Content-type: text/xml");
print_r($responseXml);
}else
{ //$responseXml is parsed in view.php
header("Content-Type: text/plain; charset=UTF-8");
//$response = simplexml_import_dom($responseDoc);
if ($entries == 0) {
echo "Sorry No entries found in the Time period requested. Change CreateTimeFrom/CreateTimeTo and Try again";
} else {
$orders = $response->OrderArray->Order;
//var_dump($orders);
if ($orders != null) {
foreach ($orders as $order) {
if (!isset($order->ShippedTime)) {
echo "Order Information:\n";
echo "OrderID ->" . $order->OrderID . "\n";
echo "Order -> Status:" . $orderStatus = $order->OrderStatus . "\n";
//if the order is completed, print details
// get the checkout message left by the buyer, if any
if ($order->BuyerCheckoutMessage) {
echo "BuyerCheckoutMsg : " . $order->BuyerCheckoutMessage . "\n";
}
// get the external transaction information - if payment is made via PayPal, then this is the PayPal transaction info
$externalTransaction = $order->ExternalTransaction;
if ($externalTransaction) {
echo "ExternalTransactionID : " . $externalTransaction->ExternalTransactionID . "\n";
}
// get the shipping service selected by the buyer
$ShippingServiceSelected = $order->ShippingServiceSelected;
if($ShippingServiceSelected){
echo "Shipping Service Selected : " . $ShippingServiceSelected->ShippingService . " \n";
$ShippingCostAttr = $ShippingServiceSelected->ShippingServiceCost->attributes();
echo "ShippingServiceCost : " . $ShippingServiceSelected->ShippingServiceCost . " " . $ShippingCostAttr["currencyID"] . "\n";
}
// get the buyer's shipping address
$shippingAddress = $order->ShippingAddress;
$citystatezip = $shippingAddress->CityName. ','. $shippingAddress->StateOrProvince . ' ' . $shippingAddress->PostalCode;
if ($shippingAddress->Street1 != null) {
$address1 = $shippingAddress->Street1;
}
if ($shippingAddress->Street2 != '') {
$address2 = $shippingAddress->Street2;
$address3 = $citystatezip;
}
else {
$address2 = $citystatezip;
$address3 = $shippingAddress->CountryName;
}
if ($shippingAddress->CountryName != null) {
$address .=
$shippingAddress->CountryName . ".\n";
}
$transactions = $order->TransactionArray;
if ($transactions) {
echo "Transaction Array \n";
// iterate through each transaction for the order
foreach ($transactions->Transaction as $transaction) {
// get the OrderLineItemID, Quantity, buyer's email and SKU
echo "OrderLineItemID : " . $transaction->OrderLineItemID . "\n";
echo "QuantityPurchased : " . $transaction->QuantityPurchased . "\n";
echo "Buyer Email : " . $transaction->Buyer->Email . "\n";
$prodname = $transaction->Item->Title;
// if the item is listed with variations, get the variation SKU
$VariationSKU = $transaction->Variation->SKU;
if ($VariationSKU != null) {
echo "Variation SKU : " . $VariationSKU. "\n";
}
echo "TransactionID: " . $transaction->TransactionID . "\n";
$transactionPriceAttr = $transaction->TransactionPrice->attributes();
echo "TransactionPrice : " . $transaction->TransactionPrice . " " . $transactionPriceAttr["currencyID"] . "\n";
echo "Platform : " . $transaction->Platform . "\n";
}
}
}//end if
if($ShippingServiceSelected){
if ($ShippingServiceSelected->ShippingService == 'ShippingMethodStandard') {
// USPS first class non-parcel label
//printLabel(substr($prodname,0,25), $shippingAddress->Name, $address1, $address2, $address3, $order->ShippingDetails->SellingManagerSalesRecordNumber);
markShipped($order->OrderID);
}
else {
// real tracking label type...
}
}
}
}else{
echo "No Order Found";
}
}
}
}
?>