programmersguide 10

31
_ ______________________________ _ _ _______________________________ ________________ __ _______ ___ _______ _ ________________ __ _______ ___ ______ _ www.intradesys.com | [email protected] _ ______________________________ _ _ ______________________________ _ IN TRADESYS ________________ __ _______ ___ ________ ________________ __ _______ ___ ________ Programmers Guide eBay Acellerator Toolkit for PHP Unified Schema, EbatNs 1.0 © 2005 / 2006 Intradesys Limited InTradeSys Limited - Niederlassung Deutschland | Dillenburger Str. 75 | D - 51105 Köln | Geschäftsführer: Carsten Harnisch | Steuernummer: 218/5720/1109 | Bankverbindung: Dresdner Bank AG Filiale Bonn | Konto: 01 769 212 00 BLZ: 370 800 40 | SWIFT-BIC: DRES DE FF 380 | IBAN: DE03 3708 0040 0176 9212 00 | HRB 53992

Upload: neerajth

Post on 12-Nov-2014

275 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.com | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide eBay Acellerator Toolkit for PHP

Unified Schema, EbatNs 1.0

© 2005 / 2006 Intradesys Limited

InTradeSys Limited - Niederlassung Deutschland | Dillenburger Str. 75 | D - 51105 Köln | Geschäftsführer: Carsten Harnisch | Steuernummer: 218/5720/1109 | Bankverbindung: Dresdner Bank AG Filiale Bonn | Konto: 01 769 212 00BLZ: 370 800 40 | SWIFT-BIC: DRES DE FF 380 | IBAN: DE03 3708 0040 0176 9212 00 | HRB 53992

Page 2: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

1 Introduction The eBay Acellerator Toolkit New Schema (EbatNs) is the next step in programming the eBay API with PHP.

It is the suceessor of the eBay Acellerator Toolkit (ebat) for the legacy schema that already exists since

2003.

The toolkit gives you a kind of SDK for usage in PHP application on the webserver and/or the command line.

2 Installation To install the EbatNs you will need a fully functional PHP installation on your system. Please first download

the package and unzip it. The package will be placed in a folder named “EbatNs” – please do not neither

rename the folder nor change the content of the folder. Although the name of the package is not really rele-

vant, any provided samples are relying on this configuration.

Be sure to place the folder somewhere within your PHP include_path. This might be a direct copy or prefer-

able a symbolic-link (if your OS supports it).

Some hosted environment does not gives you the ability to alter the include_path nor gives you direct access

to it. In such cases please use the procedure described under “Altering include_path”.

2.1 Needed PHP Installation on the Server

To successfully run any scripts using the EbatNs you will need a fully configured PHP installation. You will

need the Curl-Module to be installed on the system. Here be sure that support for OpenSSL and zLib is in-

cluded. If you have Curl but not zLib please refer to the configuration section below to disable HTTP-

Compression.

2.2 Altering include_path

You can set the include_path using the php-function set_ini_path. The following e.g. alters the include_path:

$incPath = "/var/www"; set_include_path($incPath . ':' . get_include_path());

Here we assume that you place the Toolkit files directly under your www-root directory (so

/var/www/EbatNs). Any the code above will only work on Unix. Please refer to the samples directory

“hosted_environment” for a full featured version.

Anyway in all cases the path-modification has to be done in all files you call as the path will be resetting on

every request.

2

Page 3: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

3 First Steps 3.1 Join the eBay Developer-Program

To use any of the eBay-API-Calls you will have to have an account in the eBay developer program. As a

result you will get a key-triple which identifies you as a developer.

For will get a key-triple for the so called “sandbox” right after you joined the program. After testing you can

switch to the production system will.

Register first to the developer program at http://developer.ebay.com. After going through the process you will

receive 3 keys (DevId, AppId and CertId) all for sandbox access. The sandbox is the eBay testing system for

the developers. Please save the 3 keys you will later store them to the configuration-file.

3.2 Setup a test-account

Browse to the site http://www.sandbox.ebay.com . Register here for a new user account.

To simplify the process you can use the “eBay Sandbox User Registration” link on www.sandbox.ebay.com.

You might use the local sandboxes (just replace .com with your local country domain, e.g.

www.sandbox.ebay.de)

Anyway you can also register manually but you will need a US-address here (checkout

www.yellowpages.com, if you are not from the US).

Although the „sandbox“ looks like ebay.com the databases behind are completely different. So, nor you can

login here with your „normal“ eBay account nor you will find any items you might find in the live-system. All

what you see in the sandbox is stuff listed by yourself or the other eBay developers worldwide.

Anyway it makes sense to register already a few accounts here - as later on - you might want to “simulate”

also some trading. As you can not buy the items you offer with the same account, a minimum of 2 different

accounts makes sense.

3.3 Create a token

Using the 3 keys and the user credentials from the sandbox registration you can generate a so called token.

The easiest way is using the „single user tool“ at http://developer.ebay.com/tokentool/; please choose the

sandbox as your system. The token is somewhat like a credential information, anyway encoded as a hash-

code. The token is about 1 kB und you should save it into a file (token-file).

3.4 Create a basic configuration

You can now ready to create a basic configuration file. As there are a lot of different parameters to store we

decided to place all of them together into a config-file. While programming with the toolkit you will always

setup first a EbatNs_Session-Object. Here you basically can set all the parameters one by one or just let the

Session-Object take them from the config-file.

Checkout the samples folder; here you will find various files named „ebay.config.php“ or similary. As the file

has sensitive information in it, it is NOT a good idea to place it into your web-root (or below). To prevent the

download we just placed everything into a php-file with a surrounding multiline comment (/* */). Be aware of

3

Page 4: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

