Open mauriciorzm opened 5 years ago
Tengo el mismo problema, el error BE/Volley ( 7990): [296] BasicNetwork.performRequest: Unexpected response code 422 for https://api.conekta.io/tokens no puede ser capturado de forma correcta y termina la ejecución. Una mejora considerable sería poder capturarlo con un catch
Hello, I will fix this issue tomorrow.
I handled to making work following conekta SDK documentation and with some native code, here is my java main file:
import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
import android.app.Activity;
import android.util.Log;
import io.conekta.conektasdk.Conekta;
import io.conekta.conektasdk.Card;
import io.conekta.conektasdk.Token;
import org.json.JSONObject;
import java.util.Map;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
public class MainActivity extends FlutterActivity {
private static final String CHANNEL = "example/conektaSDK";
private Activity activity = this;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
new MethodChannel(getFlutterView(), CHANNEL).setMethodCallHandler(
new MethodCallHandler() {
@Override
public void onMethodCall(MethodCall call, Result result) {
if (call.method.equals("tokenizeCard")) {
handleTokenizeCard(call, result);
} else {
result.notImplemented();
}
}
});
}
private void handleTokenizeCard(MethodCall call, final Result result) {
Map<String, String> arguments = call.arguments();
String publicKey = arguments.get("publicKey");
String cardholderName = arguments.get("cardholderName");
String cardNumber = arguments.get("cardNumber");
String cvv = arguments.get("cvv");
String expiryMonth = arguments.get("expiryMonth");
String expiryYear = arguments.get("expiryYear");
Conekta.setPublicKey(publicKey);
Card card = new Card(cardholderName, cardNumber, cvv, expiryMonth, expiryYear);
Token token = new Token(activity);
token.onCreateTokenListener(new Token.CreateToken() {
@Override
public void onCreateTokenReady(JSONObject data) {
try {
result.success(data.getString("id"));
} catch (Exception err) {
result.error("ERROR_UNABLE_TO_TOKENIZE", err.getMessage(), null);
}
}
});
token.create(card);
}
}
Now I can try-catch this: (flutterClass.dart)
static const platform = const MethodChannel('example/conektaSDK');
try{
final String result = await platform.invokeMethod('tokenizeCard', {
"cardholderName": _name,
"cardNumber": _number,
"cvv": _cvc,
"expiryMonth": _expMonth,
"expiryYear": _expYear,
"publicKey": tokenConekta,
});
}
catch(e){
//do something
}
I don't know if it helps but this is how I made it work.
@alfredoqt
Hasn't this problem been fixed yet? It does not throw me an exception when the call is made without internet connection.
Saludos nuevamente @alfredoqt, han pasado 6 meses y aun no veo algún mantenimiento en este plug-in, o es que ya no piensas darle mas seguimiento?
Me encantaría ayudar pero nativo no es mi fuerte.
Por favor si encuentras un tiempo libre un fin de semana para este plug-in seria genial.
De ser posible también migrarlo a null-safety esa parte no creo sea difícil (desde que todo el SDK en Dart solo es un método).
When trying to tokenize a Card if it doesn't succeed I only get and the execution of the method the tokenization was called on ends, having no way to handle the exception.
E/Volley ( 7990): [296] BasicNetwork.performRequest: Unexpected response code 422 for https://api.conekta.io/tokens
In the code above if the tokenizations succeeds the then statement is reached and the parent method execution continues, while if it doesn't get tokenized, the execution of the parent method gets terminated and the print("Continue") is never reached.