coinpayment api in mvc - asp.net-mvc

I am in beginner programming. I want to get some coins on my site through https://www.coinpayments.net/
I found a class library on that site to call API for transactions
And a form tag to post values
Now I'm confused which one should I use?
<form action="https://www.coinpayments.net/index.php" method="post">
<input type="hidden" name="cmd" value="_pay">
<input type="hidden" name="reset" value="1">
<input type="hidden" name="merchant" value="606a89bb575311badf510a4a8b79a45e">
<input type="hidden" name="currency" value="LTC">
<input type="hidden" name="amountf" value="10.00">
<input type="hidden" name="item_name" value="Test Item">
<input type="image" src="https://www.coinpayments.net/images/pub/buynow-grey.png" alt="Buy Now with CoinPayments.net">
Has anyone experienced the launch of coinpayment in mvc?

You can use this code in your controller
Create a method that a return string with this code:
NameValueCollection data = new NameValueCollection();
data.Add("cmd", "_pay"); // the api method. you can found more method in www.coinpayments.net/apidoc
data.Add("merchant", "your merchant id "); // you can get it in your cp account
data.Add("currency", "USD");
data.Add("item_name", "the item name to buy");
data.Add("want_shipping", "0");
data.Add("quantity", "1");
data.Add("amount", amount);
data.Add("amountf", amount);
data.Add("item_number", "1");
data.Add("invoice", invoce nick);
data.Add("allow_extra", "0");
data.Add("reset", "1");
data.Add("email", "email#example"); // very importat to buyer in refund case
data.Add("custom", "email#example");
data.Add("first_name", "first name");
data.Add("last_name", "last name");
data.Add("ipn_url", "Your ipn url"); // you can get it in your cp account
data.Add("success_url", "https://myfxagents.com/bo/BackOffice/MakeDeposit.aspx?s=yes");
data.Add("cancel_url", "https://myfxagents.com/bo/BackOffice/MakeDeposit.aspx?s=no");
//Prepare the Posting form, Note this return a string
return PreparePOSTForm("https://www.coinpayments.net/index.php", data);
Create other method with name PreparePOSTForm with this code:
private static String PreparePOSTForm(string url, NameValueCollection data)
{
//Set a name for the form
string formID = "PostForm";
//Build the form using the specified data to be posted.
StringBuilder strForm = new StringBuilder();
strForm.Append("<form id=\"" + formID + "\" name=\"" +
formID + "\" action=\"" + url +
"\" method=\"POST\">");
foreach (string key in data)
{
strForm.Append("<input type=\"hidden\" name=\"" + key +
"\" value=\"" + data[key] + "\">");
}
strForm.Append("</form>");
//Build the JavaScript which will do the Posting operation.
StringBuilder strScript = new StringBuilder();
strScript.Append("<script language='javascript'>");
strScript.Append("var v" + formID + " = document." +
formID + ";");
strScript.Append("v" + formID + ".submit();");
strScript.Append("</script>");
//Return the form and the script concatenated.
//(The order is important, Form then JavaScript)
return strForm.ToString() + strScript.ToString();
}
next run your application in that method.
I hope i've helped.

Related

Passing Razor MVC Form to Controller

I have a table in which each row has a jQuery datepicker in the last cell. Along with a submit button labeled 'Update'. The last cell also contains the Issue.ID in a hidden textbox. I am trying to retrieve these values in my controller but I get a System.ArgumentOutOfRangeException.
Here is part of my view:
#foreach (Issue issue in Model.IssueSet.IssueList)
{
<tr class="altsec" id="#issue.RowID">
<td>#issue.Zone.ToString()</td>
<td>#issue.Station.ToString()</td>
<td>#issue.WhenOpened.Date.ToShortDateString()</td>
<td>#issue.What.ToString()</td>
<td>#issue.Why.ToString()</td>
<td>#issue.How.ToString()</td>
<td>#issue.Who.ToString()</td>
<td>
#using (Html.BeginForm()) {
<fieldset>
<input type="text" style="width: 100px; display: none" value="#issue.ID" name="stringID"/>
<input class="datepicker" type='text' style="width: 100px" id="#issue.DateID" />
<input class="updateButtons" type="submit" value="Update" /></fieldset>
}</td>
</tr>
}
My controller for POST is as follows:
[HttpPost]
public ActionResult Index(string stringID)
{
var ID = Request.Form[0].ToString();
var date = Convert.ToDateTime(Request.Form[1]);
string strSQL = "UPDATE bp_open_issues SET WhenFixed = '" + date + "' WHERE ID = '" + ID + "' ";
SqlConnection con =
new SqlConnection("Data Source=10.67.XX.XXX;Initial Catalog=XXX111; User Id=XXXXXX; Password=XXXXXX;");
SqlCommand cmd = new SqlCommand(strSQL, con);
con.Open();
cmd.ExecuteNonQuery();
TempData["msg"] = "<script>alert('Change succesfully');</script>";
return Redirect("/");
}

