示例#1
0
 public ActionResult Index(PaypalViewModel model)
 {
     TempData["paypalviewmodel"] = model;
     if (model.IsPayPalPayment == true)
         return RedirectToAction("PaypalPayment", "Paypal");
     else
         return RedirectToAction("CardPayment", "Paypal");
 }
示例#2
0
        public ActionResult CardPayment(PaypalViewModel model)
        {
            //create and item for which you are taking payment
            //if you need to add more items in the list
            //Then you will need to create multiple item objects or use some loop to instantiate object

            PaypalViewModel model1 = (PaypalViewModel)TempData["paypalviewmodel"];

            Payment pyt = CardDetailsModel.GetCardPaymentDetailsForPaypal(model1.Amount);

            model.PayPalPayment = pyt;
            model.Amount = model1.Amount;
            model.TransactionGuid = pyt.transactions[0].invoice_number.ToString();

            //before payment, move details to confirm payment view

            TempData["paypalviewmodel1"] = model;

            return View("ConfirmPaymentView", model);
        }
示例#3
0
        public ActionResult ConfirmPaymentView(PaypalViewModel model)
        {
            PaypalViewModel model1 = (PaypalViewModel)TempData["paypalviewmodel1"];
            try
            {
                // ### Api Context
                // Pass in a `APIContext` object to authenticate
                // the call and to send a unique request id
                // (that ensures idempotency). The SDK generates
                // a request id if you do not pass one explicitly.
                // See [Configuration.cs](/Source/Configuration.html) to know more about APIContext.
                APIContext apiContext = Configuration.GetAPIContext();

                // Create is a Payment class function which actually sends the payment details to the paypal API for the payment. The function is passed with the ApiContext which we received above.

                Payment createdPayment = model1.PayPalPayment.Create(apiContext);

                //if the createdPayment.State is "approved" it means the payment was successfull else not

                if (createdPayment.state.ToLower() != "approved")
                {
                    model1.PayPalRestError.message = createdPayment.state.ToString();
                    return View("FailureView", model1);
                }
            }
            catch (PayPal.PayPalException ex)
            {
                Logger.Log("Error: " + ex.Message);
                model1.ErrMessage = ex.Message;
                return View("FailureView", model1);
            }

            TempData["paypalviewmodel"] = model1;
            return RedirectToAction("SuccessView");
            //return View("SuccessView");
        }
示例#4
0
        public ActionResult Index()
        {
            PaypalViewModel model = new PaypalViewModel();

            return View(model);
        }
示例#5
0
        public ActionResult SuccessView(PaypalViewModel model)
        {
            PaypalViewModel model1 = (PaypalViewModel)TempData["paypalviewmodel"];

            var apiContext = Configuration.GetAPIContext();

            //**************************************
            //Getting back error here:
            //{"name":"BUSINESS_ERROR","message":"Invalid encrypted id.","debug_id":"8b3f27ecb634d"}
            //so hard code invoiceId from PayPal example to show workflow

            //string invoiceId = model1.TransactionGuid;
            string invoiceId = "INV2-W6VG-MFK4-HQRT-RS6Z";
            try
            {
                model1.PayPalInvoice = Invoice.Get(apiContext, invoiceId);
            }
            catch (PayPal.PayPalException ex)
            {
                Logger.Log("Error: " + ex.Message);
                model1.PayPal_Exception = ex;
                model1.ErrMessage = "You payment was successful, however there's been a problem trying to display your receipt";
                return View(model1);
            }

            return View(model1);
        }