Beispiel #1
0
        protected override IPaymentValidation ValidatePayment(HttpContext context, IDataAdapterDependencies dataAdapterDependencies, Tuple <Guid, string> quoteAndReturnUrl)
        {
            var transactionId = context.Request["tx"];
            var data          = context.Request.QueryString.ToString();

            if (string.IsNullOrWhiteSpace(transactionId))
            {
                return(new UnsuccessfulPaymentValidation(data, ResourceManager.GetString("TransactionID_Parameter_Not_Provided_Validation_Message")));
            }

            var portalContext = PortalCrmConfigurationManager.CreatePortalContext(PortalName);
            var identityToken = PayPalHelper.GetPayPalPdtIdentityToken(portalContext);

            if (string.IsNullOrWhiteSpace(identityToken))
            {
                return(new UnsuccessfulPaymentValidation(data, ResourceManager.GetString("Required_Site_Setting_Not_Exist_Validation_Message")));
            }

            var payPalHelper = new PayPalHelper(portalContext);
            var response     = payPalHelper.GetPaymentDataTransferResponse(identityToken, transactionId);

            switch (response.Status)
            {
            case PayPalHelper.PaymentDataTransferStatus.Unknown:
                return(new UnsuccessfulPaymentValidation(data,
                                                         ResourceManager.GetString("Null_PDT_Response")));

            case PayPalHelper.PaymentDataTransferStatus.Fail:
                return(new UnsuccessfulPaymentValidation(data,
                                                         ResourceManager.GetString("PDT_Returned_Fail_Response")));

            case PayPalHelper.PaymentDataTransferStatus.Success:
                //if (!payPalHelper.VerifyIPNOrder(new Dictionary<string, string>(), portalContext))
                if (!payPalHelper.VerifyIPNOrder(response.Details, portalContext))
                {
                    string paymentStatus;
                    response.Details.TryGetValue("payment_status", out paymentStatus);
                    return(new UnsuccessfulPaymentValidation(data, paymentStatus));
                }
                return(new SuccessfulPaymentValidation(data));

            default:
                return(new UnsuccessfulPaymentValidation(data,
                                                         ResourceManager.GetString("PDT_Response_Not_Valid")));
            }
        }
        protected override IPaymentValidation ValidatePayment(HttpContext context, IDataAdapterDependencies dataAdapterDependencies, Tuple <Guid, string> quoteAndReturnUrl)
        {
            var portalContext = PortalCrmConfigurationManager.CreatePortalContext(PortalName);
            var payPalHelper  = new PayPalHelper(portalContext);
            var requestForm   = context.Request.Form.ToString();

            var response = payPalHelper.GetPaymentWebResponse(requestForm);

            if (response == null)
            {
                return(new UnsuccessfulPaymentValidation(requestForm, ResourceManager.GetString("Get_Payment_Web_Response_Failed")));
            }

            var responseStream = response.GetResponseStream();

            if (responseStream == null)
            {
                return(new UnsuccessfulPaymentValidation(requestForm, ResourceManager.GetString("Get_Payment_Web_Response_Stream_Failed")));
            }

            using (var reader = new StreamReader(responseStream))
            {
                var responseText = reader.ReadToEnd();

                if (!string.Equals(responseText, "VERIFIED", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(new UnsuccessfulPaymentValidation(requestForm, responseText));
                }

                if (!payPalHelper.VerifyIPNOrder(context.Request.Form, portalContext))
                {
                    return(new UnsuccessfulPaymentValidation(requestForm, responseText));
                }

                return(new SuccessfulPaymentValidation(requestForm));
            }
        }