2 |
- |
1 |
<?php
|
157 |
- |
2 |
/* (C) 2013 eBay Inc., All Rights Reserved */
|
2 |
- |
3 |
/* Licensed under CDDL 1.0 - http://opensource.org/licenses/cddl1.php */
|
|
|
4 |
?>
|
|
|
5 |
<?php
|
12 |
- |
6 |
$DEBUG = false;
|
2 |
- |
7 |
$capturePath = "captures/";
|
|
|
8 |
|
|
|
9 |
// be sure include path contains current and shopify directory
|
75 |
- |
10 |
ini_set('include_path', ini_get('include_path') . ':.:../php:../../shopify/php');
|
2 |
- |
11 |
|
|
|
12 |
// Load general helper classes for eBay SOAP API
|
|
|
13 |
require_once 'keys.php';
|
|
|
14 |
require_once 'eBaySOAP.php';
|
|
|
15 |
require_once 'Shopify.php';
|
|
|
16 |
|
|
|
17 |
function debug_string_backtrace() {
|
|
|
18 |
ob_start();
|
|
|
19 |
debug_print_backtrace();
|
|
|
20 |
$trace = ob_get_contents();
|
|
|
21 |
ob_end_clean();
|
|
|
22 |
|
|
|
23 |
// Remove first item from backtrace as it's this function which is redundant.
|
157 |
- |
24 |
$trace = preg_replace('/^#0\s+' . __FUNCTION__ . "[^\n]*\n/", '', $trace, 1);
|
2 |
- |
25 |
|
|
|
26 |
return $trace;
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
class eBayPlatformNotificationListener extends eBayPlatformNotifications {
|
157 |
- |
30 |
protected $NotificationSignature;
|
2 |
- |
31 |
|
157 |
- |
32 |
// Dispatch method to ensure signature validation
|
|
|
33 |
public function __call($method, $args) {
|
|
|
34 |
$s = "Called with $method";
|
|
|
35 |
$this->carp($s);
|
2 |
- |
36 |
|
157 |
- |
37 |
// Print backtrace and arguments
|
|
|
38 |
$this->carp(debug_string_backtrace());
|
|
|
39 |
$this->carp("args=" . print_r($args, true));
|
2 |
- |
40 |
|
157 |
- |
41 |
if ($this->ValidateSignature($args[0])) {
|
|
|
42 |
// strip off trailing "Request"
|
|
|
43 |
$method = substr($method, 0, -8);
|
|
|
44 |
if (method_exists($this, $method)) {
|
|
|
45 |
return call_user_func_array(array(
|
|
|
46 |
$this,
|
|
|
47 |
$method
|
|
|
48 |
) , $args);
|
|
|
49 |
}
|
|
|
50 |
else {
|
|
|
51 |
$this->errorLog("Unhandled Event: args=" . print_r($args, true));
|
|
|
52 |
}
|
|
|
53 |
}
|
2 |
- |
54 |
|
157 |
- |
55 |
// Today is a good day to die.
|
|
|
56 |
die("Death");
|
|
|
57 |
}
|
2 |
- |
58 |
|
157 |
- |
59 |
// Extract Signature for validation later
|
|
|
60 |
// Can't validate here because we don't have access to the Timestamp
|
|
|
61 |
public function RequesterCredentials($RequesterCredentials) {
|
|
|
62 |
$this->NotificationSignature = $RequesterCredentials->NotificationSignature;
|
|
|
63 |
}
|
2 |
- |
64 |
|
157 |
- |
65 |
protected function ValidateSignature($Timestamp) {
|
|
|
66 |
// Check for Signature Match
|
|
|
67 |
$CalculatedSignature = $this->CalculateSignature($Timestamp);
|
|
|
68 |
$NotificationSignature = $this->NotificationSignature;
|
2 |
- |
69 |
|
157 |
- |
70 |
if ($CalculatedSignature != $NotificationSignature) {
|
|
|
71 |
//bugbug $this->errorLog("Sig Mismatch: Calc: $CalculatedSignature, Note: $NotificationSignature");
|
|
|
72 |
//bugbug return false;
|
|
|
73 |
|
|
|
74 |
}
|
|
|
75 |
else {
|
|
|
76 |
$this->carp("Sig Match: $NotificationSignature");
|
|
|
77 |
}
|
2 |
- |
78 |
|
157 |
- |
79 |
// Check that Timestamp is within 10 minutes of now
|
|
|
80 |
$tz = date_default_timezone_get();
|
|
|
81 |
date_default_timezone_set('UTC');
|
|
|
82 |
$then = strtotime($Timestamp);
|
|
|
83 |
$now = time();
|
|
|
84 |
date_default_timezone_set($tz);
|
2 |
- |
85 |
|
157 |
- |
86 |
$drift = $now - $then;
|
|
|
87 |
$ten_minutes = 60 * 10;
|
|
|
88 |
if ($drift > $ten_minutes) {
|
|
|
89 |
$this->errorLog("Time Drift is too large: $drift seconds, Note: $NotificationSignature");
|
|
|
90 |
return false;
|
|
|
91 |
}
|
|
|
92 |
else {
|
|
|
93 |
$this->carp("Time Drift is okay: $drift seconds");
|
|
|
94 |
}
|
2 |
- |
95 |
|
157 |
- |
96 |
return true;
|
|
|
97 |
}
|
2 |
- |
98 |
|
157 |
- |
99 |
// Arg order is brittle, assumes constant return ordering from eBay
|
|
|
100 |
public function GetMemberMessages($Timestamp, $Ack, $CorrelationID, $Version, $Build, $NotificationEventName, $RecipientUserID, $SellerEIASToken, $MemberMessage, $PaginationResult, $HasMoreItems) {
|
|
|
101 |
$ItemID = $MemberMessage
|
|
|
102 |
->MemberMessageExchange
|
|
|
103 |
->Item->ItemID;
|
|
|
104 |
$Seller = $MemberMessage
|
|
|
105 |
->MemberMessageExchange
|
|
|
106 |
->Item
|
|
|
107 |
->Seller->UserID;
|
|
|
108 |
$Sender = $MemberMessage
|
|
|
109 |
->MemberMessageExchange
|
|
|
110 |
->Question->SenderID;
|
|
|
111 |
$this->notificationLog("$NotificationEventName: From $Sender to $Seller regarding Item $ItemID");
|
2 |
- |
112 |
|
157 |
- |
113 |
return "";
|
|
|
114 |
}
|
2 |
- |
115 |
|
157 |
- |
116 |
public function GetItem($Timestamp, $Ack, $CorrelationID, $Version, $Build, $NotificationEventName, $RecipientUserID, $BuyerEIASToken, $Item) {
|
2 |
- |
117 |
|
157 |
- |
118 |
$ItemID = $Item->ItemID;
|
|
|
119 |
$Title = $Item->Title;
|
2 |
- |
120 |
|
157 |
- |
121 |
$UPC = (isset($Item
|
|
|
122 |
->ProductListingDetails
|
|
|
123 |
->UPC) ? $Item
|
|
|
124 |
->ProductListingDetails->UPC : "");
|
|
|
125 |
$SKU = (isset($Item->SKU) ? $Item->SKU : "");
|
|
|
126 |
$this->notificationLog("$NotificationEventName: ItemId=$ItemID; Title=$Title; SKU=$SKU; UPC=$UPC");
|
2 |
- |
127 |
|
157 |
- |
128 |
if ($NotificationEventName == "BidReceived") {
|
|
|
129 |
$list = shopifyProductAdjust($Title, $SKU, 1);
|
|
|
130 |
$this->notificationLog($list[1]);
|
|
|
131 |
if ($list[0] == false) {
|
|
|
132 |
$this->errorLog($list[1]);
|
|
|
133 |
}
|
|
|
134 |
}
|
2 |
- |
135 |
|
157 |
- |
136 |
return "";
|
|
|
137 |
}
|
2 |
- |
138 |
|
157 |
- |
139 |
public function GetItemTransactions($Timestamp, $Ack, $CorrelationID, $Version, $Build, $NotificationEventName, $SellerName, $BuyerEIASToken, $PaginationResult, $HasMoreItems, $x1, $x2, $x3, $Item, $Transaction) {
|
2 |
- |
140 |
|
157 |
- |
141 |
$ItemID = $Item->ItemID;
|
|
|
142 |
$Title = $Item->Title;
|
|
|
143 |
$SKU = (isset($Item->SKU) ? $Item->SKU : "");
|
|
|
144 |
$Quantity = (isset($Transaction
|
|
|
145 |
->Transaction
|
|
|
146 |
->QuantityPurchased) ? $Transaction
|
|
|
147 |
->Transaction->QuantityPurchased : "1");
|
|
|
148 |
$this->notificationLog("$NotificationEventName: ItemId=$ItemID; Title=$Title; SKU=$SKU; Quantity=$Quantity");
|
2 |
- |
149 |
|
157 |
- |
150 |
//if ($NotificationEventName == "AuctionCheckoutComplete") {
|
|
|
151 |
if ($NotificationEventName == "FixedPriceTransaction") {
|
|
|
152 |
$list = shopifyProductAdjust($Title, $SKU, $Quantity);
|
|
|
153 |
$this->notificationLog($list[1]);
|
|
|
154 |
if ($list[0] == false) {
|
|
|
155 |
$this->errorLog($list[1]);
|
|
|
156 |
}
|
|
|
157 |
}
|
2 |
- |
158 |
|
157 |
- |
159 |
return "";
|
|
|
160 |
}
|
2 |
- |
161 |
|
157 |
- |
162 |
public function GetFeedback($Timestamp, $Ack, $CorrelationID, $Version, $Build, $NotificationEventName, $SellerName, $BuyerEIASToken, $Feedback, $x1, $BuyerScore, $PaginationResult, $x2, $x3) {
|
2 |
- |
163 |
|
157 |
- |
164 |
$ItemID = $Feedback
|
|
|
165 |
->FeedbackDetail->ItemID;
|
|
|
166 |
$Type = $Feedback
|
|
|
167 |
->FeedbackDetail->CommentType;
|
|
|
168 |
$Role = $Feedback
|
|
|
169 |
->FeedbackDetail->Role;
|
|
|
170 |
$Text = $Feedback
|
|
|
171 |
->FeedbackDetail->CommentText;
|
|
|
172 |
$this->notificationLog("$Type $Role Feedback for Item $ItemID=$Text");
|
2 |
- |
173 |
|
157 |
- |
174 |
return "";
|
|
|
175 |
}
|
2 |
- |
176 |
|
157 |
- |
177 |
public function GetMyMessages($Timestamp, $Ack, $CorrelationID, $Version, $Build, $NotificationEventName, $SellerName, $SenderEIASToken, $Message) {
|
2 |
- |
178 |
|
157 |
- |
179 |
$Sender = $Message
|
|
|
180 |
->Message->Sender;
|
|
|
181 |
$Recipient = $Message
|
|
|
182 |
->Message->RecipientUserID;
|
|
|
183 |
$Subject = $Message
|
|
|
184 |
->Message->Subject;
|
|
|
185 |
$this->notificationLog("Message from $Sender to $Recipient regarding $Subject");
|
2 |
- |
186 |
|
157 |
- |
187 |
return "";
|
|
|
188 |
}
|
2 |
- |
189 |
|
157 |
- |
190 |
public function GetBestOffers($Timestamp, $Ack, $CorrelationID, $Version, $Build, $NotificationEventName, $SellerName, $SenderEIASToken, $BestOffer, $BuyItNow) {
|
2 |
- |
191 |
|
157 |
- |
192 |
$Sender = $BestOffer
|
|
|
193 |
->BestOffer
|
|
|
194 |
->Buyer->UserID;
|
|
|
195 |
$BestOfferAmount = $BestOffer
|
|
|
196 |
->BestOffer->Price;
|
|
|
197 |
$Title = $BuyItNow->Title;
|
|
|
198 |
$OriginalPrice = $BuyItNow->BuyItNowPrice;
|
|
|
199 |
$ItemID = $BuyItNow->ItemID;
|
2 |
- |
200 |
|
157 |
- |
201 |
$this->notificationLog("$NotificationEventName: $Sender offered $BestOfferAmount (originally $OriginalPrice) for $ItemID ($Title)");
|
2 |
- |
202 |
|
157 |
- |
203 |
return "";
|
|
|
204 |
}
|
2 |
- |
205 |
|
|
|
206 |
}
|
|
|
207 |
|
|
|
208 |
// Create and configure session
|
|
|
209 |
$session = new eBaySession($dev, $app, $cert);
|
|
|
210 |
|
|
|
211 |
if ($DEBUG) {
|
157 |
- |
212 |
error_log(serialize(apache_request_headers()));
|
2 |
- |
213 |
}
|
|
|
214 |
|
194 |
- |
215 |
#$stdin = $GLOBALS['HTTP_RAW_POST_DATA'];
|
|
|
216 |
$stdin = file_get_contents("php://input");
|
2 |
- |
217 |
if ($DEBUG) {
|
194 |
- |
218 |
error_log("STDIN: " . $stdin);
|
2 |
- |
219 |
}
|
|
|
220 |
|
|
|
221 |
$action = basename(str_replace('"', '', $_SERVER['HTTP_SOAPACTION']));
|
|
|
222 |
file_put_contents($capturePath . $action . '.xml', $stdin . "\n\n", FILE_APPEND);
|
|
|
223 |
if ($DEBUG) {
|
157 |
- |
224 |
error_log('EVENT NAME: ' . $action);
|
2 |
- |
225 |
}
|
|
|
226 |
|
157 |
- |
227 |
$server = new SOAPServer(null, array(
|
|
|
228 |
'uri' => 'urn:ebay:apis:eBLBaseComponents'
|
|
|
229 |
));
|
2 |
- |
230 |
$server->setClass('eBayPlatformNotificationListener', $session, $DEBUG);
|
|
|
231 |
$server->handle();
|
|
|
232 |
|
|
|
233 |
?>
|