Exemple #1
0
        public DoExpressCheckoutPaymentResponse SendPayPalDoExpressCheckoutPaymentRequest(ApplicationCart cart, string token, string payerId)
        {
            try
            {
                WebUILogging.LogMessage("SendPayPalDoExpressCheckoutPaymentRequest");
                DoExpressCheckoutPaymentResponse response = _payPalTransactionRegistrar.SendDoExpressCheckoutPayment(token, payerId, cart.Currency, cart.TotalPrice);

                // Add a PayPal transaction record
                PayPalTransaction transaction = new PayPalTransaction
                {
                    RequestId            = response.RequestId,
                    TrackingReference    = cart.Id.ToString(),
                    RequestTime          = DateTime.Now,
                    RequestStatus        = response.ResponseStatus.ToString(),
                    TimeStamp            = response.TIMESTAMP,
                    RequestError         = response.ErrorToString,
                    Token                = response.TOKEN,
                    RequestData          = response.ToString,
                    PaymentTransactionId = response.PaymentTransactionId,
                    PaymentError         = response.PaymentErrorToString,
                };

                // Store this transaction in your Database

                return(response);
            }
            catch (Exception ex)
            {
                WebUILogging.LogException(ex.Message, ex);
            }
            return(null);
        }
Exemple #2
0
        public DoExpressCheckoutPaymentResponse SendPayPalDoExpressCheckoutPaymentRequest(PanierViewModel panier, string token, string payerId)
        {
            try
            {
                DoExpressCheckoutPaymentResponse response = _payPalTransactionRegistrar.SendDoExpressCheckoutPayment(token, payerId, "EUR", new decimal(panier.GlobalPrice));

                return(response);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message, ex);
            }
            return(null);
        }
Exemple #3
0
        public ActionResult OrderPaypalAuthorized(string token, string PayerID)
        {
            PanierViewModel panier = (PanierViewModel)Session["Panier"];

            //Récupération des détails de l'appel Express Checkout
            GetExpressCheckoutDetailsResponse getDetailsResponse = paypalService.SendPayPalGetExpressCheckoutDetailsRequest(token);

            if (getDetailsResponse == null || getDetailsResponse.ResponseStatus != Core.Transcoder.PayPalMvc.Enums.ResponseType.Success)
            {
                string errorMessage = (getDetailsResponse == null) ? "Null Transaction Response" : getDetailsResponse.ErrorToString;
                Debug.WriteLine("Error initiating PayPal GetExpressCheckoutDetails transaction. Error: " + errorMessage);
                return(RedirectToAction("Panier", panier));
            }

            //Paiement de la commande
            DoExpressCheckoutPaymentResponse doCheckoutRepsonse = paypalService.SendPayPalDoExpressCheckoutPaymentRequest(panier, token, PayerID);

            if (doCheckoutRepsonse == null || doCheckoutRepsonse.ResponseStatus != Core.Transcoder.PayPalMvc.Enums.ResponseType.Success)
            {
                if (doCheckoutRepsonse != null && doCheckoutRepsonse.L_ERRORCODE0 == "10486")
                {
                    Debug.WriteLine("10486 error (bad funding method - typically an invalid credit card)");
                    return(Redirect(string.Format(Configuration.Current.PayPalRedirectUrl, token)));
                }
                string errorMessage = (doCheckoutRepsonse == null) ? "Null Transaction Response" : doCheckoutRepsonse.ErrorToString;
                Debug.WriteLine("Error initiating PayPal DoExpressCheckoutPayment transaction. Error: " + errorMessage);
                return(RedirectToAction("Panier", panier));
            }

            if (doCheckoutRepsonse.PaymentStatus == PaymentStatus.Completed)
            {
                taskService.SetAllTasksPaidForTransaction(panier.TransactionId);
                MailUtil.SendMail(Core.Transcoder.Service.Enums.StringManager.PAIEMENT_ACCEPTE, null, panier);

                return(RedirectToAction("OrderPaidConfirm"));
            }
            else
            {
                Debug.WriteLine($"Error taking PayPal payment. Error: " + doCheckoutRepsonse.ErrorToString +
                                " - Payment Error: " + doCheckoutRepsonse.PaymentErrorToString);
                TempData["TransactionResult"] = doCheckoutRepsonse.PAYMENTREQUEST_0_LONGMESSAGE;
                return(RedirectToAction("Panier", panier));
            }
        }
        public ActionResult ConfirmPayPalPayment(bool confirmed = true)
        {
            WebUILogging.LogMessage("Express Checkout Confirmed");
            ApplicationCart cart = (ApplicationCart)Session["Cart"];
            // DoExpressCheckoutPayment
            string token   = TempData["token"].ToString();
            string payerId = TempData["payerId"].ToString();
            DoExpressCheckoutPaymentResponse transactionResponse = transactionService.SendPayPalDoExpressCheckoutPaymentRequest(cart, token, payerId);

            if (transactionResponse == null || transactionResponse.ResponseStatus != PayPalMvc.Enums.ResponseType.Success)
            {
                if (transactionResponse != null && transactionResponse.L_ERRORCODE0 == "10486")
                {
                    // Redirect user back to PayPal in case of Error 10486 (bad funding method)
                    // https://www.x.com/developers/paypal/documentation-tools/how-to-guides/how-to-recover-funding-failure-error-code-10486-doexpresscheckout
                    WebUILogging.LogMessage("Redirecting User back to PayPal due to 10486 error (bad funding method - typically an invalid or maxed out credit card)");
                    return(Redirect(string.Format(PayPalMvc.Configuration.Current.PayPalRedirectUrl, token)));
                }
                SetUserNotification("Sorry there was a problem with taking the PayPal payment, so no money has been transferred. Please try again and contact an Administrator if this still doesn't work.");
                string errorMessage = (transactionResponse == null) ? "Null Transaction Response" : transactionResponse.ErrorToString;
                WebUILogging.LogMessage("Error initiating PayPal DoExpressCheckoutPayment transaction. Error: " + errorMessage);
                return(RedirectToAction("Error", "Purchase"));
            }

            if (transactionResponse.PaymentStatus == PaymentStatus.Completed)
            {
                payoutFunction(cart);
                return(RedirectToAction("PostPaymentSuccess"));
            }
            else
            {
                // Something went wrong or the payment isn't complete
                WebUILogging.LogMessage("Error taking PayPal payment. Error: " + transactionResponse.ErrorToString + " - Payment Error: " + transactionResponse.PaymentErrorToString);
                TempData["TransactionResult"] = transactionResponse.PAYMENTREQUEST_0_LONGMESSAGE;
                return(RedirectToAction("PostPaymentFailure"));
            }
        }