-1

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?

wowkin2
  • 5,895
  • 5
  • 23
  • 66

1 Answers1

-1

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.

Jun De Leon
  • 331
  • 3
  • 11