Skip to content

Commit

Permalink
refactor: rename onOrderCreated to onOrderUpdated
Browse files Browse the repository at this point in the history
  • Loading branch information
m1aw committed Dec 6, 2023
1 parent 62f4518 commit 4cf1e54
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 25 deletions.
2 changes: 1 addition & 1 deletion packages/e2e-playwright/app/src/pages/ANCV/ANCV.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const initCheckout = async () => {
locale: shopperLocale,
countryCode,
showPayButton: true,
onOrderCreated: data => {
onOrderUpdated: data => {
showAuthorised('Partially Authorised');
},
onError: handleError
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-playwright/tests/ancv/ancv.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { setupMock } from '../../mocks/setup/setup.mock';
import { statusMock } from '../../mocks/status/status.mock';

test.describe('ANCV - Sessions', () => {
test('should call onOrderCreated when payment is partially authorised (Sessions flow)', async ({ ancvPage }) => {
test('should call onOrderUpdated when payment is partially authorised (Sessions flow)', async ({ ancvPage }) => {
const { ancv, page } = ancvPage;

await createOrderMock(page, orderCreatedMockData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const initCheckout = async () => {
core: window.sessionCheckout,
type: 'giftcard',
brand: 'valuelink',
onOrderCreated: data => {
window.onOrderCreatedTestData = data;
onOrderUpdated: data => {
window.onOrderUpdatedTestData = data;
},
onRequiringConfirmation: () => {
window.onRequiringConfirmationTestData = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RequestMock, RequestLogger } from 'testcafe';
import { BASE_URL } from '../../pages';

import { mock, loggers } from '../onOrderCreated/onOrderCreated.mocks';
import { mock, loggers } from '../onOrderUpdated/onOrderUpdated.mocks';

const path = require('path');
require('dotenv').config({ path: path.resolve('../../', '.env') });
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/src/components/ANCV/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export interface ANCVConfiguration extends UIElementProps {
paymentData?: any;
data: ANCVDataState;
onOrderRequest?: any;
onOrderCreated?: any;
onOrderUpdated?: any;
}

export interface ANCVDataState {
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/src/components/Giftcard/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface GiftCardConfiguration extends UIElementProps {
expiryDateRequired?: boolean;
brandsConfiguration?: any;
brand?: string;
onOrderCreated?(data): void;
onOrderUpdated?(data): void;
onOrderRequest?(resolve, reject, data): void;
onBalanceCheck?(resolve, reject, data): void;
onRequiringConfirmation?(): void;
Expand Down
5 changes: 2 additions & 3 deletions packages/lib/src/components/internal/UIElement/UIElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export abstract class UIElement<P extends UIElementProps = UIElementProps> exten
: this.core.update({ order });

updateCorePromise.then(() => {
this.props.onOrderCreated?.({ order });
this.props.onOrderUpdated?.({ order });
});
};

Expand Down Expand Up @@ -401,10 +401,9 @@ export abstract class UIElement<P extends UIElementProps = UIElementProps> exten
orderData: order.orderData,
pspReference: order.pspReference
},
amount: this.props.amount,
locale: this.core.options.locale
};
this.props.onPaymentMethodsRequest(resolve, reject, data);
this.props.onPaymentMethodsRequest(data, { resolve, reject });
})
.then(paymentMethodsResponse => {
return this.core.update({ paymentMethodsResponse, order, amount: order.remainingAmount });
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/src/components/internal/UIElement/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CoreConfiguration, ICore } from '../../../core/types';
export type PayButtonFunctionProps = Omit<PayButtonProps, 'amount'>;

// TODO add onPaymentCompleted
type CoreCallbacks = Pick<CoreConfiguration, 'onSubmit' | 'onPaymentFailed' | 'onOrderCreated' | 'onPaymentMethodsRequest'>;
type CoreCallbacks = Pick<CoreConfiguration, 'onSubmit' | 'onPaymentFailed' | 'onOrderUpdated' | 'onPaymentMethodsRequest'>;

export type UIElementProps = BaseElementProps &
CoreCallbacks & {
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/src/core/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const GENERIC_OPTIONS = [
'onError',
'onBalanceCheck',
'onOrderRequest',
'onOrderCreated',
'onOrderUpdated',
'setStatusAutomatically',
'onPaymentMethodsRequest'
];
Expand Down
11 changes: 7 additions & 4 deletions packages/lib/src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,19 @@ export interface CoreConfiguration {

onOrderRequest?(resolve: PromiseResolve, reject: PromiseReject, data: PaymentData): Promise<void>;

onPaymentMethodsRequest?(resolve: (response: PaymentMethodsResponse) => void, reject: () => void, data: PaymentMethodsRequestData): void;
onPaymentMethodsRequest?(
data: PaymentMethodsRequestData,
actions: { resolve: (response: PaymentMethodsResponse) => void; reject: () => void }
): void;

onOrderCancel?(order: Order): void;

/**
* Only used in Components combined with Sessions flow
* Callback used to inform when the order is created.
* Called when the gift card balance is less than the transaction amount.
* Returns an Order object that includes the remaining amount to be paid.
* https://docs.adyen.com/payment-methods/gift-cards/web-component?tab=config-sessions_1
*/
onOrderCreated?(data: { order: Order }): void;
onOrderUpdated?(data: { order: Order }): void;

/**
* Used only in the Donation Component when shopper declines to donate
Expand Down
5 changes: 2 additions & 3 deletions packages/lib/src/types/global-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,8 @@ export type OnPaymentFailedData =

//TODO double check these values
export interface PaymentMethodsRequestData {
order: Order;
amount: PaymentAmount;
locale: string;
order?: Order;
locale?: string;
countryCode?: string;
}

Expand Down
19 changes: 16 additions & 3 deletions packages/playground/src/pages/Dropin/manual.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AdyenCheckout, Dropin, Card, GooglePay, PayPal, Ach, Affirm, WeChat, Giftcard, AmazonPay } from '@adyen/adyen-web';
import '@adyen/adyen-web/styles/adyen.css';
import { getPaymentMethods, makePayment, checkBalance, createOrder, cancelOrder, makeDetailsCall } from '../../services';
import { amount, shopperLocale, countryCode, returnUrl } from '../../config/commonConfig';
import { amount, shopperLocale, countryCode } from '../../config/commonConfig';
import { getSearchParameters } from '../../utils';
import getTranslationFile from '../../config/getTranslation';

Expand Down Expand Up @@ -102,20 +102,33 @@ export async function initManual() {
}
},
onBalanceCheck: async (resolve, reject, data) => {
console.log('onBalanceCheck', data);
resolve(await checkBalance(data));
},
onOrderRequest: async (resolve, reject) => {
onOrderRequest: async resolve => {
console.log('onOrderRequested');
resolve(await createOrder({ amount }));
},
onOrderUpdated: data => {
console.log('onOrderUpdated', data);
},
onOrderCancel: async order => {
await cancelOrder(order);
checkout.update({ paymentMethodsResponse: await getPaymentMethods({ amount, shopperLocale }), order: null, amount });
checkout.update({
paymentMethodsResponse: await getPaymentMethods({ amount, shopperLocale }),
order: null,
amount
});
},
onError: (error, component) => {
console.info(error.name, error.message, error.stack, component);
},
onActionHandled: rtnObj => {
console.log('onActionHandled', rtnObj);
},
onPaymentMethodsRequest: async (data, { resolve, reject }) => {
console.log('onPaymentMethodsRequest', data);
resolve(await getPaymentMethods({ amount, shopperLocale: data.locale, order: data.order }));
}
});

Expand Down
4 changes: 2 additions & 2 deletions packages/playground/src/pages/GiftCards/GiftCards.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ import getTranslationFile from '../../config/getTranslation';
core: sessionCheckout,
type: 'giftcard',
brand: 'svs',
onOrderCreated: () => {
console.log('onOrderCreated');
onOrderUpdated: () => {
console.log('onOrderUpdated');
},
onRequiringConfirmation: () => {
console.log('onRequiringConfirmation');
Expand Down
6 changes: 5 additions & 1 deletion packages/playground/src/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ export const getOriginKey = (originKeyOrigin = document.location.origin) =>
httpPost('originKeys', { originDomains: [originKeyOrigin] }).then(response => response.originKeys[originKeyOrigin]);

export const checkBalance = data => {
return httpPost('paymentMethods/balance', data)
const payload = {
...data,
amount: paymentMethodsConfig.amount
};
return httpPost('paymentMethods/balance', payload)
.then(response => {
if (response.error) throw 'Balance call failed';
return response;
Expand Down

0 comments on commit 4cf1e54

Please sign in to comment.