the same fact regarding the token-file. Here the extension .token is used by default, so the file can be

downloaded if someone know the path and exact file-name !!!

Please insert into these files the information you collected before:

For the sandbox environment enter the following entries: dev-key-test=ddd

app-key-test=aaa

cert-id-test=ccc

(the keys from the registration)

site-id=0

app-mode=1

token-mode=1

token-pickup-file=/path/sandbox.token

(please enter the file name where you stored the token)

3.5 Samples

The first sample should run now, try „getTime.php“. We will provide with much more sample over the time.

4

Page 5: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

4 Basic Operations To issue a call to the eBay API you will need a Session. Then create a ServiceProxy with the Session. The

parameters of a call are always given in a call-specific Request-Object. The ServiceProxy will have a PHP-

Method for all known API-call that takes the Request as a parameter and returns the call-specific Response-

Object.

4.1 Proxy, Session

You first lets create a Session and a ServiceProxy.

require_once 'EbatNs_ServiceProxy.php'; $session = new EbatNs_Session('/config/ebay.config.php'); $sp = new EbatNs_ServiceProxy($session);

The Session could take a path to the config-file to initialize all needed information form it.

There is also a short-version to let the ServiceProxy create the session for you. Here you only give the con-

fig-file.

$sp = new EbatNs_ServiceProxy($cfg = '/config/ebay.config.php');

Note: The ServiceProxy will take a reference-parameter, so you will need this rarely used syntax here. So

the method can distinguish weather you passed a session or the config-file.

4.2 Request, Call, Response

Having the ServiceProxy you can setup your Request-Object. To not overload the memory with preloading

files, you have to include the needed type-file for your own. But this is easy: If you known the Name of the

Call to issue just append “…RequestType.php”.

So let’s try with a GetItem-Call. The responding Request-Type would be “GetItemRequestType.php”

require_once 'GetItemRequestType.php'; $req = new GetItemRequestType(); $req->setItemID(4504181935);

The Request-Type might (normally) need various data to be set. Here as we want to retrieve an Item we only

need to set the ItemID. Within the EbatNs you will find “setter”-methods for all parameters you can use.

Note: You might get back data here as the Item above with the ID 4504181935 might be already expired

when you do the call.

Next you can issue the call :

$res = $cs->GetItem($req);

Easy doing you will get back the response with the Item you are interested in.

Next you can check the Response and retrieve the information of interest. In this case we can just print out

the item.

echo "<pre>"; print_r($res->getItem());

5

Page 6: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

Also the Response Object will have methods to access the data. Here you will find “getter”-methods for all

data.

Note: Please take care that not all data is returned by all calls. The eBay Unified Schema might define data

for various type that is only returned under certain circumstances.

Ok, here is the complete script altogether :

require_once 'EbatNs_ServiceProxy.php'; require_once 'GetItemRequestType.php'; $session = new EbatNs_Session('/config/ebay.config.php'); $sp = new EbatNs_ServiceProxy($session); $req = new GetItemRequestType(); $req->setItemID(4504181935); $res = $cs->GetItem($req); echo "<pre>"; print_r($res->getItem());

4.3 Handling Errors

The eBay API will respond with error information in certain situations. You might check this conditions to

handle these errors. Please be aware that you might get errors and warnings, whereas warning will mainly

have only informational intense.

To check the success (nor errors or warnings) by check the field Ack in the Response-Object :

$req = new GetItemRequestType(); $req->setItemID(1); $res = $cs->GetItem($req); if ($res->getAck() != 'Success') echo "we got a failure";

Here you can also retrieve the Errors-Array and show the error you got :

foreach ($res->getErrors() as $error) { echo "#" . $error->getErrorCode() . " " . htmlentities($error->getShortMessage()) . "/" . htmlentities($error->getLongMessage()) . "<br>"; }

6

Page 7: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

5 Correlation to the API Documentation The EbatNs is based on the SOAP API and basically you will find all needed information within the online-

documentation on http://develoeper.ebay.com.

The online could be read here http://developer.ebay.com/DevZone/SOAP/docs/WebHelp/index.htm.

As all stuff could be found here we skipped a documentation of the Toolkit and you should relate to the docs

above. Be sure that you relate to the documentation version of the Toolkit you are using.

For all API-calls (found under API Call Reference Guide) you will find a method in the ServiceProxy and the

request/response datatypes. All schema datatype will correlate to a PHP file that implements the datatype.

We have made minimal adoption to the way to eBay Schema datatypes are transferred to PHP objects. You

can find details within the following paragraphs.

Note: We had integrated comments within the EbatNs code to let an intelligent IDE use this information and

provide you with some hints while programming. You can use a documentor on this information and gener-

