-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add payment canceled exception #82
Add payment canceled exception #82
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JlUgia I think this PR is a very useful and demanded feature. Could you take a quick look into it?
pay_android/android/src/main/kotlin/io/flutter/plugins/pay_android/GooglePayHandler.kt
Outdated
Show resolved
Hide resolved
Co-authored-by: Jaime Blasco <jaimeblasco97@gmail.com>
@jamesblasco thx! I fixed the error message. |
Huge thanks for the commits! however I just tested the update on Android, it seems it won't throw the exception when payment sheet is dragged down and dismissed, the function did not return either, any idea? |
@xmany Thanks for trying it out! |
Thanks! My device is Samsung S20 plus, Android 11 |
It might have something to do with debug/release mode (Flutter), on iOS, when I was in debug mode, the fix was working, in release mode it was not. Haven't test the debug/release difference on Android, will test soon. However the above issue about not working on Android happened in release mode. |
@xmany I think the Android Please share the results of your tests, I am not aware of issues with release mode. |
You are right, After cleaning up and referencing the repo locally, the commits you had worked correctly, it's my environment a bit messed up, Sorry |
@jamesblasco @JlUgia still looking to get this in as it's blocking the release of a project for me. This has been opened for over a month now. Can this be merged and released? |
Thank you everyone. |
@@ -33,7 +38,7 @@ typealias PaymentCompletionHandler = (Bool) -> Void | |||
class PaymentHandler: NSObject { | |||
|
|||
/// Holds the current status of the payment process. | |||
var paymentStatus = PKPaymentAuthorizationStatus.failure | |||
var paymentHandlerStatus: PaymentHandlerStatus = .started |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to use implicit unwrapping (PaymentHandlerStatus!
) instead of initializing to an arbitrary value. Now that we are using startPayment
to set the status to .started
we can treat the declaration as a late initialization instead.
paymentStatus = .success | ||
completion(PKPaymentAuthorizationResult(status: paymentStatus, errors: nil)) | ||
paymentHandlerStatus = .authorized | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think removing this line would be useful to conceptually connect calling the completion
handler and the status update.
Left two comments. |
@JlUgia I updated the PR with your recommended changes (I hope). |
@@ -194,8 +194,6 @@ extension PaymentHandler: PKPaymentAuthorizationControllerDelegate { | |||
// Return the result back to the channel | |||
self.paymentResult(String(decoding: paymentResultData, as: UTF8.self)) | |||
|
|||
paymentHandlerStatus = .authorized | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually meant to only remove this white line to group lines of code according to their role in the class.
I think that the .authorized
state has its place there and helps with clarity.
In other words, I'd suggest we keep lines 197 and 26 as they were prior to this commit.
Apologies for the confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, alright. Will fix ASAP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JlUgia Thanks for the feedback, I "reverted" the changes.
Hi @stsc3000! Thank you for the commit. |
👋 Hi,
as outlined in #61, it would be nice to have consistent feedback when the user cancels payment authorization by closing the native payment selector.
The proposed changes end up throwing a
PlatformException(code: 'paymentCanceled')
.The Android implementation is straightforward, as
Activity.RESULT_CANCELED
makes it obvious when the user canceled.The iOS implementation is more involved, as it requires a more detailed tracking via delegate methods to make sure that the user canceled voluntarily, i.e. user canceled if:
paymentAuthorizationControllerWillAuthorizePayment
)didAuthorizePayment
)paymentAuthorizationControllerDidFinish
)The implementation also fixes #77.