Send a mail in mvc 3

A question regarding send mail in mvc 3.
When I click on btnApply it should send 2 emails to abcd#gmail.com and also send an acknowledgement to (who filled email id in apply form like be 123#gmail.com)
For example:
Email1 : xyz#gamail.com
Email2 : abcd#gmail.com
Email3 : email entered in apply form, e.g 123#gmail.com
when a Email3 click apply send mail from Email1(Sender) to Email2(receiver) & Email3(receiver)
or
when a Email3 click apply send mail from Email2(Sender) to Email2(receiver) & Email3(receiver)
I have form in popup:
#using (Html.BeginForm()){
Your Full Name
<input type="text" value="" id="txtname" name="txtname" required />
Your Email
<input type="email" value="" id="txtemail" name="txtemail" required />
Upload Your Resume
<input name="Upload Saved Replay" id="btnFile" type="file" />
<input type="button" id="btnApply" name="btnApply" value="Apply" />
}
I have a email manager, it only send 1 mail that from xyz#gmail.com to email id that specified in apply form (123#gmail.com )
public class EmailManager
{
private const string EmailFrom = "xyz#gmail.com";
public static void Enquiry( int JobId, string UserName, string Email, string Massage)
{
using (var client = new SmtpClient()) {
using (var message = new MailMessage(EmailFrom, Email)) {
message.Subject = "Successful";
message.Body = "<html><head><meta content=\"text/html; charset=utf-8\" /></head><body><p>Dear " + UserName +
", </p> <p>Thankyou for Registering</p>"
+ "</a></p><div>Best regards,</div><div>Nisha</div></body></html>";
message.IsBodyHtml = true;
client.EnableSsl = true;
client.Send(message);
};
};
}
}
You could use a for loop between two usings.
string[] Emails = { Email,"abcd#gmail.com", "xyz#gmail.com" }
for(var i = 0; i < 3; i++)
{
using (var message = new MailMessage(EmailFrom, Emails[i]))
{
message.Subject = "Successful";
message.Body = "<html><head><meta content=\"text/html; charset=utf-8\" /></head><body><p>Dear " + UserName +
", </p> <p>Thankyou for Registering</p>"
+ "</a></p><div>Best regards,</div><div>Nisha</div></body></html>";
message.IsBodyHtml = true;
client.EnableSsl = true;
client.Send(message);
};
}
Variable Email comes from void Enquiry, others are hard coded

Get file upload for email attachment umbraco

I am creating one simple page which has one form. Its code is like below :
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage
#using System.Net;
#using System.Net.Mail;
#{
if(IsPost)
{
//Way 1: to get attachment
var fileSavePath = "";
var uploadedFile = Request.Files[0];//Here not getting file name
var fileName = Path.GetFileName(uploadedFile.FileName);
fileSavePath = Server.MapPath("~/media/" + fileName);
uploadedFile.SaveAs(fileSavePath);
FileInfo info = new FileInfo(fileSavePath);
string[] ext = fileName.Split('.');
//Way 2 :
var a = Request["fluld"];//Getting file name only
var b = Request.Files;//Getting null here
string d = Path.GetFullPath(Request["fluld"]);
string c = string.Empty;
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("xyz#gmail.com");
mail.To.Add("xyz#gmail.com");
mail.Subject = "Test Mail";
mail.Body = "This is for testing SMTP mail from GMAIL";
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("filepath");
mail.Attachments.Add(attachment);
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("xyz#gmail.com", "******");
SmtpServer.EnableSsl = true;
//SmtpServer.Send(mail);
//MessageBox.Show("mail Send");
}
catch (Exception ex)
{
throw new Exception(ex.Message.ToString());
}
}
}
<form method="post">
<input type="file" name="fluld" id="fluld" />
<input type="submit" value="Sub"/>
</form>
I am not able to get file for email attachment with this Request.Files. Help me with this. Any thing I need to add? This code is in template of umbraco.
Thanks
Dipa
Your form needs to be a 'multipart/form-data'
<form enctype="multipart/form-data" method="post">
<input type="file" name="fluld" id="fluld" />
<input type="submit" value="Sub"/>
</form>

ASP.Net MVC 3 Dictionary Binding