ate a help file (checkout http://www.phpdoc.de/).

7

Page 8: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

6 Data Structure The eBay Acellerator for PHP Unified Schema is using SOAP calls to communicate with eBay API Servers.

When starting with the project we saw a lot of different SOAP implementations on PHP (NuSoap, PEAR-

SOAP, etc.). As none of them really fitted our needs we just rewrote our own implementation. Definitely our

SOAP client is not tested with others than the eBay WebService and we assume it should not a good idea to

use it for other purposes. But it is rather light-weight and so the performance should not be an issue.

What was basically done her is a kind of type-aware DOM parsing but without using the PHP DOM Libraries

but only the “normal” XML (Expat) parser that PHP is providing as a internal module. So you will get PHP

objects with member-variables, in case of arrays these variables are just PHP arrays. The underlying E-

batNs_Parser will include any needed PHP class-files if needed, so the resulting object-structure should be

very clean.

6.1 Basic Mapping

As a basic guideline all eBay Schema datatypes are mapped against single PHP files which you can find in

the EbatNs installation folder. For each call you will find a file corresponding to the Request and Response

datatype. The files will auto-include any needed sub-types that are used within here.

The implementation of the datatypes in PHP are based on PHP-classes. For any child-elements these clas-

ses implements a member-variable with the same name. All variables could be either accessed directly or

via provided getter- and setter-methods.

If the Schema datatype is a “simple-type” we provided a member-variable which is named “value” and a set-

TypeValue($value) and getTypeValue() method (see EbatNs_SimpleType.php for details).

Most of the Schema datatype do not have XML-Attributes but a few do (e.g. the AmountType). Here you can

use the provided methods setTypeAttribute( $key, $value ) and getTypeAttribute( $key ) to access the Attrib-

utes. Sounds very complex but in reality it is not. PHP is very “type-lax” so we thought the best way was to

do it like this.

Let’s setup a basic AddItemRequestType to see the implications to code:

$item = new ItemType(); $item->ListingDuration = ‘Days_7’; $item->StartPrice = new AmountType(); $item->StartPrice->setTypeValue(3.99); $item->StartPrice->setTypeAttribute(‘currencyID’, ‘EUR’); $item->BuyItNowPrice = new AmountType(); $item->BuyItNowPrice->setTypeValue(9.99); $item->BuyItNowPrice->setTypeAttribute(‘currencyID’, ‘EUR’); … $req = new AddItemRequestType(); $req->Item = $item;

If you prefer using the setter-method you might code :

8

Page 9: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

$item = new ItemType(); $item->setListingDuration(‘Days_7’); $amount = new AmountType(); $amount->setTypeValue(3.99); $amount->setTypeAttribute(‘currencyID’, ‘EUR’); $item->setStartPrice($amount); // reuse the amount object $amount->setTypeValue(9.99); $item->setBuyItNowPrice($amount);

6.1.1 Special Handling of ArrayTypes A lot of the eBay-schema-elements are returning arrays. Anyway if you look at the names of the elements

you will often but not always see names like “xxxArrayType” or a plural like “someTypes” (so with an ‘s’ at

the end).

Sometimes these arrays are called just with a singularname (e.g. InternationalShippingServiceOption instead

of InternationalShippingServiceOptionS but correctly ShippingServiceOptions). Anyway maybe the eBay

guys are going to change it in the future but for the moment we have to handle this.

The schema provides information if an element has a cardinality of greater than 1 (so being an array) and so

we used this information. An important issue is that such an array-element is always an array. Sound para-

dox but other SOAP implementation where just returning plain-value for array of size 1, the EbatNs will cor-

rectly return – in such a situation - just an array with a single element. Although you can be sure to get an

array this result also to some implications (as a few elements e.g. the parent-id of a category are defined as

array-types although mostly you will only get 1 element).

For such elements the getter-/setter-method are a little different. Here you will have an optional argument

$index which let you access a single element of the array.

e.g.

$category->getParentId(0); $ShippingDetails->setShippingServiceOptions($option, 2);

Leaving out the $index argument will set/get the internal array itself (so all elements). Although all of this

seems easy and obvious you might trigger some problems here as the API docs does not directly points you

to the cardinality (anyway it is in the WSDL and Visual Schema Reference).

6.1.2 Setter- and Getter-methods For all Schema object the appropriate access methods are generated. The names are just prefixed by “get”

and “set”.

Schema:

Item.ListingDuration

will result to:

$item->getListingDuration(); $item->setListingDuration($duration);

9

Page 10: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

If an element is an array you will get extra arguments $index to access the indexed values. Beware that lea-

ving the argument out will result to access the internal array, but a single value.

Setting array-type values:

$paymentMethods[] = ‘PersonalCheck’; $paymentMethods[] = ‘MoneyXferAccepted’; $paymentMethods[] = ‘PayPal’; // setting the array as a value $item->setPaymentMethods($paymentMethods); or

// setting the values one by one $item->setPaymentMethods($paymentMethods[0], 0); $item->setPaymentMethods($paymentMethods[1], 1); $item->setPaymentMethods($paymentMethods[2], 2); $item->setPaymentMethods(‘COD’, 3);

Accessing array-type values:

// getting all as an array $array = $item->getPaymentMethods();

// getting a single value if ( count($item->getPaymentMethods() > 4) ) $value = $item->getPaymentMethods(4);

6.1.3 Handling on “empty” values To save memory we decided to reduce all objects to the minimum. So the EbatNs will NOT contain variables

for Schema elements that are not returned from the API Servers. The eBay unified schema will always return

e.g. an Item as a complete ItemType, but this does not mean that all fields will be returned. In case eBay

does not return a value you will not have the member variable.

Although this should not bring you in trouble you will encounter that PHP will throw a Notice if you try to ac-

cess the variable (this might be also happen if you use the get-Method).

error_reporting(E_ALL); … $item = $res->getItem(); echo "ShippingTerms : " . $item->getShippingTerms() . "<br>";

would throw this if the item you work on does not have ShippingTerms : Notice: Undefined property: ShippingTerms in ../ItemType.php on line xxx

You should then switch off error_reporting for E_NOTICE (which is the default on PHP 4) or test the value

first.

6.1.4 Data Conversion The EbatNs will do data conversion internally. As SOAP and PHP differs in the way certain data types are

coded we did some internal conversion here. Besides you would like to work in your scripts not using UTF-8

Charset Encoding (what is needed for the eBay API) but using PHP’s ISO-8859-1 charset.

10

Page 11: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

We placed DataConversion into a separate class called EbatNs_DataConverter. Here you will find handler

method for encoding and decoding data. You might decide to re-model the DataConverter for your needs.

IMPORTANT NOTE : Currently the EbatNs_ServiceProxy is using a DataConverterIso as default which will encode/decode to ISO-8859-1. So any string sended will be encoded using utf8_encode and any strings coming back will be decoded using utf8_decode. Besides this the field “Description” is always placed into a <![CDATA[ ]]> construct.

11

Page 12: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

7 Advanced Operations 7.1 Working with Pagination

A few API call have the ability to retrieve data in data-page so you can retrieve the returned data in chunk

(the so called pages) giving a page-size and a page-number.

The unified schema does simplified the procedure using the PaginationType. Please following the code be-

low to clarify the way it works.

$cs = new EbatNs_ServiceProxy($session); $req = new GetPopularKeywordsRequestType(); // getting chunk of page-size 100 ... // ... and current page 1 $req->Pagination = new PaginationType(); $req->Pagination->EntriesPerPage = 100; $req->Pagination->PageNumber = 1; $res = $cs->GetPopularKeywords($req);

7.2 UTF8 and ISO8859-1

The eBay API is working with UTF8 only – in the EbatNs you can decide if you like to go with ISO8859-1

(which is the default) or work in UTF8 mode.

To change over to UTF8 you will need to adapt the way how the EbatNs_ServiceProxy is created.

// creating a proxy with (default) Iso-Converter $cs = new EbatNs_ServiceProxy($session); // ... the same as $cs = new EbatNs_ServiceProxy($session, 'EbatNs_DataConverterIso'); // creating a proxy for UTF8 (or custom converters) $cs = new EbatNs_ServiceProxy($session, 'EbatNs_DataConverterUtf8');

7.3 Working with Notifications

You can handle eBay Platform Notifications with a special helper-class provided. The subscription process is

out of scope of this document so please refer to the API documentation.

A sample handler for PHP might be worked out with this code:

require_once 'EbatNs_NotificationClient.php'; $handler = new EbatNs_NotificationClient(); $msg = file_get_contents('php://input'); $res = $handler->getResponse($msg);

Anyway what you get back in $res will depend on the notification that is handled. Anyway you check in the

fields NotificationEventName, NotificationSignature and RecipientUserID for the notification informational

data.

12

Page 13: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

8 Special EbatNs-Features 8.1 Using a DataType-Handler

Depending on the amount and way you would like to handle the returned data you might use the “DataType-

Handler”-feature of the EbatNs.

Basically you hook into the parsing process of the ResponseParser and will be notify if a certain Element

was parsed. The hook is based on the Type of object that needs to be stored. Normally the parser would just

attach the data within the structure (ResponseObject) and returns all data as a return of the call.

Especially if you have to handle of large amount of data (e.g. a category-download) this way would create a

very large response-object. So the script would consume a lot of memory and resources. Anyway afterwards

you would go and loop the response-data and handle it.

The way the DataType-handler works will make the procedure much easier and normally you can work with

a much lower memory-limit.

So setup a handler you will need a callback-function (either a global function or an object’s method). You will

then inform the ServiceProxy about the handler and the DataType is should work on. Within your handler

you can decide weather you like to attach the parsed object to the result or not.

The function signature has to be like this :

function callback($type, & $data) { return true; }

Ok so let bring it into a bigger context and hook in for ItemTypes :

$cs = new EbatNs_ServiceProxy($session); $cs->setHandler('ItemType', 'handleItem'); $req = new GetItemRequestType(); $req->setItemID(4504181935); $res = $cs->GetItem($req); function handleItem($type, & $data) { echo "Hello Item<pre><br>"; print_r($data); return false; }

The function handleItem will be called on each Item retrieved. Returning false in the function will let the par-

ser attach the Item to the response. If you return true the Item would NOT be attached.

Anyway the same functionality could also be done using an object as the handler. Here is a sample for a

category-download.

13

Page 14: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

$cs = new EbatNs_ServiceProxy($session); $handler = new handlerMethods($cs); $req = new GetCategoriesRequestType(); $req->CategorySiteID = 77; $req->LevelLimit = 1; $req->DetailLevel = 'ReturnAll'; $res = $cs->GetCategories($req); class handlerMethods { // import-need to pass in by ref ! function handlerMethods(& $cs) { $cs->setHandler('CategoryType', array(& $this, 'handleCategory')); } function handleCategory($type, & $Category) { echo "(" . $Category->CategoryID . "/" . $Category->CategoryParentID[0] . ") " . $Category->CategoryName . "<br>"; return true; } }

8.2 Using a Database – Handler

As very often a call will result to a database operation, e.g retrieve Categories and store them into a databa-

se-table, we build a module for simply the process. Basically the class (EbatNs_DatabaseProvider) is

nothing more than a accessor to a database. Currently only the usage of MySQL is supported.

The basic structure is very near to the DataType Handler above but the extra database functionality is added

in a convenient way. Please refer to the cookbook in the appendix to see a sample of usage.

8.3 Working on the Command-Line

The EbatNs is fully supported also on the PHP command line. Anyway we found it very helpful to use scripts

on the command-line which are time-consuming (e.g. the category download).

8.4 Maintain Session without config-files

$session = new EbatNs_Session(); $session->setAppId($appId); setDevId($devId); setCertId($certId); // depends on the site working on (needs ID-Value !) setSiteId(77); // environment (0=production, 1=sandbox) setAppMode(0); // use a token as credential setTokenMode(true); // do NOT use a token file ! setTokenUsePickupFile(false); // token of the user setRequestToken($token); // if using user/password credentials only : setTokenMode(false); setRequestUser($userid); setRequestPassword ($password);

14

Page 15: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

9 Appendix 9.1 Cookbook

The cookbook lists ready-made scripts for usage in standard-situations. This should guide beginners as a

starting point to the usage of the EbatNs.

Most of the following script could also be found in the addional sample pack. Before you try to integrate the

snipple be sure that the the EbatNs-Folder is within your include path and that you have access to specifc

config-file

9.1.1 Download and Maintain Categories <?php

set_time_limit(0);

require_once 'EbatNs/EbatNs_ServiceProxy.php';

require_once 'EbatNs/GetCategoriesRequestType.php';

require_once 'EbatNs/GetCategoriesResponseType.php';

require_once 'EbatNs/CategoryType.php';

$session = new EbatNs_Session('config/ebay.config.php');

$cs = new EbatNs_ServiceProxy($session);

$cs->_debugLogDestination = '';

$handler = new handlerMethods($cs);

$req = new GetCategoriesRequestType();

$req->CategorySiteID = 77;

$req->LevelLimit = 1;

$req->DetailLevel = 'ReturnAll';

$res = $cs->GetCategories($req);

class handlerMethods

{

// import-need to pass in by ref !

function handlerMethods(& $cs) {

$cs->setHandler('CategoryType', array(& $this, 'handleCategory'));

}

function handleCategory($type, & $Category) {

//#type $Category CategoryType

echo "(" . $Category->CategoryID .

"/" . $Category->CategoryParentID[0] .

") " . $Category->CategoryName . "<br>";

return true;

}

}

?>

15

Page 16: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

9.1.2 List an Item 9.1.2.1 simple-listing Be aware here that the shipping services are specific for eBay.de ! <?php

require_once 'EbatNs/EbatNs_ServiceProxy.php';

require_once 'EbatNs/EbatNs_Logger.php';

require_once 'EbatNs/VerifyAddItemRequestType.php';

require_once 'EbatNs/AddItemRequestType.php';

require_once 'EbatNs/ItemType.php';

$session = new EbatNs_Session('config/ebay-sandbox.config.php');

$cs = new EbatNs_ServiceProxy($session);

$cs->_logger = new EbatNs_Logger(true);

$item = new ItemType();

$item->Description = 'test öäü á <b>Some bold text</b>';

$item->ListingDuration = 'Days_7';

$item->Title = 'äöü test-titel';

$item->Currency = 'EUR';

$item->ListingType = 'FixedPriceItem';

$item->Quantity = 1;

$item->StartPrice = new AmountType();

$item->StartPrice->setTypeValue('1.0');

$item->StartPrice->setTypeAttribute('currencyID', 'EUR');

$item->Country = 'DE';

$item->Location = '-- not given --';

$item->PrimaryCategory = new CategoryType();

$item->PrimaryCategory->CategoryID = 31448;

$item->Site = 'Germany';

$item->ShipToLocations[]="Europe";

$ShippingServiceOptions = new ShippingServiceOptionsType();

$cost = new AmountType();

$cost->setTypeValue($amount);

$cost->setTypeAttribute('currencyID', 'EUR');

$ShippingServiceOptions->setShippingService('DE_InsuredDispatch');

$ShippingServiceOptions->setShippingServiceCost(3.33);

$ShippingServiceOptions->setShippingServicePriority(1);

$shipping[]=$ShippingServiceOptions;

$InternationalShippingServiceOptions = new InternationalShippingServiceOptionsType();

$cost = new AmountType();

$cost->setTypeValue($amount);

$cost->setTypeAttribute('currencyID', 'EUR');

16

Page 17: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

$InternationalShippingServiceOptions-

>setShippingService('DE_VersicherterVersandInternational');

$InternationalShippingServiceOptions->setShippingServiceCost(4.44);

$InternationalShippingServiceOptions->setShippingServicePriority(1);

$InternationalShippingServiceOptions->setShipToLocation('Europe');

$shippingInternational[]=$InternationalShippingServiceOptions;

$shippingObj = new ShippingDetailsType();

$shippingObj->ShippingType='Flat';

$shippingObj->setShippingServiceOptions($shipping, 0);

$shippingObj->setInternationalShippingServiceOption($InternationalShippingServiceOptions,

0);

$item->setPaymentMethods($Facet_BuyerPaymentMethodCodeType->PaymentSeeDescription, 2);

$item->setPaymentMethods($Facet_BuyerPaymentMethodCodeType->COD, 3);

$item->setPaymentMethods($Facet_BuyerPaymentMethodCodeType->PayPal, 4);

$item->setPayPalEmailAddress('[email protected]');

$item->setShippingDetails($shippingObj,0);

$req = new AddItemRequestType();

$req->Item = $item;

$res = $cs->AddItem($req);

// $res = $cs->VerifyAddItem($req);

echo "<pre>";

print_r($res);

?>

9.1.2.2 list with attributes <?php

require_once 'EbatNs/EbatNs_ServiceProxy.php';

require_once 'EbatNs/EbatNs_Logger.php';

require_once 'EbatNs/VerifyAddItemRequestType.php';

require_once 'EbatNs/AddItemRequestType.php';

require_once 'EbatNs/ItemType.php';

$session = new EbatNs_Session('config/ebay.config.php');

$cs = new EbatNs_ServiceProxy($session);

$cs->_logger = new EbatNs_Logger(true);

$item = new ItemType();

$item->Description = 'test öäü á <b>Some bold text</b>';

$item->ListingDuration = 'Days_7';

$item->Title = 'äöü test-titel';

$item->Currency = $Facet_CurrencyCodeType->EUR;

$item->ListingType=$Facet_ListingTypeCodeType->Chinese;

$item->Quantity = 1;

17

Page 18: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

$item->StartPrice = new AmountType();

$item->StartPrice->setTypeValue('1.00');

$item->StartPrice->setTypeAttribute('currencyID', $Facet_CurrencyCodeType->EUR);

$item->Country = $Facet_CountryCodeType->DE;

$item->Location = '-- not given --';

$item->PrimaryCategory = new CategoryType();

$item->PrimaryCategory->CategoryID = 31448;

$item->PaymentMethods[] = $Facet_BuyerPaymentMethodCodeType->MoneyXferAccepted;

$item->PaymentMethods[] = $Facet_BuyerPaymentMethodCodeType->PayPal;

$item->PayPalEmailAddress = '[email protected]';

// setting item-condition for site Germany

$condition = null;

if ($condition !== null)

{

// create a new AttributeSet (CsSet 1950 / site-wide condition)

$attSet = new AttributeSetType();

$attSet->setTypeAttribute('attributeSetID', 1950);

// create a Attribute with id 10244

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 10244);

// create the value for the attribute

// and associate the value new/used

$attValue = new ValType();

if ($condition == '1')

{

$attValue->setValueID('10425'); // neu

$attValue->setValueLiteral('Neu');

}

else

{

$attValue->setValueID('10426'); // gebraucht

}

// append the value to the attribute ...

$att->setValue($attValue, 0);

// ... and attach the value to the attribute

$attSet->Attribute[] = $att;

// create the AttributeSet Array for the item ...

$atts = new AttributeSetArrayType();

// ... and attach the set to it

$atts->setAttributeSet($attSet, 0);

// finally attach the set-array to the item

18

Page 19: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

$attSet = new AttributeSetType();

$attSet->setTypeAttribute('attributeSetID', 2136);

// create a Attribute with id 10244

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 3803);

// create the value for the attribute

// and associate the value new/used

$attValue = new ValType();

$attValue->setValueID('32040'); // neu

// append the value to the attribute ...

$att->setValue($attValue, 0);

// ... and attach the value to the attribute

$attSet->Attribute[] = $att;

$att->setTypeAttribute('attributeID', 3806);

// create the value for the attribute

// and associate the value new/used

$attValue = new ValType();

$attValue->setValueID('-3'); // neu

$attValue->setValueLiteral('Der Käufer hat das Recht, den Artikel

zurückzugeben');

// append the value to the attribute ...

$att->setValue($attValue, 0);

// ... and attach the value to the attribute

$attSet->Attribute[] = $att;

// create the AttributeSet Array for the item ...

$atts = new AttributeSetArrayType();

// ... and attach the set to it

$atts->setAttributeSet($attSet, 0);

// finally attach the set-array to the item

$item->AttributeSetArray = $atts;

}

else

{

$condAttSet = new AttributeSetType();

$condAttSet->setTypeAttribute('attributeSetID', 1950);

$condAtt = new AttributeType();

$condAtt->setTypeAttribute('attributeID', 10244);

$condAttValue = new ValType();

$condAttValue->setValueID(10425);

$condAttValue->setValueLiteral("Neu");

$condAtt->setValue($condAttValue, 0);

19

Page 20: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

$condAttSet->Attribute[] = $condAtt;

$attSet = new AttributeSetType();

$attSet->setTypeAttribute('attributeSetID', 2136);

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 3803);

$attValue = new ValType();

$attValue->setValueID('32040');

$att->setValue($attValue, 0);

$attSet->Attribute[] = $att;

$att2 = new AttributeType();

$att2->setTypeAttribute('attributeID',3806);

$attValue2 = new ValType();

$attValue2->setValueID(-3);

$attValue2->setValueLiteral('Der Käufer hat das Recht, den Artikel

zurückzugeben');

$att2->setValue($attValue2, 0);

$attSet->Attribute[] = $att2;

$attSetArray = new AttributeSetArrayType();

$attSetArray->AttributeSet[] = $attSet;

$attSetArray->AttributeSet[] = $condAttSet;

$item->AttributeSetArray = $attSetArray;

$item->ShipToLocations[]="Europe";

$ShippingServiceOptions = new ShippingServiceOptionsType();

$cost = new AmountType();

$cost->setTypeValue($amount);

$cost->setTypeAttribute('currencyID', 'EUR');

$ShippingServiceOptions->setShippingService('DE_InsuredDispatch');

$ShippingServiceOptions->setShippingServiceCost(3.33);

$ShippingServiceOptions->setShippingServicePriority(1);

$shipping[]=$ShippingServiceOptions;

$shippingObj = new ShippingDetailsType();

$shippingObj->ShippingType='Flat';

$shippingObj->setShippingServiceOptions($shipping, 0);

$item->setShippingDetails($shippingObj,0);

}

$req = new AddItemRequestType();

$req->Item = $item;

$res = $cs->AddItem($req);

echo "<pre>";

20

Page 21: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

print_r($res);

?>

9.1.2.3 list to real-estate category (germany) <?php

require_once 'EbatNs/EbatNs_ServiceProxy.php';

require_once 'EbatNs/EbatNs_Logger.php';

require_once 'EbatNs/AddItemRequestType.php';

require_once 'EbatNs/ItemType.php';

$session = new EbatNs_Session('config/thc.ebay.config.php');

$cs = new EbatNs_ServiceProxy($session);

$cs->attachLogger(new EbatNs_Logger(true));

$req = new AddItemRequestType();

$item = new ItemType();

$item->Description = 'Mein wunderbares Wohnobjekt';

$item->ListingDuration = $Facet_ListingDurationCodeType->Days_10;

$item->Title = 'eimw-test-0001';

$item->Currency = 'EUR';

$item->ListingType = $Facet_ListingTypeCodeType->AdType;

$item->Quantity = 1;

$item->StartPrice = new AmountType();

$item->StartPrice->setTypeValue('1.0');

$item->StartPrice->setTypeAttribute('currencyID', 'EUR');

$item->Country = 'DE';

$item->Location = '-- not given --';

$item->ListingDuration = 'Days_30';

$item->PrimaryCategory = new CategoryType();

// wohnen

$item->PrimaryCategory->CategoryID = 60092;

$item->Site = 'Germany';

$attSet = new AttributeSetType();

$attSet->setTypeAttribute('attributeSetID', 1903);

// objekt-typ : Wohung vermieten

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 19);

