问题描述
我想开发一个通过authorize.net进行支付处理的应用程序
但每次我遇到未知错误.
首先,我填充所有文本框并在按钮单击事件上使用这些值.
我的代码是:
txtAmount=Double.parseDouble(Amount.getText().toString());txtFName = FName.getText().toString();txtLName=LName.getText().toString();txtAddress=Address.getText().toString();txtCity=City.getText().toString();txtState=State.getText().toString();txtzipcode=zipcode.getText().toString();txtEmail=Email.getText().toString();txtCreditCard=CreditCard.getText().toString();txtCVV2=CVV2.getText().toString();drpMonth=选定月份;drpYear=选定年份;日期= drpMonth.concat(drpYear);尝试 {URL post_url = new URL("https://test.authorize.net/gateway/transact.dll");哈希表 post_values = new Hashtable();//API 登录 ID 和交易密钥必须替换为有效值post_values.put ("x_login", "8SX5gkJb46g");post_values.put ("x_tran_key", "8Wx295Gr4hd9Y5kd");post_values.put ("x_version", "3.1");post_values.put ("x_delim_data", "TRUE");post_values.put("x_delim_char", "|");post_values.put ("x_relay_response", "FALSE");post_values.put ("x_type", "AUTH_CAPTURE");post_values.put("x_method", "CC");post_values.put ("x_card_num", txtCreditCard);post_values.put ("x_exp_date", 日期);post_values.put("x_amount", txtAmount);post_values.put ("x_description", "示例交易");post_values.put("x_first_name",txtFName);post_values.put ("x_last_name",txtLName);post_values.put("x_address", txtAddress);post_values.put ("x_city", txtCity);post_values.put("x_state",txtState);post_values.put ("x_zip", txtzipcode);post_values.put ("x_email", txtEmail);//可以在此处添加其他字段,如 AIM 集成中所述//指南:http://developer.authorize.net//此部分获取输入字段并将它们转换为正确的格式//对于 http 帖子.例如:x_login=username&x_tran_key=a1B2c3D4"StringBuffer post_string = new StringBuffer();枚举键 = post_values.keys();while(keys.hasMoreElements()) {String key = URLEncoder.encode(keys.nextElement().toString(),"UTF-8");String value = URLEncoder.encode(post_values.get(key).toString(),"UTF-8");post_string.append(key + "=" + value + "&");}//打开一个指向指定帖子 url 的 URLConnectionURLConnection 连接 = post_url.openConnection();connection.setDoOutput(true);connection.setUseCaches(false);//这行不是必需的,但修复了一些服务器的错误connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");//提交 post_string 并关闭连接DataOutputStream requestObject = new DataOutputStream(connection.getOutputStream());requestObject.write(post_string.toString().getBytes());requestObject.flush();requestObject.close();//处理并读取网关响应BufferedReader rawResponse = new BufferedReader(new InputStreamReader(connection.getInputStream()));字符串线;String responseData = rawResponse.readLine();rawResponse.close();//没有更多数据//将响应拆分为一个数组String [] 响应 = responseData.split("|");//结果以html编号列表的形式输出到屏幕上.for(Iterator iter=Arrays.asList(responses).iterator(); iter.hasNext();) {result="
"+ iter.next() +" ";tv.setText(结果);//out.println("<LI>" + iter.next() + " </LI>");}设置内容视图(电视);} 捕获(异常 e){tv.setText(e.getMessage());设置内容视图(电视);}
有人可以帮我吗?
通过 setContentView 我显示了我的分割结果,但我只得到了未知的错误异常.没有显示其他说明.是我的方法错误还是有其他方法来实现付款处理?
感谢您的代码 :) 我从您的代码中获得了在 android 中实现 authorize.net 的新想法我不知道您遇到了什么错误但是当我尝试使用 post url 进行集成我遇到了一个错误,我在我的代码中添加了x_market_type",我得到了结果post_values.put ("x_market_type", "2");
我还集成了 authorize.net 提供的示例代码,但对于我的自定义要求,您的代码对我有很大帮助.
如果您需要任何帮助而不是发表评论.:)
I want to develop an application which does payment processing through authorize.net
But everytime I get unknown error.
First I fill all the textboxes and use these values on a button click event.
My code is:
txtAmount=Double.parseDouble(Amount.getText().toString());
txtFName = FName.getText().toString();
txtLName=LName.getText().toString();
txtAddress=Address.getText().toString();
txtCity=City.getText().toString();
txtState=State.getText().toString();
txtzipcode=zipcode.getText().toString();
txtEmail=Email.getText().toString();
txtCreditCard=CreditCard.getText().toString();
txtCVV2=CVV2.getText().toString();
drpMonth=selectedmonth;
drpYear=selectedyear;
date= drpMonth.concat(drpYear);
try {
URL post_url = new URL("https://test.authorize.net/gateway/transact.dll");
Hashtable post_values = new Hashtable();
// the API Login ID and Transaction Key must be replaced with valid values
post_values.put ("x_login", "8SX5gkJb46g");
post_values.put ("x_tran_key", "8Wx295Gr4hd9Y5kd");
post_values.put ("x_version", "3.1");
post_values.put ("x_delim_data", "TRUE");
post_values.put ("x_delim_char", "|");
post_values.put ("x_relay_response", "FALSE");
post_values.put ("x_type", "AUTH_CAPTURE");
post_values.put ("x_method", "CC");
post_values.put ("x_card_num", txtCreditCard);
post_values.put ("x_exp_date", date);
post_values.put ("x_amount", txtAmount);
post_values.put ("x_description", "Sample Transaction");
post_values.put ("x_first_name",txtFName);
post_values.put ("x_last_name",txtLName);
post_values.put ("x_address", txtAddress);
post_values.put ("x_city", txtCity);
post_values.put ("x_state",txtState);
post_values.put ("x_zip", txtzipcode);
post_values.put ("x_email", txtEmail);
// Additional fields can be added here as outlined in the AIM integration
// guide at: http://developer.authorize.net
// This section takes the input fields and converts them to the proper format
// for an http post. For example: "x_login=username&x_tran_key=a1B2c3D4"
StringBuffer post_string = new StringBuffer();
Enumeration keys = post_values.keys();
while( keys.hasMoreElements() ) {
String key = URLEncoder.encode(keys.nextElement().toString(),"UTF-8");
String value = URLEncoder.encode(post_values.get(key).toString(),"UTF-8");
post_string.append(key + "=" + value + "&");
}
// Open a URLConnection to the specified post url
URLConnection connection = post_url.openConnection();
connection.setDoOutput(true);
connection.setUseCaches(false);
// this line is not necessarily required but fixes a bug with some servers
connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
// submit the post_string and close the connection
DataOutputStream requestObject = new DataOutputStream(connection.getOutputStream());
requestObject.write(post_string.toString().getBytes());
requestObject.flush();
requestObject.close();
// process and read the gateway response
BufferedReader rawResponse = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
String responseData = rawResponse.readLine();
rawResponse.close(); // no more data
// split the response into an array
String [] responses = responseData.split("|");
// The results are output to the screen in the form of an html numbered list.
for(Iterator iter=Arrays.asList(responses).iterator(); iter.hasNext();) {
result="
"+ iter.next() +" ";
tv.setText(result);
//out.println("<LI>" + iter.next() + " </LI>");
}
setContentView(tv);
} catch(Exception e) {
tv.setText(e.getMessage());
setContentView(tv);
}
Can anyone help me?
through setContentView I am showing my splited result and I get only unknown error exception. No other description is shown. Is my method wrong or there is any other method to implement payment processing ?
Thanks for your code :) I got new idea form your code to implement authorize.net in android I have no idea what you faced error but when I tried to use post url for integration I faced one error and I have added "x_market_type" in my code and I got the result
post_values.put ("x_market_type", "2");
I have also integrated Sample code which authorize.net provide, but for my custom requirement your code helps me lot.
If you need any help than post comment. :)
这篇关于在android中实现authorize.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!