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

Add redirect to error page if payment failed on checkout side #779

Merged
merged 5 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 18 additions & 7 deletions clients/payment/src/components/CardPayment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
InitiateCardMerchantPaymentDocument,
} from "../graphql/unauthenticated";
import { t } from "../utils/i18n";
import { Router } from "../utils/routes";
import { CarteBancaireLogo, MaestroLogo, MastercardLogo, VisaLogo } from "./CardLogos";

const styles = StyleSheet.create({
Expand Down Expand Up @@ -202,8 +201,8 @@ export const CardPayment = ({ paymentLink, paymentMethodId, publicKey }: Props)
.mapOk(data => data.unauthenticatedInitiateMerchantCardPaymentFromPaymentLink)
.mapOkToResult(filterRejectionsToResult),
)
.tapOk(() => {
Router.replace("PaymentSuccess", { paymentLinkId: paymentLink.id });
.tapOk(({ redirectUrl }) => {
window.location.replace(redirectUrl);
})
.tapError(error => {
showToast({ variant: "error", error, title: translateError(error) });
Expand Down Expand Up @@ -241,7 +240,10 @@ export const CardPayment = ({ paymentLink, paymentMethodId, publicKey }: Props)
<View
style={[
styles.cardLogo,
(isPaymentMethodValid === false || cardNumberState !== "valid") && {
(isPaymentMethodValid === false ||
cardNumberState === "cardNotSupported" ||
cardNumberState === "empty" ||
cardNumberState === "invalid") && {
borderColor: colors.negative[500],
},
]}
Expand All @@ -253,7 +255,10 @@ export const CardPayment = ({ paymentLink, paymentMethodId, publicKey }: Props)
<View
style={[
styles.cardLogo,
(isPaymentMethodValid === false || cardNumberState !== "valid") && {
(isPaymentMethodValid === false ||
sandrine-ds marked this conversation as resolved.
Show resolved Hide resolved
cardNumberState === "cardNotSupported" ||
cardNumberState === "empty" ||
cardNumberState === "invalid") && {
borderColor: colors.negative[500],
},
]}
Expand All @@ -265,7 +270,10 @@ export const CardPayment = ({ paymentLink, paymentMethodId, publicKey }: Props)
<View
style={[
styles.cardLogo,
(isPaymentMethodValid === false || cardNumberState !== "valid") && {
(isPaymentMethodValid === false ||
cardNumberState === "cardNotSupported" ||
cardNumberState === "empty" ||
cardNumberState === "invalid") && {
borderColor: colors.negative[500],
},
]}
Expand All @@ -277,7 +285,10 @@ export const CardPayment = ({ paymentLink, paymentMethodId, publicKey }: Props)
<View
style={[
styles.cardLogo,
(isPaymentMethodValid === false || cardNumberState !== "valid") && {
(isPaymentMethodValid === false ||
cardNumberState === "cardNotSupported" ||
cardNumberState === "empty" ||
cardNumberState === "invalid") && {
borderColor: colors.negative[500],
},
]}
Expand Down
28 changes: 18 additions & 10 deletions clients/payment/src/components/PaymentArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useResponsive } from "@swan-io/lake/src/hooks/useResponsive";
import { isNotNullish, isNullish } from "@swan-io/lake/src/utils/nullish";
import { useMemo, useState } from "react";
import { GetMerchantPaymentLinkDocument } from "../graphql/unauthenticated";
import { CardErrorPage } from "../pages/CardErrorPage";
import { ExpiredPage } from "../pages/ExpiredPage";
import { NotFoundPage } from "../pages/NotFoundPage";
import { PaymentPage } from "../pages/PaymentPage";
Expand Down Expand Up @@ -138,19 +139,26 @@ export const PaymentArea = ({ paymentLinkId }: Props) => {

<Space height={24} />

{match({ route: route?.name, mandateUrlStatus })
{match({ route: route?.name, params: route?.params, mandateUrlStatus })
.with({ route: "PaymentForm", mandateUrlStatus: "Active" }, () =>
match(merchantPaymentLink.paymentMethods)
.with([P.nonNullable, ...P.array()], merchantPaymentMethods => (
<PaymentPage
merchantPaymentMethods={merchantPaymentMethods}
paymentLink={merchantPaymentLink}
setMandateUrl={setMandateUrl}
nonEeaCountries={nonEEACountries}
/>
))
match({
paymentMethods: merchantPaymentLink.paymentMethods,
params: route?.params,
})
.with(
{ paymentMethods: [P.nonNullable, ...P.array()] },
({ paymentMethods }) => (
<PaymentPage
merchantPaymentMethods={paymentMethods}
paymentLink={merchantPaymentLink}
setMandateUrl={setMandateUrl}
nonEeaCountries={nonEEACountries}
/>
),
)
.otherwise(() => <ErrorView />),
)
.with({ params: { error: "true" } }, () => <CardErrorPage />)
.with({ route: "PaymentSuccess", mandateUrlStatus: "Completed" }, () => (
<SuccessPage mandateUrl={mandateUrl} />
))
Expand Down
3 changes: 3 additions & 0 deletions clients/payment/src/graphql/unauthenticated.gql
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ mutation InitiateCardMerchantPayment(
) {
unauthenticatedInitiateMerchantCardPaymentFromPaymentLink(input: $input) {
__typename
... on UnauthenticatedInitiateMerchantCardPaymentFromPaymentLinkSuccessPayload {
redirectUrl
}
... on Rejection {
message
}
Expand Down
9 changes: 5 additions & 4 deletions clients/payment/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
"paymentLink.card.cvv": "CVV",
"paymentLink.cardNumberRequired": "Your card number is required",
"paymentLink.expiryDateRequired": "Your expiry date is required",
"paymentLink.cardNotSupported": "American Express cards are not supported. Please try with another card.",
"paymentLink.cardNotSupported": "Your card isn't supported. Please try with another card.",
"paymentLink.cvvRequired": "Your CVV is required",
"paymentLink.city": "City",
"paymentLink.country": "Country",
"paymentLink.error.subtitle": "We couldn't set up your Direct Debit with Swan.\n Please try again or contact the support system.",
"paymentLink.error.retry": "Try again",
"paymentLink.error.subtitle": "We couldn't set up your payment with Swan.\n Please try again or contact the Customer Support.",
"paymentLink.error.title": "Something went wrong",
"paymentLink.iban": "IBAN",
"paymentLink.invalidCardNumber": "Invalid card number",
Expand All @@ -27,7 +28,7 @@
"paymentLink.postalCode": "Postal code",
"paymentLink.poweredBySwan": "Powered by",
"paymentLink.state": "State",
"paymentLink.success.subtitle": "Your payment setup was successful.\nYou can close this window.",
"paymentLink.success.subtitle": "Your payment was successful.\nYou can close this window.",
"paymentLink.success.title": "Thanks!",
"paymentLink.termsAndConditions": "By clicking Pay, you're agreeing a direct debit mandate electronically. The mandate authorizes: (1) {merchantName} to share payment information with Swan, and (2) Swan to debit your account accordingly. Refund requests will be processed according to your bank's terms and conditions."
"paymentLink.termsAndConditions": "By clicking Pay, you're agreeing to a direct debit mandate electronically. The mandate authorizes: (1) {merchantName} to share payment information with Swan, and (2) Swan to debit your account accordingly. Refund requests will be processed according to your bank's terms and conditions."
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ const styles = StyleSheet.create({
},
});

export const ErrorPage = () => {
type CardErrorPage = {
paymentLinkId: string;
};
export const CardErrorPage = () => {
return (
<Box alignItems="center" justifyContent="center" style={styles.fill}>
<BorderedIcon name={"lake-warning"} color="negative" size={70} padding={16} />
Expand All @@ -32,6 +35,8 @@ export const ErrorPage = () => {
<LakeText align="center" color={colors.gray[500]} style={styles.subtitle}>
{t("paymentLink.error.subtitle")}
</LakeText>

<Space height={32} />
</Box>
);
};
7 changes: 3 additions & 4 deletions clients/payment/src/pages/PaymentPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ export const PaymentPage = ({

const methodIds = merchantPaymentMethods.reduce<Partial<Record<SupportedMethodType, string>>>(
(acc, { type, id }) => {
match(type)
.with("Card", () => (acc["Card"] = id))
.with("SepaDirectDebitB2b", "SepaDirectDebitCore", () => (acc["DirectDebit"] = id))
return match(type)
.with("Card", () => ({ ...acc, Card: id }))
.with("SepaDirectDebitB2b", "SepaDirectDebitCore", () => ({ ...acc, DirectDebit: id }))
.otherwise(() => acc);
return acc;
},
{},
);
Expand Down
2 changes: 1 addition & 1 deletion clients/payment/src/utils/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createGroup, createRouter } from "@swan-io/chicane";
export const Router = createRouter(
createGroup("Payment", "/:paymentLinkId", {
Area: "/*",
Form: "/",
Form: "/?:error{true}",
Success: "/success",
Error: "/error",
}),
Expand Down
Loading