$val = new ValType();

$val->setValueID(26777);

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// objekt-subtyp : Neubau

21

Page 22: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 27774);

$val = new ValType();

$val->setValueID(26782);

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// bundesland : NRW

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 9);

$val = new ValType();

$val->setValueID(26801);

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// stadt : Köln

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 10);

$val = new ValType();

$val->setValueID(26896);

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// stadtteil : poll

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 27775);

$val = new ValType();

$val->setValueID(29389);

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// anzahl-zimmer : 4

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 29);

$val = new ValType();

$val->setValueLiteral('4');

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// stockwerk : 3

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 27783);

$val = new ValType();

$val->setValueID(32472);

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// qm : 150

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 27776);

22

Page 23: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

$val = new ValType();

$val->setValueLiteral('150');

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// NK : 111

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 27784);

$val = new ValType();

$val->setValueLiteral('111');

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// miete : 666

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 30249);

$val = new ValType();

$val->setValueLiteral('666');

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// kaution : 3 mm

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 32462);

$val = new ValType();

$val->setValueLiteral('1998');

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// provision : 1 mm

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 32463);

$val = new ValType();

$val->setValueLiteral('666');

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// baujahr : 2000

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 30737);

$val = new ValType();

$val->setValueLiteral('2000');

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// verfügbar : 01.03.2006

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 32464);

