代码之家  ›  专栏  ›  技术社区  ›  Hina Khuman Santosh Pillai

如何获得IPN加密货币的响应

  •  12
  • Hina Khuman Santosh Pillai  · 技术社区  · 7 年前

    以下是如何创建付款请求:

    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", "a@a.com");
        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());
    } 
    

    enter image description here

    当用户点击返回卖家的站点时,我试图获取数据 Request.Form ,但没有得到任何形式上的价值。

    this woocommerce code ,但我不知道PHP以及他们是如何处理它的。

    编辑

    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);
    }
    
    2 回复  |  直到 5 年前
        1
  •  5
  •   Divyang Desai Jonny B'Good    7 年前

    检查webhook响应的最简单方法是使用诸如 Webhook Tester ,它将提供一个URL,您必须将其设置为您的IPN URL,每当服务器发送数据时,您只需在web上看到即可。要检查这一点,请创建一个URL并设置为您的IPN URL,如下所示:

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

    在从本地机器运行支付周期之后,支付服务器将向该IPN URL发送通知。

    确保你理解正确! success_url cancel_url 对于用户重定向,您将不会得到任何响应代码在那里,检查 seller's store URL提供与您传递的URL完全相同的URL,因此建议为每个订单使用唯一的URL(即在URL中最后添加订单id),这将使您了解哪些订单付款已完成或取消。

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

    1) 添加一个新方法来监听IPN响应

    [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(""); 
    } 
    

    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());
    }
    

    IPNHandler 方法。

        2
  •  7
  •   Gillsoft AB    7 年前

    不能将localhost用于IPN回调。您必须使用公共域名。

    例如,我将更改以下参数:

    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()
    

    由于您正在创建自己的网关,因此还需要按照上的文档中所述正确实现它 CoinPayments API Instant Payment Notifications (IPN) .

    我已经测试了你的 状态代码:100 (进入时)状态:100). 我看到您使用表单数据,但我不知道这是否是故意的/必需的。

    岗位 http://kugugshivom-001-site1.atempurl.com/Home/SuccessResponse 身体 选项卡窗体数据是用 批量编辑

    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