Professional Web APIs with PHP. eBay, Google, PayPal, Amazon, FedEx, Plus Web Feeds

Using the new makeAPICall() function, additional requests can be coded and handled quickly. For example, the code necessary to search for a transaction by email address (which might be easily tied to a support system or a user look-up feature) would look like this:

function searchEmail($email) { $parameters = array(); $parameters[] = array("StartDate", "ebl:dateTime", "2000-01-29T12:00:01.00Z"); $parameters[] = array("Payer", "ebl:string", "$email"); $xml = makeAPICall("TransactionSearch", $parameters); return $xml; }

StartDate is a required element in the request, so it is sent to an arbitrary date before any transactions are performed. Payer is used to search by the payer's email address, which is very useful because it will even find an email address if a user has changed his since payment. Unlike TransactionDetailsSearch, this will return multiple results matching your search criteria (which could include EndDate, Payer, Receiver, ReceiptID, TransactionID, InvoiceID, PayerName, or AuctionItemNumber). When called with

searchEmail("bigbird@example.com");

the results will look something like this:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ebl=" urn:ebay:apis:eBLBaseComponents" xmlns:ns=" urn:ebay:api:PayPalAPI"> <SOAP-ENV:Header> ... </SOAP-ENV:Header> <SOAP-ENV:Body > <TransactionSearchResponse xmlns="urn:ebay:api:PayPalAPI"> <Timestamp xmlns="urn:ebay:apis:eBLBaseComponents">2005-04-19T02:51:29Z </Timestamp> <Ack xmlns="urn:ebay:apis:eBLBaseComponents">Success</Ack> <Version xmlns="urn:ebay:apis:eBLBaseComponents">1.000000</Version> <Build xmlns="urn:ebay:apis:eBLBaseComponents">1.0006</Build> <PaymentTransactions xmlns="urn:ebay:apis:eBLBaseComponents" xsi:type="ebl:PaymentTransactionSearchResultType"> <Timestamp xsi:type="xs:dateTime">2005-04-15T04:05:16Z</Timestamp> <Timezone xsi:type="xs:string">GMT</Timezone> <Type xsi:type="xs:string">Refund</Type> <Payer xsi:type="ebl:EmailAddressType">bigbird@example.com</Payer> <PayerDisplayName xsi:type="xs:string">Big Bird</PayerDisplayName> <TransactionID>0B816375MA2010907</TransactionID> <Status xsi:type="xs:string">Completed</Status> <GrossAmount xsi:type="cc:BasicAmountType" currency>-29.95</GrossAmount> <FeeAmount xsi:type="cc:BasicAmountType" currency>1.47</FeeAmount> <NetAmount xsi:type="cc:BasicAmountType" currency>-28.48</NetAmount> </PaymentTransactions> <PaymentTransactions xmlns="urn:ebay:apis:eBLBaseComponents" xsi:type="ebl:PaymentTransactionSearchResultType"> <Timestamp xsi:type="xs:dateTime">2005-04-15T02:48:34Z</Timestamp> <Timezone xsi:type="xs:string">GMT</Timezone> <Type xsi:type="xs:string">Payment</Type> <Payer xsi:type="ebl:EmailAddressType">bigbird@example.com</Payer> <PayerDisplayName xsi:type="xs:string">Big Bird</PayerDisplayName> <TransactionID>8N604562NC480291D</TransactionID> <Status xsi:type="xs:string">Refunded</Status> <GrossAmount xsi:type="cc:BasicAmountType" currency>29.95</GrossAmount> <FeeAmount xsi:type="cc:BasicAmountType" currency>-1.47</FeeAmount> <NetAmount xsi:type="cc:BasicAmountType" currency>28.48</NetAmount> </PaymentTransactions> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

As you can see, all of the transactions for this customer have been refunded — the amount refunded, as well as the fee (and finally the NetAmount that was deducted from your account).

Категории