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

fix(PAYMENTS-18786) google pay, payment methods #81

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type GooglePayButtonColorType = 'default' | 'white' | 'black';
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { SecureComponentAbstract } from '../../../../../core/web-components/secure-component/secure-component.abstract';
import { headlessCheckoutAppUrl } from '../../../environment';
import { GooglePayButtonColorType } from './google-pay-button-color.type';

export class GooglePayButtonComponent extends SecureComponentAbstract {
protected componentName = 'pages/google-pay-button';
private buttonColor: GooglePayButtonColorType = 'default';

public setButtonColor(color: GooglePayButtonColorType): void {
this.buttonColor = color;
}

protected getHtml(): string {
return this.getSecureHtml();
}

protected getSecureHtml(): string {
return `<iframe allow='payment' src='${headlessCheckoutAppUrl}/secure-components/${this.componentName}'></iframe>`;
return `<iframe allow='payment' src='${headlessCheckoutAppUrl}/secure-components/${this.componentName}?buttonColor=${this.buttonColor}'></iframe>`;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export enum PaymentMethodsAttributes {
country = 'country',
skipPaymentMethodsCount = 'skipPaymentMethodsCount',
notFound = 'not-found',
searchPlaceholder = 'search-placeholder',
saveMethodMode = 'save-method-mode',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ export class PaymentMethodsComponent extends WebComponentAbstract {
}

public static get observedAttributes(): string[] {
return [PaymentMethodsAttributes.country];
return [
PaymentMethodsAttributes.country,
PaymentMethodsAttributes.skipPaymentMethodsCount,
];
}

protected connectedCallback(): void {
Expand Down Expand Up @@ -78,6 +81,7 @@ export class PaymentMethodsComponent extends WebComponentAbstract {
private loadRegularMethods(): void {
const country =
this.getAttribute(PaymentMethodsAttributes.country) ?? undefined;

void this.headlessCheckout
.getRegularMethods({ country, isSaveMethodMode: this.isSaveMethodMode })
.then(this.paymentMethodsLoadedHandler);
Expand All @@ -86,7 +90,11 @@ export class PaymentMethodsComponent extends WebComponentAbstract {
private readonly paymentMethodsLoadedHandler = (
paymentMethods: PaymentMethod[],
): void => {
this.paymentMethods = paymentMethods;
const skipPaymentMethodsCount = Number(
this.getAttribute(PaymentMethodsAttributes.skipPaymentMethodsCount),
);

this.paymentMethods = paymentMethods.slice(skipPaymentMethodsCount);
this.visibleMethods = this.paymentMethods;
this.filteredMethods = this.visibleMethods.slice();

Expand Down
Loading