Created
April 18, 2016 21:09
-
-
Save matiasgualino/bde001e8196b3df84a519cdd25ae8781 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Button onClick method | |
public void startPaymentMethodsActivity(View view) { | |
// Decinos qué tipos de pagos soportas. | |
protected List<string> mSupportedPaymentTypes = new ArrayList<string>(){{ | |
add("credit_card"); | |
add("debit_card"); | |
add("prepaid_card"); | |
add("ticket"); | |
add("atm"); | |
}}; | |
// Llamar al activity propuesta por MP | |
// especificando qué medios soporto | |
new MercadoPago.StartActivityBuilder() | |
.setActivity(this) | |
.setPublicKey(yourPublicKey) | |
.setSupportedPaymentTypes(mSupportedPaymentTypes) | |
.startPaymentMethodsActivity(); | |
} | |
@Override | |
protected void onActivityResult(int requestCode, int resultCode, | |
Intent data) { | |
if (requestCode == MercadoPago.PAYMENT_METHODS_REQUEST_CODE) { | |
if (resultCode == RESULT_OK && data != null) { | |
// Obtené el medio de pago | |
PaymentMethod paymentMethod = JsonUtil.getInstance() | |
.fromJson(data.getStringExtra("paymentMethod"), PaymentMethod.class); | |
// Ahora podes continuar con tu flujo. | |
// No te olvides de verificar si el medio de pago es offline! | |
} else { | |
if ((data != null) && | |
(data.getSerializableExtra("apiException") != null)) { | |
ApiException apiException | |
= (ApiException) data.getSerializableExtra("apiException"); | |
Toast.makeText(getApplicationContext(), apiException.getMessage(), | |
Toast.LENGTH_LONG).show(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment