mkharibalaji / react-native-adyen-payment

React Native Adyen Payment
https://mkharibalaji.github.io/react-native-adyen-payment/
MIT License
35 stars 35 forks source link

Crash on Android during startActivity() #6

Closed murrple-1 closed 4 years ago

murrple-1 commented 4 years ago

I am attempting to run the library on Android, but it is crashing with the following message: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

The full logcat/stacktrace is as follows:

D/OkHttp: --> POST https://checkout-test.adyen.com/checkout/V52/paymentMethods
D/OkHttp: Content-Type: application/json
    Content-Length: 240
    Accept: application/json
    Accept-Charset: utf-8
    x-api-key: [redacted]
    {"additionalData":{},"allowedPaymentMethods":[],"amount":{"currency":"CAD","value":200},"blockedPaymentMethods":[],"channel":"Android","countryCode":"CA","merchantAccount":"[redacted]","shopperLocale":"en_CA","shopperReference":"XXXXXX"}
    --> END POST (240-byte body)
D/OkHttp: <-- 200 OK https://checkout-test.adyen.com/checkout/V52/paymentMethods (683ms)
    Date: Tue, 11 Feb 2020 03:52:45 GMT
D/OkHttp: Server: Apache
    Set-Cookie: [redacted]
    pspReference: [redacted]
    Keep-Alive: timeout=15, max=100
    Connection: Keep-Alive
    Transfer-Encoding: chunked
    Content-Type: application/json;charset=UTF-8
D/OkHttp: {"groups":[{"name":"Credit Card","types":["visa","mc"]}],"paymentMethods":[{"brands":["visa","mc"],"details":[{"key":"encryptedCardNumber","type":"cardToken"},{"key":"encryptedSecurityCode","type":"cardToken"},{"key":"encryptedExpiryMonth","type":"cardToken"},{"key":"encryptedExpiryYear","type":"cardToken"},{"key":"holderName","optional":true,"type":"text"}],"name":"Credit Card","type":"scheme"}]}
D/OkHttp: <-- END HTTP (400-byte body)
I/AdyenPaymentModule: com.adyen.checkout.base.model.paymentmethods.PaymentMethod@739432e
D/CO.AdyenComponent: Init
D/CO.AdyenComponent: Updating supported cards to - [VISA, MASTERCARD]
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.happy_goat_mobile, PID: 25873
    android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
        at android.app.ContextImpl.startActivity(ContextImpl.java:952)
        at android.app.ContextImpl.startActivity(ContextImpl.java:928)
        at android.content.ContextWrapper.startActivity(ContextWrapper.java:383)
        at android.content.ContextWrapper.startActivity(ContextWrapper.java:383)
        at com.rnlib.adyen.AdyenComponent$Companion.startPayment(AdyenComponent.kt:70)
        at com.rnlib.adyen.AdyenPaymentModule.showCardComponent(AdyenPaymentModule.kt:360)
        at com.rnlib.adyen.AdyenPaymentModule.access$showCardComponent(AdyenPaymentModule.kt:73)
        at com.rnlib.adyen.AdyenPaymentModule$showPayment$1.onResponse(AdyenPaymentModule.kt:205)
        at retrofit2.DefaultCallAdapterFactory$ExecutorCallbackCall$1$1.run(DefaultCallAdapterFactory.java:83)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I/Process: Sending signal. PID: 25873 SIG: 9
Process 25873 terminated.

Am I calling something wrong, or is this a bug, as it seems?

This answer seems to suggest it could be fixed with a simple extra line before startActivity() is called. I don't mind doing a pull request if this is the solution.

mkharibalaji commented 4 years ago

@murrple-1 - Please raise a PR happy to merge.