Skip to content

Commit

Permalink
Merge pull request #94 from xsolla/PAYMENTS-19061
Browse files Browse the repository at this point in the history
feat(PAYMENTS-19061): add finance details update method
  • Loading branch information
Aleksey-Kornienko-xsolla authored May 2, 2024
2 parents 8de7328 + 4e9e376 commit ded9953
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xsolla/pay-station-sdk",
"version": "0.0.22",
"version": "0.0.23",
"description": "Pay Station SDK",
"main": "dist/main.js",
"types": "dist/index.d.ts",
Expand Down
23 changes: 16 additions & 7 deletions src/features/headless-checkout/headless-checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ import { FormFieldsStatus } from '../../core/form/form-fields-status.interface';
import { getCombinedPaymentMethodsHandler } from './post-messages-handlers/get-combined-payment-methods.handler';
import { CombinedPaymentMethods } from '../../core/combined-payment-methods.interface';
import { ThemesLoader } from '../../core/customization/themes-loader';
import { Themes } from '../../core/customization/themes.type';
import { Lang } from '../../core/i18n/lang.enum';
import { getCountryListHandler } from './post-messages-handlers/get-country-list.handler';
import { CountryResponse } from '../../core/country-response.interface';
import { FormLoader } from '../../core/form/form-loader';
import { InitialOptions } from './initial-options.interface';

@singleton()
export class HeadlessCheckout {
Expand Down Expand Up @@ -165,12 +165,7 @@ export class HeadlessCheckout {
private readonly formLoader: FormLoader,
) {}

public async init(environment: {
isWebview?: boolean;
sandbox?: boolean;
theme?: Themes;
language?: Lang;
}): Promise<void> {
public async init(environment: InitialOptions): Promise<void> {
this.isWebView = environment.isWebview;
this.isSandbox = environment.sandbox;
this.theme = environment.theme;
Expand Down Expand Up @@ -249,6 +244,20 @@ export class HeadlessCheckout {
) as Promise<FinanceDetails | null>;
}

public onUpdateFinanceDetails(
callbackFn: (financeDetails: FinanceDetails) => void,
): void {
this.postMessagesClient.listen<FinanceDetails | null>(
EventName.financeDetails,
getFinanceDetailsHandler,
(financeDetails) => {
if (financeDetails) {
callbackFn(financeDetails);
}
},
);
}

/**
* Returns available payment methods except quick methods
* @param country Country that quick methods should be loaded for.
Expand Down
9 changes: 9 additions & 0 deletions src/features/headless-checkout/initial-options.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Themes } from '../../core/customization/themes.type';
import { Lang } from '../../core/i18n/lang.enum';

export interface InitialOptions {
isWebview?: boolean;
sandbox?: boolean;
theme?: Themes;
language?: Lang;
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ export * from './web-components';
export { Lang } from './core/i18n/lang.enum';
export { EventName } from './core/event-name.enum';
export { NextActionType } from './core/actions/next-action-type.enum';
export { FinanceDetails } from './core/finance-details/finance-details.interface';
export { InitialOptions } from './features/headless-checkout/initial-options.interface';

0 comments on commit ded9953

Please sign in to comment.