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): PAYPAL-4937 Update PaymentRequestSender with new GQL API #2754

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

bc-nick
Copy link
Contributor

@bc-nick bc-nick commented Dec 16, 2024

What?

Updated PaymentMethodRequestSender by adding an additional method
Updated PaymentMethodActionCreator by adding an additional method

Why?

As part of the implementation of Headless Wallet Buttons (POC)

Testing / Proof

Manual

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

@bc-nick bc-nick marked this pull request as ready for review December 16, 2024 16:25
@bc-nick bc-nick requested a review from a team as a code owner December 16, 2024 16:25
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.

Looks good to me 👍

@@ -0,0 +1,6 @@
export default interface HeadlessPaymentMethod<T = any> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can any type be changed to unknown?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would be better to use the any type in this case for matching initializationData type with PaymentMethod interface which also uses any for initializationData.

@@ -0,0 +1,7 @@
import HeadlessPaymentMethod from './headless-payment-method';

export interface HeadlessPaymentMethodResponse<T = any> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Will it work for you, if any be changed with unknown?

Suggested change
export interface HeadlessPaymentMethodResponse<T = any> {
export interface HeadlessPaymentMethodResponse<T = unknown> {

Copy link
Contributor

@bc-peng bc-peng Dec 18, 2024

Choose a reason for hiding this comment

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

Are we not able to define the actual type here?

Copy link
Contributor Author

@bc-nick bc-nick Dec 18, 2024

Choose a reason for hiding this comment

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

@bc-peng removed T parameter as unnecessary in this case. we can define type as string

Comment on lines 10 to 13
import HeadlessPaymentMethodConfig from './headless-payment-method-config';
import { HeadlessPaymentMethodResponse } from './headless-payment-method-response';
import { HeadlessPaymentMethodType } from './headless-payment-method-type';
import HeadlessPaymentRequestOptions from './headless-payment-request-options';
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we group them into a headless-payment folder for better orgnization as I can see things are quite different 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.

Moved to the separate folder

methodId: string,
options: HeadlessPaymentRequestOptions,
): Promise<Response<PaymentMethod>> {
const url = `/graphql`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this be reused?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

Comment on lines +122 to +124
if (!entityId) {
throw new Error('Unable to get payment entity id.');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What would happen after throwing this error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are not be able to make a request in this case. It will be catch with PaymentMethodActionCreator when i add it by the next PR

};
}

private getPaymentEntityId(methodId: string): HeadlessPaymentMethodType {
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
private getPaymentEntityId(methodId: string): HeadlessPaymentMethodType {
private _getPaymentEntityId(methodId: string): HeadlessPaymentMethodType {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

.then((response) => this.transformToPaymentMethodResponse(response, methodId));
}

private transformToPaymentMethodResponse(
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
private transformToPaymentMethodResponse(
private _transformToPaymentMethodResponse(

Copy link
Contributor

Choose a reason for hiding this comment

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

Also maybe refactor this to a separate transformer file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to the separate file

const graphQLQuery = `
query {
site {
paymentWalletWithInitializationData(filter: {paymentWalletEntityId: "${entityId}"}) {
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
paymentWalletWithInitializationData(filter: {paymentWalletEntityId: "${entityId}"}) {
paymentWalletWithInitializationData(filter: { paymentWalletEntityId: "${entityId}"}) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

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