Estoy trabajando un proyecto de integración del API de Paypal en Android Studio, pero al hacer el Intent de la actividad me genera el siguiente error:
Process: com.example.vivotelecom, PID: 1655
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.vivotelecom/com.paypal.android.sdk.payments.PaymentActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f0d0000
Se anexa el archivo java de la actividad para tener un mayor panorama de lo que podría estar mal.
La métodos procesarPago(String amount) y onResultActivity(int, int, Intent) son conforme a la API de PayPal para procesar los pagos.
public class PagoLinea extends AppCompatActivity {
//Request PAYPAL
private static final int PAYPAL_REQUEST_CODE = 1;
public static final String PAYPAL_CLIENT_ID="Aciz1zl044BrRO9GKMA7B38BZ5mDJLGai9eGTTbp9ftgd9D4GdcGLx7f0oLWD0Pr0grY3RHGugmMzpG3";
private static final PayPalConfiguration config = new PayPalConfiguration().environment(PayPalConfiguration.ENVIRONMENT_SANDBOX).clientId(PAYPAL_CLIENT_ID);
ImageButton backPay, b_historial, btnPago;
TextView t_historial, txtPago, txtPagoIva, fpago, month;
EditText pago;
String amount;
JSONObject jsonObject;
RequestQueue requestQueue;
@Override
protected void onDestroy() {
stopService(new Intent(this, PayPalService.class));
super.onDestroy();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pago_linea);
Intent intent = new Intent(this, PayPalService.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION,config);
startService(intent);
txtPago = (TextView) findViewById(R.id.cant_pago);
txtPagoIva = (TextView) findViewById(R.id.cant_pago_iva);
fpago = (TextView) findViewById(R.id.txtFUpdate);
month = (TextView) findViewById(R.id.txtMes);
pago = (EditText) findViewById(R.id.etPago);
backPay = (ImageButton) findViewById(R.id.ibtnBackPay);
btnPago = (ImageButton) findViewById(R.id.btn_payment);
backPay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
t_historial = (TextView) findViewById(R.id.tbtnHistorial);
t_historial.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(),Historial.class);
startActivity(intent);
}
});
b_historial = (ImageButton) findViewById(R.id.btnHistorial);
b_historial.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(),Historial.class);
startActivity(intent);
}
});
btnPago.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
procesarPago(pago.getText().toString());
}
});
Intent intent1 = getIntent();
String exContrato = intent1.getStringExtra("con");
obtenerMens("http://10.0.2.2/BD_VivoSistemas/WS_DatosPago.php?num_contrato_con="+exContrato);
}
private void obtenerMens(String URL){
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(URL, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
//Toast.makeText(PagoLinea.this, "Si entra", Toast.LENGTH_SHORT).show();
for (int i = 0; i < response.length(); i++) {
try {
jsonObject = response.getJSONObject(i);
txtPagoIva.setText(jsonObject.getString("costo_mensualidad_paq"));
datosPago();
} catch (JSONException e) {
Toast.makeText(PagoLinea.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(PagoLinea.this, "Error de conexión", Toast.LENGTH_SHORT).show();
}
});
requestQueue = Volley.newRequestQueue(this);
requestQueue.add(jsonArrayRequest);
}
private void datosPago(){
String txPago = txtPagoIva.getText().toString();
//Toast.makeText(this, "El texto es: "+txPago, Toast.LENGTH_SHORT).show();
double pagoSub = Double.parseDouble(txPago);
double pagar = pagoSub*0.84;
String pagoTot = String.valueOf(pagar);
txtPago.setText(pagoTot);
Intent intent = getIntent();
String exFUpdate = intent.getStringExtra("fupdate");
fpago.setText(exFUpdate);
String mes = intent.getStringExtra("mes");
month.setText(mes);
pago.setText(txPago);
}
private void procesarPago(String amount){
amount = pago.getText().toString();
PayPalPayment payPalPayment = new PayPalPayment(new BigDecimal(amount), "MXN", "Pagado", PayPalPayment.PAYMENT_INTENT_SALE);
Intent intent = new Intent(getApplication(), PaymentActivity.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION,config);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, payPalPayment);
startActivityForResult(intent, PAYPAL_REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == PAYPAL_REQUEST_CODE){
if(resultCode == Activity.RESULT_OK){
PaymentConfirmation confirmation = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if(confirmation != null){
try {
String paymentDetails = confirmation.toJSONObject().toString(4);
Log.i("paymentExample", paymentDetails);
startActivity(new Intent(this ,DetallePago.class).putExtra("PaymentDetails", paymentDetails).putExtra("PaymentAmount", pago.getText().toString()));
} catch (JSONException e) { e.printStackTrace(); }
}
}else if(resultCode == Activity.RESULT_CANCELED)
Toast.makeText(this, "Cancelada", Toast.LENGTH_SHORT).show();
}else if(resultCode == PaymentActivity.RESULT_EXTRAS_INVALID)
Toast.makeText(this, "Invalida", Toast.LENGTH_SHORT).show();
super.onActivityResult(requestCode, resultCode, data);
}
public void onBackPressed() {
if(getFragmentManager().getBackStackEntryCount() == 0) {
super.onBackPressed();
}
else {
getFragmentManager().popBackStack();
}
}
}
Y sí, ya agregué los datos de mi sandbox de Paypal para las pruebas. Se ha actualizado la pregunta con el código completo de la actividad y la
backPay = (ImageButton) findViewById(R.id.ibtnBackPay);
y a las otras imágenes que tienes en tu código. Si es posible, agrega también el XML del layout a la pregunta.