Ingenico-ePayments / connect-sdk-client-android

Ingenico Connect Android Client SDK
https://docs.connect.worldline-solutions.com/documentation/sdk/mobile/android/
Other
35 stars 17 forks source link

onBasicPaymentItemsCallComplete is not invoked after few times; #6

Closed Mactub07 closed 1 year ago

Mactub07 commented 5 years ago

HI, I've detected that if I try to get payment items 2-3 times , onBasicPaymentItemsCallComplete callback is not invoked. I'm a new in Android, need help:

package com.myApp.rningenicobridge;

import android.support.annotation.Nullable;

import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.WritableMap; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.WritableArray; import com.facebook.react.modules.core.DeviceEventManagerModule; import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.Promise; import com.facebook.react.uimanager.IllegalViewOperationException; import android.content.Intent;

import java.util.HashMap; import java.util.Map; import android.util.Log;

//ingenico import com.globalcollect.gateway.sdk.client.android.sdk.GcUtil; import com.globalcollect.gateway.sdk.client.android.sdk.asynctask.BasicPaymentItemsAsyncTask.OnBasicPaymentItemsCallCompleteListener; import com.globalcollect.gateway.sdk.client.android.sdk.asynctask.PaymentProductAsyncTask.OnPaymentProductCallCompleteListener; import com.globalcollect.gateway.sdk.client.android.sdk.asynctask.PaymentProductGroupAsyncTask.OnPaymentProductGroupCallCompleteListener; import com.globalcollect.gateway.sdk.client.android.sdk.communicate.C2sCommunicatorConfiguration; import com.globalcollect.gateway.sdk.client.android.sdk.manager.AssetManager; import com.globalcollect.gateway.sdk.client.android.sdk.model.PaymentContext; import com.globalcollect.gateway.sdk.client.android.sdk.model.PaymentRequest; import com.globalcollect.gateway.sdk.client.android.sdk.model.PreparedPaymentRequest; import com.globalcollect.gateway.sdk.client.android.sdk.model.Size; import com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.AccountOnFile; import com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItem; import com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItems; import com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct; import com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroup; import com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentItem; import com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProduct; import com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProductGroup; import com.globalcollect.gateway.sdk.client.android.sdk.session.GcSession; import com.globalcollect.gateway.sdk.client.android.sdk.session.GcSessionEncryptionHelper; import com.google.android.gms.common.api.Status; import com.google.android.gms.wallet.AutoResolveHelper; import com.google.android.gms.wallet.PaymentData; import com.google.android.gms.wallet.WalletConstants; import com.google.gson.Gson; import com.google.gson.JsonParser; import org.json.JSONObject;

import java.io.InputStreamReader; import java.io.Reader; import java.io.Serializable; import com.globalcollect.gateway.sdk.client.android.sdk.model.AmountOfMoney; import com.globalcollect.gateway.sdk.client.android.sdk.model.CountryCode; import com.globalcollect.gateway.sdk.client.android.sdk.model.CurrencyCode; import com.globalcollect.gateway.sdk.client.android.sdk.model.PaymentContext;

import android.content.Context; import android.app.Application; import be.sncb.mobile.MainApplication; import java.security.InvalidParameterException; import com.facebook.react.uimanager.IllegalViewOperationException;

import com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItem; import com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.displayhints.DisplayHintsPaymentItem;

import static com.globalcollect.gateway.sdk.client.android.sdk.configuration.Constants.PAYMENTPRODUCTGROUPID_CARDS; import static com.globalcollect.gateway.sdk.client.android.sdk.configuration.Constants.PAYMENTPRODUCTID_AFTERPAY_INSTALLMENTS; import static com.globalcollect.gateway.sdk.client.android.sdk.configuration.Constants.PAYMENTPRODUCTID_AFTERPAY_INVOICE; import static com.globalcollect.gateway.sdk.client.android.sdk.configuration.Constants.PAYMENTPRODUCTID_GOOGLEPAY; import static com.globalcollect.gateway.sdk.client.android.sdk.configuration.Constants.PAYMENTPRODUCTID_BanContact; import static com.globalcollect.gateway.sdk.client.android.sdk.configuration.Constants.PAYMENTPRODUCTID_BOLETOBANCARIO;

