2 |
- |
1 |
<?php
|
|
|
2 |
/* © 2013 eBay Inc., All Rights Reserved */
|
|
|
3 |
/* Licensed under CDDL 1.0 - http://opensource.org/licenses/cddl1.php */
|
|
|
4 |
?>
|
|
|
5 |
<?php
|
|
|
6 |
// be sure include path contains current directory
|
|
|
7 |
// to make sure samples work
|
|
|
8 |
ini_set('include_path', ini_get('include_path') . ':.:../php');
|
|
|
9 |
|
|
|
10 |
// Load general helper classes for eBay SOAP API
|
|
|
11 |
require_once 'eBaySOAP.php';
|
|
|
12 |
|
|
|
13 |
class eBayPlatformNotificationGenerator extends eBayPlatformNotifications {
|
|
|
14 |
protected $ApplicationURL = null;
|
|
|
15 |
|
|
|
16 |
public function __construct(eBaySession $session, $debug = false) {
|
|
|
17 |
parent::__construct($session, $debug);
|
|
|
18 |
|
|
|
19 |
$this->ApplicationURL = $this->GetApplicationURL();
|
|
|
20 |
}
|
|
|
21 |
|
|
|
22 |
protected function GetApplicationURL() {
|
|
|
23 |
//// $client = new eBaySOAP($this->session);
|
|
|
24 |
////
|
|
|
25 |
//// $params = array('Version' => 1081);
|
|
|
26 |
//// $results = $client->GetNotificationPreferences($params);
|
|
|
27 |
////
|
|
|
28 |
//// return $results->ApplicationDeliveryPreferences->ApplicationURL;
|
193 |
- |
29 |
return 'https://dev.munatrading.com/ebay/notifications/listener-dev.php';
|
2 |
- |
30 |
}
|
|
|
31 |
|
|
|
32 |
public function GenerateNotification($notification) {
|
|
|
33 |
$ch = curl_init($this->ApplicationURL);
|
|
|
34 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
35 |
$httpheader = array(
|
|
|
36 |
"SOAPAction: \"http://developer.ebay.com/notification/{$notification}\"",
|
|
|
37 |
"Content-Type: text/xml;charset=utf-8",);
|
|
|
38 |
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
|
|
|
39 |
curl_setopt($ch, CURLOPT_HEADER, true);
|
|
|
40 |
|
|
|
41 |
// XXX: Hardcoded pathname
|
|
|
42 |
$postfields = file_get_contents("./notifications/{$notification}.xml");
|
|
|
43 |
|
|
|
44 |
$dom = DOMDocument::loadXML($postfields);
|
|
|
45 |
// XXX: This generates a slightly different, but I believe equally valid, formatted time
|
|
|
46 |
// XXX: It lacks fractional seconds, and shows UTC as "+0:00" instead of "Z"
|
|
|
47 |
$now = gmdate(DATE_ISO8601);
|
|
|
48 |
|
|
|
49 |
$Timestamp = $dom->getElementsByTagNameNS('urn:ebay:apis:eBLBaseComponents', 'Timestamp')->item(0);
|
|
|
50 |
$Timestamp->nodeValue = $now;
|
|
|
51 |
|
|
|
52 |
$signature = $this->CalculateSignature($now);
|
|
|
53 |
$NotificationSignature = $dom->getElementsByTagNameNS('urn:ebay:apis:eBLBaseComponents', 'NotificationSignature')->item(0);
|
|
|
54 |
$NotificationSignature->nodeValue = $signature;
|
|
|
55 |
|
|
|
56 |
$postfields = $dom->saveXML();
|
|
|
57 |
|
|
|
58 |
$this->carp($postfields);
|
|
|
59 |
|
|
|
60 |
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
|
|
|
61 |
|
|
|
62 |
$out = curl_exec($ch);
|
|
|
63 |
curl_close($ch);
|
|
|
64 |
|
|
|
65 |
return $out;
|
|
|
66 |
}
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
// Load configuration data from ebay ini file
|
|
|
71 |
$config = parse_ini_file('ebay.ini', true);
|
|
|
72 |
$site = $config['settings']['site'];
|
|
|
73 |
$dev = $config[$site]['devId'];
|
|
|
74 |
$app = $config[$site]['appId'];
|
|
|
75 |
$cert = $config[$site]['cert'];
|
|
|
76 |
$token = $config[$site]['authToken'];
|
|
|
77 |
$location = $config[$site]['gatewaySOAP'];
|
|
|
78 |
|
|
|
79 |
// Create and configure session
|
|
|
80 |
$session = new eBaySession($dev, $app, $cert);
|
|
|
81 |
$session->token = $token;
|
|
|
82 |
$session->site = 0; // 0 = US;
|
|
|
83 |
$session->location = $location;
|
|
|
84 |
|
|
|
85 |
if ($argc == 1) {
|
|
|
86 |
$notifications = array('AskSellerQuestion');
|
|
|
87 |
} else {
|
|
|
88 |
$notifications = array_slice($argv, 1);
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
// Generate a ASQ notification
|
|
|
92 |
try {
|
|
|
93 |
$debug = true;
|
|
|
94 |
$ng = new eBayPlatformNotificationGenerator($session, $debug);
|
|
|
95 |
|
|
|
96 |
foreach ($notifications as $n) {
|
|
|
97 |
$results = $ng->GenerateNotification($n);
|
|
|
98 |
print $results;
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
} catch (SOAPFault $f) {
|
|
|
102 |
print $f; // error handling
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
/*
|
|
|
106 |
// View SOAP envelopes
|
|
|
107 |
print "Request: \n".$client->__getLastRequestHeaders()."\n";
|
|
|
108 |
print "Request: \n".$client->__getLastRequest()."\n";
|
|
|
109 |
print "Response: \n".$client->__getLastResponseHeaders()."\n";
|
|
|
110 |
print "Response: \n".$client->__getLastResponse()."\n";
|
|
|
111 |
*/
|
|
|
112 |
?>
|