Skip to content

Commit

Permalink
[change] Select toast level based on payment status
Browse files Browse the repository at this point in the history
The `getPaymentStatus` would use toast.error if the response
included  "error" payment status. It would use toast.info
otherwise.
  • Loading branch information
pandafy committed Nov 16, 2023
1 parent 4507596 commit f5a8c3a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion client/utils/get-payment-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export const getPaymentStatus = async (orgSlug, paymentId, tokenInfo) => {
});
if (response.status === 200) {
if (response.data.message) {
toast.error(response.data.message);
if (response.data.status === "failed") {
toast.error(response.data.message);
} else {
toast.info(response.data.message);
}
}
return response.data.status;
}
Expand Down
4 changes: 4 additions & 0 deletions client/utils/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,12 +783,14 @@ describe("getPaymentStatusRedirectUrl tests", () => {
});
it("should return success URL if payment status is success", async () => {
const {orgSlug, paymentId, tokenInfo, setUserData, userData} = getArgs();
const infoToast = jest.spyOn(dependency.toast, "info");
axios.mockImplementationOnce(() =>
Promise.resolve({
status: 200,
statusText: "OK",
data: {
status: "success",
message: "Payment succeeded",
},
}),
);
Expand All @@ -806,6 +808,8 @@ describe("getPaymentStatusRedirectUrl tests", () => {
mustLogin: true,
payment_url: null,
});
expect(infoToast).toHaveBeenCalledTimes(1);
expect(infoToast).toHaveBeenCalledWith("Payment succeeded");
});
it("should return failure URL if payment status is failed", async () => {
const {orgSlug, paymentId, tokenInfo, setUserData, userData} = getArgs();
Expand Down

0 comments on commit f5a8c3a

Please sign in to comment.