// A helper method used by APIResponse.aspx that returns select response parameters // of interest. You must process API response objects as applicable to your application private void setKeyResponseObjects(PayPalAPIInterfaceServiceService service, DoAuthorizationResponseType response) { Dictionary<string, string> responseParams = new Dictionary<string, string>(); responseParams.Add("Transaction Id", response.TransactionID); responseParams.Add("Payment status", response.AuthorizationInfo.PaymentStatus.ToString()); responseParams.Add("Pending reason", response.AuthorizationInfo.PendingReason.ToString()); HttpContext CurrContext = HttpContext.Current; CurrContext.Items.Add("Response_keyResponseObject", responseParams); CurrContext.Items.Add("Response_apiName", "DoAuthorization"); CurrContext.Items.Add("Response_redirectURL", null); CurrContext.Items.Add("Response_requestPayload", service.getLastRequest()); CurrContext.Items.Add("Response_responsePayload", service.getLastResponse()); if (response.Ack.Equals(AckCodeType.FAILURE) || (response.Errors != null && response.Errors.Count > 0)) { CurrContext.Items.Add("Response_error", response.Errors); } else { CurrContext.Items.Add("Response_error", null); } Server.Transfer("../APIResponse.aspx"); }
//# DoAuthorization API Operation //Authorize a payment. public DoAuthorizationResponseType DoAuthorizationAPIOperation() { // Create the DoAuthorizationResponseType object DoAuthorizationResponseType responseDoAuthorizationResponseType = new DoAuthorizationResponseType(); try { // Create the DoAuthorizationReq object DoAuthorizationReq doAuthorization = new DoAuthorizationReq(); // `Amount` which takes mandatory params: // // * `currencyCode` // * `amount` BasicAmountType amount = new BasicAmountType(CurrencyCodeType.USD, "4.00"); // `DoAuthorizationRequest` which takes mandatory params: // // * `Transaction ID` - Value of the order's transaction identification // number returned by PayPal. // * `Amount` - Amount to authorize. DoAuthorizationRequestType doAuthorizationRequest = new DoAuthorizationRequestType("O-4VR15106P7416533H", amount); doAuthorization.DoAuthorizationRequest = doAuthorizationRequest; // Create the service wrapper object to make the API call PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(); // # API call // Invoke the DoAuthorization method in service wrapper object responseDoAuthorizationResponseType = service.DoAuthorization(doAuthorization); if (responseDoAuthorizationResponseType != null) { // Response envelope acknowledgement string acknowledgement = "DoAuthorization API Operation - "; acknowledgement += responseDoAuthorizationResponseType.Ack.ToString(); logger.Info(acknowledgement + "\n"); Console.WriteLine(acknowledgement + "\n"); // # Success values if (responseDoAuthorizationResponseType.Ack.ToString().Trim().ToUpper().Equals("SUCCESS")) { // Authorization identification number logger.Info("Transaction ID : " + responseDoAuthorizationResponseType.TransactionID + "\n"); Console.WriteLine("Transaction ID : " + responseDoAuthorizationResponseType.TransactionID + "\n"); } // # Error Values else { // Access error values from error list using getter methods List<ErrorType> errorMessages = responseDoAuthorizationResponseType.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 responseDoAuthorizationResponseType; }