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

user cancelled the flow on web fix #61

Merged
merged 1 commit into from
Aug 23, 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
2 changes: 2 additions & 0 deletions payment_sdk/src/assets/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
"CANCEL_PAYMENT": "Cancel Payment",
"PAYMENT_SUCCESS": "Payment Success",
"PAYMENT_FAILED": "Payment Failed",
"PAYMENT_CANCELLED": "Payment Canceled",
"ORDER_THANK_YOU_NOTE": "Thank you for your order",
"PAYMENT_RE_TRY_MSG": "We tried to charge your card but, something went wrong. Please update your payment method below to continue",
"PAYMENT_CANCELLED_MSG": "We noticed that you’ve canceled the payment process. If this was a mistake, you can try again to complete your purchase.",
"BACK_TO_STORE": "Back to store",
"UPDATE_PAYMENT_METHOD": "Update payment method",

Expand Down
4 changes: 3 additions & 1 deletion payment_sdk/src/assets/languages/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@
"NO": "いいえ",
"CANCEL_PAYMENT": "支払いのキャンセル",
"PAYMENT_SUCCESS": "支払い完了",
"PAYMENT_FAILED": "支払いができませんでした",
"PAYMENT_FAILED": "支払いができませんでした",
"PAYMENT_CANCELLED": "支払いがキャンセルされました",
"ORDER_THANK_YOU_NOTE": "ご購入ありがとうございました",
"PAYMENT_RE_TRY_MSG": "入力していただいたカードで支払いを行うことができませんでした。別の支払い方法を試してみてください。",
"PAYMENT_CANCELLED_MSG": "お支払いプロセスがキャンセルされたことを確認しました。もしこれが誤りであれば、再度お試しいただき、購入を完了してください。",
"BACK_TO_STORE": "ストアに戻る",
"UPDATE_PAYMENT_METHOD": "支払い方法を変更する",

