private void processResponse(PayPalAPIInterfaceServiceService service, TransactionSearchResponseType response) { HttpContext CurrContext = HttpContext.Current; CurrContext.Items.Add("Response_apiName", "TransactionSearch"); CurrContext.Items.Add("Response_redirectURL", null); CurrContext.Items.Add("Response_requestPayload", service.getLastRequest()); CurrContext.Items.Add("Response_responsePayload", service.getLastResponse()); Dictionary<string, string> keyParameters = new Dictionary<string, string>(); keyParameters.Add("Correlation Id", response.CorrelationID); keyParameters.Add("API Result", response.Ack.ToString()); if (response.Errors != null && response.Errors.Count > 0) { CurrContext.Items.Add("Response_error", response.Errors); } else { CurrContext.Items.Add("Response_error", null); } if(!response.Ack.Equals(AckCodeType.FAILURE)) { keyParameters.Add("Total matching transactions", response.PaymentTransactions.Count.ToString()); for (int i = 0; i < response.PaymentTransactions.Count; i++ ) { PaymentTransactionSearchResultType result = response.PaymentTransactions[i]; String label = "Result " + (i+1); keyParameters.Add(label + " Payer", result.Payer); keyParameters.Add(label + " Transaction Id", result.TransactionID); keyParameters.Add(label + " Payment status", result.Status); keyParameters.Add(label + " Payment timestamp", result.Timestamp); keyParameters.Add(label + " Transaction type", result.Type); if (result.NetAmount != null) { keyParameters.Add(label + " Net amount", result.NetAmount.value + result.NetAmount.currencyID.ToString()); } if (result.GrossAmount != null) { keyParameters.Add(label + " Gross amount", result.GrossAmount.value + result.GrossAmount.currencyID.ToString()); } } } CurrContext.Items.Add("Response_keyResponseObject", keyParameters); Server.Transfer("../APIResponse.aspx"); }
// # TransactionSearch API Operation // The TransactionSearch API searches transaction history for transactions that meet the specified criteria public TransactionSearchResponseType TransactionSearchAPIOperation() { // Create the TransactionSearchResponseType object TransactionSearchResponseType responseTransactionSearchResponseType = new TransactionSearchResponseType(); try { // # Create the TransactionSearchReq object TransactionSearchReq requestTransactionSearch = new TransactionSearchReq(); // `TransactionSearchRequestType` which takes mandatory argument: // // * `Start Date` - The earliest transaction date at which to start the // search. TransactionSearchRequestType transactionSearchRequest = new TransactionSearchRequestType("2012-12-25T00:00:00+0530"); requestTransactionSearch.TransactionSearchRequest = transactionSearchRequest; // Create the service wrapper object to make the API call PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(); // # API call // Invoke the TransactionSearch method in service wrapper object responseTransactionSearchResponseType = service.TransactionSearch(requestTransactionSearch); if (responseTransactionSearchResponseType != null) { // Response envelope acknowledgement string acknowledgement = "TransactionSearch API Operation - "; acknowledgement += responseTransactionSearchResponseType.Ack.ToString(); logger.Info(acknowledgement + "\n"); Console.WriteLine(acknowledgement + "\n"); // # Success values if (responseTransactionSearchResponseType.Ack.ToString().Trim().ToUpper().Equals("SUCCESS")) { // Search Results IEnumerator<PaymentTransactionSearchResultType> iterator = responseTransactionSearchResponseType.PaymentTransactions.GetEnumerator(); while (iterator.MoveNext()) { PaymentTransactionSearchResultType searchResult = iterator.Current; // Merchant's transaction ID. logger.Info("Transaction ID : " + searchResult.TransactionID + "\n"); Console.WriteLine("Transaction ID : " + searchResult.TransactionID + "\n"); } } // # Error Values else { List<ErrorType> errorMessages = responseTransactionSearchResponseType.Errors; foreach (ErrorType error in errorMessages) { logger.Debug("API Error Message : " + error.LongMessage); Console.WriteLine("API Error Message : " + error.LongMessage + "\n"); } } } } // # Exception log catch (System.Exception ex) { // Log the exception message logger.Debug("Error Message : " + ex.Message); Console.WriteLine("Error Message : " + ex.Message); } return responseTransactionSearchResponseType; }