/// <summary>
        /// Handle CancelPreapproval API call
        /// </summary>
        /// <param name="contextHttp"></param>
        private void CancelPreapproval(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. 
            // preapproval key : (Required) A preapproval key that identifies the preapproval for which you want to retrieve details. The preapproval key is returned in the PreapprovalResponse message
            CancelPreapprovalRequest request = new CancelPreapprovalRequest(new RequestEnvelope("en_US"),
                parameters["preapprovalKey"]);
           
            AdaptivePaymentsService service = null;
            CancelPreapprovalResponse 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.CancelPreapproval(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))
            {
                
                responseValues.Add("Acknowledgement", response.responseEnvelope.ack.ToString());
            }
            Display(contextHttp, "CancelPreapproval", responseValues, service.getLastRequest(), service.getLastResponse(), response.error, redirectUrl);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handle CancelPreapproval API call
        /// </summary>
        /// <param name="context"></param>
        private void CancelPreapproval(HttpContext context)
        {
            NameValueCollection parameters = context.Request.Params;
            CancelPreapprovalRequest req = new CancelPreapprovalRequest(new RequestEnvelope("en_US"),
                parameters["preapprovalKey"]);

            // All set. Fire the request
            AdaptivePaymentsService service = new AdaptivePaymentsService();
            CancelPreapprovalResponse resp = null;
            try
            {
                resp = service.CancelPreapproval(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))
            {
                //Selenium Test Case
                keyResponseParams.Add("Acknowledgement", resp.responseEnvelope.ack.ToString());
            }
            displayResponse(context, "CancelPreapproval", keyResponseParams, service.getLastRequest(), service.getLastResponse(),
                resp.error, redirectUrl);
        }
Exemplo n.º 3
0
        public ActionResult GetPaypalPreapprovalCancel()
        {
            var api = GoPlayApi.Instance;

            var paypalPreapproval = api.FindPaypalPreapproval(true).Data.SingleOrDefault();
            if (paypalPreapproval != null)
            {
                var headers = PaypalHelper.GetHeader();

                RequestEnvelope requestEnvelope = new RequestEnvelope("en_US");

                CancelPreapprovalRequest cancelPreapprovalRequest = new CancelPreapprovalRequest
                {
                    requestEnvelope = requestEnvelope,
                    preapprovalKey = paypalPreapproval.preapproval_key
                };


                AdaptivePaymentsService adaptivePaymentsService = new AdaptivePaymentsService(headers);
                CancelPreapprovalResponse cancelPreapprovalResponse = adaptivePaymentsService.CancelPreapproval(cancelPreapprovalRequest);
                if (cancelPreapprovalResponse.responseEnvelope.ack.HasValue && cancelPreapprovalResponse.responseEnvelope.ack.Value.ToString().ToLower() == "success")
                {
                    paypalPreapproval.is_active = false;
                    api.UpdatePaypalPreapproval(paypalPreapproval.id, false);
                    this.Flash("Transaction is successful.", FlashLevel.Success);
                    return Json(new { success = true });
                }
                else
                {
                    return Json(new { error = cancelPreapprovalResponse.error[0].message });
                }
            }
            return RedirectToAction("index", "paypal");
        }