PayPal Hacks. 100 Industrial-Strength Tips and Tools Free Open Book

PayPal Hacks. 100 Industrial-Strength Tips and Tools

Previous Section  < Day Day Up >  Next Section

Hack 93 Retrieve Transaction Details with the API

figs/expert.gif figs/hack93.gif

Given only a transaction ID, use the GetTransactionDetail API call with the API wrapper DLL to retrieve the details of the transaction.

The GetTransactionDetail API call is a more detailed in terms of the data it returns than the RefundTransaction call [Hack #91] . The initiating call is made in the same fashion, but the response object holds many types that you need to access to get the transaction details. These types are designed to hold information pertaining to the myriad of PayPal transaction types, so if you use PayPal only to process sales from your Shopping Cart (as opposed to eBay auctions or digital subscriptions), you might not need all the information it returns.

But since retrieving information is so important (not to mention loads of fun), this example puts the call through its paces and retrieves all the available transaction details. The response object has a few Type objects that are of interest, because they hold the details of the entire transaction:


PaymentInfoType

Information about the payment, including gross payment amount, fee amount, date of payment, and so on.


ReceiverInfoType

Information about the person or entity who sent the payment.


PaymentItemInfoType

If you sold items, their details are captured in the PaymentItemInfoType.


AuctionInfoType

Returns information about the auction (if the payment came from an auction).


SubscriptionInfoType

Subscription information, including interval, start date, and so on.

The PayPal API uses its BasicAmountType object to store monetary values (e.g., dollar amounts), such as any property of a Type object with the word amount in it. If there is no amount, the property will be null, which can trip up your routines. To return safe values from these fields, the following code makes use of the GetAmountValue() function [Hack #89] to return a string value.

8.9.1 The Code

Here's the GetTransactionDetail() method that retrieves the transaction details for a given PayPal transaction ID:

public string GetTransactionDetail(string transactionID, string delimiter){

string sOut="";



//Create the request type, which holds information about the transaction you //want more 

information about

GetTransactionDetailsRequestType detailRequest=new GetTransactionDetailsRequestType( );

detailRequest.TransactionID=transactionID;



//Set the request type of the request object

GetTransactionDetailsReq request=new GetTransactionDetailsReq( );

request.GetTransactionDetailsRequest=detailRequest;



//send the request to PayPal

GetTransactionDetailsResponseType

response=service.GetTransactionDetails(request);



//make sure there is a response

if(response!=null){



//use a StringBuilder as this return uses a lot of resources if you just

//just append a regular string value

1.  StringBuilder sb=new StringBuilder( );



sb.Append("************ Payment Information "+ **************"+delimiter);



//access each response type, gathering the information

//payment info

PaymentInfoType payment=response.PaymentTransactionDetails.PaymentInfo;

sb.Append("ReceiptID: "+payment.ReceiptID+delimiter);

sb.Append("TransactionID: "+payment.TransactionID+delimiter);

sb.Append("PaymentDate: "+payment.PaymentDate+delimiter);      

sb.Append("GrossAmount: "+GetAmountValue(payment.GrossAmount)+delimiter);

sb.Append("SettleAmount: " + 

                GetAmountValue(payment.SettleAmount)+delimiter);



sb.Append("FeeAmount: "+GetAmountValue(payment.FeeAmount)+delimiter);

sb.Append("TaxAmount: "+GetAmountValue(payment.TaxAmount)+delimiter);

sb.Append("PaymentStatus: "+payment.PaymentStatus+delimiter);

sb.Append("PaymentType: "+payment.PaymentType+delimiter);

sb.Append("TransactionType: "+payment.TransactionType+delimiter);



2.  //item info



PaymentItemInfoType item=response.PaymentTransactionDetails.PaymentItemInfo;

int i=1;

sb.Append("************** Item Information ******************"+delimiter);

sb.Append("Custom: "+item.Custom+delimiter);

sb.Append("InvoiceID: "+item.InvoiceID+delimiter);

sb.Append("Memo: "+item.Memo+delimiter);

sb.Append("SalesTax: "+item.SalesTax+delimiter);



//The items are returned in an array of PaymentItemType

//loop through the items array, accessing item information

foreach(PaymentItemType itm in item.PaymentItem){

sb.Append(delimiter);

sb.Append("Item "+i.ToString( )+":"+delimiter);

sb.Append("Name: "+itm.Name+delimiter);

sb.Append("Number: "+itm.Number+delimiter);

sb.Append("Options: "+itm.Options+delimiter);

sb.Append("Quantity: "+itm.Quantity+delimiter);

sb.Append("SalesTax: "+itm.SalesTax+delimiter);

sb.Append(delimiter);

i++;

}



//if you are dealing in auctions, the information about

//the auction will be in the AuctionInfoType

sb.Append("************ Auction Information *************"+delimiter);



AuctionInfoType auction=new AuctionInfoType( );

sb.Append("BuyerID: "+auction.BuyerID+delimiter);

sb.Append("ClosingDate: "+auction.ClosingDate+delimiter);

sb.Append("ClosingDateSpecified: "+auction.ClosingDateSpecified+delimiter);

sb.Append("multiItem: "+auction.multiItem+delimiter);



//Same with Subscriptions

sb.Append("********** Subscription Information ***********"+delimiter);



SubscriptionInfoType sub=new SubscriptionInfoType( );



sb.Append("EffectiveDate: "+sub.EffectiveDate+delimiter);

sb.Append("EffectiveDateSpecified: "+sub.EffectiveDateSpecified+delimiter);

sb.Append("Password: "+sub.Password+delimiter);

sb.Append("reattempt: "+sub.reattempt+delimiter);

sb.Append("Recurrences: "+sub.Recurrences+delimiter);

sb.Append("recurring: "+sub.recurring+delimiter);

sb.Append("RetryTime: "+sub.RetryTime+delimiter);

sb.Append("RetryTimeSpecified: "+sub.RetryTimeSpecified+delimiter);

sb.Append("SubscriptionDate: "+sub.SubscriptionDate+delimiter);

sb.Append("SubscriptionDateSpecified: "+sub.SubscriptionDateSpecified+delimiter);

sb.Append("SubscriptionID: "+sub.SubscriptionID+delimiter);

sb.Append("Terms: "+sub.Terms+delimiter);

sb.Append("Username: "+sub.Username+delimiter);

sReturn=sb.ToString( );

}

return sReturn;

PayPal does not know the type of the transaction for which you are requesting details, so the web service returns every possible bit of information it can. In this example, all this information is appended to a single string so that it can be displayed easily. Since the string can be long, you'll need a StringBuilder object (line 1). A more practical approach might be to add tables to a DataSet object (if you are using .NET) or perhaps to create your own class to handle this information.

If you are developing a typical commerce site, in which items are sold using PayPal as the payment processor, the section beginning on line 2 will interest you the most. Each item sold is handed back to you in the PaymentTransactionDetails.PaymentItemInfo.PaymentItem array. Each item in the transaction is represented by a PaymentItemType that has pertinent information, such as item number (a.k.a. SKU), price, quantity, and so on.

8.9.2 Running the Hack

To use the API wrapper class to look up details of a transaction, you need to add the Auction and Subscription code to the GetTransactionDetail() method in your API wrapper class and run your PayPalTestApp application. See [Hack #90] for further details.

--Rob Conery and Dave Nielsen

    Previous Section  < Day Day Up >  Next Section
    Index: [SYMBOL][A][B][C][D][E][F][G][H][I][J][L][M][N][O][P][Q][R][S][T][U][V][W][X][Y]


         Main Menu
    PayPal Hacks
    Table of Contents
    Copyright
    Credits
    Preface
    Chapter 1. Account Management
    Chapter 2. Making Payments
    Chapter 3. Selling with PayPal
    Chapter 4. Payment Buttons
    Chapter 5. Storefronts and Shopping Carts
    Chapter 6. Managing Subscriptions
    Chapter 7. IPN and PDT
    Chapter 8. The PayPal Web Services API
    Introduction: Hacks #87-100
    8.2 Create a Developer Account
    Hack 87 Set up the Sandbox
    Hack 88 Make Your First API Call
    Hack 89 Create a Wrapper Class for Your API Calls
    Hack 90 Use the PayPal API Wrapper Class
    Hack 91 Refund Payments with the API
    Hack 92 Handle Transaction Errors within the API Wrapper
    Hack 93 Retrieve Transaction Details with the API
    Hack 94 Search for PayPal Transactions
    Hack 95 Hack the API Wrapper
    Hack 96 Issue Payments en Masse with the Mass Pay API
    Hack 97 Pay Affiliates and Suppliers on a Schedule
    Hack 98 Search eBay for Listings that Accept PayPal
    Hack 99 Test IPN and PDT in the Sandbox
    Hack 100 Go Live
    Colophon
    Index


    More Books
    PHP Hacks
    Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax
    The Koran (Holy Qur'an)
    Macromedia Flash 8 Bible
    Search Engine Optimization for Dummies
    YouTube Traffic
    PHP 5 for Dummies
    Harry Potter and The Chamber of Secrets
    Harry Potter and the Sorcerer's Stone
    The Pilgrim's Progress
    Wireless Hacks
    Flash Hacks. 100 Industrial-Strength Tips & Tools
    PayPal Hacks. 100 Industrial-Strength Tips and Tools
    Amazon Hacks
    Pdf Hacks
    The Da Vinci Code
    Google Hacks
    The Holy Bible
    Windows XP For Dummies
    Harry Potter and the Half-Blood Prince
    Seo Book
    Upgrading and Repairing Networks
    Macromedia Dreamweaver 8 UNLEASHED
    Windows XP Annoyances
    Windows XP Hacks
    Microsoft Windows XP Power Toolkit
    Teach Yourself MS Office In 24Hours
    iPod & iTunes Missing Manual
    PC Hacks 100 Industrial-Strength Tips and Tools
    PC Overclocking, Optimization, and Tuning - 2th Edition
    PC Hardware In A Nutshell 3rd Edition
    PC Hardware in a Nutshell, 2nd Edition
    Upgrading and Repairing PCs
    Google for Dummies
    MySQL Cookbook
    Teach Yourself Macromedia Flash 8 In 24 Hours
    PHP CookBook
    Sams Teach Yourself JavaScript in 24 Hours
    PHP5 Manual
    Free Games Paper Airplanes
    500 Juegos Gratis 500 Giochi Gratis 500 Jeux Gratuits 500 Jogos Gratis 500 Kostenlose Spiele