Android integration
To simplify integrating see the following JAVA sample code.
MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void creditCardPaymentRequest() {
new CreditCardPaymentTask().execute();
}
public void idealPaymentRequest() {
new IdealPaymentTask().execute();
}
public void bankTransferRequest() {
new BankTransferTask().execute();
}
public void orderStatusRequest(String orderID) {
new OrderStatusTask(orderID).execute();
}
}
OrderStatusTask.java
public class OrderStatusTask extends AsyncTask<Void, Void, Void> {
private String orderID;
public OrderStatusTask(String orderID) {
this.orderID = orderID;
}
@Override
protected Void doInBackground(Void... voids) {
URL url = null;
try {
url = new URL("<apiURL>/v1/orders/" + orderID + "/");
} catch (MalformedURLException e) {
e.printStackTrace();
}
HttpURLConnection connection = null;
try {
connection = (HttpURLConnection) url.openConnection();
} catch (IOException e) {
e.printStackTrace();
}
try {
connection.setRequestMethod("GET");
} catch (ProtocolException e) {
e.printStackTrace();
}
String userName = "<apiKey>"; //API key as provided to you
String password = ""; //should remain empty
String usernamePassword = userName + ":" + password;
String basicAuthPayload = "Basic " + Base64.getEncoder().encodeToString(usernamePassword.getBytes());
connection.addRequestProperty("Authorization", basicAuthPayload);
try {
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
// Handle response
} else {
// Handle error
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
BankTransferTask.java
public class BankTransferTask extends AsyncTask<Void, Void, Void> {
public BankTransferTask() {}
@Override
protected Void doInBackground(Void... voids) {
URL url = null;
try {
url = new URL("<apiURL>/v1/orders/");
} catch (MalformedURLException e) {
e.printStackTrace();
}
HttpURLConnection connection = null;
try {
connection = (HttpURLConnection) url.openConnection();
} catch (IOException e) {
e.printStackTrace();
}
try {
connection.setRequestMethod("POST");
} catch (ProtocolException e) {
e.printStackTrace();
}
connection.setDoOutput(true);
connection.setDoInput(true);
String userName = "<apiKey>"; //API key as provided to you
String password = ""; //should remain empty
String usernamePassword = userName + ":" + password;
String basicAuthPayload = "Basic " + Base64.getEncoder().encodeToString(usernamePassword.getBytes());
connection.addRequestProperty("Authorization", basicAuthPayload);
connection.setRequestProperty("Content-Type", "application/json");
JSONObject transaction = new JSONObject();
try {
transaction.put("payment_method", "bank-transfer");
} catch (JSONException e) {
e.printStackTrace();
}
JSONArray transactions = new JSONArray();
transactions.put(transaction);
JSONObject root = new JSONObject();
try {
root.put("currency", "EUR");
root.put("amount", 10);
root.put("merchant_order_id", "EXAMPLE001");
root.put("description", "Exampe bank transfer order");
root.put("return_url", "http://www.example.com/");
root.put("transactions", transactions);
} catch (JSONException e) {
e.printStackTrace();
}
OutputStream outputStream;
try {
outputStream = connection.getOutputStream();
outputStream.write(root.toString().getBytes("UTF-8"));
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_CREATED) {
// Handle response
} else {
// Handle error
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
CreditCardPaymentTask.java
public class CreditCardPaymentTask extends AsyncTask<Void, Void, Void> {
public CreditCardPaymentTask() {}
@Override
protected Void doInBackground(Void... voids) {
URL url = null;
try {
url = new URL("<apiURL>/v1/orders/");
} catch (MalformedURLException e) {
e.printStackTrace();
}
HttpURLConnection connection = null;
try {
connection = (HttpURLConnection) url.openConnection();
} catch (IOException e) {
e.printStackTrace();
}
try {
connection.setRequestMethod("POST");
} catch (ProtocolException e) {
e.printStackTrace();
}
connection.setDoOutput(true);
connection.setDoInput(true);
String userName = "<apiKey>"; //API key as provided to you
String password = ""; //should remain empty
String usernamePassword = userName + ":" + password;
String basicAuthPayload = "Basic " + Base64.getEncoder().encodeToString(usernamePassword.getBytes());
connection.addRequestProperty("Authorization", basicAuthPayload);
connection.setRequestProperty("Content-Type", "application/json");
JSONObject transaction = new JSONObject();
try {
transaction.put("payment_method", "credit-card");
} catch (JSONException e) {
e.printStackTrace();
}
JSONArray transactions = new JSONArray();
transactions.put(transaction);
JSONObject root = new JSONObject();
try {
root.put("currency", "EUR");
root.put("amount", 10);
root.put("merchant_order_id", "EXAMPLE002");
root.put("description", "Example credit card order");
root.put("return_url", "http://www.example.com/");
root.put("transactions", transactions);
} catch (JSONException e) {
e.printStackTrace();
}
OutputStream outputStream;
try {
outputStream = connection.getOutputStream();
outputStream.write(root.toString().getBytes("UTF-8"));
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_CREATED) {
// Handle response
} else {
// Handle error
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
IdealPaymentTask.java
public class IdealPaymentTask extends AsyncTask<Void, Void, Void> {
public IdealPaymentTask() {}
@Override
protected Void doInBackground(Void... voids) {
URL url = null;
try {
url = new URL("<apiURL>/v1/orders/");
} catch (MalformedURLException e) {
e.printStackTrace();
}
HttpURLConnection connection = null;
try {
connection = (HttpURLConnection) url.openConnection();
} catch (IOException e) {
e.printStackTrace();
}
try {
connection.setRequestMethod("POST");
} catch (ProtocolException e) {
e.printStackTrace();
}
connection.setDoOutput(true);
connection.setDoInput(true);
String userName = "<apiKey>"; //API key as provided to you
String password = ""; //should remain empty
String usernamePassword = userName + ":" + password;
String basicAuthPayload = "Basic " + Base64.getEncoder().encodeToString(usernamePassword.getBytes());
connection.addRequestProperty("Authorization", basicAuthPayload);
connection.setRequestProperty("Content-Type", "application/json");
JSONObject transaction = new JSONObject();
try {
transaction.put("payment_method", "ideal");
transaction.put("issuer_id", "INGBNL2A");
} catch (JSONException e) {
e.printStackTrace();
}
JSONArray transactions = new JSONArray();
transactions.put(transaction);
JSONObject root = new JSONObject();
try {
root.put("currency", "EUR");
root.put("amount", 10);
root.put("merchant_order_id", "EXAMPLE002");
root.put("description", "Example iDEAL order");
root.put("return_url", "http://www.example.com/");
root.put("transactions", transactions);
} catch (JSONException e) {
e.printStackTrace();
}
OutputStream outputStream;
try {
outputStream = connection.getOutputStream();
outputStream.write(root.toString().getBytes("UTF-8"));
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_CREATED) {
// Handle response
} else {
// Handle error
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}