gpt4 book ai didi

java - 在 android 中实现 authorize.net

转载 作者:太空狗 更新时间:2023-10-29 14:34:43 28 4
gpt4 key购买 nike

我想开发一个通过 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=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="\n"+ iter.next() +"&nbsp";
tv.setText(result);
//out.println("<LI>" + iter.next() + "&nbsp;</LI>");
}

setContentView(tv);
} catch(Exception e) {
tv.setText(e.getMessage());
setContentView(tv);
}

谁能帮帮我?

通过 setContentView 我正在显示我的拆分结果,但我只得到未知错误异常。没有显示其他描述。是我的方法不对还是有其他方法可以实现支付处理?

最佳答案

感谢您的代码 :) 我从您的代码中得到了在 android 中实现 authorize.net 的新想法 我不知道您遇到了什么错误但是当我尝试使用 post url 进行集成时我遇到了一个错误并且我添加了“x_market_type"在我的代码中,我得到了结果

 post_values.put ("x_market_type", "2");
我还集成了 authorize.net 提供的示例代码,但对于我的自定义要求,您的代码对我有很大帮助。

如果您需要任何帮助而不是发表评论。 :)

关于java - 在 android 中实现 authorize.net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2310375/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com