$val = new ValType();

$val->setValueLiteral('2006-03-01');

23

Page 24: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// ausstattung : Balkon + Garten

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 35);

$val = new ValType();

$val->setValueID(26829); // balkon

$att->Value[] = $val;

$val = new ValType();

$val->setValueID(26815); // garten

$att->Value[] = $val;

$attSet->Attribute[] = $att;

$atts = new AttributeSetArrayType();

$atts->setAttributeSet($attSet, 0);

$item->AttributeSetArray = $atts;

$req->Item = $item;

$res = $cs->AddItem($req);

echo "<pre>";

print_r($res);

?>

9.1.3 Retrieve a single item 9.1.3.1 Simple GetItem: <?php

require_once 'EbatNs/EbatNs_ServiceProxy.php';

require_once 'EbatNs/EbatNs_Logger.php';

require_once 'EbatNs/GetItemShippingRequestType.php';

$session = new EbatNs_Session('config/ebay.config.php');

$cs = new EbatNs_ServiceProxy($session);

// $cs->setHandler('ItemType', 'handleItem');

$cs->attachLogger(new EbatNs_Logger(true, 'stdout', true, false));

$req = new GetItemShippingRequestType();

$req->ItemID = '110005425865';

$req->setDestinationPostalCode('51105');

$res = $cs->GetItemShipping($req);