public class RNIngenicoBridgeModule extends ReactContextBaseJavaModule { public static final String REACT_CLASS = "RNIngenicoBridge"; private static ReactApplicationContext reactContext; private static Context appContext; private static final String GET_PAYMENT_ITEMS_ERROR = "GET_PAYMENT_ITEMS_ERROR";

// The session object that is used to connect to the API
private GcSession session;

// Parameters used to initialize the connection
private String clientSessionId;
private String customerId;
private String merchantId;
private String merchantName;
private String clientApiUrl;
private String assetUrl;
private boolean environmentIsProduction;

// Variables required to retrieve the payment items that are available for payment
private PaymentContext paymentContext;
private boolean groupPaymentProducts;
private PaymentProduct paymentProduct;

// Loaded payment product and selected Account On File information
private BasicPaymentItems paymentItems;
private AccountOnFile accountOnFile;

private OnBasicPaymentItemsCallCompleteListener onBasicPaymentItemsCallCompleteListener;

@Override
public String getName() {
    // Tell React the name of the module
    // https://facebook.github.io/react-native/docs/native-modules-android.html#the-toast-module
    return REACT_CLASS;
}

public RNIngenicoBridgeModule(ReactApplicationContext context) {
    // Pass in the context to the constructor and save it so you can emit events
    super(context);
}

@ReactMethod
public void getPaymentItems(
        ReadableMap sessionParams,
        String amountValue,
        Boolean isRecurring,
        Boolean isProductionMode,
        final Promise promise
) {
    //loadIntentData();
    CurrencyCode currencyCode = CurrencyCode.EUR;
    CountryCode countryCode = CountryCode.BE;

    final String clientSessionId = sessionParams.getString("clientSessionId");
    final String customerId = sessionParams.getString("customerId");
    final String clientApiUrl = sessionParams.getString("baseURL");
    final String assetBaseUrl = sessionParams.getString("assetsBaseURL");
    final boolean environmentIsProduction = isProductionMode;
    final String applicationIdentifier = "Example Application/v1";
    final String region = sessionParams.getString("region");
    final String splitter = "splitter";

    if (paymentItems == null) {
        try {
            session = C2sCommunicatorConfiguration.initWithClientSessionId(
                    clientSessionId,
                    customerId,
                    clientApiUrl,
                    assetBaseUrl,
                    environmentIsProduction,
                    applicationIdentifier);
        } catch (IllegalViewOperationException e) {
            Log.d("SOMETAG========================= session error", e.getMessage());
        }
    }

    Log.d("SOMETAG=========================", "start getting PaymentItems");

    AmountOfMoney amountOfMoney = new AmountOfMoney(Long.parseLong(amountValue), currencyCode);
    // Create the PaymentContext
    final PaymentContext paymentContext = new PaymentContext(amountOfMoney, countryCode, isRecurring);
    // Create listener for the BasicPaymentItemsAsyncTask callback
    onBasicPaymentItemsCallCompleteListener = new OnBasicPaymentItemsCallCompleteListener() {

        @Override
        public void onBasicPaymentItemsCallComplete(BasicPaymentItems basicPaymentItems) {
            Log.d("SOMETAG=========================", "callback is invoked");
            if (basicPaymentItems != null && basicPaymentItems.getBasicPaymentItems() != null && !basicPaymentItems.getBasicPaymentItems().isEmpty()) {
                paymentItems = basicPaymentItems;
                Log.d("SOMETAG=========================", "Success");
                Integer size = basicPaymentItems.getBasicPaymentItems().size();
                WritableArray array = Arguments.createArray();

                for (int i = 0; i < basicPaymentItems.getBasicPaymentItems().size(); i++) {
                    BasicPaymentItem item = basicPaymentItems.getBasicPaymentItems().get(i);
                    String id = item.getId();
                    DisplayHintsPaymentItem Hints = item.getDisplayHints();
                    String logoUrl = Hints.getLogoUrl();
                    array.pushString(splitter);
                    array.pushString(id);
                    array.pushString(logoUrl);
                }
                 promise.resolve((WritableArray) array);
            } else {
                WritableArray array = Arguments.createArray();
                promise.reject(GET_PAYMENT_ITEMS_ERROR);
                Log.d("SOMETAG=========================", "reject");
            }
        }
    };

    boolean groupPaymentProducts = false;
    Context context = MainApplication.getAppContext();
    session.getBasicPaymentItems(
            MainApplication.getAppContext(),
            paymentContext,
            onBasicPaymentItemsCallCompleteListener,
            groupPaymentProducts
    );
}

}

LeonStemerdink commented 5 years ago

Hi Mactub07, Have you verified that the call itself <session.getBasicPaymentItems( ... )> is invoked the 2nd and 3rd time?

Mactub07 commented 5 years ago

Hi @LeonStemerdink , yes, I've checked this case. there is test scheme:

I've noticed that if I rebuild app it start work again and after 3th time it happens again.

Mactub07 commented 5 years ago

I'm wondering:

LeonStemerdink commented 5 years ago

Looking at the SDK code there is no reason why you wouldn't receive a response every time. Even if the server would ignore repeated requests, you would still receive a response. It seems to me that the issue is probably with React Native, as you have different results with Rebuilding and Reloading.