mirror of
https://github.com/jlengrand/adyen-web.git
synced 2026-03-10 08:01:22 +00:00
Storybook - Adjusted GooglePay/ApplePay express stories (#2468)
This commit is contained in:
committed by
GitHub
parent
54d056b38b
commit
f0aefbdee3
@@ -17,10 +17,16 @@ const meta: Meta = {
|
||||
};
|
||||
export default meta;
|
||||
|
||||
const getShippingMethods = (countryCode: string): ApplePayJS.ApplePayShippingMethod[] => {
|
||||
/**
|
||||
* Method that fetches the shipping options according to the country.
|
||||
* This function in most of the cases is asynchronous, as it will request shipping options in the backend
|
||||
*
|
||||
* @param countryCode - country code
|
||||
*/
|
||||
const getShippingMethods = (countryCode: string): Promise<ApplePayJS.ApplePayShippingMethod[]> => {
|
||||
switch (countryCode) {
|
||||
case 'US': {
|
||||
return [
|
||||
return Promise.resolve([
|
||||
{
|
||||
label: 'Standard Shipping',
|
||||
detail: 'Arrives in 5 to 7 days',
|
||||
@@ -33,11 +39,11 @@ const getShippingMethods = (countryCode: string): ApplePayJS.ApplePayShippingMet
|
||||
amount: '10.99',
|
||||
identifier: 'Express'
|
||||
}
|
||||
];
|
||||
]);
|
||||
}
|
||||
case 'NL':
|
||||
default: {
|
||||
return [
|
||||
return Promise.resolve([
|
||||
{
|
||||
label: 'Free Shipping',
|
||||
detail: 'Arrives in 10 to 15 days',
|
||||
@@ -56,7 +62,7 @@ const getShippingMethods = (countryCode: string): ApplePayJS.ApplePayShippingMet
|
||||
amount: '15.99',
|
||||
identifier: 'Express'
|
||||
}
|
||||
];
|
||||
]);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -176,7 +182,7 @@ export const Express: Story = {
|
||||
return;
|
||||
}
|
||||
|
||||
const newShippingMethods = getShippingMethods(countryCode);
|
||||
const newShippingMethods = await getShippingMethods(countryCode);
|
||||
const newLineItems = createLineItems(newShippingMethods[0]);
|
||||
const newTotal = createApplePayTotal(newLineItems);
|
||||
|
||||
|
||||
@@ -19,6 +19,11 @@ const meta: Meta = {
|
||||
};
|
||||
export default meta;
|
||||
|
||||
/**
|
||||
* Method that calculate the shipping costs based on the country/shipping options
|
||||
*
|
||||
* @param countryCode - country code
|
||||
*/
|
||||
function getShippingCost(countryCode) {
|
||||
switch (countryCode) {
|
||||
case 'BR':
|
||||
@@ -36,10 +41,16 @@ function getShippingCost(countryCode) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method that fetches the shipping options according to the country.
|
||||
* This function in most of the cases is asynchronous, as it will request shipping options in the backend
|
||||
*
|
||||
* @param countryCode - country code
|
||||
*/
|
||||
function getShippingOptions(countryCode?: string) {
|
||||
switch (countryCode) {
|
||||
case 'BR': {
|
||||
return {
|
||||
return Promise.resolve({
|
||||
defaultSelectedOptionId: 'shipping-001',
|
||||
shippingOptions: [
|
||||
{
|
||||
@@ -53,10 +64,10 @@ function getShippingOptions(countryCode?: string) {
|
||||
description: 'Standard shipping delivered in 2 business days.'
|
||||
}
|
||||
]
|
||||
};
|
||||
});
|
||||
}
|
||||
default: {
|
||||
return {
|
||||
return Promise.resolve({
|
||||
defaultSelectedOptionId: 'shipping-001',
|
||||
shippingOptions: [
|
||||
{
|
||||
@@ -75,7 +86,7 @@ function getShippingOptions(countryCode?: string) {
|
||||
description: 'Express shipping delivered in 1 business day.'
|
||||
}
|
||||
]
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -179,7 +190,7 @@ export const Express: Story = {
|
||||
|
||||
paymentDataCallbacks: {
|
||||
onPaymentDataChanged(intermediatePaymentData) {
|
||||
return new Promise(resolve => {
|
||||
return new Promise(async resolve => {
|
||||
const { callbackTrigger, shippingAddress, shippingOptionData } = intermediatePaymentData;
|
||||
const paymentDataRequestUpdate: google.payments.api.PaymentDataRequestUpdate = {};
|
||||
|
||||
@@ -193,7 +204,7 @@ export const Express: Story = {
|
||||
}
|
||||
/** If it initializes or changes the shipping address, we calculate the shipping options and transaction info */
|
||||
if (callbackTrigger === 'INITIALIZE' || callbackTrigger === 'SHIPPING_ADDRESS') {
|
||||
paymentDataRequestUpdate.newShippingOptionParameters = getShippingOptions(shippingAddress.countryCode);
|
||||
paymentDataRequestUpdate.newShippingOptionParameters = await getShippingOptions(shippingAddress.countryCode);
|
||||
const selectedShippingOptionId = paymentDataRequestUpdate.newShippingOptionParameters.defaultSelectedOptionId;
|
||||
paymentDataRequestUpdate.newTransactionInfo = calculateNewTransactionInfo(
|
||||
shippingAddress.countryCode,
|
||||
|
||||
@@ -13781,16 +13781,11 @@ regenerate@^1.4.2:
|
||||
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.2.tgz#b9346d8827e8f5a32f7ba29637d398b69014848a"
|
||||
integrity sha512-zrceR/XhGYU/d/opr2EKO7aRHUeiBI8qjtfHqADTwZd6Szfy16la6kqD0MIUs5z5hx6AaKa+PixpPrR289+I0A==
|
||||
|
||||
regenerator-runtime@^0.13.11:
|
||||
regenerator-runtime@^0.13.11, regenerator-runtime@^0.13.9, regenerator-runtime@^0.14.0:
|
||||
version "0.13.11"
|
||||
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz#f6dca3e7ceec20590d07ada785636a90cdca17f9"
|
||||
integrity sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==
|
||||
|
||||
regenerator-runtime@^0.14.0:
|
||||
version "0.14.0"
|
||||
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.14.0.tgz#5e19d68eb12d486f797e15a3c6a918f7cec5eb45"
|
||||
integrity sha512-srw17NI0TUWHuGa5CFGGmhfNIeja30WMBfbslPNhf6JrqQlLN5gcrvig1oqPxiVaXb0oW0XRKtH6Nngs5lKCIA==
|
||||
|
||||
regenerator-transform@^0.15.1:
|
||||
version "0.15.1"
|
||||
resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.15.1.tgz#f6c4e99fc1b4591f780db2586328e4d9a9d8dc56"
|
||||
|
||||
Reference in New Issue
Block a user