Adyen / adyen-android

Adyen Android Drop-in and Components
https://docs.adyen.com/checkout/android
MIT License
119 stars 66 forks source link

WeChatPayComponent not returns "isValid as true immediately" #185

Closed kami4ka closed 3 years ago

kami4ka commented 4 years ago

Hi. I'm trying to implement Wechat Pay with Android component by a guide from site.

My code is the following:

val component = WeChatPayComponent.PROVIDER.get(
            this@AdyenWechatPaymentFragment,
            dataModel.paymentMethod,
            WeChatPayConfiguration.Builder(unsafeContext).build()
        )

        component.observe(
            this@AdyenWechatPaymentFragment,
            Observer {
                presenter.onWechatPayComponentStateChanged(it)
            }
        )

The problem is that presenter.onWechatPayComponentStateChanged is not triggered.

Maybe it somehow related with #182

caiofaustino commented 4 years ago

Hey there,

Without knowing more about the code it's hard to see the issue clearly, but out the top of my head I can see a few things.

1- Maybe WeChat app is not installed, and you are not checking for availablity, there is an example in the Docs specific to Android here

2- Maybe there is some issue related with the presenter, can you add a Log on the observer itself to see if that is triggered?

3- Make sure you are using the correct Payment Method object from the response with type wechatpaySDK

kami4ka commented 4 years ago

Hello.

Thanks for the answer. So a bit of details: 1) WeChat app is installed and I'm checking the availability on another screen, as I'm doing it with Google Pay via Adyen. 2) The same behavior reproduces with logging function instead of presenter call as well. As well, I'm debugging this line, and debugger is not stoped there. WeChatPayComponent.PROVIDER.get returns component as expected. 3) Type is wechatpaySDK as expected.

The only thing was changed in my implementation is described here: https://github.com/Adyen/adyen-android/issues/170

But, as I understand, it should not affect this part of the flow.

I'm only aware of the part with an immediate return for the observer. I will appreciate any clues for further debugging.

caiofaustino commented 4 years ago

Hmm, indeed this looks weird. I'll investigate this further since it could be a bug, but in the mean time you can add this line after the observe to trigger the callback that should have been sent.

component.inputDataChanged(EmptyInputData())

kami4ka commented 4 years ago

Thanks. It works like a charm. But I've faced another one problem: I'm receiving the following action:

{
   "action":{
      "paymentData":"***",
      "paymentMethodType":"wechatpaySDK",
      "sdkData":{
         "appid":"***",
         "noncestr":"***",
         "packageValue":"***",
         "partnerid":"***",
         "prepayid":"***",
         "sign":"***",
         "timestamp":"1589884598"
      },
      "type":"sdk"
   }
}

But looks like there is no such Action with that type. As well, tutorial sais about another type:

{
   "action":{
      "paymentData":"***",
      "paymentMethodType":"wechatpaySDK",
      "sdkData":{
         "appid":"***",
         "noncestr":"***",
         "packageValue":"***",
         "partnerid":"***",
         "prepayid":"***",
         "sign":"***",
         "timestamp":"1589884598"
      },
      "type":"sdk"
   }
}

PS: my excuses for asking this here, but can not figure out how to raise this question, because it looks like not an Android SDK problem, but kind of related to WeChat integration and Android tutorial for it implementation

caiofaustino commented 4 years ago

No worries, this action type issue is related to the SDK as well.

Seems like there was a change in the backend system with the action types that we didn't update in the SDK, so this change will require a new release to fix. I'll try to fix both issues and make a release next week.

kami4ka commented 4 years ago

Great, thanks for the estimated timelines and help!

caiofaustino commented 3 years ago

Hey man, just wanted to let you know the release might take a bit longer, in order to properly test the WeChat flow I need a device that was in the office, so I don't have it available right now.

I'll keep you posted.

kami4ka commented 3 years ago

Thanks for the info. The feature is really important for us to implement all the available payment methods in the app with using Adyen and get rid of all other libraries :-)

kami4ka commented 3 years ago

Hi, @caiofaustino. Any updates regarding the upcoming release?

caiofaustino commented 3 years ago

Hey @kami4ka, the change is already tested and merged, we are in the release process so it shouldn't take long. Sorry for the delay.

kami4ka commented 3 years ago

Awesome, thanks for such good news.

caiofaustino commented 3 years ago

Hey man, 3.6.6 was just released. Can you please test and let me know how it goes? Sorry for taking so long, we had a few delays.

kami4ka commented 3 years ago

Thanks! Will get back to you ASAP!

kami4ka commented 3 years ago

@caiofaustino Am I right, that I can not longer use PolymorphicJsonAdapterFactory for new SdkAction as I did it for all other actions:

PolymorphicJsonAdapterFactory.of(Action::class.java, Action.TYPE)
                    .withSubtype(RedirectAction::class.java, RedirectAction.ACTION_TYPE)
                    .withSubtype(Threeds2FingerprintAction::class.java, Threeds2FingerprintAction.ACTION_TYPE)
                    .withSubtype(Threeds2ChallengeAction::class.java, Threeds2ChallengeAction.ACTION_TYPE)
                    .withSubtype(QrCodeAction::class.java, QrCodeAction.ACTION_TYPE)
                    .withSubtype(VoucherAction::class.java, VoucherAction.ACTION_TYPE)

?

caiofaustino commented 3 years ago

Yeah unfortunately I don't think that's possible. Before only the Action.TYPE could identify the type of action class to be used, but since they generalised the API we need both the type to be "sdk" and the payment method, so there are 2 keys used in the diferentiation.

You can still use our SERIALIZER class thought, something like this

val action = Action.SERIALIZER.deserialize(JSONObject("action_object_string"))
kami4ka commented 3 years ago

Thanks. Will try to modify the code to be able to fit a new approach.

kami4ka commented 3 years ago

Looks like the updated SDK is working for SDK action. Thanks for the update.