Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get response from IPN cryptocurrencies

We're trying to receive payment with cryptocurrencies using coinpayment IPN. We are able to create a request and able to do a payment. However, not able to get success or failure response while user come back to the seller side.

Here is how payment request created:

public ActionResult IPN()
{                        

    var uri = new UriBuilder("https://www.coinpayments.net/index.php");
    uri.SetQueryParam("cmd", "_pay_auto"); 
    uri.SetQueryParam("merchant", "merchant_key");
    uri.SetQueryParam("allow_extra", "0");
    uri.SetQueryParam("currency", "USD"); 
    uri.SetQueryParam("reset", "1");
    uri.SetQueryParam("success_url", "http://localhost:49725/home/SuccessResponse"); //todo: redirect to confirm success page
    uri.SetQueryParam("key", "wc_order_5b7b84b91a882");
    uri.SetQueryParam("cancel_url", "http://localhost:49725/home/FailiureResponse");
    uri.SetQueryParam("order_id", "36");
    uri.SetQueryParam("invoice", "PREFIX-36");
    uri.SetQueryParam("ipn_url", "http://localhost:49725/?wc-api=WC_Gateway_Coinpayments");
    uri.SetQueryParam("first_name", "John");
    uri.SetQueryParam("last_name", "Smith");
    uri.SetQueryParam("email", "[email protected]");
    uri.SetQueryParam("want_shipping", "1");
    uri.SetQueryParam("address1", "228 Park Ave S&address2");
    uri.SetQueryParam("city", "New York");
    uri.SetQueryParam("state", "NY");
    uri.SetQueryParam("zip", "10003-1502");
    uri.SetQueryParam("country", "US");
    uri.SetQueryParam("item_name", "Order 33");
    uri.SetQueryParam("quantity", "1");
    uri.SetQueryParam("amountf", "100.00000000");
    uri.SetQueryParam("shippingf", "0.00000000");            

    return Redirect(uri.ToString());
} 

This will be redirected to the coinpayment site, once payment done, it is showing the following screen.

enter image description here

And trying to get data when user click on back to seller's site, I have tried to get data using Request.Form, but not getting any value in form.

The same thing, working with this woocommerce code, but I have no idea of PHP and how they are dealing with it.

Any thought to get IPN response?

Note: there is no development documentation or sample code available for IPN in .NET

Edit I'm trying to get value from IPN success

Public ActionResult SuccessResponse()
{
    var ipn_version = Request.Form["ipn_version"];
    var ipn_id = Request.Form["ipn_id"];
    var ipn_mode = Request.Form["ipn_mode"];
    var merchant = Request.Form["merchant"];
    var txn_id = Request.Form["txn_id"];
    var status = Request.Form["status"];

    return Content(status);
}
like image 399
Hina Khuman Avatar asked Sep 02 '18 17:09

Hina Khuman


People also ask

What is IPN Crypto?

Instant payment notification (IPN) is a method for online retailers to automatically track purchases and other server-to-server communication in real time. This allows E-commerce systems the opportunity to store payment transactions, order information and other sales internally.

How do I send LTCT?

Copy the LTCT payment address and the make a note of the amount of LTCT to complete the payment. Login to your email account and click the verification link in the withdraw request email from CoinPayments. Alternatively, you can use the CoinPayments App to scan the QR code and send the LTCT payment.


2 Answers

As updated answer stated by @Gillsoft AB, you should need to use valid IPN URL from the code end. Also webhook would not work with localhost. thus, you should listen the request with live server.

Simplest way to check webhook response is to use online tool such as Webhook Tester, it will provide an URL which you have to set as your IPN URL, whenever server will sends the data, you can simply see it to the web. To check that, create one URL and set as your IPN URL as below:

 uri.SetQueryParam("ipn_url", "https://webhook.site/#/457f5c55-c9ce-4db4-8f57-20194c17d0ae");

After that run the payment cycle from local machine, payment server will sends notification to that IPN URL.

Make sure you understood it right! success_url and cancel_url are for user redirection, you will not get any response code over there, inspection of seller's store URL give your exact same URL that you have been passing though, so it is recommended to use unique URLs for each order(i.e add order id at last to the URL) which will give you an idea which order payment has been done or canceled.

http://localhost:49725/home/SuccessResponse?orderid=123

In order to test your local code, add following changes and deployed it to server.

1) Add one new method which will listen IPN response

[ValidateInput(false)]
public ActionResult IPNHandler()
{
    byte[] param = Request.BinaryRead(Request.ContentLength);
    string strRequest = Encoding.ASCII.GetString(param);

    //TODO: print string request 

    //nothing should be rendered to visitor
    return Content(""); 
} 

2) Pass IPN URL while creating a request:

public ActionResult IPN()
{                        
    var uri = new UriBuilder("https://www.coinpayments.net/index.php");
    ...
    ..
    uri.SetQueryParam("success_url", "http://localhost:49725/home/SuccessResponse"); 
    uri.SetQueryParam("cancel_url", "http://localhost:49725/home/FailiureResponse");    
    uri.SetQueryParam("ipn_url", "http://localhost:49725/home/IPNHandler");
    ....
    ..
    return Redirect(uri.ToString());
}

You will get all status code responses in IPNHandler method.

Hope this helps!

like image 159
Divyang Desai Avatar answered Oct 13 '22 13:10

Divyang Desai


You cannot use localhost for a IPN callback. You must use a public domain name.

As an example I would change the following parameters:

var uri = new UriBuilder("https://www.coinpayments.net/api.php"); 
uri.SetQueryParam("success_url", "http://kugugshivom-001-site1.atempurl.com/Home/SuccessResponse");
uri.SetQueryParam("cancel_url", "http://kugugshivom-001-site1.atempurl.com/Home/FailiureResponse");
uri.SetQueryParam("ipn_url", "http://kugugshivom-001-site1.atempurl.com/Home/CoinPaymentsIPN"); // Public ActionResult CoinPaymentsIPN()

Since you are creating your own gateway you also need to implement it properly as described in the documentation at CoinPayments API and Instant Payment Notifications (IPN).

I have tested your success_url endpoint, and got status code: 100 (when entering status:100). I see you use form-data, but I don't know if that's on purpose / required.

Postman POST http://kugugshivom-001-site1.atempurl.com/Home/SuccessResponse In Body tab form-data is selected with Bulk Edit values:

ipn_version:1.0
ipn_type:api
ipn_mode:hmac
ipn_id:your_ipn_id
merchant:your_merchant_id
txn_id:your_transaction_id
status:100
like image 27
Gillsoft AB Avatar answered Oct 13 '22 12:10

Gillsoft AB