fix(paytr): encode hyphens in tenantId as Z in merchantOid

PayTR rejects merchant_oid with non-alphanumeric chars. Real Appwrite
tenant IDs are hex (a-z0-9) and safe, but demo-tenant-001 contains
hyphens. Encode - as Z (never appears in Appwrite hex IDs) in the
merchantOid; decode back in the callback.
This commit is contained in:
egecankomur
2026-05-14 23:12:36 +03:00
parent 1618db57db
commit 7660901eb0
2 changed files with 7 additions and 5 deletions
+3 -2
View File
@@ -16,8 +16,9 @@ export async function POST(req: Request): Promise<Response> {
}
if (status === "success") {
// merchant_oid: {tenantId}T{timestamp}{random}P{plan}X{period}
const tenantId = merchantOid.split("T")[0];
// merchant_oid: {encodedTenantId}T{timestamp}{random}P{plan}X{period}
// Hyphens were encoded as Z — decode back
const tenantId = (merchantOid.split("T")[0] ?? "").replace(/Z/g, "-");
const planPart = merchantOid.split("P")[1]; // "{plan}X{period}"
const plan = (planPart?.split("X")[0] ?? "pro") as TenantPlan;
const period = (planPart?.split("X")[1] ?? "monthly") as PlanPeriod;