Skip to content

Commit 98337a4

Browse files
committed
feat(payment): PAYPAL-4937 updates related to new requirements
1 parent a14e11b commit 98337a4

File tree

10 files changed

+21
-72
lines changed

10 files changed

+21
-72
lines changed

packages/core/src/config/config-selector.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export default interface ConfigSelector {
1818
getHost(): string | undefined;
1919
getLocale(): string | undefined;
2020
getVariantIdentificationToken(): string | undefined;
21-
getStorefrontJwtToken(): string | undefined;
2221
getLoadError(): Error | undefined;
2322
isLoading(): boolean;
2423
}
@@ -57,11 +56,6 @@ export function createConfigSelectorFactory(): ConfigSelectorFactory {
5756
},
5857
);
5958

60-
const getStorefrontJwtToken = createSelector(
61-
(state: ConfigState) => state.meta && state.meta.storefrontJwtToken,
62-
(data) => () => data,
63-
);
64-
6559
const getStoreConfig = createSelector(
6660
(state: ConfigState) => state.data,
6761
(_: ConfigState, { formState }: ConfigSelectorDependencies) => formState && formState.data,
@@ -126,7 +120,6 @@ export function createConfigSelectorFactory(): ConfigSelectorFactory {
126120
getContextConfig: getContextConfig(state),
127121
getExternalSource: getExternalSource(state),
128122
getHost: getHost(state),
129-
getStorefrontJwtToken: getStorefrontJwtToken(state),
130123
getLocale: getLocale(state),
131124
getVariantIdentificationToken: getVariantIdentificationToken(state),
132125
getLoadError: getLoadError(state),

packages/core/src/config/config-state.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export interface ConfigMetaState {
1212
variantIdentificationToken?: string;
1313
host?: string;
1414
locale?: string;
15-
storefrontJwtToken?: string;
1615
}
1716

1817
export interface ConfigErrorsState {

packages/core/src/payment-integration/create-payment-integration-selectors.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export default function createPaymentIntegrationSelectors({
1414
getStoreConfig,
1515
getStoreConfigOrThrow,
1616
getConfig,
17-
getStorefrontJwtToken,
1817
},
1918
consignments: { getConsignments, getConsignmentsOrThrow },
2019
countries: { getCountries },
@@ -81,7 +80,6 @@ export default function createPaymentIntegrationSelectors({
8180
getPaymentStatusOrThrow,
8281
getPaymentRedirectUrl,
8382
getPaymentRedirectUrlOrThrow,
84-
getStorefrontJwtToken,
8583
getPaymentMethod: clone(getPaymentMethod),
8684
getPaymentMethodOrThrow: clone(getPaymentMethodOrThrow),
8785
getPaymentMethodsMeta: clone(getPaymentMethodsMeta),
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { RequestOptions } from '../../common/http-request';
22

33
export default interface HeadlessPaymentRequestOptions extends RequestOptions {
4-
body?: { query: string };
5-
headers: { Authorization: string; [key: string]: string };
4+
body: { entityId: string };
65
}

packages/core/src/payment/payment-method-action-creator.spec.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ describe('PaymentMethodActionCreator', () => {
4848
).mockReturnValue(Promise.resolve(paymentMethodResponse));
4949

5050
jest.spyOn(store.getState().cart, 'getCartOrThrow').mockReturnValue(getCheckout().cart);
51-
52-
jest.spyOn(store.getState().config, 'getStorefrontJwtToken').mockReturnValue(
53-
'storefront_jwt_token',
54-
);
5551
});
5652

5753
describe('#loadPaymentMethods()', () => {
@@ -214,12 +210,7 @@ describe('PaymentMethodActionCreator', () => {
214210

215211
expect(
216212
paymentMethodRequestSender.loadPaymentWalletWithInitializationData,
217-
).toHaveBeenCalledWith(methodId, {
218-
headers: {
219-
Authorization: `Bearer storefront_jwt_token`,
220-
'Content-Type': 'application/json',
221-
},
222-
});
213+
).toHaveBeenCalledWith(methodId, undefined, undefined);
223214
});
224215

225216
it('loads payment wallet method with timeout', async () => {
@@ -237,13 +228,7 @@ describe('PaymentMethodActionCreator', () => {
237228

238229
expect(
239230
paymentMethodRequestSender.loadPaymentWalletWithInitializationData,
240-
).toHaveBeenCalledWith(methodId, {
241-
headers: {
242-
Authorization: `Bearer storefront_jwt_token`,
243-
'Content-Type': 'application/json',
244-
},
245-
...options,
246-
});
231+
).toHaveBeenCalledWith(methodId, undefined, options);
247232
});
248233

249234
it('emits actions if able to load payment wallet method', async () => {

packages/core/src/payment/payment-method-action-creator.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Observable, Observer } from 'rxjs';
44

55
import { InternalCheckoutSelectors } from '../checkout';
66
import { ActionOptions, cachableAction } from '../common/data-store';
7-
import { MissingDataError, MissingDataErrorType } from '../common/error/errors';
87
import { RequestOptions } from '../common/http-request';
98

109
import {
@@ -169,11 +168,7 @@ export default class PaymentMethodActionCreator {
169168
return (store) =>
170169
Observable.create((observer: Observer<LoadPaymentMethodAction>) => {
171170
const state = store.getState();
172-
const jwtToken = state.config.getStorefrontJwtToken();
173-
174-
if (!jwtToken) {
175-
throw new MissingDataError(MissingDataErrorType.MissingPaymentToken);
176-
}
171+
const host = state.config.getHost();
177172

178173
observer.next(
179174
createAction(PaymentMethodActionType.LoadPaymentMethodRequested, undefined, {
@@ -182,13 +177,7 @@ export default class PaymentMethodActionCreator {
182177
);
183178

184179
this._requestSender
185-
.loadPaymentWalletWithInitializationData(methodId, {
186-
headers: {
187-
Authorization: `Bearer ${jwtToken}`,
188-
'Content-Type': 'application/json',
189-
},
190-
...options,
191-
})
180+
.loadPaymentWalletWithInitializationData(methodId, host, options)
192181
.then((response) => {
193182
observer.next(
194183
createAction(

packages/core/src/payment/payment-method-request-sender.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,26 +141,27 @@ describe('PaymentMethodRequestSender', () => {
141141

142142
describe('#loadPaymentWalletWithInitializationData()', () => {
143143
let response: Response<HeadlessPaymentMethodResponse>;
144-
const authorization = 'authorization-1234';
145144

146145
beforeEach(() => {
147146
response = getHeadlessPaymentResponse(getHeadlessPaymentMethod());
148147
jest.spyOn(requestSender, 'post').mockReturnValue(Promise.resolve(response));
149148
});
150149

151150
it('loads headless payment method', async () => {
151+
const host = 'https://test.com';
152+
const path = 'get-initialization-data';
153+
152154
const walletInitData =
153155
await paymentMethodRequestSender.loadPaymentWalletWithInitializationData(
154156
'paypalcommerce',
155-
{ headers: { Authorization: authorization } },
157+
host,
156158
);
157159

158160
expect(requestSender.post).toHaveBeenCalledWith(
159-
'/graphql',
161+
`${host}/${path}`,
160162
expect.objectContaining({
161-
headers: {
162-
Authorization: authorization,
163-
'Content-Type': 'application/json',
163+
body: {
164+
entityId: 'paypalcommerce.paypal',
164165
},
165166
}),
166167
);

packages/core/src/payment/payment-method-request-sender.ts

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import {
1111
HeadlessPaymentMethodConfig,
1212
HeadlessPaymentMethodResponse,
1313
HeadlessPaymentMethodType,
14-
HeadlessPaymentRequestOptions,
1514
} from './headless-payment';
15+
import HeadlessPaymentRequestOptions from './headless-payment/headless-payment-request-options';
1616
import PaymentMethod from './payment-method';
1717
import paymentMethodTransformer from './payment-method-transformer';
1818

@@ -53,37 +53,25 @@ export default class PaymentMethodRequestSender {
5353
}
5454

5555
/**
56-
* GraphQL payment requests
56+
* Headless payment requests
5757
*/
5858
loadPaymentWalletWithInitializationData(
5959
methodId: string,
60-
options: HeadlessPaymentRequestOptions,
60+
host?: string,
61+
{ timeout }: RequestOptions = {},
6162
): Promise<Response<PaymentMethod>> {
62-
const entityId = this._getPaymentEntityId(methodId);
63-
64-
const graphQLQuery = `
65-
query {
66-
site {
67-
paymentWalletWithInitializationData(filter: { paymentWalletEntityId: "${entityId}" }) {
68-
clientToken
69-
initializationData
70-
}
71-
}
72-
}
73-
`;
63+
const path = 'get-initialization-data';
64+
const url = host ? `${host}/${path}` : `/${path}`;
7465

7566
const requestOptions: HeadlessPaymentRequestOptions = {
76-
headers: {
77-
...options.headers,
78-
'Content-Type': 'application/json',
79-
},
8067
body: {
81-
query: graphQLQuery,
68+
entityId: this._getPaymentEntityId(methodId),
8269
},
70+
timeout,
8371
};
8472

8573
return this._requestSender
86-
.post<HeadlessPaymentMethodResponse>('/graphql', requestOptions)
74+
.post<HeadlessPaymentMethodResponse>(url, requestOptions)
8775
.then((response) => paymentMethodTransformer(response, methodId));
8876
}
8977

packages/payment-integration-api/src/payment-integration-selectors.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ export default interface PaymentIntegrationSelectors {
8585

8686
getInstrumentsMeta(): InstrumentMeta | undefined;
8787

88-
getStorefrontJwtToken(): string | undefined;
89-
9088
getOrderMeta(): OrderMetaState | undefined;
9189

9290
getPaymentMethodsMeta(): PaymentMethodMeta | undefined;

packages/payment-integrations-test-utils/src/test-utils/payment-integration-service.mock.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ const state = {
5959
getPaymentRedirectUrl: jest.fn(),
6060
getPaymentRedirectUrlOrThrow: jest.fn(),
6161
isPaymentDataRequired: jest.fn(),
62-
getStorefrontJwtToken: jest.fn(),
6362
};
6463

6564
const createBuyNowCart = jest.fn(() => Promise.resolve(getCart()));

0 commit comments

Comments
 (0)