24

Page 25: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

print_r($res);

?>

9.1.3.2 Full-Featured GetItem: <?php

error_reporting(E_ALL ^ E_NOTICE);;

require_once 'EbatNs/EbatNs_ServiceProxy.php';

require_once 'EbatNs/EbatNs_Logger.php';

require_once 'EbatNs/GetItemRequestType.php';

require_once 'EbatNs/ItemType.php';

$session = new EbatNs_Session('config/thc.ebay.config.php');

$cs = new EbatNs_ServiceProxy($session);

// $cs->setHandler('ItemType', 'handleItem');

$cs->attachLogger(new EbatNs_Logger(true, 'stdout', true, false));

$req = new GetItemRequestType();

$req->setItemID(7226162372);

$req->setDetailLevel($Facet_DetailLevelCodeType->ReturnAll);

$res = $cs->GetItem($req);

echo "<pre>";

if ($res->getAck() != $Facet_AckCodeType->Success)

{

echo "we got a failure<br>";

foreach ($res->getErrors() as $error)

{

echo "#" . $error->getErrorCode() . " " .

htmlentities($error->getShortMessage()) . "/" .

htmlentities($error->getLongMessage()) . "<br>";

}

}

else

{

$item = $res->getItem();

echo "Title Variation 1: ";

echo $item->getTitle() . "<br>";

// or

echo "Title Variation 2: ";

echo $item->Title . "<br>";

echo "Title Variation 3: ";

echo $res->Item->Title . "<br>";

echo $item->getDescription() . "<br>";

25

Page 26: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

foreach ($item->getPaymentMethods() as $payMethod)

{

echo "PayMethod " . $payMethod . "<br>";

}

$listDet = $item->ListingDetails;

echo $listDet->ViewItemURL . "<br>";

echo "2nd Variation direkt: " .

$res->Item->ListingDetails->ViewItemURL . "<br>";

}

