Skip to content
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

APM Mobile - Add new API for handling payment method change #1

Merged
merged 3 commits into from
Nov 10, 2021

Conversation

anncheng999
Copy link

No description provided.

@anncheng999
Copy link
Author

@chen-zhu
Copy link

chen-zhu commented Nov 4, 2021

Humm wondering if this library has any testing to cover & validate all the changes we will made.

Also, do we have a list of PaymentMethod that would be returned by api? Or should we enumerate them?

Would make sense to put it inside the apm-mobile packages as a mono-repo.

Copy link

@jasonmally jasonmally left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need test coverage, especially for the PaymentRequest-related changes and the paymentMethodCompletion-related changes.

) {
throw new Error(
`Only "${SHIPPING_ADDRESS_CHANGE_EVENT}" and "${SHIPPING_OPTION_CHANGE_EVENT}" event listeners are supported.`
`Only "${SHIPPING_ADDRESS_CHANGE_EVENT}" and "${SHIPPING_OPTION_CHANGE_EVENT} and "${PAYMENT_METHOD_CHANGE_EVENT}"" event listeners are supported.`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`Only "${SHIPPING_ADDRESS_CHANGE_EVENT}" and "${SHIPPING_OPTION_CHANGE_EVENT} and "${PAYMENT_METHOD_CHANGE_EVENT}"" event listeners are supported.`
`Only "${SHIPPING_ADDRESS_CHANGE_EVENT}", "${SHIPPING_OPTION_CHANGE_EVENT} and "${PAYMENT_METHOD_CHANGE_EVENT}"" event listeners are supported.`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This is a nitpick suggestion just to improve readability. This change is not essential.)

@@ -14,6 +14,7 @@ import type {
PaymentShippingType,
PaymentDetailsIOS,
PaymentDetailsIOSRaw,
PaymentMethod

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PaymentMethod type only contains one attribute: a payment method type string. Maybe it would be simpler to just handle that information as a string without wrapping it in an object.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it matches the response body of the new API, so we need to have a object that includes attribute paymentMethodType

@@ -106,26 +109,33 @@ export default class PaymentRequest {
_serializedModifierData: string;
_details: Object;
_options: Object;
_creditDebitDetails: Object;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to name this object _cardType? If that name is accurate, I think it would be clear and concise. I might just be misunderstanding the usage of this object though.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_creditDebitDetails includes all the details of both debit and credit cards :)

Comment on lines +280 to +281
_handlePaymentMethodChange(paymentMethod: PaymentMethod) {
this._paymentMethod = paymentMethod.paymentMethodType;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we treated paymentMethod as a string, we could simplify this to:

Suggested change
_handlePaymentMethodChange(paymentMethod: PaymentMethod) {
this._paymentMethod = paymentMethod.paymentMethodType;
_handlePaymentMethodChange(paymentMethod: string) {
this._paymentMethod = paymentMethod;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

paymentMethod is handling the response body

completion:(nonnull void (^)(NSArray<PKPaymentSummaryItem *> * _Nonnull))completion
{
self.paymentMethodCompletion = completion;
NSString *type = [self paymentMethodTypeToString:paymentMethod.type];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to explicitly define paymentMethodTypeToString somewhere?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, paymentMethodTypeToString is defined at line 447 in ReactNativePayments.m

}
else if (this._paymentMethod === 'PKPaymentMethodTypeDebit') {
this._details = this._creditDebitDetails.debit;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just prototype code (nice prototype code with unit tests!), but this is one part that i'd add a todo for. Handle the else statement.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point for clarification, the to-do has been added.

we have another investigation card about that the supported cards can only be shown up in apple pay flow to avoid other card problem, and this is handle in this investigation card https://trello.com/c/jXpIHzT6/2280-investigate-apm-mobile-only-show-up-the-supported-cards.

Copy link

@ltewksbury ltewksbury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a tiny comment!

Copy link

@trcoffman trcoffman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a couple of things we can iterate on in later PRs but overall I think this looks fine.

_userDismissSubscription: any; // TODO: - add proper type annotation
_userAcceptSubscription: any; // TODO: - add proper type annotation
_gatewayErrorSubscription: any; // TODO: - add proper type annotation
_shippingAddressChangesCount: number;
_paymentMethodChangesCount: number;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up: Do we need to handle this the way it's handled on lines 319-326 for the shipping address change event?

_handlePaymentMethodChange(paymentMethod: PaymentMethod) {
this._paymentMethod = paymentMethod.paymentMethodType;

if(this._paymentMethod === 'PKPaymentMethodTypeCredit') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up: This should be moved up to the application layer and the library should be more generic.

@trcoffman trcoffman merged commit a4ee27d into master Nov 10, 2021
trcoffman added a commit that referenced this pull request Nov 22, 2021
We are no longer changing behavior for how PaymentRequest handles its details
constructor argument, so the test changes from PR #1 are no longer valid. Revert these.

There is a better way of changing PaymentRequestUpdateEvent, so revert all the
changes from PR #1 and then re-do the tests in a following commit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants