Guest User

AUth

a guest
May 2nd, 2013
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. txtAmount=Double.parseDouble(Amount.getText().toString());
  2. txtFName = FName.getText().toString();
  3. txtLName=LName.getText().toString();
  4. txtAddress=Address.getText().toString();
  5. txtCity=City.getText().toString();
  6. txtState=State.getText().toString();
  7. txtzipcode=zipcode.getText().toString();
  8. txtEmail=Email.getText().toString();
  9. txtCreditCard=CreditCard.getText().toString();
  10. txtCVV2=CVV2.getText().toString();
  11.  
  12. drpMonth=selectedmonth;
  13. drpYear=selectedyear;
  14. date= drpMonth.concat(drpYear);
  15.  
  16. try {
  17. URL post_url = new URL("https://test.authorize.net/gateway/transact.dll");
  18.  
  19. Hashtable post_values = new Hashtable();
  20.  
  21. // the API Login ID and Transaction Key must be replaced with valid values
  22. post_values.put ("x_login", "8SX5gkJb46g");
  23. post_values.put ("x_tran_key", "8Wx295Gr4hd9Y5kd");
  24.  
  25. post_values.put ("x_version", "3.1");
  26. post_values.put ("x_delim_data", "TRUE");
  27. post_values.put ("x_delim_char", "|");
  28. post_values.put ("x_relay_response", "FALSE");
  29.  
  30. post_values.put ("x_type", "AUTH_CAPTURE");
  31. post_values.put ("x_method", "CC");
  32. post_values.put ("x_card_num", txtCreditCard);
  33. post_values.put ("x_exp_date", date);
  34.  
  35. post_values.put ("x_amount", txtAmount);
  36. post_values.put ("x_description", "Sample Transaction");
  37.  
  38. post_values.put ("x_first_name",txtFName);
  39. post_values.put ("x_last_name",txtLName);
  40. post_values.put ("x_address", txtAddress);
  41. post_values.put ("x_city", txtCity);
  42. post_values.put ("x_state",txtState);
  43. post_values.put ("x_zip", txtzipcode);
  44. post_values.put ("x_email", txtEmail);
  45. // Additional fields can be added here as outlined in the AIM integration
  46. // guide at: http://developer.authorize.net
  47.  
  48. // This section takes the input fields and converts them to the proper format
  49. // for an http post. For example: "x_login=username&x_tran_key=a1B2c3D4"
  50.  
  51. StringBuffer post_string = new StringBuffer();
  52. Enumeration keys = post_values.keys();
  53. while( keys.hasMoreElements() ) {
  54. String key = URLEncoder.encode(keys.nextElement().toString(),"UTF-8");
  55. String value = URLEncoder.encode(post_values.get(key).toString(),"UTF-8");
  56. post_string.append(key + "=" + value + "&");
  57. }
  58.  
  59. // Open a URLConnection to the specified post url
  60. URLConnection connection = post_url.openConnection();
  61. connection.setDoOutput(true);
  62. connection.setUseCaches(false);
  63.  
  64. // this line is not necessarily required but fixes a bug with some servers
  65. connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
  66.  
  67. // submit the post_string and close the connection
  68.  
  69.  
  70. DataOutputStream requestObject = new DataOutputStream(connection.getOutputStream());
  71. requestObject.write(post_string.toString().getBytes());
  72. requestObject.flush();
  73. requestObject.close();
  74.  
  75. // process and read the gateway response
  76. BufferedReader rawResponse = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  77. String line;
  78. String responseData = rawResponse.readLine();
  79. rawResponse.close(); // no more data
  80.  
  81. // split the response into an array
  82. String [] responses = responseData.split("|");
  83.  
  84. // The results are output to the screen in the form of an html numbered list.
  85.  
  86. for(Iterator iter=Arrays.asList(responses).iterator(); iter.hasNext();) {
  87. result="\n"+ iter.next() +"&nbsp";
  88. tv.setText(result);
  89. //out.println("<LI>" + iter.next() + "&nbsp;</LI>");
  90. }
  91.  
  92. setContentView(tv);
  93. } catch(Exception e) {
  94. tv.setText(e.getMessage());
  95. setContentView(tv);
  96. }
Advertisement
Add Comment
Please, Sign In to add comment