Hello I have a model object defined in an MVC 3 project that has a Dictionary property as follows:
MyObj.ObjDictionary<string,string>
I have two controller methods, one which handles returning the view and another that handles the POSTed form from the view
public ActionResult Scanner(string val_1, string val_2, string val_3)
{
//Fetch sessionObj from Model
MyObj sessionObj = getSessionObj(val_1, val_2, val_3);
//At this point model.ObjDictionary<string,string> contains data
return View(sessionObj);
}
[HttpParamAction]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Scanner(MyObj model)
{
//At this point model.ObjDictionary<string,string> is null
//i.e. binding is not being properly achieved
//Validate POSTed data
}
In the View, I iterate through each key-value pair (kvp). It has to be done this way since the property is dynamic and I have no way of knowing how many dictionary values there will be.
#using (Html.BeginForm("Action", "Home"))
{
#foreach (var kvp in Model.ObjDictionary)
{
<span>#Html.Label("Scan " + #kvp.Key)</span>
<span>#Html.TextBox(kvp.Key, "", new { #style = "font-size:Medium;width:400px;" })</span>
}
<input type="submit" name="Cancel" value="Cancel" />
<input type="submit" id="Scanner" name="Scanner" value="Scanner" />
}
The goal is to provide a way for users to input data and have that data bound to the values of the specific key. My problem is that the Model.ObjDictionary is null when it gets POSTed. I'm not sure what I'm doing wrong, I read over this article, but this assumes pre-existing values in a dictionary. Is there a way the ModelBinder can bind the data, entered by a user, to a dictionary value mapped to a specific key?
The article you referenced answers your question, you simply need to provide the correct names for your controls, try:
#using (Html.BeginForm("Action", "Home")) {
var i = 0;
foreach (var kvp in Model.ObjDictionary)
{
#Html.Hidden("ObjDictionary[" + i + "].Key", kvp.Key)#kvp.Key
<span>#Html.TextBox("ObjDictionary[" + i + "].Value", kvp.Value, new { #style = "font-size:Medium;width:400px;" })</span>
i++;
<br />
}
<input type="submit" value="Submit" />
}
For dictionaries, each entry should have one field for the key and one field for the value.
#using (Html.BeginForm("Action", "Home"))
{
var index = 0;
#foreach (var kvp in Model.ObjDictionary)
{
<span>#Html.Hidden("ObjDictionary[" + index + "].Key", kvp.Key)
<span>#Html.Label("Scan " + #kvp.Key)</span>
<span>#Html.TextBox("ObjDictionary[" + index + "].Value", kvp.Value, new { #style = "font-size:Medium;width:400px;" })</span>
index++;
}
<input type="submit" name="Cancel" value="Cancel" />
<input type="submit" id="Scanner" name="Scanner" value="Scanner" />
}
By the way, I have encapsulated this functionality in an HTML helper class. You can find it and a working demonstration here: https://github.com/ErikSchierboom/aspnetmvcdictionaryserialization

Passing Record Id into view and then getting back on Form Post

MVC 3. VB.NET application.. I am trying to pass a id along to keep track of which record a file name needs to be saved in.. The problem is that the id is getting passed into the view but on post back to the controller it is being lost...I have hammered on this for hours now and I am stuck... Any Ideas??
#ModelType xxxxxxxxxxx.fileUploadVM
#Code
ViewData("Title") = "Upload Resume"
Layout = "~/Views/Shared/_Layout.vbhtml"
End Code
#Html.HiddenFor(Function(m) m.id)
<h2>Upload Resume</h2>
<p style="text-align: center">Please Upload your resume below.</p>
<ul>
<form action="UploadResume" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label> <input type="file" name="file" id="file" />
<input type="submit" name="submit" value="Submit" /></form>
</ul>
Controller functions look like this:
Function UploadResume(ByVal id As Integer) As ActionResult
Dim filevm As New fileUploadVM
filevm.id = id
Return View(filevm)
End Function
<AcceptVerbs(HttpVerbs.Post)>
Public Function UploadResume(ByVal fvm As fileUploadVM) As ActionResult
Dim _filename As String = String.Empty
For Each File As String In Request.Files
Dim hpf As HttpPostedFileBase = TryCast(Request.Files(File), HttpPostedFileBase)
If hpf.ContentLength = 0 Then
Continue For
End If
Dim savedfileName As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\CoursePropResumes\" + Path.GetFileName(hpf.FileName)
hpf.SaveAs(savedfileName)
_filename = hpf.FileName
Next
Dim e As courseproposal = db.courseproposals.Single(Function(f) f.idCourseProposal = fvm.id)
e.resume_file_Name = _filename
UpdateModel(e)
db.SaveChanges()
Return RedirectToAction("Index")
End Function
Your #Html.HiddenFor needs to be placed inside your form.

Resources