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

feat(payment): PI-3068 moved my account logic to hosted card v2 package #2767

Merged
merged 1 commit into from
Jan 28, 2025

Conversation

vitalii-koshovyi
Copy link
Contributor

@vitalii-koshovyi vitalii-koshovyi commented Jan 21, 2025

What?

Moved my account logic to the hosted card v2 package.

  1. Added StoredCardHostedFormService to the hosted fields v2 for storing credit cards on the My Account Page;
  2. Added hosted-field.spec.ts test, due to the absence.
    But still need to improve coverage for the submitManualOrderForm and submitStoredCardForm methods, didn't do that due to the already huge changes;
  3. Added additional logic to use different iframe URLs for the storefront and CP fields usage. If you have better ideas on how to implement that, please share them with me.

Why?

Storefront account payments could use hosted fields without importing whole SDK.

Testing / Proof

manual-orders.mov
My.Account.mov

*logs in the console show that modified version of SDK loaded both in the microapp and in the iframe

@bigcommerce/team-checkout @bigcommerce/team-payments

@vitalii-koshovyi vitalii-koshovyi requested a review from a team as a code owner January 21, 2025 16:31
@vitalii-koshovyi vitalii-koshovyi force-pushed the PI-3068 branch 3 times, most recently from e1f494f to 9c691e9 Compare January 22, 2025 11:43
Comment on lines 54 to 56
typeof _orderId !== 'undefined'
? `/admin/payments/${this._orderId}/hosted-form-field?version=${LIBRARY_VERSION}`
: `/checkout/payment/hosted-field?version=${LIBRARY_VERSION}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
typeof _orderId !== 'undefined'
? `/admin/payments/${this._orderId}/hosted-form-field?version=${LIBRARY_VERSION}`
: `/checkout/payment/hosted-field?version=${LIBRARY_VERSION}`;
!(_orderId)
? `/checkout/payment/hosted-field?version=${LIBRARY_VERSION}`
: `/admin/payments/${this._orderId}/hosted-form-field?version=${LIBRARY_VERSION}`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure about that, theoretically orderId could be equal 0, in that case yours suggestion could cause issues.
Generally, I thought to pass some kind of a flag like isControlPannelframe but it looks excessive.

Copy link
Contributor

Choose a reason for hiding this comment

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

I personally don't mind the idea of a function like getFrameSrc that returns a url based on some params passed. Since this could eventually be rolled out for checkout page or some other context.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also AFAIK orderId should never be 0 in this case, but don't mind the typeof check. Can also do !!(_orderId) which checks if the value is truthy or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

!!(_orderId) linter will not pass it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will create a getFrameSrc, it'll look a lot cleaner.

Copy link
Contributor

@serhii-tkachenko serhii-tkachenko left a comment

Choose a reason for hiding this comment

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

LGTM 👍

fieldOptions.placeholder || '',
fieldOptions.accessibilityLabel || '',
options.styles || {},
new IframeEventPoster(host),
new IframeEventListener(host),
new DetachmentObserver(new MutationObserverFactory()),
options.orderId,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason we are moving the order here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, because it's not required param anymore, due to the usage with vaulting functionality.
By our linting rules it should be after required params.


export interface HostedInputStoredCardErrorEvent {
type: HostedInputEventType.StoredCardFailed;
payload?: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Will there ever be a case that payload is not present?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@vitalii-koshovyi vitalii-koshovyi Jan 23, 2025

Choose a reason for hiding this comment

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

Yes, we had similar comment in the initial PR. It gonna be done in separate ticket.
We need to improve error handling in general for the Stored cards functionality.

Copy link
Contributor Author

@vitalii-koshovyi vitalii-koshovyi Jan 23, 2025

Choose a reason for hiding this comment

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

We need to make strict types for the possible endpoint response errors, so it'll be done in the future My account developing, feature is still under development, not released yet.

@vitalii-koshovyi vitalii-koshovyi merged commit 2082af7 into bigcommerce:master Jan 28, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants