// Este ejemplo contiene la creación de la orden y el checkout. Sin embargo, la creación de la orden la puede realizar desde el backend.
try {
//Create gpOrder, in this case order is create when globally
GreenPayProduct product = new GreenPayProduct();
product.setDescription("Telefono celular");
product.setPrice(340000.00);
product.setQuantity(1);
product.setSkuId("COD120");
product.setType("Fisico");
List<GreenPayProduct> products = new ArrayList<GreenPayProduct>();
products.add(product);
GreenPayAddress address = new GreenPayAddress("CR", "C087 Freses");
GreenPayOrderInfo gpOrderInfo = new GreenPayOrderInfo("John Doe", "jdoe@example.com", address, address, 100.00, "CRC", "My order", "Android-or-412389", products);
greenPay.createNewGreenPayOrder(gpOrderInfo, new ResponseCallback<GreenPayOrderResult>() {
@Override
public void onSuccess(GreenPayOrderResult response) {
Log.d("GreenPayTestApp", "Create Order Response from Activity: " + response.getSecurityInfo().getSession() + ", " + response.getSecurityInfo().getToken());
try {
// 6. Create a GreenPayCreditCard object to hold the card information to charge.
GreenPayCreditCard gpCreditCard = new GreenPayCreditCard();
gpCreditCard.setCardHolder("Jhon Doe");
gpCreditCard.setCardNumber("4795736054664396");
gpCreditCard.setCvc("123");
gpCreditCard.setExpirationMonth(9);
gpCreditCard.setExpirationYear(21);
gpCreditCard.setNickname("visa2449");
// 7. Using the GreenPayOrderResult object (which holds the session id and transaction token).
// call checkoutExistingOrder to process the payment
greenPay.checkoutExistingOrder(gpCreditCard, response, new ResponseCallback<GreenPayCheckoutOrderResult>() {
@Override
public void onSuccess(GreenPayCheckoutOrderResult response) {
Log.d("GreenPayTestApp", "Checkout Order Response from Activity: " + response.getStatus() + ": " + response.getAuthorization());
Toast.makeText(getApplicationContext(), "Order paid. Status: " + response.getStatus() + ". Auth: " + response.getAuthorization(), Toast.LENGTH_LONG).show();
}
@Override
public void onError(String errorReason) {
Toast.makeText(getApplicationContext(), "Error making the payment: " + errorReason, Toast.LENGTH_LONG).show();
}
});
} catch (GreenPayException e) {
e.printStackTrace();
} catch (ConfigurationException e) {
e.printStackTrace();
}
}
@Override
public void onError(String errorReason) {
}
});
} catch (GreenPayException e) {
e.printStackTrace();
} catch (ConfigurationException e) {
e.printStackTrace();
}