Example #1
0
        public GetExpressCheckoutDetailsResponse SendPayPalGetExpressCheckoutDetailsRequest(string token)
        {
            try
            {
                WebUILogging.LogMessage("SendPayPalGetExpressCheckoutDetailsRequest");
                GetExpressCheckoutDetailsResponse response = _payPalTransactionRegistrar.SendGetExpressCheckoutDetails(token);

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

                // Store this transaction in your Database

                return(response);
            }
            catch (Exception ex)
            {
                WebUILogging.LogException(ex.Message, ex);
            }
            return(null);
        }
Example #2
0
        public GetExpressCheckoutDetailsResponse SendPayPalGetExpressCheckoutDetailsRequest(string token)
        {
            try
            {
                GetExpressCheckoutDetailsResponse response = _payPalTransactionRegistrar.SendGetExpressCheckoutDetails(token);

                return(response);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message, ex);
            }
            return(null);
        }
        public ActionResult PayPalExpressCheckoutAuthorisedSuccess(string token, string PayerID) // Note "PayerID" is returned with capitalisation as written
        {
            // PayPal redirects back to here
            WebUILogging.LogMessage("Express Checkout Authorised");
            // GetExpressCheckoutDetails
            TempData["token"]   = token;
            TempData["payerId"] = PayerID;
            GetExpressCheckoutDetailsResponse transactionResponse = transactionService.SendPayPalGetExpressCheckoutDetailsRequest(token);

            if (transactionResponse == null || transactionResponse.ResponseStatus != PayPalMvc.Enums.ResponseType.Success)
            {
                SetUserNotification("Sorry there was a problem with initiating a PayPal transaction. 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 GetExpressCheckoutDetails transaction. Error: " + errorMessage);
                return(RedirectToAction("Error", "Purchase"));
            }
            return(RedirectToAction("ConfirmPayPalPayment"));
        }
Example #4
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));
            }
        }