public async Task <ActionResult> PaymentSuccessReturnUrl(IPNModel ipnModel) { PDTRequestModel model = new PDTRequestModel(pdtToken, ipnModel.TransactionId, ipnModel.MerchantOrderId); model.UseSandbox = checkoutoptions.UseSandbox; var pdtResponse = await CheckoutHelper.RequestPDT(model); if (pdtResponse.Count() > 0) { if (pdtResponse["Status"] == "Paid") { //This means the payment is completed. //You can extract more information of the transaction from the pdtResponse dictionary //You can now mark the order as "Paid" or "Completed" here and start the delivery process } } else { //This means the pdt request has failed. //possible reasons are //1. the TransactionId is not valid //2. the PDT_Key is incorrect } //return RedirectToAction("DepositToWallet", _wallet); return(null); }
private static void Mail(int paymentId, IPNModel callback, string box_status) { const string host = ""; const string fromEmail = ""; const string fromPassword = ""; const string toEmail = ""; if (host == "" || fromEmail == "" || fromPassword == "" || toEmail == "") { throw new ArgumentException("Please initialise smtp server for email."); } var fromAddress = new MailAddress(fromEmail, "From Test Payment Server"); var toAddress = new MailAddress(toEmail, "To You"); if (callback.err == null) { callback.err = ""; } string details = Json.Encode(callback); Regex reg = new Regex(@"\\/Date\(\d+\)\\/"); details = reg.Replace(details, callback.date.ToString("dd MMMM yyyy"), 1); details = reg.Replace(details, callback.datetime.ToString("yyyy-MM-dd HH:mm:ss")); const string subject = "Subject"; string body = "Payment - " + paymentId + " - " + box_status + "\nDetails:\n" + details; var smtp = new SmtpClient { Host = host, Port = 25, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromAddress.Address, fromPassword), Timeout = 10000 }; using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body }) { smtp.Send(message); } }
public async Task <string> IPNDestination(IPNModel ipnModel) { var result = string.Empty; ipnModel.UseSandbox = checkoutoptions.UseSandbox; if (ipnModel != null) { var isIPNValid = await CheckIPN(ipnModel); if (isIPNValid) { //This means the payment is completed //You can now mark the order as "Paid" or "Completed" here and start the delivery process } } return(result); }
public async Task <string> PaymentCancelReturnUrl(IPNModel ipnModel) { PDTRequestModel model = new PDTRequestModel(pdtToken, ipnModel.TransactionId, ipnModel.MerchantOrderId); var pdtResponse = await CheckoutHelper.RequestPDT(model); if (pdtResponse.Count() > 0) { if (pdtResponse["Status"] == "Canceled") { //This means the payment is canceled. //You can extract more information of the transaction from the pdtResponse dictionary //You can now mark the order as "Canceled" here. } } else { //This means the pdt request has failed. //possible reasons are //1. the TransactionId is not valid //2. the PDT_Key is incorrect } return(string.Empty); }
async Task ProcessVerificationResponse(IPNContext ipnContext) { if (ipnContext.Verification.Equals("VERIFIED")) { var ipnModel = new IPNModel(); var pairs = ParseIPN(ipnContext.RequestBody); ipnModel.Custom = pairs["custom"]; ipnModel.ItemName = pairs["item_name"]; ipnModel.PaymentStatus = pairs["payment_status"]; if (ipnModel.PaymentStatus.Equals("Completed")) { if (ipnModel.ItemName.Equals("1Unlimited") || ipnModel.ItemName.Equals("3Unlimited") || ipnModel.ItemName.Equals("6Unlimited") || ipnModel.ItemName.Equals("12Unlimited")) { if (ipnModel.ItemName.Equals("1Unlimited")) { await AddTimeToAccount(ipnModel.Custom, 1); } if (ipnModel.ItemName.Equals("3Unlimited")) { await AddTimeToAccount(ipnModel.Custom, 3); } if (ipnModel.ItemName.Equals("6Unlimited")) { await AddTimeToAccount(ipnModel.Custom, 6); } if (ipnModel.ItemName.Equals("12Unlimited")) { await AddTimeToAccount(ipnModel.Custom, 12); } await AddRewardTimeToAccount(ipnModel.Custom, 1); } } } }
public static void Main(int paymentId, IPNModel callback, string box_status) { //PLACE YOUR CODE HERE //Mail(paymentId, callback, box_status); }
public ActionResult Callback(IPNModel callback) { bool valid_key = false; if (!string.IsNullOrEmpty(callback.private_key_hash) && callback.private_key_hash.Length == 128 && Regex.IsMatch(callback.private_key_hash, "[a-zA-Z0-9]+")) { string[] ss = ConfigurationManager.AppSettings["PrivateKeys"].Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); List <string> s = new List <string>(); foreach (string s1 in ss) { s.Add(Calculator.md512(s1)); } valid_key = s.Contains(callback.private_key_hash); } if (!string.IsNullOrEmpty(Request.Form["plugin_ver"]) && string.IsNullOrEmpty(callback.status) && valid_key) { return(new ContentResult() { Content = "cryptoboxver_asp_1.0" }); } if (callback.order == null) { callback.order = ""; } if (callback.user == null) { callback.user = ""; } if (callback.usercountry == null) { callback.usercountry = ""; } string box_status = "cryptobox_nochanges"; if (ModelState.IsValid) { int paymentId = 0; crypto_payments obj = Context.crypto_payments.FirstOrDefault(x => x.boxID == callback.box && x.orderID == callback.order && x.userID == callback.user && x.txID == callback.tx && x.amount == callback.amount && x.addr == callback.addr); if (obj == null) { crypto_payments newPayments = new crypto_payments() { boxID = callback.box, boxType = callback.boxtype, orderID = callback.order, userID = callback.user, countryID = callback.usercountry, coinLabel = callback.coinlabel, amount = callback.amount, amountUSD = callback.amountusd, unrecognised = (byte)(callback.status == "payment_received_unrecognised" ? 1 : 0), addr = callback.addr, txID = callback.tx, txDate = callback.datetime, txConfirmed = callback.confirmed, txCheckDate = DateTime.Now, recordCreated = DateTime.Now }; try { Context.crypto_payments.Add(newPayments); Context.SaveChanges(); paymentId = newPayments.paymentID; } catch (DbEntityValidationException dbEx) { var modelErrors2 = new List <string>(); foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { modelErrors2.Add("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage); } } return(new ContentResult() { Content = String.Join(", ", modelErrors2.ToArray()) }); } obj = newPayments; box_status = "cryptobox_newrecord"; } else if (callback.confirmed == 1 && obj.txConfirmed == 0) { obj.txConfirmed = 1; obj.txCheckDate = DateTime.Now; Context.SaveChanges(); paymentId = obj.paymentID; box_status = "cryptobox_updated"; } else { paymentId = obj.paymentID; } NewPayment.Main(paymentId, callback, box_status); return(new ContentResult() { Content = box_status }); } //for test var modelErrors = new List <string>(); foreach (ModelState err in ViewData.ModelState.Values) { foreach (ModelError error in err.Errors) { modelErrors.Add(error.ErrorMessage); } } return(new ContentResult() { Content = String.Join(", ", modelErrors.ToArray()) }); }
private async Task <bool> CheckIPN(IPNModel model) { return(await CheckoutHelper.IsIPNAuthentic(model)); }