通过Ajax将数据POST到Yandex支付网关


POST data via Ajax to a Yandex Payment Gateway

我有一个这样发布的表单;

<form action="https://money.yandex.ru/eshop.xml" method="post">
    <input name="shopId" value="1234" type="hidden"/>
    <input name="scid" value="4321" type="hidden"/>
    <input name="sum" value="100.50" type="hidden">
    <input name="customerNumber" value="abc000" type="hidden"/>
    <input name="shopArticleId" value="567890" type="hidden"/>
    <input name="paymentType" value="AC" type="hidden"/>
    <input name="orderNumber" value="abc1111111" type="hidden"/>
    <input name="cps_phone" value="79110000000" type="hidden"/>
    <input name="cps_email" value="user@domain.com" type="hidden"/>
  <input type="submit" value="Pay"/>
</form>

这是Yandex文档中的一个示例。但我自己的形式看起来会很相似。我的问题是,我如何测试sum(金额)与项目的总成本相同?

对于其他支付网关,我已经使用ajax实现了这一点。因此,首先向我的数据库提交一个查询,然后重定向(尽管这个词可能不正确)到支付网关。然后当响应返回时,我可以将其与数据库中的记录进行比较。

但这在这里是如何运作的呢?他们的网关似乎没有考虑到这种令牌处理。

忘记了网关的细节,是否可以只使用ajax"发布"数据?

更新

用这个怎么样?

$.ajax({ 
        method: 'POST',
        url: 'https://money.yandex.ru/eshop.xml',
        data: {
            shopId: shopId,
            scid: scid,
            etc: etc
        }
    }

是。仅仅通过AJAX发布数据是可能的。这里有一个基本的例子。

<form id="exampleForm">
    <input name="name" value="A random name" />
    <input type="submit" value="Post through AJAX">
</form>
<script>
    $( "#exampleForm" ).submit(function( event ) {
      // Stop default form submit
      event.preventDefault();
      //Serialize the form data
      var formData = $(this).serializeArray();
      // Send the data using post
      var posting = $.post( 'HERE THE DESTINATION URL OF THE POST', formData, function(responseData
      {
        //An action when the POST request is done
      }));
    });
</script>

不要忘记包含JQuery库

更新对于交叉浏览AJAX请求,您需要使用dataType"jsonp"。根据您的样品要求,您可以尝试以下方法:

$.ajax({
    url: 'https://money.yandex.ru/eshop.xml',
    data: {
        shopId: shopId,
        scid: scid,
        etc: etc
    },
    type: 'POST',
    dataType: 'jsonp',
    success: function() 
    { 
        alert('Success callback'); 
    },
    error: function() 
    { 
        alert('Error callback'); 
    }
});