Git Product home page Git Product logo

checkout-android's People

Contributors

damilola-paystack avatar jubril-paystack avatar michael-paystack avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

checkout-android's Issues

Crash: Cannot use PaystackCheckout in a fragment "LifecycleOwners must call register before they are STARTED"

I'm using this library in a fragment and I get a crash when I try to initiate a charge.

I called initiateCharge() in onViewCreated().

Issue seems similar to https://stackoverflow.com/questions/64476827/how-to-resolve-the-error-lifecycleowners-must-call-register-before-they-are-sta

Code sample:


 private fun initiateCharge() {

        val checkoutResultListener = object : CheckoutResultListener {
            override fun onSuccess(transaction: Transaction) {
                // Executed when transaction is successful
                print("Paystack transaction $transaction")
            }

            override fun onError(exception: Throwable) {
                // Executed when an error occurs
                print("Paystack error $exception")
            }

            override fun onCancelled() {
                // Executed when the user cancels the payment process
                print("Paystack onCancelled()")
            }
        }
        val email = "[email protected]"
        val amount = 1000
        val currency = "NGN"
        PaystackCheckout.Builder(requireActivity() as AppCompatActivity, email, amount, currency)
            .build()
            .charge(checkoutResultListener)

    }

Error logs

2022-01-23 23:15:09.928 20620-20620/com.sample.mobile.sampleAndroid E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.sample.mobile.sampleAndroid, PID: 20620
    java.lang.IllegalStateException: LifecycleOwner com.sample.mobile.sampleAndroid.features.auth.activity.AuthActivity@e34c27c is attempting to register while current state is RESUMED. LifecycleOwners must call register before they are STARTED.
        at androidx.activity.result.ActivityResultRegistry.register(ActivityResultRegistry.java:123)
        at androidx.activity.ComponentActivity.registerForActivityResult(ComponentActivity.java:673)
        at com.paystack.checkout.PaystackCheckout.charge(PaystackCheckout.kt:57)
        at com.sample.mobile.sampleAndroid.features.auth.fragment.NewLoginFragment.initiateCharge(NewLoginFragment.kt:198)
        at com.sample.mobile.sampleAndroid.features.auth.fragment.NewLoginFragment.access$initiateCharge(NewLoginFragment.kt:31)
        at com.sample.mobile.sampleAndroid.features.auth.fragment.NewLoginFragment$onViewCreated$4$invokeSuspend$$inlined$collect$1.emit(Collect.kt:135)
        at kotlinx.coroutines.flow.FlowKt__ChannelsKt.emitAllImpl$FlowKt__ChannelsKt(Channels.kt:62)
        at kotlinx.coroutines.flow.FlowKt__ChannelsKt.access$emitAllImpl$FlowKt__ChannelsKt(Channels.kt:1)
        at kotlinx.coroutines.flow.FlowKt__ChannelsKt$emitAllImpl$1.invokeSuspend(Unknown Source:14)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTaskKt.resume(DispatchedTask.kt:235)
        at kotlinx.coroutines.DispatchedTaskKt.resumeUnconfined(DispatchedTask.kt:191)
        at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:162)
        at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:406)
        at kotlinx.coroutines.CancellableContinuationImpl.completeResume(CancellableContinuationImpl.kt:522)
        at kotlinx.coroutines.channels.AbstractChannel$ReceiveElement.completeResumeReceive(AbstractChannel.kt:932)
        at kotlinx.coroutines.channels.ArrayChannel.offerInternal(ArrayChannel.kt:76)
        at kotlinx.coroutines.channels.AbstractSendChannel.trySend-JP2dKIU(AbstractChannel.kt:155)
        at kotlinx.coroutines.channels.SendChannel$DefaultImpls.offer(Channel.kt:166)
        at kotlinx.coroutines.channels.AbstractSendChannel.offer(AbstractChannel.kt:143)
        at kotlinx.coroutines.channels.ChannelCoroutine.offer(Unknown Source:2)
        at reactivecircus.flowbinding.common.SafeOfferKt.safeOffer(SafeOffer.kt:11)
        at reactivecircus.flowbinding.android.view.ViewClickedFlowKt$clicks$1$listener$1.onClick(ViewClickedFlow.kt:34)
        at android.view.View.performClick(View.java:7441)
        at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
        at android.view.View.performClickInternal(View.java:7418)
        at android.view.View.access$3700(View.java:835)
        at android.view.View$PerformClick.run(View.java:28676)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7809)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

Payment Data Class Typecast

I am facing this issue in the checkoutResultListener in the onError method

Issue:- com.squareup.moshi.JsonDataException: Expected an int but was 2396035915 at path $.data.id

Response:-
{"status":true,"message":"Transaction initialized","data":{"status":"success","message":"successful","access_code":"ky55egezwiperel","id":2396035915,"amount":100,"plan":"","email":"[email protected]","merchant_name":"Viago Inc","merchant_logo":"https://public-files-paystack-prod.s3.eu-west-1.amazonaws.com/integration-logos/paystack.jpg","currency":"GHS","testmode":true,"original_amount":100,"added_fees":0,"merchant_id":893465,"merchant_key":"pk_test_8515ab2a469baba33eae8adb797c738847aa4940","domain":"test","transaction_status":"abandoned","log":null,"custom_filters":0,"customer":{"id":"106354627","first_name":"","last_name":"","email":"[email protected]","phone":"","metadata":null,"created_at":"2022-12-21 12:02:29","updated_at":"2022-12-21 12:02:29"},"plan_details":null,"channels":["card","mobile_money"],"channel_options":{"mobile_money":[{"key":"MTN","value":"MTN","isNew":false,"phoneNumberRegex":"^\+233(5(5|4|9)|2(4|5))\d{7}$","phoneNumberPlaceholder":"050 000 0000"},{"key":"ATL","value":"Airtel/Tigo","isNew":false,"phoneNumberRegex":"^\+233(5(6|7)|2(6|7))\d{7}$","phoneNumberPlaceholder":"050 000 0000"},{"key":"VOD","value":"Vodafone","isNew":false,"phoneNumberRegex":"^\+233(50|20)\d{7}$","phoneNumberPlaceholder":"050 000 0000"}]},"merchant_channel_settings":{},"elevy_percentage":0.015,"is_remember_me_enabled":null,"skip_pin_check_for_card_types":["visa"]}}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.