/// <summary> /// Handle ExecutePayment API call /// </summary> /// <param name="context"></param> private void ExecutePayment(HttpContext context) { NameValueCollection parameters = context.Request.Params; ExecutePaymentRequest req = new ExecutePaymentRequest(new RequestEnvelope("en_US"), parameters["payKey"]); //Fix for release req.fundingPlanId = parameters["fundingPlanId"]; // All set. Fire the request AdaptivePaymentsService service = new AdaptivePaymentsService(); ExecutePaymentResponse resp = null; try { resp = service.ExecutePayment(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("Payment exeucution status", resp.paymentExecStatus); //Selenium Test Case keyResponseParams.Add("Acknowledgement", resp.responseEnvelope.ack.ToString()); } displayResponse(context, "ExecutePayment", keyResponseParams, service.getLastRequest(), service.getLastResponse(), resp.error, redirectUrl); }
// # ExecutePayment API Operation // The ExecutePayment API operation lets you execute a payment set up with the Pay API operation with the actionType CREATE. To pay receivers identified in the Pay call, set the pay key from the PayResponse message in the ExecutePaymentRequest message. public ExecutePaymentResponse ExecutePaymentAPIOperation() { // Create the ExecutePaymentResponse object ExecutePaymentResponse responseExecutePayment = new ExecutePaymentResponse(); try { // # ExecutePaymentRequest // The code for the language in which errors are returned RequestEnvelope envelopeRequest = new RequestEnvelope(); envelopeRequest.errorLanguage = "en_US"; // ExecutePaymentRequest which takes, // // * `Request Envelope` - Information common to each API operation, such // as the language in which an error message is returned. // * `Pay Key` - The pay key that identifies the payment for which you // want to set payment options. This is the pay key returned in the // PayResponse message. Action Type in PayRequest must be `CREATE` ExecutePaymentRequest requestExecutePayment = new ExecutePaymentRequest(envelopeRequest, "AP-1VB65877N5917862M"); // The ID of the funding plan from which to make this payment. requestExecutePayment.fundingPlanId = "0"; // Create the service wrapper object to make the API call AdaptivePaymentsService service = new AdaptivePaymentsService(); // # API call // Invoke the ExecutePayment method in service wrapper object responseExecutePayment = service.ExecutePayment(requestExecutePayment); if (responseExecutePayment != null) { // Response envelope acknowledgement string acknowledgement = "ExecutePayment API operation - "; acknowledgement += responseExecutePayment.responseEnvelope.ack.ToString(); logger.Info(acknowledgement + "\n"); Console.WriteLine(acknowledgement + "\n"); // # Success values if (responseExecutePayment.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 // * 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 logger.Info("Payment Execution Status: " + responseExecutePayment.paymentExecStatus + "\n"); Console.WriteLine("Payment Execution Status : " + responseExecutePayment.paymentExecStatus + "\n"); } // # Error Values else { List<ErrorData> errorMessages = responseExecutePayment.error; foreach (ErrorData error in errorMessages) { logger.Debug("API Error Message : " + error.message); Console.WriteLine("API Error Message : " + 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 responseExecutePayment; }
public override ProcessPaymentResult ProcessPayment(ProcessPaymentEvaluationContext context) { var retVal = new ProcessPaymentResult(); if (context.Store == null) throw new NullReferenceException("no store with this id"); if (!(!string.IsNullOrEmpty(context.Store.SecureUrl) || !string.IsNullOrEmpty(context.Store.Url))) throw new NullReferenceException("store must specify Url or SecureUrl property"); var url = string.Empty; if (!string.IsNullOrEmpty(context.Store.SecureUrl)) { url = context.Store.SecureUrl; } else { url = context.Store.Url; } var config = GetConfigMap(); var service = new AdaptivePaymentsService(config); var request = CreatePaypalRequest(context.Order, context.Payment, url); var payResponse = service.Pay(request); var setPaymentOptionsResponse = service.SetPaymentOptions(new SetPaymentOptionsRequest { payKey = payResponse.payKey, senderOptions = new SenderOptions { referrerCode = "Virto_SP" } }); var executePaymentResponse = service.ExecutePayment(new ExecutePaymentRequest { payKey = payResponse.payKey, actionType = "PAY", requestEnvelope = new RequestEnvelope { errorLanguage = "en_US" } }); if (executePaymentResponse.error != null && executePaymentResponse.error.Count > 0) { var sb = new StringBuilder(); foreach (var error in executePaymentResponse.error) { sb.AppendLine(error.message); } retVal.Error = sb.ToString(); retVal.NewPaymentStatus = PaymentStatus.Voided; } else { retVal.OuterId = payResponse.payKey; retVal.IsSuccess = true; var redirectBaseUrl = GetBaseUrl(Mode); retVal.RedirectUrl = string.Format(redirectBaseUrl, retVal.OuterId); retVal.NewPaymentStatus = PaymentStatus.Pending; } return retVal; }
/// <summary> /// Handle ExecutePayment API call /// </summary> /// <param name="contextHttp"></param> private void ExecutePayment(HttpContext contextHttp) { NameValueCollection parameters = contextHttp.Request.Params; // error language : (Required) RFC 3066 language in which error // messages are returned; by default it is en_US, which is the only language currently supported. // paykey : (Optional) The pay key that identifies the payment to be executed. // This is the pay key returned in the PayResponse message. ExecutePaymentRequest request = new ExecutePaymentRequest(new RequestEnvelope("en_US"), parameters["payKey"]); // (Optional) The ID of the funding plan from which to make this payment. request.fundingPlanId = parameters["fundingPlanId"]; AdaptivePaymentsService service = null; ExecutePaymentResponse 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.ExecutePayment(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)) { //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 // 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 // Important: You must test the value of paymentExecStatus for an error even if // responseEnvelope.ack is Success. If the PaymentExecStatus is ERROR, // the Pay Key can no longer be used. responseValues.Add("Payment exeucution status", response.paymentExecStatus); responseValues.Add("Acknowledgement", response.responseEnvelope.ack.ToString()); } Display(contextHttp, "ExecutePayment", responseValues, service.getLastRequest(), service.getLastResponse(), response.error, redirectUrl); }
public ActionResult paypalPaymentExecute(string id) { var api = GoPlayApi.Instance; var transaction = api.GetGcoinTransaction(id); if (transaction.HasData) { var headers = PaypalHelper.GetHeader(); RequestEnvelope requestEnvelope = new RequestEnvelope("en_US"); ExecutePaymentRequest executePayment = new ExecutePaymentRequest { requestEnvelope = requestEnvelope, payKey = transaction.Data.pay_key }; AdaptivePaymentsService adaptivePaymentsService = new AdaptivePaymentsService(headers); ExecutePaymentResponse executePaymentResponse = adaptivePaymentsService.ExecutePayment(executePayment); if (executePaymentResponse.responseEnvelope.ack.Value.ToString().ToLower() == "success" && executePaymentResponse.paymentExecStatus == "COMPLETED" && executePaymentResponse.error[0].errorId.Value.ToString() == "580022") { transaction.Data.status = "success"; //update trans api.UpdateGCoinTransaction(transaction.Data); logger.Fatal("update payment success"); this.Flash("Transaction is successful.", FlashLevel.Success); return Json(new { success = true }); } else { var error_msg = executePaymentResponse.error[0].message; logger.Fatal(error_msg); this.Flash(error_msg, FlashLevel.Error); } return RedirectToAction("gcoinTransactionIndex", "paypal"); } return Json(new { success = false }); }