From 76692ce121f4e0babc47ce67b8ea91b219b07169 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Ferreira?= Date: Mon, 16 Sep 2024 11:12:47 +0200 Subject: [PATCH] send browser info on commit (#2847) * send browser info on commit * add changeset --- .changeset/polite-timers-sniff.md | 5 +++++ packages/lib/src/core/CheckoutSession/CheckoutSession.ts | 9 ++++++--- packages/lib/src/core/CheckoutSession/types.ts | 7 ++++++- packages/lib/src/core/Services/sessions/setup-session.ts | 5 +++-- 4 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 .changeset/polite-timers-sniff.md diff --git a/.changeset/polite-timers-sniff.md b/.changeset/polite-timers-sniff.md new file mode 100644 index 0000000000..80853189ba --- /dev/null +++ b/.changeset/polite-timers-sniff.md @@ -0,0 +1,5 @@ +--- +'@adyen/adyen-web': patch +--- + +send browserInfo in setup call diff --git a/packages/lib/src/core/CheckoutSession/CheckoutSession.ts b/packages/lib/src/core/CheckoutSession/CheckoutSession.ts index b95d0ca847..44627bc8db 100644 --- a/packages/lib/src/core/CheckoutSession/CheckoutSession.ts +++ b/packages/lib/src/core/CheckoutSession/CheckoutSession.ts @@ -12,11 +12,13 @@ import { CheckoutSessionOrdersResponse, CheckoutSessionPaymentResponse, CheckoutSessionSetupResponse, - SessionConfiguration + SessionConfiguration, + SetupSessionOptions } from './types'; import cancelOrder from '../Services/sessions/cancel-order'; import { onOrderCancelData } from '../../components/Dropin/types'; import type { AdditionalDetailsData } from '../types'; +import collectBrowserInfo from '../../utils/browserInfo'; class Session { private readonly session: CheckoutSession; @@ -66,8 +68,9 @@ class Session { /** * Fetches data from a session */ - setupSession(options): Promise { - return setupSession(this, options).then(response => { + setupSession(options: SetupSessionOptions): Promise { + const mergedOptions = { ...options, browserInfo: collectBrowserInfo() } + return setupSession(this, mergedOptions).then(response => { if (response.configuration) { this.configuration = { ...response.configuration }; } diff --git a/packages/lib/src/core/CheckoutSession/types.ts b/packages/lib/src/core/CheckoutSession/types.ts index 0008b8c46c..fa6c23be76 100644 --- a/packages/lib/src/core/CheckoutSession/types.ts +++ b/packages/lib/src/core/CheckoutSession/types.ts @@ -1,5 +1,5 @@ import { InstallmentOptions } from '../../components/Card/components/CardInput/components/types'; -import { PaymentAction, PaymentAmount, ResultCode } from '../../types/global-types'; +import { BrowserInfo, Order, PaymentAction, PaymentAmount, ResultCode } from '../../types/global-types'; export type CheckoutSession = { id: string; @@ -57,3 +57,8 @@ export type CheckoutSessionOrdersResponse = { orderData: string; pspReference: string; }; + +export type SetupSessionOptions = { + browserInfo?: BrowserInfo, + order?: Order +} \ No newline at end of file diff --git a/packages/lib/src/core/Services/sessions/setup-session.ts b/packages/lib/src/core/Services/sessions/setup-session.ts index b9e4ebbf97..01614b325c 100644 --- a/packages/lib/src/core/Services/sessions/setup-session.ts +++ b/packages/lib/src/core/Services/sessions/setup-session.ts @@ -1,11 +1,12 @@ import { httpPost } from '../http'; import Session from '../../CheckoutSession'; -import { CheckoutSessionSetupResponse } from '../../CheckoutSession/types'; +import { CheckoutSessionSetupResponse, SetupSessionOptions } from '../../CheckoutSession/types'; import { API_VERSION } from './constants'; -function setupSession(session: Session, options): Promise { +function setupSession(session: Session, options: SetupSessionOptions): Promise { const path = `${API_VERSION}/sessions/${session.id}/setup?clientKey=${session.clientKey}`; const data = { + browserInfo: options.browserInfo, sessionData: session.data, ...(options.order ? {