Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature]: Display "no payment method available" message if no allowed or configured payment methods are present #2855

Merged
merged 17 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/venia-ui/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
"checkoutPage.paymentInformationStep": "3. Payment Information",
"checkoutPage.paymentMethodStatus": "{selectedPaymentMethod} is not supported for editing.",
"checkoutPage.paymentSummary": "{cardType} ending in {lastFour}",
"checkoutPage.paymentLoadingError": "There was an error loading payments.",
"checkoutPage.refreshOrTryAgainLater": "Please refresh or try again later.",
"checkoutPage.placeOrder": "Place Order",
"checkoutPage.quantity": "Qty : {quantity}",
"checkoutPage.quickCheckout": "Quick Checkout When You Return",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.root {
display: grid;
padding: 2rem;
}

.payment_method {
padding: 1.5rem;
border-bottom: 1px solid rgb(var(--venia-global-color-border));
}

Expand All @@ -15,3 +15,9 @@
font-weight: 600;
justify-self: start;
}

.payment_errors {
display: grid;
gap: 0.5em;
color: rgb(var(--venia-global-color-error));
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { shape, string, bool, func } from 'prop-types';
import { RadioGroup } from 'informed';
import { useIntl } from 'react-intl';

import { usePaymentMethods } from '@magento/peregrine/lib/talons/CheckoutPage/PaymentInformation/usePaymentMethods';

Expand All @@ -19,6 +20,8 @@ const PaymentMethods = props => {
shouldSubmit
} = props;

const { formatMessage } = useIntl();

const classes = mergeClasses(defaultClasses, propClasses);

const talonProps = usePaymentMethods({
Expand All @@ -36,37 +39,56 @@ const PaymentMethods = props => {
return null;
}

const radios = availablePaymentMethods.map(({ code, title }) => {
// If we don't have an implementation for a method type, ignore it.
if (!Object.keys(payments).includes(code)) {
return;
}

const isSelected = currentSelectedPaymentMethod === code;
const PaymentMethodComponent = payments[code];
const renderedComponent = isSelected ? (
<PaymentMethodComponent
onPaymentSuccess={onPaymentSuccess}
onPaymentError={onPaymentError}
resetShouldSubmit={resetShouldSubmit}
shouldSubmit={shouldSubmit}
/>
) : null;
const radios = availablePaymentMethods
.map(({ code, title }) => {
// If we don't have an implementation for a method type, ignore it.
if (!Object.keys(payments).includes(code)) {
return;
}

return (
<div key={code} className={classes.payment_method}>
<Radio
label={title}
value={code}
classes={{
label: classes.radio_label
}}
checked={isSelected}
const isSelected = currentSelectedPaymentMethod === code;
const PaymentMethodComponent = payments[code];
const renderedComponent = isSelected ? (
<PaymentMethodComponent
onPaymentSuccess={onPaymentSuccess}
onPaymentError={onPaymentError}
resetShouldSubmit={resetShouldSubmit}
shouldSubmit={shouldSubmit}
/>
{renderedComponent}
</div>
);
});
) : null;

return (
<div key={code} className={classes.payment_method}>
<Radio
label={title}
value={code}
classes={{
label: classes.radio_label
}}
checked={isSelected}
/>
{renderedComponent}
</div>
);
})
.filter(paymentMethod => !!paymentMethod);

const noPaymentMethodMessage = !radios.length ? (
<div className={classes.payment_errors}>
<span>
{formatMessage({
id: 'checkoutPage.paymentLoadingError',
defaultMessage: 'There was an error loading payments.'
})}
</span>
<span>
{formatMessage({
id: 'checkoutPage.refreshOrTryAgainLater',
defaultMessage: 'Please refresh or try again later.'
})}
</span>
</div>
) : null;

return (
<div className={classes.root}>
Expand All @@ -76,6 +98,7 @@ const PaymentMethods = props => {
>
{radios}
</RadioGroup>
{noPaymentMethodMessage}
</div>
);
};
Expand Down