【问题标题】:Using C# to call Dwolla Off-Site Gateway / Submit Directly使用C#调用Dwolla异地网关/直接提交
【发布时间】:2013-08-05 19:31:11
【问题描述】:

我正在尝试通过“直接提交”工作流程 (https://developers.dwolla.com/dev/pages/gateway#submit-directly) 将 Dwolla 的场外网关用于我的基于 ASPX/C# 的自定义网站。

我已经能够使用他们提供的脚本成功地将 Dwolla 按钮添加到 ASPX 页面:

<script
    src="https://www.dwolla.com/scripts/button.min.js" class="dwolla_button" type="text/javascript"
    data-key="ConsumerKeyObtainedFromDwolla"
    data-redirect="RedirectPage.aspx"
    data-label="Dwolla"
    data-name="MyNameGoesHere"
    data-description="MyDescriptionGoesHere"
    data-amount="123.45"
    data-shipping="0"
    data-tax="0"
    data-guest-checkout="true"
    data-type="freetype"
    >
</script>

但是,我还需要在同一页面上包含一个 PayPal 按钮,并且不希望脚本输入标签发生冲突。我还想轻松填充变量(例如消费者密钥、时间戳和订单 ID 的 HMAC-SHA1 十六进制散列)并进行一些计算,而无需在 javascript 中这样做。所以我的目标是在页面的 C# 代码隐藏中完成这一切。

我的第一步是简单地从 PayPal 脚本中删除表单标签,并添加一个带有 PayPal 的 PostBackURL 的 ASP 按钮。这很奏效,所以我进一步从 ASPX 中完全重构了 PayPal 部分,并实现了 C# 代码以基于 PayPal 脚本的内容构建重定向 URL:

string txtRedirectURL = "";
txtRedirectURL += "https://www.paypal.com/cgi-bin/webscr?&cmd=_xclick";
txtRedirectURL += "&business=A1B2C3D4";
txtRedirectURL += "&lc=US";
...
txtRedirectURL += "&item_name=abcdefg";
txtRedirectURL += "&amount=123.45";
txtRedirectURL += "&currency_code=USD";
Response.Redirect(txtRedirectURL);

这很好用,所以我希望对 Dwolla 使用的脚本做同样的事情(如上文所述)。不幸的是,这种方法并没有被证明是成功的。我尝试的第一个选项是根据 Dwolla 脚本中的数据字段模拟 PayPal 重定向:

string txtRedirectURL = "";
txtRedirectURL += "https://www.dwolla.com/payment/pay?";
txtRedirectURL += "key=ConsumerKeyObtainedFromDwolla";
txtRedirectURL += "&label=Dwolla";
txtRedirectURL += "&name=MyNameGoesHere";
txtRedirectURL += "&description=MyDescriptionGoesHere";
txtRedirectURL += "&amount=123.45";
txtRedirectURL += "&shipping=0.00";
txtRedirectURL += "&tax=0.00";
Response.Redirect(txtRedirectURL);

这确实尝试将我导航到 Dwolla 的 https://www.dwolla.com/payment/pay 页面,但它最终将我导航到 Dwolla 的 404 页面(哭泣的蓝色考拉熊)。我还添加了以下行的各种版本,但没有取得更好的成功:

txtRedirectURL += "&signature=HMACSHA1Hash;
txtRedirectURL += "&test=true";
txtRedirectURL += "&destinationid=UserIDObtainedFromDwolla";
txtRedirectURL += "&orderid=999;
txtRedirectURL += "&timestamp=" + txtTimeStamp;
txtRedirectURL += "&allowFundingSources=true";

我的假设是:

  1. 我的 URL 中的某些内容正在抛出问题,Dwolla 的错误处理将我带到 404 页面而不是显示错误(正如我在玩按钮时看到的那样)

  2. button.min.js 脚本正在做一些我需要在我的 C# 中重新创建的时髦的事情。我已经查看了它,但无法确定缺少的步骤可能是什么。

我还尝试了一种更直接的方法来尝试从 C# 内部执行脚本:

string dwollaScript = "<script
    src="https://www.dwolla.com/scripts/button.min.js" class="dwolla_button" type="text/javascript"
    data-key="ConsumerKeyObtainedFromDwolla"
    data-redirect="RedirectPage.aspx"
    data-label="Dwolla"
    data-name="MyNameGoesHere"
    data-description="MyDescriptionGoesHere"
    data-amount="123.45"
    data-shipping="0"
    data-tax="0"
    data-guest-checkout="true"
    data-type="freetype"
    >
</script>";
System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), "123", dwollaScript.ToString(), false);

当绑定到按钮单击时,它会成功触发,但它所做的只是在我的页面回发后显示一个 Dwolla 按钮。它不像常规的 Dwolla 按钮那样将我导航到 Dwolla。

有什么想法吗?

【问题讨论】:

    标签: c# dwolla


    【解决方案1】:

    首先,重要说明:

    更好的解决方案是使用Server to Server Checkout 请求而不是直接提交,因为它不允许用户修改任何请求的参数。您只需要 POST 到端点并接收结帐 ID,您可以使用该 ID 生成结帐 URL 供用户关注。无需 JS 技巧。

    我想你可能会发现这个Dwolla C# wrapper 很有帮助。它支持两种类型的网关请求和回调处理。

    回答您的问题:

    您似乎正在尝试使用查询字符串变量中的结帐参数获取 https://www.dwolla.com/payment/pay,这不是请求结帐会话的有效方式。

    直接提交工作流程要求您创建一个表单,该表单将发布到https://www.dwolla.com/payment/pay。例如:

        <form accept-charset="UTF-8" action="https://www.dwolla.com/payment/pay" method="post">
        <input id="key" name="key" type="hidden" value="abcdefg" />
        <input id="signature" name="signature" type="hidden" value="abcd" />
        <input id="callback" name="callback" type="hidden" 
        value="http://www.mywebsite.com/callback.aspx" />
        <input id="redirect" name="redirect" type="hidden" 
        value="http://www.mywebsite.com/redirect.aspx" />
        <input id="test" name="test" type="hidden" value="true" />
        <input id="name" name="name" type="hidden" value="Purchase" />
        <input id="description" name="description" type="hidden" 
        value="Description" />
        <input id="destinationid" name="destinationid" type="hidden" 
        value="812-111-1111" />
        <input id="amount" name="amount" type="hidden" value="1.00" />
        <input id="shipping" name="shipping" type="hidden" value="0.00" />
        <input id="tax" name="tax" type="hidden" value="0.00" />
        <input id="orderid" name="orderid" type="hidden" value="188375" />
        <input id="timestamp" name="timestamp" type="hidden" 
        value="1323302400" />
    
        <button type="submit">Submit Order</button>
        </form>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-21
      • 2012-12-19
      • 1970-01-01
      • 1970-01-01
      • 2020-10-21
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多