diff --git a/.gitignore b/.gitignore index e9fdf56c2..b709d07ef 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ /bin /obj *.xml +src/Api.Socioboard/obj/ +src/Api.Socioboard/bin/ +*.rsp diff --git a/.vs/Socioboard/v14/.suo b/.vs/Socioboard/v14/.suo index 761dedd77..6412b07bf 100644 Binary files a/.vs/Socioboard/v14/.suo and b/.vs/Socioboard/v14/.suo differ diff --git a/.vs/config/applicationhost.config b/.vs/config/applicationhost.config deleted file mode 100644 index 4c5e1546a..000000000 --- a/.vs/config/applicationhost.config +++ /dev/null @@ -1,1097 +0,0 @@ - - - - - - - -
-
-
-
-
-
-
-
- - - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
- -
-
-
-
-
-
- -
-
-
-
-
- -
-
-
- -
-
- -
-
- -
-
-
- - -
-
-
-
-
-
- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/.vs/restore.dg b/.vs/restore.dg deleted file mode 100644 index a9dc0b43a..000000000 --- a/.vs/restore.dg +++ /dev/null @@ -1,10 +0,0 @@ -#:E:\Github\Socioboard-Core-3.0\src\Socioboard\Socioboard.xproj -E:\Github\Socioboard-Core-3.0\src\Socioboard\Socioboard.xproj|E:\Github\Socioboard-Core-3.0\src\Socioboard.Facebook\Socioboard.Facebook.xproj -E:\Github\Socioboard-Core-3.0\src\Socioboard\Socioboard.xproj|E:\Github\Socioboard-Core-3.0\src\Socioboard.Pinterest\Socioboard.Pinterest.xproj -E:\Github\Socioboard-Core-3.0\src\Socioboard.Facebook\Socioboard.Facebook.xproj|E:\Github\Socioboard-Core-3.0\src\Domain.Socioboard\Domain.Socioboard.xproj -#:E:\Github\Socioboard-Core-3.0\src\AdvancedContentSearch\AdvancedContentSearch.xproj -E:\Github\Socioboard-Core-3.0\src\AdvancedContentSearch\AdvancedContentSearch.xproj|E:\Github\Socioboard-Core-3.0\src\Socioboard\Socioboard.xproj -E:\Github\Socioboard-Core-3.0\src\AdvancedContentSearch\AdvancedContentSearch.xproj|E:\Github\Socioboard-Core-3.0\src\Socioboard.Instagram\Socioboard.Instagram.xproj -E:\Github\Socioboard-Core-3.0\src\Socioboard\Socioboard.xproj|E:\Github\Socioboard-Core-3.0\src\Socioboard.Facebook\Socioboard.Facebook.xproj -E:\Github\Socioboard-Core-3.0\src\Socioboard\Socioboard.xproj|E:\Github\Socioboard-Core-3.0\src\Socioboard.Pinterest\Socioboard.Pinterest.xproj -E:\Github\Socioboard-Core-3.0\src\Socioboard.Facebook\Socioboard.Facebook.xproj|E:\Github\Socioboard-Core-3.0\src\Domain.Socioboard\Domain.Socioboard.xproj diff --git a/src/Api.Socioboard/Controllers/PaymentTransactionController.cs b/src/Api.Socioboard/Controllers/PaymentTransactionController.cs index 10ffdd751..4d9cf29d7 100644 --- a/src/Api.Socioboard/Controllers/PaymentTransactionController.cs +++ b/src/Api.Socioboard/Controllers/PaymentTransactionController.cs @@ -77,6 +77,20 @@ public IActionResult GetPaymentTransactiondata(long id) } + /// + /// + /// + /// + /// + [HttpGet("GetUserPaymentProfiles")] + public IActionResult GetUserPaymentProfiles(Int64 id) + { + var dbr = new DatabaseRepository(_logger, _appEnv); + var payments = dbr.Find(t => t.userid == id); + var filterPayment = payments.ToList().OrderByDescending(x => x.paymentdate).FirstOrDefault(); + return Ok(filterPayment); + } + /// /// /// diff --git a/src/Socioboard/Controllers/HomeController.cs b/src/Socioboard/Controllers/HomeController.cs index df6a76514..4c96cd9b8 100644 --- a/src/Socioboard/Controllers/HomeController.cs +++ b/src/Socioboard/Controllers/HomeController.cs @@ -917,11 +917,13 @@ public async Task PayPalAccount(string emailId, bool isLogin) HttpContext.Session.SetObjectAsJson("paymentsession", true); if (user.PaymentType == Domain.Socioboard.Enum.PaymentType.paypal) - return Redirect(Payment.PaypalRecurringPayment(sessionPackage.amount, - sessionPackage.packagename, user.FirstName + " " + user.LastName, user.PhoneNumber, - user.EmailId, "USD", _appSettings.paypalemail, _appSettings.callBackUrl, - _appSettings.failUrl, _appSettings.callBackUrl, _appSettings.cancelurl, - _appSettings.notifyUrl, "", _appSettings.PaypalURL, user.Id)); + { + + var payment = new Payment(_appSettings); + var redirect = await payment.PaypalExpressPayment(sessionPackage.amount, "USD", sessionPackage.packagename, user.EmailId, user.Id, Guid.NewGuid().ToString()); + return Redirect(redirect); + } + return RedirectToAction("paymentWithPayUMoney", "Index", new { contesnt = false }); @@ -1228,8 +1230,13 @@ public async Task BluesnapAccount(string emailId, bool IsLogin) if (user.PaymentType == Domain.Socioboard.Enum.PaymentType.paypal) { HttpContext.Session.SetObjectAsJson("paymentsession", true); - string paypalUrl = Helpers.Payment.PaypalRecurringPayment(_Package.amount, _Package.packagename, user.FirstName + " " + user.LastName, user.PhoneNumber, user.EmailId, "USD", _appSettings.paypalemail, _appSettings.callBackUrl, _appSettings.failUrl, _appSettings.callBackUrl, _appSettings.cancelurl, _appSettings.notifyUrl, "", _appSettings.PaypalURL, user.Id); - return Content(paypalUrl); + + var payment = new Payment(_appSettings); + + var paypalUrl = await payment.PaypalExpressPayment(_Package.amount, "USD", _Package.packagename, user.EmailId, user.Id, + Guid.NewGuid().ToString()); + + return Content(paypalUrl); } else { @@ -1242,7 +1249,10 @@ public async Task BluesnapAccount(string emailId, bool IsLogin) if (user.PaymentType == Domain.Socioboard.Enum.PaymentType.paypal) { HttpContext.Session.SetObjectAsJson("paymentsession", true); - return Redirect(Helpers.Payment.PaypalRecurringPayment(_Package.amount, _Package.packagename, user.FirstName + " " + user.LastName, user.PhoneNumber, user.EmailId, "USD", _appSettings.paypalemail, _appSettings.callBackUrl, _appSettings.failUrl, _appSettings.callBackUrl, _appSettings.cancelurl, _appSettings.notifyUrl, "", _appSettings.PaypalURL, user.Id)); + var payment = new Payment(_appSettings); + var paypalUrl = await payment.PaypalExpressPayment(_Package.amount, "USD", _Package.packagename, user.EmailId, user.Id, + Guid.NewGuid().ToString()); + return Redirect(paypalUrl); } else { diff --git a/src/Socioboard/Controllers/IndexController.cs b/src/Socioboard/Controllers/IndexController.cs index 89b866fdb..bc491d547 100644 --- a/src/Socioboard/Controllers/IndexController.cs +++ b/src/Socioboard/Controllers/IndexController.cs @@ -16,7 +16,7 @@ using Socioboard.Helper; using System.Linq; using System.Net; - +using Domain.Socioboard.Enum; namespace Socioboard.Controllers @@ -449,25 +449,23 @@ public async Task UpgradeAccount(string packagename) { var package = await response.Content.ReadAsAsync(); HttpContext.Session.SetObjectAsJson("Package", package); - + var payment = new Payment(_appSettings); if (user.CreateDate.AddDays(29) > DateTime.UtcNow) { - return user.PaymentType == Domain.Socioboard.Enum.PaymentType.paypal - ? (IActionResult)Content(Payment.PaypalRecurringPayment(package.amount, - package.packagename, - user.FirstName + " " + user.LastName, user.PhoneNumber, user.EmailId, "USD", - _appSettings.paypalemail, _appSettings.callBackUrl, _appSettings.failUrl, - _appSettings.callBackUrl, _appSettings.cancelurl, _appSettings.notifyUrl, "", - _appSettings.PaypalURL, user.Id)) - : RedirectToAction("paymentWithPayUMoney", "Index"); - } + if (user.PaymentType == PaymentType.paypal) + { + var redirect = await payment.PaypalExpressPayment(package.amount, "USD", package.packagename, user.EmailId, user.Id, Guid.NewGuid().ToString()); + return (IActionResult)Content(redirect); + } + return RedirectToAction("paymentWithPayUMoney", "Index"); + } if (user.PaymentType == Domain.Socioboard.Enum.PaymentType.paypal) - return Content(Payment.PaypalRecurringPayment(package.amount, package.packagename, user.FirstName + " " + user.LastName, user.PhoneNumber, user.EmailId, "USD", _appSettings.paypalemail, _appSettings.callBackUrl, _appSettings.failUrl, _appSettings.callBackUrl, _appSettings.cancelurl, _appSettings.notifyUrl, "", _appSettings.PaypalURL, user.Id)); - - return RedirectToAction("paymentWithPayUMoney", "Index"); - + { + var redirect = await payment.PaypalExpressPayment(package.amount, "USD", package.packagename, user.EmailId, user.Id, Guid.NewGuid().ToString()); + return (IActionResult)Content(redirect); + } } catch (Exception ex) { diff --git a/src/Socioboard/Controllers/PaymentController.cs b/src/Socioboard/Controllers/PaymentController.cs index cbad76138..5ec938251 100644 --- a/src/Socioboard/Controllers/PaymentController.cs +++ b/src/Socioboard/Controllers/PaymentController.cs @@ -69,12 +69,12 @@ public async Task Index(string emailId) HttpContext.Session.SetObjectAsJson("paymentsession", true); if (user.PaymentType == PaymentType.paypal) - return Content(Payment.PaypalRecurringPayment(sessionPackage.amount, - sessionPackage.packagename, user.FirstName + " " + user.LastName, user.PhoneNumber, - user.EmailId, "USD", _appSettings.paypalemail, _appSettings.callBackUrl, - _appSettings.failUrl, _appSettings.callBackUrl, _appSettings.cancelurl, - _appSettings.notifyUrl, "", _appSettings.PaypalURL, user.Id)); - + { + var payment = new Payment(_appSettings); + var paypalUrl = await payment.PaypalExpressPayment(sessionPackage.amount, "USD", sessionPackage.packagename, user.EmailId, user.Id, + Guid.NewGuid().ToString()); + return Content(paypalUrl); + } if (user.PaymentType == PaymentType.bluesnap) { return RedirectToAction("paymentWithPayUMoney", "Index", new { contesnt = false }); @@ -250,6 +250,129 @@ public async Task PaypalSuccess() return Content(output); } + + public async Task PaypalExpressSuccess() + { + + var payment = new Payment(_appSettings); + + var token = Utils.GetBetween(Request.QueryString + "&", "token=", "&"); + var user = HttpContext.Session.GetObjectFromJson("User"); + var packageDetails = HttpContext.Session.GetObjectFromJson("Package"); + + try + { + await payment.CancelRecurring(user.Id.ToString()); + } + catch (Exception e) + { + Console.WriteLine(e); + } + + var payerId = await payment.GetPayPalPayerId(token); + + var paymentResponse = await payment.PaypalInitialPayment(token, payerId, packageDetails.packagename, packageDetails.amount); + + var status = Utils.GetBetween(paymentResponse, "ACK=", "&"); + + if (status != "Success") + return RedirectToAction("Index", "Home"); + + var transactionId = Utils.GetBetween(paymentResponse, "PAYMENTINFO_0_TRANSACTIONID=", "&"); + var paidAmount = Uri.UnescapeDataString(Utils.GetBetween(paymentResponse, "PAYMENTINFO_0_AMT=", "&")); + var paymentDate = Uri.UnescapeDataString(Utils.GetBetween(paymentResponse, "PAYMENTINFO_0_ORDERTIME=", "&")); + var payerEmail = Uri.UnescapeDataString(Utils.GetBetween(paymentResponse, "PAYMENTINFO_0_SELLERPAYPALACCOUNTID=", "&")); + var paymentStatus = Uri.UnescapeDataString(Utils.GetBetween(paymentResponse, "PAYMENTINFO_0_PAYMENTSTATUS=", "&")); + var itemName = $"Socioboard_{packageDetails.packagename}"; + + var charset = Uri.UnescapeDataString(Utils.GetBetween(paymentResponse, "PAYMENTINFO_0_SECUREMERCHANTACCOUNTID=", "&")); + var details = await payment.PaypalRecurringCreation(token, payerId, packageDetails.packagename, packageDetails.amount); + var profileId = Uri.UnescapeDataString(Utils.GetBetween(details, "PROFILEID=", "&")); + var profileDetails = await payment.GetRecurringProfileDetails(profileId); + var payerName = Uri.UnescapeDataString(Utils.GetBetween(profileDetails, "SUBSCRIBERNAME=", "&")); + + var parameters = new List> + { + new KeyValuePair("userId", user.Id.ToString()), + new KeyValuePair("UserName", user.FirstName + " " + user.LastName), + new KeyValuePair("email", user.EmailId), + new KeyValuePair("amount", paidAmount), + new KeyValuePair("PaymentType", user.PaymentType.ToString()), + new KeyValuePair("trasactionId", transactionId), + new KeyValuePair("paymentId", profileId), + new KeyValuePair("accType", packageDetails.packagename), + new KeyValuePair("subscr_date", paymentDate.ToString(CultureInfo.InvariantCulture)), + new KeyValuePair("payer_email", payerEmail), + new KeyValuePair("Payername", payerName), + new KeyValuePair("payment_status", paymentStatus), + new KeyValuePair("item_name", itemName), + new KeyValuePair("media", charset) + }; + + var paymentTransaction = new PaymentTransaction + { + amount = paidAmount, + email = user.EmailId, + paymentdate = DateTime.Parse(paymentDate), + userid = user.Id, + PaymentType = PaymentType.paypal, + trasactionId = transactionId, + paymentId = profileId, + payeremail = payerEmail, + Payername = payerName, + paymentstatus = paymentStatus, + itemname = itemName, + media = charset, + subscrdate = DateTime.Parse(paymentDate) + }; + + var passingData = Newtonsoft.Json.JsonConvert.SerializeObject(paymentTransaction); + + var param = new List> + { + new KeyValuePair("information", passingData) + }; + + var response = await WebApiReq.PostReq("/api/PaymentTransaction/UpdatePaypalTransactions", param, "", "", _appSettings.ApiDomain); + + if (response.IsSuccessStatusCode) + try + { + var data = await response.Content.ReadAsStringAsync(); + + if (data == "Completed") + { + var responseMessage = await WebApiReq.GetReq("/api/User/GetUser?Id=" + user.Id, "", "", + _appSettings.ApiDomain); + + if (response.IsSuccessStatusCode) + try + { + var userCurrentDetails = await responseMessage.Content.ReadAsAsync(); + + if (user.ReferralStatus == "InActive" && user.ReferdBy != null) + await WebApiReq.PostReq("/api/User/UpdateRefrralStatus", parameters, "", "", _appSettings.ApiDomain); + + HttpContext.Session.SetObjectAsJson("User", userCurrentDetails); + HttpContext.Session.SetObjectAsJson("paymentsession", false); + return RedirectToAction("Index", "Home"); + } + catch (Exception ex) + { + Console.WriteLine(ex.StackTrace); + } + } + } + catch (Exception) + { + return RedirectToAction("Index", "Index"); + } + + var output = "false"; + return Content(output); + } + + public IActionResult PaypalFailed() { return RedirectToAction("Index", "Index"); @@ -637,23 +760,30 @@ public async Task UpgradeAccount(string packagename) HttpContext.Session.SetObjectAsJson("Package", package); if (user.CreateDate.AddDays(29) > DateTime.UtcNow) - return user.PaymentType == PaymentType.paypal - ? (IActionResult)Content(Payment.PaypalRecurringPayment(package.amount, - package.packagename, - user.FirstName + " " + user.LastName, user.PhoneNumber, user.EmailId, "USD", - _appSettings.paypalemail, _appSettings.callBackUrl, _appSettings.failUrl, - _appSettings.callBackUrl, _appSettings.cancelurl, _appSettings.notifyUrl, "", - _appSettings.PaypalURL, user.Id)) - : RedirectToAction("paymentWithPayUMoney", "Index"); + { + if (user.PaymentType == PaymentType.paypal) + { + var payment = new Payment(_appSettings); + var paypalUrl = await payment.PaypalExpressPayment(package.amount, "USD", package.packagename, user.EmailId, user.Id, + Guid.NewGuid().ToString()); + return Content(paypalUrl); + } + else + { + return RedirectToAction("paymentWithPayUMoney", "Index"); + } + } if (user.PaymentType == PaymentType.paypal) - return Content(Payment.PaypalRecurringPayment(package.amount, package.packagename, - user.FirstName + " " + user.LastName, user.PhoneNumber, user.EmailId, "USD", - _appSettings.paypalemail, _appSettings.callBackUrl, _appSettings.failUrl, - _appSettings.callBackUrl, _appSettings.cancelurl, _appSettings.notifyUrl, "", - _appSettings.PaypalURL, user.Id)); + { + var payment = new Payment(_appSettings); + var paypalUrl = await payment.PaypalExpressPayment(package.amount, "USD", package.packagename, user.EmailId, user.Id, + Guid.NewGuid().ToString()); + return Content(paypalUrl); + } + return RedirectToAction("paymentWithPayUMoney", "Index"); } catch (Exception ex) diff --git a/src/Socioboard/Helpers/AppSettings.cs b/src/Socioboard/Helpers/AppSettings.cs index c0eb1f59e..b155ee1e6 100644 --- a/src/Socioboard/Helpers/AppSettings.cs +++ b/src/Socioboard/Helpers/AppSettings.cs @@ -67,6 +67,19 @@ public class AppSettings public string PaypalPdtToken { get; set; } + + public string PaypalApiUsername { get; set; } + + public string PaypalApiPassword { get; set; } + + public string PaypalApiSignature { get; set; } + + public string PaypalSuccessUrl { get; set; } + + public string PaypalExpressUrl { get; set; } + + public string PaypalRedirectUrl { get; set; } + public string AgencycallBackUrl { get; set; } public string TrainingcallBackUrl { get; set; } diff --git a/src/Socioboard/Helpers/Payment.cs b/src/Socioboard/Helpers/Payment.cs index 59da02162..f83bd2bf1 100644 --- a/src/Socioboard/Helpers/Payment.cs +++ b/src/Socioboard/Helpers/Payment.cs @@ -5,12 +5,22 @@ using System.Net.Http; using System.Security.Cryptography; using System.Text; +using System.Threading.Tasks; using System.Web; +using Domain.Socioboard.Models; namespace Socioboard.Helpers { public class Payment { + + private readonly AppSettings _appSettings; + + public Payment(AppSettings settings) + { + _appSettings = settings; + } + public static string RecurringPaymentWithPayPal(string amount, string itemInfo, string name, string phone, string email, string currency, string paypalemail, string successUrl, string failUrl, string callBackUrl, string cancelurl, string notifyurl, string custom, string PaypalURL) { string redirecturl = ""; @@ -533,6 +543,268 @@ public static string PaypalRecurringPayment(string amount, string itemInfo, stri } + public async Task PaypalExpressPayment(string amount, string currency, string description, string email, long userId, string invoiceNumber) + { + var redirectUrl = string.Empty; + + + try + { + var parameters = new List>{ + new KeyValuePair("METHOD", "SetExpressCheckout"), + new KeyValuePair("VERSION", "204.0"), + new KeyValuePair("USER", _appSettings.PaypalApiUsername), + new KeyValuePair("PWD", _appSettings.PaypalApiPassword), + new KeyValuePair("SIGNATURE", _appSettings.PaypalApiSignature), + new KeyValuePair("PAYMENTREQUEST_0_AMT", amount), + new KeyValuePair("L_BILLINGTYPE0","RecurringPayments"), + new KeyValuePair("L_BILLINGAGREEMENTDESCRIPTION0","SocioboardMembership"), + new KeyValuePair("returnUrl", _appSettings.PaypalSuccessUrl), + new KeyValuePair("cancelUrl", _appSettings.failUrl), + }; + + var response = await WebApiReq.PostReq("", parameters, "", "", _appSettings.PaypalExpressUrl); + + if (response.IsSuccessStatusCode) + { + try + { + var data = await response.Content.ReadAsStringAsync(); + var token = Uri.UnescapeDataString(Utils.GetBetween(data, "TOKEN=", "&")); + + redirectUrl = $"{_appSettings.PaypalRedirectUrl}?cmd=_express-checkout&token={token}"; + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + return redirectUrl; + } + + public async Task GetPayPalPayerId(string token) + { + var payerId = string.Empty; + try + { + var parameters = new List>{ + new KeyValuePair("METHOD", "GetExpressCheckoutDetails"), + new KeyValuePair("VERSION", "204.0"), + new KeyValuePair("TOKEN", HttpUtility.UrlEncode(token)), + new KeyValuePair("USER", _appSettings.PaypalApiUsername), + new KeyValuePair("PWD", _appSettings.PaypalApiPassword), + new KeyValuePair("SIGNATURE", _appSettings.PaypalApiSignature), + }; + + var response = await WebApiReq.PostReq("", parameters, "", "", _appSettings.PaypalExpressUrl); + + if (response.IsSuccessStatusCode) + { + try + { + var data = await response.Content.ReadAsStringAsync(); + payerId = Uri.UnescapeDataString(Utils.GetBetween(data, "PAYERID=", "&")); + } + catch (Exception e) + { + Console.WriteLine(e); + } + } + } + catch (Exception e) + { + Console.WriteLine(e); + } + + return payerId; + } + + public async Task PaypalInitialPayment(string token, string payerId, string description, string amount) + { + var responseData = string.Empty; + try + { + var parameters = new List>{ + new KeyValuePair("METHOD", "DoExpressCheckoutPayment"), + new KeyValuePair("VERSION", "204.0"), + new KeyValuePair("USER", _appSettings.PaypalApiUsername), + new KeyValuePair("PWD", _appSettings.PaypalApiPassword), + new KeyValuePair("SIGNATURE", _appSettings.PaypalApiSignature), + new KeyValuePair("TOKEN",token), + new KeyValuePair("PAYERID",payerId), + new KeyValuePair("PAYMENTREQUEST_0_PAYMENTACTION", "Sale"), + new KeyValuePair("PAYMENTREQUEST_0_AMT", amount), + new KeyValuePair("PAYMENTREQUEST_0_CURRENCYCODE", "USD"), + new KeyValuePair("PAYMENTREQUEST_0_DESC", "Initial Payment") + }; + var response = await WebApiReq.PostReq("", parameters, "", "", _appSettings.PaypalExpressUrl); + + if (response.IsSuccessStatusCode) + { + try + { + responseData = await response.Content.ReadAsStringAsync(); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + return responseData; + } + + public async Task PaypalRecurringCreation(string token, string payerId, string description, string amount) + { + var recurringResponse = string.Empty; + try + { + var parameters = new List>{ + new KeyValuePair("METHOD", "CreateRecurringPaymentsProfile"), + new KeyValuePair("VERSION", "204.0"), + new KeyValuePair("USER", _appSettings.PaypalApiUsername), + new KeyValuePair("PWD", _appSettings.PaypalApiPassword), + new KeyValuePair("SIGNATURE", _appSettings.PaypalApiSignature), + new KeyValuePair("TOKEN",token), + new KeyValuePair("PAYERID",payerId), + new KeyValuePair("PROFILESTARTDATE", $"{DateTime.UtcNow.AddMonths(1):yyyy-MM-ddTHH:mm:ss.FFFZ}"), + new KeyValuePair("DESC", "SocioboardMembership"), + new KeyValuePair("BILLINGPERIOD", "Month"), + new KeyValuePair("BILLINGFREQUENCY","1"), + new KeyValuePair("AMT", amount), + new KeyValuePair("CURRENCYCODE", "USD"), + new KeyValuePair("COUNTRYCODE","US"), + new KeyValuePair("MAXFAILEDPAYMENTS","3") + }; + var response = await WebApiReq.PostReq("", parameters, "", "", _appSettings.PaypalExpressUrl); + + if (response.IsSuccessStatusCode) + { + try + { + recurringResponse = await response.Content.ReadAsStringAsync(); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + return recurringResponse; + } + + public async Task GetRecurringProfileDetails(string profileId) + { + var responseData = string.Empty; + + try + { + var parameters = new List>{ + new KeyValuePair("METHOD", "GetRecurringPaymentsProfileDetails"), + new KeyValuePair("VERSION", "204.0"), + new KeyValuePair("USER", _appSettings.PaypalApiUsername), + new KeyValuePair("PWD", _appSettings.PaypalApiPassword), + new KeyValuePair("SIGNATURE", _appSettings.PaypalApiSignature), + new KeyValuePair("PROFILEID", profileId), + }; + var response = await WebApiReq.PostReq("", parameters, "", "", _appSettings.PaypalExpressUrl); + + if (response.IsSuccessStatusCode) + { + try + { + responseData = await response.Content.ReadAsStringAsync(); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + + return responseData; + } + + public async Task CancelRecurring(string userId = null, string profileId = null) + { + var responseData = string.Empty; + + try + { + var parameters = new List>{ + new KeyValuePair("METHOD", "ManageRecurringPaymentsProfileStatus"), + new KeyValuePair("VERSION", "204.0"), + new KeyValuePair("USER", _appSettings.PaypalApiUsername), + new KeyValuePair("PWD", _appSettings.PaypalApiPassword), + new KeyValuePair("SIGNATURE", _appSettings.PaypalApiSignature), + new KeyValuePair("ACTION","Cancel") + }; + + + if (!string.IsNullOrEmpty(userId)) + { + var paymentResponse = await WebApiReq.GetReq($"/api/PaymentTransaction/GetUserPaymentProfiles?id={userId}", "", "", _appSettings.ApiDomain); + if (paymentResponse.IsSuccessStatusCode) + { + var payments = await paymentResponse.Content.ReadAsAsync(); + profileId = payments.paymentId; + } + } + + if (!string.IsNullOrEmpty(profileId)) + { + parameters.Add(new KeyValuePair("PROFILEID", profileId)); + + var response = await WebApiReq.PostReq("", parameters, "", "", _appSettings.PaypalExpressUrl); + + if (response.IsSuccessStatusCode) + { + try + { + responseData = await response.Content.ReadAsStringAsync(); + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + } + } + } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } + + return responseData; + + } } } \ No newline at end of file diff --git a/src/Socioboard/appsettings.json b/src/Socioboard/appsettings.json index 443712f81..843997d03 100644 --- a/src/Socioboard/appsettings.json +++ b/src/Socioboard/appsettings.json @@ -60,6 +60,21 @@ "paypalemail": "", "PaypalPdtToken": "", + + "PaypalSuccessUrl": "http://localhost:9821/Payment/PaypalExpressSuccess", + "PaypalApiUsername": "any_merchent_account", + "PaypalApiPassword": "password", + "PaypalApiSignature": "signature", + + // Sandbox: https://api-3t.sandbox.paypal.com/nvp + // Live: https://api-3t.paypal.com/nvp + "PaypalExpressUrl": "https://api-3t.sandbox.paypal.com/nvp", + + + // Sandbox: https://www.sandbox.paypal.com/cgi-bin/webscr + // Live: https://www.paypal.com/cgi-bin/webscr + "PaypalRedirectUrl": "https://www.sandbox.paypal.com/cgi-bin/webscr", + "PayUMoneyURL": "https://secure.payu.in/", "PayuMoneyemail": "", "payurl": "https://www.payumoney.com",