Skip to content

Commit

Permalink
Merge pull request #81 from xsolla/PAYMENTS-18786
Browse files Browse the repository at this point in the history
fix(PAYMENTS-18786) google pay, payment methods
  • Loading branch information
ekireevxs authored Apr 2, 2024
2 parents 8ef47f0 + 8775364 commit 5e1055b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
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

0 comments on commit 5e1055b

Please sign in to comment.