/// <summary>
        /// Handle PaymentDetails API call
        /// </summary>
        /// <param name="context"></param>
        private void PaymentDetails(HttpContext context)
        {
            NameValueCollection parameters = context.Request.Params;
            PaymentDetailsRequest req = new PaymentDetailsRequest(new RequestEnvelope("en_US"));
            // set optional parameters
            if (parameters["payKey"] != "")
                req.payKey = parameters["payKey"];
            if (parameters["transactionId"] != "")
                req.transactionId = parameters["transactionId"];
            if (parameters["trackingId"] != "")
                req.trackingId = parameters["trackingId"];

            // All set. Fire the request
            AdaptivePaymentsService service = new AdaptivePaymentsService();
            PaymentDetailsResponse resp = null;
            try
            {
                resp = service.PaymentDetails(req);
            }
            catch (System.Exception e)
            {
                context.Response.Write(e.Message);
                return;
            }

            // Display response values.
            Dictionary<string, string> keyResponseParams = new Dictionary<string, string>();
            string redirectUrl = null;
            if (!(resp.responseEnvelope.ack == AckCode.FAILURE) &&
                !(resp.responseEnvelope.ack == AckCode.FAILUREWITHWARNING))
            {
                keyResponseParams.Add("Pay key", resp.payKey);
                keyResponseParams.Add("Payment execution status", resp.status);
                keyResponseParams.Add("Sender email", resp.senderEmail);

                //Selenium Test Case
                keyResponseParams.Add("Acknowledgement", resp.responseEnvelope.ack.ToString());
                keyResponseParams.Add("Action Type", resp.actionType);
            }
            displayResponse(context, "PaymentDetails", keyResponseParams, service.getLastRequest(), service.getLastResponse(),
                resp.error, redirectUrl);
        }
		public override PostProcessPaymentResult PostProcessPayment(PostProcessPaymentEvaluationContext context)
		{
			var retVal = new PostProcessPaymentResult();

			var config = GetConfigMap();

			var service = new AdaptivePaymentsService(config);

			var response = service.PaymentDetails(new PaymentDetailsRequest
			{
				payKey = context.OuterId,
				requestEnvelope = new RequestEnvelope { errorLanguage = "en_US" }
			});

			if (response.status == "COMPLETED")
			{
				retVal.IsSuccess = true;
				retVal.NewPaymentStatus = PaymentStatus.Paid;
			}
			else if (response.status == "INCOMPLETE" && response.status == "ERROR" && response.status == "REVERSALERROR")
			{
				if (response.error != null && response.error.Count > 0)
				{
					var sb = new StringBuilder();
					foreach (var error in response.error)
					{
						sb.AppendLine(error.message);
					}
					retVal.Error = sb.ToString();
				}
				else
				{
					retVal.Error = "payment canceled";
				}

				retVal.NewPaymentStatus = PaymentStatus.Voided;
			}
			else
			{
				retVal.NewPaymentStatus = PaymentStatus.Pending;
			}

			return retVal;
		}
    // # PaymentDetails API Operation
    // Use the PaymentDetails API operation to obtain information about a payment. You can identify the payment by your tracking ID, the PayPal transaction ID in an IPN message, or the pay key associated with the payment. 
    public PaymentDetailsResponse PaymentDetailsAPIOperation()
    {
        // Create the PaymentDetailsResponse object
        PaymentDetailsResponse responsePaymentDetails = new PaymentDetailsResponse();

        try
        {
            // # PaymentDetailsRequest
            // The code for the language in which errors are returned
            RequestEnvelope envelopeRequest = new RequestEnvelope();
            envelopeRequest.errorLanguage = "en_US";

            // PaymentDetailsRequest which takes,
            // `Request Envelope` - Information common to each API operation, such
            // as the language in which an error message is returned.
            PaymentDetailsRequest requestPaymentDetails = new PaymentDetailsRequest(envelopeRequest);

            // You must specify either,
            //
            // * `Pay Key` - The pay key that identifies the payment for which you want to retrieve details. This is the pay key returned in the PayResponse message.
            // * `Transaction ID` - The PayPal transaction ID associated with the payment. The IPN message associated with the payment contains the transaction ID.
            // `payDetailsRequest.transactionId = transactionId`
            // * `Tracking ID` - The tracking ID that was specified for this payment in the PayRequest message.
            // `requestPaymentDetails.trackingId = trackingId`
            requestPaymentDetails.payKey = "AP-86H50830VE600922B";

            // Create the service wrapper object to make the API call
            AdaptivePaymentsService service = new AdaptivePaymentsService();

            // # API call
            // Invoke the PaymentDetails method in service wrapper object
            responsePaymentDetails = service.PaymentDetails(requestPaymentDetails);

            if (responsePaymentDetails != null)
            {
                // Response envelope acknowledgement
                string acknowledgement = "PaymentDetails API Operation - ";
                acknowledgement += responsePaymentDetails.responseEnvelope.ack.ToString();
                logger.Info(acknowledgement + "\n");
                Console.WriteLine(acknowledgement + "\n");

                // # Success values
                if (responsePaymentDetails.responseEnvelope.ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                {
                    // The status of the payment. Possible values are:
                    //
                    // * CREATED - The payment request was received; funds will be
                    // transferred once the payment is approved
                    // * COMPLETED - The payment was successful
                    // * INCOMPLETE - Some transfers succeeded and some failed for a
                    // parallel payment or, for a delayed chained payment, secondary
                    // receivers have not been paid
                    // * ERROR - The payment failed and all attempted transfers failed
                    // or all completed transfers were successfully reversed
                    // * REVERSALERROR - One or more transfers failed when attempting
                    // to reverse a payment
                    // * PROCESSING - The payment is in progress
                    // * PENDING - The payment is awaiting processing
                    logger.Info("Payment Execution Status : " + responsePaymentDetails.status + "\n");
                    Console.WriteLine("Payment Execution Status : " + responsePaymentDetails.status + "\n");
                }
                // # Error Values
                else
                {
                    List<ErrorData> errorMessages = responsePaymentDetails.error;
                    foreach (ErrorData error in errorMessages)
                    {
                        logger.Debug(error.message);
                        Console.WriteLine(error.message + "\n");
                    }
                }
            }
        }
        // # Exception log    
        catch (System.Exception ex)
        {
            // Log the exception message       
            logger.Debug("Error Message : " + ex.Message);
            Console.WriteLine("Error Message : " + ex.Message);
        }
        return responsePaymentDetails;
    }
        /// <summary>
        /// Handle PaymentDetails API call
        /// </summary>
        /// <param name="contextHttp"></param>
        private void PaymentDetails(HttpContext contextHttp)
        {
            NameValueCollection parameters = contextHttp.Request.Params;
            PaymentDetailsRequest request = new PaymentDetailsRequest(new RequestEnvelope("en_US")); 
            // set optional parameters
            //(Optional) The pay key that identifies the payment for which 
            // you want to retrieve details. This is the pay key returned in the PayResponse message. 
            if (parameters["payKey"] != string.Empty)
                request.payKey = parameters["payKey"];
            // (Optional) The PayPal transaction ID associated with the payment. 
            // The IPN message associated with the payment contains the transaction ID. 
            if (parameters["transactionId"] != string.Empty)
                request.transactionId = parameters["transactionId"];
            // (Optional) The tracking ID that was specified for this payment 
            // in the PayRequest message. Maximum length: 127 characters 
            if (parameters["trackingId"] != string.Empty)
                request.trackingId = parameters["trackingId"];
          
            AdaptivePaymentsService service = null;
            PaymentDetailsResponse response = null;
            try
            {
                // Configuration map containing signature credentials and other required configuration.
                // For a full list of configuration parameters refer in wiki page 
                // (https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters)
                Dictionary<string, string> configurationMap = Configuration.GetAcctAndConfig();

                // Creating service wrapper object to make an API call and loading
                // configuration map for your credentials and endpoint
                service = new AdaptivePaymentsService(configurationMap);
                response = service.PaymentDetails(request);
            }
            catch (System.Exception e)
            {
                contextHttp.Response.Write(e.Message);
                return;
            }

            Dictionary<string, string> responseValues = new Dictionary<string, string>();
            string redirectUrl = null;
            if (!(response.responseEnvelope.ack == AckCode.FAILURE) &&
                !(response.responseEnvelope.ack == AckCode.FAILUREWITHWARNING))
            {
                //(Optional) The pay key that identifies the payment 
                responseValues.Add("Pay key", response.payKey);
                // The status of the payment. Possible values are:
                // CREATED – The payment request was received; funds will be transferred once the payment is approved
                // COMPLETED – The payment was successful
                // INCOMPLETE – Some transfers succeeded and some failed for a parallel payment or, for a delayed chained payment, secondary receivers have not been paid
                // ERROR – The payment failed and all attempted transfers failed or all completed transfers were successfully reversed
                // REVERSALERROR – One or more transfers failed when attempting to reverse a payment
                // PROCESSING – The payment is in progress
                // PENDING – The payment is awaiting processing
                responseValues.Add("Payment execution status", response.status);

                // The sender's email address. 
                responseValues.Add("Sender email", response.senderEmail);

                //Acknowledgement code. It is one of the following values:
                // Success – The operation completed successfully.
                // Failure – The operation failed.
                // SuccessWithWarning – The operation completed successfully; however, there is a warning message.
                // FailureWithWarning – The operation failed with a warning message.
                responseValues.Add("Acknowledgement", response.responseEnvelope.ack.ToString());

                // Whether the Pay request is set up to create a payment request with the SetPaymentOptions 
                // request, and then fulfill the payment with the ExecutePayment request. 
                // Possible values are:
                // PAY – Use this option if you are not using the Pay request in combination with ExecutePayment.
                // CREATE – Use this option to set up the payment instructions with SetPaymentOptions and then execute the payment at a later time with the ExecutePayment.
                // PAY_PRIMARY – For chained payments only, specify this value to delay payments to the secondary receivers; only the payment to the primary receiver is processed.
                responseValues.Add("Action Type", response.actionType);
            }
            Display(contextHttp, "PaymentDetails", responseValues, service.getLastRequest(), service.getLastResponse(), response.error, redirectUrl);
        }
        private PaymentDetailsResponse PaypalPaymentDetail(string payKey)
        {
            var api = GoPlayApi.Instance;
            var headers = PaypalHelper.GetHeader();
            PaymentDetailsRequest request = new PaymentDetailsRequest
            {
                payKey = payKey,
                requestEnvelope = new RequestEnvelope("en_US")
                {
                    detailLevel = DetailLevelCode.RETURNALL
                }
            };

            AdaptivePaymentsService adaptivePaymentsService = new AdaptivePaymentsService(headers);
            PaymentDetailsResponse payResponse = adaptivePaymentsService.PaymentDetails(request);
            return payResponse;
        }