Búsqueda


Categorías

C# [15]
PHP [6]
Zend [1]
FileMaker [1]
.NET [6]
CVS [3]
General [9]
Javascript [2]
Paypal [1]
.NET Compact Framework [3]
C++ [1]
mysql [4]
Linux [1]

Últimos post

Dónde guardar los archivos de configuración en ClickOnce
phpinfo: Valores en error_reporting
Notes about Zend Server and Zend Studio setup
What's new in C# 4
Resolving a 'sticky tag is not a branch' error
Resumen del CodeCamp
CodeCamp Tarragona 2009
Acerca de la calidad del código
ClickOnce en Linux
Programando en PHP (y con CVS) en Visual Studio 2008

Sindicación

RSS 0.90
RSS 1.0
RSS 2.0
Atom 0.3

Get more 100 matched results using Paypal TransactionSearch

ctg | 07 Julio, 2008 14:11

One of the main problems using TransactionSearch on Paypal API is only returns last 100 records. In this case, TransactionSearch returns a SuccessWithWarning ack to indicate this problem.
To fix it, I made a code to get the status of one day transactions doing a "hack" to avoid 100 records problem.

// Sets user, password and signature
UserIdPasswordType user = new UserIdPasswordType();
user.Username = this.user;
user.Password = this.password;
user.Signature = this.signature;

// Define TransactionSearchResponseType. Inside loop we add params to adjust search
TransactionSearchResponseType transactionSearchResponseType = null;

// Paypal only can get 100 results at time.
do
{
    // Prepare the interface with user
    using (PayPalAPISoapBinding paypalInterfaceSearch = new PayPalAPISoapBinding())
    {
        paypalInterfaceSearch.RequesterCredentials = new CustomSecurityHeaderType();
        paypalInterfaceSearch.Url = "https://api-3t.paypal.com/2.0/";
        paypalInterfaceSearch.RequesterCredentials.Credentials = user;
    
        // Prepare TransactionSearch request
        TransactionSearchRequestType transactionSearchRequestType = new TransactionSearchRequestType();
        transactionSearchRequestType.Version = "3.2";
        transactionSearchRequestType.TransactionClass = PaymentTransactionClassCodeType.All;
        transactionSearchRequestType.TransactionClassSpecified = true;
    
        // Adjust the dates according is in loop or not
        if (null != transactionSearchResponseType)
        {
            // StartDate always is 0:00:00 hours
            transactionSearchRequestType.StartDate = new DateTime(
            transactionSearchResponseType.PaymentTransactions[99].Timestamp.Year,
            transactionSearchResponseType.PaymentTransactions[99].Timestamp.Month,
            transactionSearchResponseType.PaymentTransactions[99].Timestamp.Day,
            0, 0, 0);
            // EndDate is last PaymentTransactions less 1 second. This way we obtain left results
            transactionSearchRequestType.EndDate = transactionSearchResponseType.PaymentTransactions[99].Timestamp;
            transactionSearchRequestType.EndDate.AddSeconds(-1);
        }
        else
        {
            transactionSearchRequestType.StartDate = startDate;
            transactionSearchRequestType.EndDate = endDate;

            if (startDate == endDate)
            {
                transactionSearchRequestType.EndDate = transactionSearchRequestType.EndDate.AddDays(1);
            }
        }
        transactionSearchRequestType.EndDateSpecified = true;

        TransactionSearchReq transactionSearchRequest = new TransactionSearchReq();
        transactionSearchRequest.TransactionSearchRequest = transactionSearchRequestType;

        // Get results and Ack
        transactionSearchResponseType = paypalInterfaceSearch.TransactionSearch(transactionSearchRequest);

        // Check Ack, if OK, get results
        if (AckCodeType.Success == transactionSearchResponseType.Ack || AckCodeType.SuccessWithWarning == transactionSearchResponseType.Ack)
        {
            if (null != transactionSearchResponseType.PaymentTransactions)
            {
                foreach (PaymentTransactionSearchResultType paymentTransactionSearchResultType in transactionSearchResponseType.PaymentTransactions)
                {
                    // PaymentTransaction only include PayPal TransactionID. To get JShop order number it's necessary get more details using TransactionID

                    // Its necessary prepare again the interface if not fails.
                    using(PayPalAPISoapBinding paypalInterfaceDetails = new PayPalAPISoapBinding())
                    {
                        paypalInterfaceDetails.RequesterCredentials = new CustomSecurityHeaderType();
                        paypalInterfaceDetails.Url = "https://api-3t.paypal.com/2.0/";
                        paypalInterfaceDetails.RequesterCredentials.Credentials = user;

                        // Prepare TransactionDetails
                        GetTransactionDetailsRequestType transactionDetailsRequesType = new GetTransactionDetailsRequestType();
                        transactionDetailsRequesType.Version = "3.2";
                        transactionDetailsRequesType.TransactionID = paymentTransactionSearchResultType.TransactionID;      // Set TransactionID to search

                        GetTransactionDetailsReq transactionDetailsRequest = new GetTransactionDetailsReq();
                        transactionDetailsRequest.GetTransactionDetailsRequest = transactionDetailsRequesType;

                        // Get results
                        GetTransactionDetailsResponseType transactionDetailsResponseType = paypalInterfaceDetails.GetTransactionDetails(transactionDetailsRequest);

                        if (AckCodeType.Success == transactionDetailsResponseType.Ack)
                        {
                            if (null != transactionDetailsResponseType)
                            {
                                // Check paymentTransactionSearchResultType to see the transaction status
                            }
                        }
                        else
                        {
                // Log message here. TransactionDetailsResponseType not successful searching TransactionID
                        }
                    }
                }
            }
            else
            {
        // Log message here. TransactionSearchResponseType not sucessful
            }
        }
    }
} while (transactionSearchResponseType.Ack == AckCodeType.SuccessWithWarning);

 

Publicado en C#, Paypal . Comentario: (0). Retroenlaces:(0). Enlace