Subversion Repositories munaweb

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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;
29
	}
30
 
31
	public function GenerateNotification($notification) {
32
		$ch = curl_init($this->ApplicationURL);
33
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
34
		$httpheader = array(
35
			"SOAPAction: \"http://developer.ebay.com/notification/{$notification}\"",
36
			"Content-Type: text/xml;charset=utf-8",);
37
		curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
38
 
39
		// XXX: Hardcoded pathname
40
		$postfields = file_get_contents("./notifications/{$notification}.xml");
41
 
42
		$dom = DOMDocument::loadXML($postfields);
43
		// XXX: This generates a slightly different, but I believe equally valid, formatted time
44
		// XXX: It lacks fractional seconds, and shows UTC as "+0:00" instead of "Z"
45
		$now = gmdate(DATE_ISO8601);
46
 
47
		$Timestamp = $dom->getElementsByTagNameNS('urn:ebay:apis:eBLBaseComponents', 'Timestamp')->item(0);
48
		$Timestamp->nodeValue = $now;
49
 
50
		$signature = $this->CalculateSignature($now);
51
		$NotificationSignature = $dom->getElementsByTagNameNS('urn:ebay:apis:eBLBaseComponents', 'NotificationSignature')->item(0);
52
		$NotificationSignature->nodeValue = $signature;
53
 
54
		$postfields = $dom->saveXML();
55
 
56
		$this->carp($postfields);
57
 
58
		curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
59
 
60
		$out = curl_exec($ch);
61
		curl_close($ch);
62
 
63
		return $out;
64
	}
65
}
66
 
67
 
68
// Load developer-specific configuration data from ini file
69
$config = parse_ini_file('ebay.ini', true);
70
$site = $config['settings']['site'];
71
$dev = $config[$site]['devId'];
72
$app = $config[$site]['appId'];
73
$cert = $config[$site]['cert'];
74
$token = $config[$site]['authToken'];
75
$location = $config[$site]['gatewaySOAP'];
76
 
77
// Create and configure session
78
$session = new eBaySession($dev, $app, $cert);
79
$session->token = $token;
80
$session->site = 0; // 0 = US;
81
$session->location = $location;
82
 
83
if ($argc == 1) {
84
    $notifications = array('AskSellerQuestion');
85
} else {
86
    $notifications = array_slice($argv, 1);
87
}
88
 
89
// Generate a ASQ notification
90
try {
91
	$debug = false;
92
	$ng = new eBayPlatformNotificationGenerator($session, $debug);
93
 
94
	foreach ($notifications as $n) {
95
		$results = $ng->GenerateNotification($n);
96
		print $results;
97
	}
98
 
99
} catch (SOAPFault $f) {
100
	print $f; // error handling
101
}
102
/*
103
// Uncomment below to view SOAP envelopes
104
print "Request: \n".$client->__getLastRequestHeaders()."\n";
105
print "Request: \n".$client->__getLastRequest()."\n";
106
print "Response: \n".$client->__getLastResponseHeaders()."\n";
107
print "Response: \n".$client->__getLastResponse()."\n";
108
*/
109
 
110
?>