Пример #1
0
        /// <summary>
        /// Checkout method
        /// </summary>
        /// <param name="amount"></param>
        /// <returns></returns>
        public string CheckOut(decimal amount, string Description)
        {
            string        paypalRedirectUrl = null;
            StringBuilder log = new StringBuilder();
            string        requestParameter = "amount = " + amount + ", " + "Description = " + Description;

            log.Append("CheckOut method called with request parameters : " + requestParameter);
            APIContext apiContext = PaypalConfiguration.GetAPIContext();

            try
            {
                var    guid           = Convert.ToString((new Random()).Next(100000));
                string baseURI        = UtilityResource.PayPalBaseURL + guid;
                var    createdPayment = this.CreatePayment(apiContext, baseURI, amount.ToString(), Description);
                var    links          = createdPayment.links.GetEnumerator();
                while (links.MoveNext())
                {
                    Links lnk = links.Current;
                    if (lnk.rel.ToLower().Trim().Equals("approval_url"))
                    {
                        paypalRedirectUrl = lnk.href;
                    }
                }
                log.Append("Redirect Url is created and returned that URL in response");
            }
            catch (Exception ex)
            {
                LogManagers.LogManagers.WriteErrorLog(ex);
            }
            finally
            {
                LogManagers.LogManagers.WriteTraceLog(log);
            }
            return(paypalRedirectUrl);
        }
Пример #2
0
        /// <summary>
        /// Execute the Payment method
        /// </summary>
        /// <param name="payerId"></param>
        /// <param name="paymentId"></param>
        /// <returns></returns>
        public Payment ExecutePayment(string payerId, string paymentId)
        {
            StringBuilder log = new StringBuilder();
            string        requestParameter = "payerId = " + payerId + ", " + "paymentId = " + paymentId;

            log.Append("ExecutePayment method called with request parameters : " + requestParameter);

            Payment res = new Payment();

            try
            {
                APIContext apiContext       = PaypalConfiguration.GetAPIContext();
                var        paymentExecution = new PaymentExecution()
                {
                    payer_id = payerId
                };
                this.payment = new Payment()
                {
                    id = paymentId
                };

                log.Append("Execution starts");
                res = this.payment.Execute(apiContext, paymentExecution);
                log.Append("Execution ends");
                log.Append("ExecutePayment method executed successfully with response " + res);
            }
            catch (Exception ex)
            {
                log.Append(UtilityResource.ErrorInMethod.Replace("{MethodName}", UtilityResource.ExecutePayment).Replace("{ErrorMessage}", ex.Message));
                LogManagers.LogManagers.WriteErrorLog(ex);
            }
            finally
            {
                LogManagers.LogManagers.WriteTraceLog(log);
            }
            return(res);
        }