如何使用php开发neteller Direct API? [英] How to develop neteller Direct API with php?

查看:111
本文介绍了如何使用php开发neteller Direct API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在网站上使用neteller直接API,用户可以将资金转入我们的商家帐户。 API步骤是:

I am working on the neteller direct api on website, where users can transfer fund to our merchant account. The API steps are:


  1. 在网站上创建表单

  2. 要求用户填写表单

  3. 将表单提交到neteller安全网址,返回包含响应元素的XML页面

困惑下一步提交表格后做什么?当我们提交表单,我们得到xml页面,那很好,但现在该怎么办?我需要将结果显示给用户,所以在提交表单用户后,将能够看到基于XML批准值说Transaction Done或类似消息的消息。我尝试通过使用jQuery ajax POST方法,以便我可以接收响应在jQuery XML对象和所有的表单提交在后台,当请求完成时,我可以获得响应xml对象显示给用户。这不工作,因为跨域POST不工作。 (我在网上的某个地方读)那么,什么是正确的步骤,以向用户提供最佳的用户体验?我们无法向用户显示此xml。所以想知道在提交表单后如何使用下一步?

I am confused about what to do next after submitting the form? When we submit the form we get xml page, that's fine but now what to do? I need to show the result back to the user so after submitting the form user would be able to see a message that saying "Transaction Done" or something similar message based upon the XML approval value. I tried by using jQuery ajax POST method so that I can receive response in jQuery XML object and all the form submission goes in background and when request completed I can get the response xml object to show to the user. This is not working because of cross domain POST does not work. (I read somewhere on net) So what will be the correct steps to provide optimal user experience to users? We cannot show this xml to users. So want to know how to work with next step after submitting the form?

表单示例:

<form method="post" action="https://api.neteller.com/netdirect">
<input type="text" name="version" value=" 4.1">
<input type="text" name="amount" size="10" value="0.02" maxlength="10">
<input type="text" name="currency" value="USD" size="10" maxlength="3">
<input type="text" name="net_account" size="20" maxlength="100">
<input type="text" name="secure_id" size="10" maxlength="6">
<input type="hidden" name="merchant_id" value="">
<input type="hidden" name="merch_key" value="">
<input type="hidden" name="merch_transid" value="" maxlength="50">
<input type="hidden" name="language_code" value="EN">
<input type="hidden" name="merch_name" value="">
<input type="hidden" name="merch_account" value="" maxlength="50">
<input type="hidden" name="custom_1" value="test123" maxlength="50">
<input type="hidden" name="custom_2" value="test123" maxlength="50">
<input type="hidden" name="custom_3" value="test123" maxlength="50">
<button type="submit" name="submit">Make Transfer</button>

这样做? AJAX或CURL或如何?

Could anyone please help on how to get this done? AJAX or CURL or how?

推荐答案

我能够通过CURL完成。我使用curl方法发布到url并获得结果在xml中,然后通过php方法解析simplexml_load_string()

I was able to get this done via CURL. I have used curl method to post to the url and getting result in xml which later parsed by the php method simplexml_load_string()

// open curl connection
$ch = curl_init('https://api.neteller.com/netdirect');

// get the vars from POST request and add them as POST fields
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
    'version' => $_POST['version'],
    'amount' => urlencode($_POST['amount']),
    'currency' => $_POST['currency'],
    'net_account' => urlencode($_POST['net_account']),
    'secure_id' => urlencode($_POST['secure_id']),
    'merchant_id' => urlencode($_POST['merchant_id']),
    'merch_key' => urlencode($_POST['merch_key']),
    'merch_transid' => urlencode($_POST['merch_transid']),
    'language_code' => $_POST['language_code'],
    'merch_name' => urlencode($_POST['merch_name']),
    'merch_account' => urlencode($_POST['merch_account']),
    'custom_1' => urlencode($_POST['custom_1']),
    'custom_2' => urlencode($_POST['custom_2']),
    'custom_3' => urlencode($_POST['custom_3']), 
    'button' => 'Make Transfer'
]));

// set other curl options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);

// execute post
$output = curl_exec($ch);
$info = curl_getinfo($ch);
$error = '';
$approval = '';

// check if curl request processed or not
if(($output == false) or ($output == '')) {
    $curlerror = curl_error($ch); 
    $error = 'Server Error. ';

} else {
    $response = simplexml_load_string($output); 
    $approval = $response->approval;
}

// close curl connection
curl_close($ch);

这篇关于如何使用php开发neteller Direct API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