stripe / stripe-terminal-android

Stripe Terminal Android SDK
https://stripe.dev/stripe-terminal-android/
Other
94 stars 46 forks source link

offline behavior issue #428

Closed thelight413 closed 8 months ago

thelight413 commented 9 months ago

Summary

I'm getting an issue with implementing Offline behavior on the app. When creating a payment intent, I set the offline behavior to FORCE_OFFLINE so I can test the offline but I get an error "Failed to create payment offline. This reader is not configured to operate offline".

Code to reproduce

`public void createPaymentIntent(ReadableMap options) { if (options != null) { if (options.hasKey(CURRENCY)) lastCurrency = options.getString(CURRENCY); } HashMap<String, String> metadata = new HashMap<>(); metadata.put("unique-id", UUID.randomUUID().toString()); PaymentIntentParameters.Builder paramsBuilder = getPaymentParams(options); paramsBuilder.setMetadata(metadata); OfflineBehavior offlineBehavior = OfflineBehavior.FORCE_OFFLINE; final CreateConfiguration createConfig = new CreateConfiguration(offlineBehavior);

    Terminal.getInstance().createPaymentIntent(paramsBuilder.build(), new PaymentIntentCallback() {
        @Override
        public void onSuccess(@Nonnull PaymentIntent paymentIntent) {
            Log.d("PAYMENT_INTENT","CREATED PAYMENT INTENT");
            lastPaymentIntent = paymentIntent;
            if(paymentIntent.getId() != null){
                Log.d("PAYMENT_INTENT","created online");

            }else{
                Log.d("PAYMENT_INTENT","created offline");

            }
            WritableMap paymentIntentCreateRespMap = Arguments.createMap();
            paymentIntentCreateRespMap.putMap(INTENT, serializePaymentIntent(paymentIntent, lastCurrency)); //No currency for android
            sendEventWithName(EVENT_PAYMENT_INTENT_CREATION, paymentIntentCreateRespMap);
        }

        @Override
        public void onFailure(@Nonnull TerminalException e) {
            lastPaymentIntent = null;
            WritableMap paymentIntentCreateRespMap = Arguments.createMap();
            paymentIntentCreateRespMap.putString(ERROR, e.getErrorMessage());
            sendEventWithName(EVENT_PAYMENT_INTENT_CREATION, paymentIntentCreateRespMap);
        }
    },createConfig);
}`

Android version

Android 14

Impacted devices (Android devices or readers)

Stripe Reader M2

SDK version

implementation "com.stripe:stripeterminal-localmobile:3.2.1" implementation "com.stripe:stripeterminal-core:3.2.1"

Other information

billfinn-stripe commented 9 months ago

Hi there -- can you confirm that you did all of the following?

  1. Enabled offline mode using the configuration API, per the docs for the reader's location (or generally for your entire account).
  2. Set an OfflineListener on the Terminal SDK.
thelight413 commented 9 months ago

Yes I did both. I enabled offline for the entire account and set the offline listener on the SDK. Does it make a difference if I'm using a Connect account?

billfinn-stripe commented 9 months ago

Ah, I should have caught this sooner -- please upgrade to 3.3.0. There was an offline-related bug in 3.2.1, so we've proactively reached out to existing users on that version and disabled it for new users.

dmatthews-stripe commented 8 months ago

@thelight413 we will be closing this ticket due to inactivity, if you have any further issues, please do not hesitate to open up a new ticket.

MeetGori1 commented 2 months ago

class=TerminalSession (Ask Gemini) com.stripe.stripeterminal.external.models.TerminalException: Failed to create payment offline. This reader is not configured to operate offline. at com.stripe.stripeterminal.internal.common.resourcerepository.DirectResourceRepositoryRouter.createPaymentIntent(DirectResourceRepositoryRouter.kt:89) at com.stripe.stripeterminal.internal.common.resourcerepository.ProxyResourceRepository$createPaymentIntent$1.invoke(ProxyResourceRepository.kt:62) at com.stripe.stripeterminal.internal.common.resourcerepository.ProxyResourceRepository$createPaymentIntent$1.invoke(ProxyResourceRepository.kt:61) at com.stripe.stripeterminal.internal.common.resourcerepository.ProxyResourceRepository.withCurrentRepository(ProxyResourceRepository.kt:157) at com.stripe.stripeterminal.internal.common.resourcerepository.ProxyResourceRepository.createPaymentIntent(ProxyResourceRepository.kt:61) at com.stripe.stripeterminal.internal.common.terminalsession.TerminalSession$CreatePaymentIntentOperation.execute(TerminalSession.kt:1900) at com.stripe.stripeterminal.internal.common.terminalsession.TerminalSession$ExternalOperation.run$terminalsession_release(TerminalSession.kt:1087) at com.stripe.stripeterminal.internal.common.terminalsession.TerminalSession.enqueueOperation$lambda$6(TerminalSession.kt:941) at com.stripe.stripeterminal.internal.common.terminalsession.TerminalSession.$r8$lambda$9_FdDGpM1BaifeFRjKBBfCCLP6o(Unknown Source:0) at com.stripe.stripeterminal.internal.common.terminalsession.TerminalSession$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0) getting this error for offline payment for stripe s700

                                            using thiis dependancy 

stripeterminalHandoffclient = "3.9.3" stripeterminalCore = "3.9.3" stripeterminal-core = { module = "com.stripe:stripeterminal-core", version.ref = "stripeterminalCore" } stripeterminal-handoffclient = { module = "com.stripe:stripeterminal-handoffclient", version.ref = "stripeterminalHandoffclient" }

 here is my configurations 

val offlineBehavior = if (amount > 1000000) { OfflineBehavior.REQUIRE_ONLINE } else { if (NetworkUtil.isInternetAvailable(requireContext())) OfflineBehavior.PREFER_ONLINE else OfflineBehavior.FORCE_OFFLINE } val createConfig = CreateConfiguration(offlineBehavior)

        Terminal.getInstance()
            .createPaymentIntent(params, createPaymentIntentCallback, createConfig)