private void VerifyTransactionType(PayPalInfo payPalInfo)
 {
     if (payPalInfo.IpnTxnType != "web_accept")
     {
         throw new Exception("ipn_txn_type is not 'web_accept'");
     }
 }
 private void VerifyReceiverEmail(PayPalInfo payPalInfo)
 {
     if (payPalInfo.IpnReceiverEmail.ToUpper() != _payPalSettings.IpnReceiverEmail.ToUpper())
     {
         throw new Exception();
     }
 }
 private void VerifyProductNumber(PayPalInfo payPalInfo)
 {
     if (payPalInfo.IpnItemNumber != ItemNumber)
     {
         throw new Exception("ipn_item_number not equal to defined item number");
     }
 }
        string EmailBody(PayPalInfo payPalInfo, string licenseCode)
        {
            var placeholders = _emailTemplatePlaceholders.Populate(licenseCode, payPalInfo);
            var bodyTemplate = File.ReadAllText(_emailTemplateFile);

            return(_templateToMessageConverter.Convert(bodyTemplate, placeholders));
        }
        private void VerifyCostTotals(PayPalInfo payPalInfo)
        {
            var checksumTotal = payPalInfo.IpnQuantity * ItemCostPerUnit + payPalInfo.Tax;

            if (checksumTotal != Convert.ToDecimal(payPalInfo.McGross))
            {
                throw new Exception("Cost does not match");
            }
        }
        public Dictionary <string, string> Populate(string licenseCode, PayPalInfo payPalInfo)
        {
            var placeholders = new Dictionary <string, string>();

            placeholders.Clear();
            AddLicensePlaceholders(licenseCode, placeholders);
            AddPayPalInfoPlaceholders(placeholders, payPalInfo);
            return(placeholders);
        }
Пример #7
0
        public void Run(PayPalInfo payPalInfo)
        {
            _paypalIpnValidation.EnsureValid(payPalInfo);
            var productProfile = _productProfileSettings.GetValueOrDefault(payPalInfo.IpnItemNumber);
            var licenseCode    = GenerateLicenseCode(payPalInfo, productProfile);
            var message        = _userLicenseEmail.ConstructEmail(payPalInfo, licenseCode);

            _emailSender.SendEmail(message);
        }
Пример #8
0
        private string GenerateLicenseCode(PayPalInfo payPalInfo, string licenseTypeProfile)
        {
            _licenseGenerator.Initialize();
            _licenseGenerator.SetActiveProfile(licenseTypeProfile);
            _licenseGenerator.NumberOfUsers = payPalInfo.IpnQuantity;
            _licenseGenerator.UserData      = payPalInfo.UserData;
            var licenseCode = _licenseGenerator.Generate();

            return(licenseCode);
        }
        public MailMessage ConstructEmail(PayPalInfo payPalInfo, string licenseCode)
        {
            var message = new MailMessage();

            message.From    = new MailAddress(_emailAddressFrom);
            message.Subject = _subject;
            message.To.Add(payPalInfo.PayerEmail);
            message.Bcc.Add(_emailAddressBcc);
            message.IsBodyHtml = true;
            message.Body       = EmailBody(payPalInfo, licenseCode);
            message.IsBodyHtml = false;

            return(message);
        }
        public bool EnsureValid(PayPalInfo payPalInfo)
        {
            DataDumper.Dump(payPalInfo.SerializedMessage());

            var cmd    = "cmd = _notify-validate &" + payPalInfo.SerializedMessage();
            var client = new WebClient();

            client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

            DataDumper.Dump(cmd);
            var bytes = Encoding.UTF8.GetBytes(cmd);

            // Send HTTP POST to verify IPN
            var responseBuffer  = client.UploadData(_payPalSettings.IpnValidationUrl, "POST", bytes);
            var responseMessage = Encoding.UTF8.GetString(responseBuffer);

            DataDumper.Dump(responseMessage);
            if (responseMessage != "VERIFIED")
            {
                return(false);
            }

            //try
            //{
            //    //VerifyTransactionType(payPalInfo);
            //    //VerifyProductNumber(payPalInfo);
            //    //VerifyCostTotals(payPalInfo);
            //    //VerifyReceiverEmail(payPalInfo);
            //}
            //catch (Exception)
            //{
            //    return false;
            //}

            return(true);
        }
 private void AddPayPalInfoPlaceholders(Dictionary <string, string> placeholders, PayPalInfo payPalInfo)
 {
     placeholders.Add("IpnItemNumber", payPalInfo.IpnItemNumber);
     placeholders.Add("LastName", payPalInfo.LastName);
     placeholders.Add("PayerCompany", payPalInfo.PayerCompany);
     placeholders.Add("IpnTxnType", payPalInfo.IpnTxnType);
     placeholders.Add("IpnItemNumber", payPalInfo.IpnItemNumber);
     placeholders.Add("McCurrency", payPalInfo.McCurrency);
     placeholders.Add("PaymentDate", payPalInfo.PaymentDate);
     placeholders.Add("PaymentType", payPalInfo.PaymentType);
     placeholders.Add("ResidenceCountry", payPalInfo.ResidenceCountry);
     placeholders.Add("TestIpn", payPalInfo.TestIpn);
     placeholders.Add("TransactionSubject", payPalInfo.TransactionSubject);
     placeholders.Add("HandlingAmount", payPalInfo.HandlingAmount.ToString());
     placeholders.Add("IpnQuantity", payPalInfo.IpnQuantity.ToString());
     placeholders.Add("McFee", payPalInfo.McFee.ToString());
     placeholders.Add("McGross", payPalInfo.McGross.ToString());
     placeholders.Add("PaymentFee", payPalInfo.PaymentFee.ToString());
     placeholders.Add("PaymentGross", payPalInfo.PaymentGross.ToString());
     placeholders.Add("Shipping", payPalInfo.Shipping.ToString());
     placeholders.Add("Tax", payPalInfo.Tax.ToString());
 }