function handleItem($type, & $data)

{

echo "Hello Item<pre><br>";

// print_r($data);

return false;

}

?>

9.1.4 Revise an Item This sample is a full revise of an item running in the real estate category on eBay Germany. <?php

require_once 'EbatNs/EbatNs_ServiceProxy.php';

require_once 'EbatNs/EbatNs_Logger.php';

require_once 'EbatNs/ReviseItemRequestType.php';

require_once 'EbatNs/ItemType.php';

$session = new EbatNs_Session('config/ebay.config.php');

$cs = new EbatNs_ServiceProxy($session);

$cs->attachLogger(new EbatNs_Logger(true));

$req = new ReviseItemRequestType();

$item = new ItemType();

$item->ItemID = "4504789605";

$item->Title = 'eimw-test-0001 Rev. 1 12h';

$item->Currency = 'EUR';

$item->ListingType = $Facet_ListingTypeCodeType->AdType;

$item->Quantity = 1;

$item->StartPrice = new AmountType();

$item->StartPrice->setTypeValue('1.99');

$item->StartPrice->setTypeAttribute('currencyID', 'EUR');

$item->Country = 'DE';

$item->Location = '-- not given --';

$item->PrimaryCategory = new CategoryType();

26

Page 27: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

// wohnen

$item->PrimaryCategory->CategoryID = 60092;