Expand Down
7 changes: 6 additions & 1 deletion payment_sdk/src/components/PaymentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ const PaymentModal = ({
return paymentSuccessCtaText;
case ResponseScreenStatuses.FAILED:
return paymentFailedCtaText;
case ResponseScreenStatuses.CANCELLED:
return paymentSuccessCtaText;
default:
return "";
}
Expand All @@ -96,6 +98,8 @@ const PaymentModal = ({
type: Actions.SET_PAYMENT_STATE,
payload: "",
});
case ResponseScreenStatuses.CANCELLED:
return closeSheet(false);
default:
return "";
}
Expand All @@ -105,6 +109,7 @@ const PaymentModal = ({
closeSheet(
!(
paymentState === ResponseScreenStatuses.SUCCESS ||
paymentState === ResponseScreenStatuses.CANCELLED ||
// TODO: Fix this type error
// @ts-expect-error - Property 'COMPLETE' does not exist on type 'ResponseScreenStatuses'.
paymentState === ResponseScreenStatuses.COMPLETE
Expand All @@ -123,7 +128,7 @@ const PaymentModal = ({

<View style={styles.bottomSheetContainer}>
<View style={styles.line}>
<KomojuText style={styles.headerLabel}>PAYMENT_OPTIONS</KomojuText>
<KomojuText style={styles.headerLabel}>{!paymentState ? 'PAYMENT_OPTIONS' : ''}</KomojuText>
<TouchableOpacity style={styles.crossBtn} onPress={onCloseModal}>
<Image
source={mode === ThemeModes.light ? closeIcon : closeDMIcon}
Expand Down
10 changes: 5 additions & 5 deletions payment_sdk/src/components/ResponseScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import KomojuText from "./KomojuText";
import SubmitButton from "./SubmitButton";

type Props = {
status: ResponseScreenStatuses.SUCCESS | ResponseScreenStatuses.FAILED;
status: ResponseScreenStatuses.SUCCESS | ResponseScreenStatuses.FAILED | ResponseScreenStatuses.CANCELLED;
message?: string;
onPressLabel: string;
onPress: () => void;
Expand All @@ -24,12 +24,12 @@ const ResponseScreen = ({ status, message, onPress, onPressLabel }: Props) => {
const renderMessageContent = useMemo(() => {
const title =
status === ResponseScreenStatuses.SUCCESS
? "PAYMENT_SUCCESS"
: "PAYMENT_FAILED";
? "PAYMENT_SUCCESS" : status === ResponseScreenStatuses.CANCELLED ?
"PAYMENT_CANCELLED" : "PAYMENT_FAILED";
const defaultMessage =
status === ResponseScreenStatuses.SUCCESS
? "ORDER_THANK_YOU_NOTE"
: "PAYMENT_RE_TRY_MSG";
? "ORDER_THANK_YOU_NOTE" : status === ResponseScreenStatuses.CANCELLED ?
"PAYMENT_CANCELLED_MSG" : "PAYMENT_RE_TRY_MSG";
const msg = message || defaultMessage;

return (
Expand Down
8 changes: 6 additions & 2 deletions payment_sdk/src/components/Sheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ const Sheet: ForwardRefRenderFunction<SheetRefProps, SheetProps> = (
return paymentSuccessCtaText;
case ResponseScreenStatuses.FAILED:
return paymentFailedCtaText;
case ResponseScreenStatuses.CANCELLED:
return paymentSuccessCtaText;
default:
return "";
}
Expand All @@ -185,6 +187,8 @@ const Sheet: ForwardRefRenderFunction<SheetRefProps, SheetProps> = (
type: Actions.SET_PAYMENT_STATE,
payload: "",
});
case ResponseScreenStatuses.CANCELLED:
return closeSheet(false);
default:
return "";
}
Expand Down Expand Up @@ -213,6 +217,7 @@ const Sheet: ForwardRefRenderFunction<SheetRefProps, SheetProps> = (
closeSheet(
!(
paymentState === ResponseScreenStatuses.SUCCESS ||
paymentState === ResponseScreenStatuses.CANCELLED ||
// TODO: Fix this type error
// @ts-expect-error - Property 'COMPLETE' does not exist on type 'ResponseScreenStatuses'.
paymentState === ResponseScreenStatuses.COMPLETE
Expand All @@ -227,8 +232,7 @@ const Sheet: ForwardRefRenderFunction<SheetRefProps, SheetProps> = (
</RNAnimated.View>
{
// TODO: Fix this type error
// @ts-expect-error - Property 'COMPLETE' does not exist on type 'ResponseScreenStatuses'.
paymentState && paymentState !== ResponseScreenStatuses.COMPLETE ? (
paymentState ? (
<ResponseScreen
status={paymentState}
onPress={ctaOnPress}
Expand Down
16 changes: 15 additions & 1 deletion payment_sdk/src/context/MainStateProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ export const MainStateProvider = (props: KomojuProviderIprops) => {
payload: ResponseScreenStatuses.FAILED,
});

// when payment is cancelled by the user
const onPaymentCancelled = () => {
dispatch({
type: Actions.RESET_STATES,
payload: initialState,
});
dispatch({
type: Actions.SET_PAYMENT_STATE,
payload: ResponseScreenStatuses.CANCELLED,
});
}

const onUserCancel = async () => {
if (onDismissCallback.current) {
const sessionShowPayload = {
Expand Down Expand Up @@ -188,7 +200,7 @@ export const MainStateProvider = (props: KomojuProviderIprops) => {
let sessionResponse = await sessionShow(sessionShowPayload);

// Polling until session verification status changes
while (sessionResponse?.status === PaymentStatuses.PENDING) {
while (sessionResponse?.status === PaymentStatuses.PENDING && sessionResponse?.payment?.status !== PaymentStatuses.CANCELLED) {
sessionResponse = await sessionShow(sessionShowPayload);
}

Expand All @@ -203,6 +215,8 @@ export const MainStateProvider = (props: KomojuProviderIprops) => {
// TODO: Fix this type error
// @ts-expect-error - Argument of type 'PaymentSessionResponse' is not assignable to parameter of type 'string'.
onCompleteCallback.current(sessionResponse);
} else if (sessionResponse?.payment?.status === PaymentStatuses.CANCELLED) {
onPaymentCancelled();
} else {
onPaymentFailed();
}
Expand Down
5 changes: 5 additions & 0 deletions payment_sdk/src/util/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export enum PaymentStatuses {
ERROR = "error",
SUCCESS = "completed",
PENDING = "pending",
CANCELLED = 'cancelled'
}

export enum TokenResponseStatuses {
Expand All @@ -90,6 +91,8 @@ export enum ResponseScreenStatuses {
FAILED = "failed",
/** For displaying payment instruction screens and disabling the cancel payment popup */
COMPLETE = "complete",
/** For displaying payment instruction screens for cancelled by the user */
CANCELLED = 'cancelled',
}

export enum CurrencySign {
Expand Down Expand Up @@ -180,6 +183,7 @@ export type SessionShowResponseType = {
payment_details: {
instructions_url?: string;
};
status?: string
};
};

Expand Down Expand Up @@ -239,6 +243,7 @@ export type State = CardDetailsType &
paymentState:
| ResponseScreenStatuses.SUCCESS
| ResponseScreenStatuses.FAILED
| ResponseScreenStatuses.CANCELLED
| "";
/**
* States of the Bank transfer and Pay Easy fields.
Expand Down
Loading