fix(subscription): preselect pay channel before navigation
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { buildPendingPaymentSubscriptionUrl } from "../pending_payment_order";
|
||||
|
||||
describe("pending payment order helpers", () => {
|
||||
it("keeps the pay channel when rebuilding subscription return urls", () => {
|
||||
expect(
|
||||
buildPendingPaymentSubscriptionUrl({
|
||||
payChannel: "ezpay",
|
||||
returnTo: "chat",
|
||||
subscriptionType: "topup",
|
||||
}),
|
||||
).toBe("/subscription?type=topup&payChannel=ezpay&paymentReturn=1&returnTo=chat");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { PayChannel } from "@/data/dto/payment";
|
||||
|
||||
export function getDefaultPayChannelForCountryCode(
|
||||
countryCode: string | null | undefined,
|
||||
): PayChannel {
|
||||
return countryCode?.trim().toUpperCase() === "PH" ? "ezpay" : "stripe";
|
||||
}
|
||||
@@ -43,10 +43,14 @@ export function clearPendingPaymentOrder(): Promise<Result<void>> {
|
||||
}
|
||||
|
||||
export function buildPendingPaymentSubscriptionUrl(
|
||||
order: Pick<PendingPaymentOrder, "subscriptionType" | "returnTo">,
|
||||
order: Pick<
|
||||
PendingPaymentOrder,
|
||||
"payChannel" | "returnTo" | "subscriptionType"
|
||||
>,
|
||||
): string {
|
||||
const params = new URLSearchParams({
|
||||
type: order.subscriptionType,
|
||||
payChannel: order.payChannel,
|
||||
paymentReturn: "1",
|
||||
});
|
||||
if (order.returnTo) params.set("returnTo", order.returnTo);
|
||||
|
||||
Reference in New Issue
Block a user