$item->Site = 'Germany';

$attSet = new AttributeSetType();

$attSet->setTypeAttribute('attributeSetID', 1903);

// objekt-typ : Wohung vermieten

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 19);

$val = new ValType();

$val->setValueID(26779);

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// objekt-subtyp : Maisonette

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 26819);

$val = new ValType();

$val->setValueID(-6);

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// bundesland : NRW

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 9);

$val = new ValType();

$val->setValueID(26801);

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// stadt : Köln

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 10);

$val = new ValType();

$val->setValueID(26896);

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// stadtteil : poll

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 27775);

$val = new ValType();

$val->setValueID(29389);

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// anzahl-zimmer : 4

$att = new AttributeType();

27

Page 28: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

$att->setTypeAttribute('attributeID', 29);

$val = new ValType();

$val->setValueLiteral('5');

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// stockwerk : 3

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 27783);

$val = new ValType();

$val->setValueID(32472);

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// qm : 150

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 27776);

$val = new ValType();

$val->setValueLiteral('200');

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// NK : 111

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 27784);

$val = new ValType();

$val->setValueLiteral('120');

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// miete : 666

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 30249);

$val = new ValType();

$val->setValueLiteral('888');

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// kaution : 3 mm

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 32462);

$val = new ValType();

$val->setValueLiteral('2500');

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// provision : 1 mm

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 32463);

$val = new ValType();

28

Page 29: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

$val->setValueLiteral('1000');

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// baujahr : 2000

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 30737);

$val = new ValType();

$val->setValueLiteral('1999');

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// verfügbar : 01.03.2006

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 32464);

$val = new ValType();

$val->setValueLiteral('2006-05-01');

$att->setValue($val, 0);

$attSet->Attribute[] = $att;

// ausstattung : Balkon + Garten

$att = new AttributeType();

$att->setTypeAttribute('attributeID', 35);

$val = new ValType();

$val->setValueID(26829); // balkon

// $val->setValueID(26819); // Maisonette

$att->Value[] = $val;

$val = new ValType();

$val->setValueID(26815); // garten

// $val->setValueID(26816); // Kabel-TV

$att->Value[] = $val;

$attSet->Attribute[] = $att;

$atts = new AttributeSetArrayType();

$atts->setAttributeSet($attSet, 0);

$item->AttributeSetArray = $atts;

$req->Item = $item;

$res = $cs->ReviseItem($req);

echo "<pre>";

print_r($res);

?>

29

Page 30: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

9.1.5 Retrieve Transactions 9.1.5.1 Using GetItemTransactions <?php

require_once 'EbatNs/EbatNs_ServiceProxy.php';

require_once 'EbatNs/EbatNs_Logger.php';

require_once 'EbatNs/GetItemTransactionsRequestType.php';

require_once 'EbatNs/GetItemTransactionsResponseType.php';

$session = new EbatNs_Session('config/ebay.config.php');

$cs = new EbatNs_ServiceProxy($session);

$cs->attachLogger(new EbatNs_Logger(true));

$req = new GetItemTransactionsRequestType();

$req->ItemID = "5664253778";

$now = time();

$start = $now - (3600 * 24 * 30);

$end = $start + (3600 * 24 * 30);

// period 30 days

$req->ModTimeFrom = gmdate('Y-m-d H:i:s', $start);

$req->ModTimeTo = gmdate('Y-m-d H:i:s', $end);

$req->DetailLevel = $Facet_DetailLevelCodeType->ReturnAll;

$res = $cs->GetItemTransactions($req);

echo "<pre>";

print_r($res);

?>

9.1.5.2 Using GetSellerTransactions: <?php

require_once 'EbatNs/EbatNs_ServiceProxy.php';

require_once 'EbatNs/EbatNs_Logger.php';

require_once 'EbatNs/GetSellerTransactionsRequestType.php';

require_once 'EbatNs/GetSellerTransactionsResponseType.php';

$session = new EbatNs_Session('config/ ebay.config.php');

$cs = new EbatNs_ServiceProxy($session);

$cs->attachLogger(new EbatNs_Logger(true));

$req = new GetSellerTransactionsRequestType();

$now = time();

$start = $now - (3600 * 24 * 30);

$end = $start + (3600 * 24 * 30);

// period 30 days

$req->ModTimeFrom = gmdate('Y-m-d H:i:s', $start);

$req->ModTimeTo = gmdate('Y-m-d H:i:s', $end);

$req->DetailLevel = $Facet_DetailLevelCodeType->ReturnAll;

30

Page 31: ProgrammersGuide 10

_________________________________________________________________ ________________ __ _______ ___ ________ ________________ __ _______ ___ _______ www.intradesys.de | [email protected] ________________________________________________________________ IN TRADESYS________________ __ _______ ___ ________________________ __ _______ ___ ________

Programmers Guide, EbatNs, 1.0

//#type $res GetSellerTransactionsResponseType

$res = $cs->GetSellerTransactions($req);

if ($res->Ack == $Facet_AckCodeType->Success)

{

echo "<pre>";

print_r($res);

}

?>

31