-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
141 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,45 @@ | ||
import { FincodeClientService, FincodeNs, FincodeService } from 'fincode'; | ||
import { NextResponse } from 'next/server'; | ||
import { getTdsRetUrl } from "@/utils"; | ||
import { FincodeClientService, FincodeNs, FincodeService } from "fincode"; | ||
import { NextResponse } from "next/server"; | ||
|
||
export async function GET(request: Request, other: { params: any }) { | ||
console.log("fincode", FincodeService.i.configData); | ||
|
||
FincodeService.i.config({ | ||
secretKey: process.env.FINCODE_SK, | ||
publicKey: process.env.NEXT_PUBLIC_FINCODE_PK | ||
publicKey: process.env.NEXT_PUBLIC_FINCODE_PK, | ||
}); | ||
FincodeClientService.i.config({ | ||
publicKey: process.env.NEXT_PUBLIC_FINCODE_PK | ||
publicKey: process.env.NEXT_PUBLIC_FINCODE_PK, | ||
}); | ||
|
||
const { searchParams } = new URL(request.url); | ||
const order_id = searchParams.get("order_id") ?? ''; | ||
const access_id = searchParams.get("access_id") ?? ''; | ||
const card_id = searchParams.get("card_id") ?? ''; | ||
const customer_id = searchParams.get("customer_id") ?? ''; | ||
const order_id = searchParams.get("order_id") ?? ""; | ||
const access_id = searchParams.get("access_id") ?? ""; | ||
const card_id = searchParams.get("card_id") ?? ""; | ||
const customer_id = searchParams.get("customer_id") ?? ""; | ||
const data: FincodeNs.PaymentExecution = { | ||
access_id, | ||
pay_type: "Card", | ||
card_id, | ||
customer_id, | ||
method: 1, | ||
tds2_ret_url: `${process.env.NEXT_PUBLIC_APP_URL}/api/validate/${order_id}`, | ||
} | ||
tds2_ret_url: getTdsRetUrl(order_id), | ||
}; | ||
try { | ||
console.log('paymentExecution', order_id, data); | ||
|
||
const res = await FincodeService.i.paymentExecution(order_id, data); | ||
console.log("paymentExecution res", res); | ||
|
||
if (res.acs_url) { | ||
const urlSearch = new URLSearchParams(); | ||
urlSearch.set('url', res.acs_url) | ||
return NextResponse.redirect(`${process.env.NEXT_PUBLIC_APP_URL}/redirect?${urlSearch.toString()}`) | ||
urlSearch.set("url", res.acs_url); | ||
return NextResponse.redirect( | ||
`${process.env.NEXT_PUBLIC_APP_URL}/redirect?${urlSearch.toString()}` | ||
); | ||
} | ||
return NextResponse.json(res); | ||
} catch (error: any) { | ||
console.error(error?.response?.data ?? error) | ||
console.error(error?.response?.data ?? error); | ||
throw error?.response?.data ?? error; | ||
} | ||
} |
122 changes: 84 additions & 38 deletions
122
example/client-server/app/src/app/api/validate/[orderId]/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,105 @@ | ||
import { FincodeClientService, FincodeService } from 'fincode'; | ||
import { NextResponse } from 'next/server'; | ||
import { getTdsRetUrl } from "@/utils"; | ||
import { FincodeClientService, FincodeService } from "fincode"; | ||
import { NextResponse } from "next/server"; | ||
|
||
export async function POST(request: Request, { params }: { params: { orderId: string } }) { | ||
const acquire3DS2 = async (access_id: string) => { | ||
try { | ||
const acquire3DS2Result = await FincodeClientService.i.acquire3DS2Result( | ||
access_id | ||
); | ||
console.log("acquire3DS2Result", acquire3DS2Result); | ||
} catch (error: any) { | ||
console.error("acquire3DS2Result error", error?.response?.data); | ||
} | ||
}; | ||
|
||
const paymentAfterAuthentication = async ( | ||
order_id: string, | ||
access_id: string | ||
) => { | ||
try { | ||
const res = await FincodeService.i.paymentAfterAuthentication(order_id, { | ||
access_id, | ||
pay_type: "Card", | ||
}); | ||
console.log("paymentAfterAuthentication res", res); | ||
} catch (error: any) { | ||
console.error( | ||
"paymentAfterAuthentication error", | ||
error?.response?.data ?? error | ||
); | ||
|
||
return NextResponse.json({ | ||
message: "paymentAfterAuthentication error", | ||
error: error?.response?.data ?? error, | ||
}); | ||
} | ||
}; | ||
|
||
const getOrderDetail = async (orderId: string) => { | ||
const res = await FincodeService.i.getPaymentsId(orderId); | ||
console.log("orderDetail", res); | ||
}; | ||
|
||
export async function POST( | ||
request: Request, | ||
{ params }: { params: { orderId: string } } | ||
) { | ||
FincodeService.i.config({ | ||
secretKey: process.env.FINCODE_SK, | ||
publicKey: process.env.NEXT_PUBLIC_FINCODE_PK | ||
publicKey: process.env.NEXT_PUBLIC_FINCODE_PK, | ||
}); | ||
FincodeClientService.i.config({ | ||
publicKey: process.env.NEXT_PUBLIC_FINCODE_PK | ||
publicKey: process.env.NEXT_PUBLIC_FINCODE_PK, | ||
}); | ||
|
||
const bodyText = await request.text(); | ||
|
||
const bodyParam = new URLSearchParams(bodyText) | ||
const param = bodyParam.get('param') ?? '' | ||
const event = bodyParam.get('event') ?? '' | ||
const bodyParam = new URLSearchParams(bodyText); | ||
const event = bodyParam.get("event") ?? ""; | ||
const param = bodyParam.get("param") ?? ""; | ||
|
||
const { searchParams } = new URL(request.url); | ||
const access_id = searchParams.get("MD") ?? ''; | ||
const { orderId } = params | ||
const access_id = searchParams.get("MD") ?? ""; | ||
const { orderId } = params; | ||
console.log("validate", { bodyText, searchParams, params }); | ||
|
||
|
||
try { | ||
const get3DS2Result = await FincodeClientService.i.get3DS2Result(access_id) | ||
console.log("get3DS2Result", get3DS2Result); | ||
} catch (error: any) { | ||
console.error("get3DS2Result error", error?.response?.data) | ||
} | ||
|
||
if (['3DSMethodFinished', '3DSMethodSkipped'].includes(event)) { | ||
if (["3DSMethodFinished", "3DSMethodSkipped"].includes(event)) { | ||
try { | ||
const run3DS2Authentication = await FincodeService.i.run3DS2Authentication(access_id, { param: `${process.env.NEXT_PUBLIC_APP_URL}/api/validate/${orderId}` }) | ||
console.log('run3DS2Authentication', access_id, run3DS2Authentication); | ||
const run3DS2Authentication = | ||
await FincodeService.i.perform3DS2Authentication(access_id, { param }); | ||
console.log("run3DS2Authentication", access_id, run3DS2Authentication); | ||
|
||
const { challenge_url } = run3DS2Authentication; | ||
if (challenge_url) { | ||
const urlSearch = new URLSearchParams() | ||
urlSearch.set('url', challenge_url) | ||
return NextResponse.redirect(`${process.env.NEXT_PUBLIC_APP_URL}/redirect?${urlSearch.toString()}`) | ||
const urlSearch = new URLSearchParams(); | ||
urlSearch.set("url", challenge_url); | ||
return NextResponse.redirect( | ||
`${process.env.NEXT_PUBLIC_APP_URL}/redirect?${urlSearch.toString()}` | ||
); | ||
} else { | ||
const res = await paymentAfterAuthentication(orderId, access_id); | ||
if (res) { | ||
return res; | ||
} | ||
} | ||
} | ||
catch (error: any) { | ||
console.error("run3DS2Authentication error", error?.response?.data ?? error) | ||
return NextResponse.json({ message: "run3DS2Authentication error, Please wait webhook", error: error?.response?.data ?? error }) | ||
} catch (error: any) { | ||
console.error( | ||
"run3DS2Authentication error", | ||
error?.response?.data ?? error | ||
); | ||
return NextResponse.json({ | ||
message: "run3DS2Authentication error", | ||
error: error?.response?.data ?? error, | ||
}); | ||
} | ||
} | ||
if (['AuthResultReady'].includes(event)) { | ||
try { | ||
await FincodeService.i.paymentAfterAuthentication(orderId, { | ||
access_id, | ||
pay_type: "Card", | ||
}); | ||
} catch (error: any) { | ||
return NextResponse.json({ message: "AuthResultReady error", error: error?.response?.data ?? error }) | ||
if (["AuthResultReady"].includes(event)) { | ||
await acquire3DS2(access_id); | ||
const res = await paymentAfterAuthentication(orderId, access_id); | ||
if (res) { | ||
return res; | ||
} | ||
} | ||
return NextResponse.json({ message: "Please wait webhook" }) | ||
} | ||
return NextResponse.json({ message: "Purchase success!" }); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,32 @@ | ||
"use client" | ||
"use client"; | ||
import { useRouter } from "next/router"; | ||
import { useEffect, useState } from "react"; | ||
|
||
const ValidatePaymentPage = () => { | ||
const router = useRouter() | ||
const [redirectUrl, setRedirectUrl] = useState<string>() | ||
const router = useRouter(); | ||
const [redirectUrl, setRedirectUrl] = useState<string>(); | ||
|
||
useEffect(() => { | ||
const { url } = router.query; | ||
if (url) { | ||
setRedirectUrl(`${url}`) | ||
setRedirectUrl(`${url}`); | ||
// router.replace(`${url}`) | ||
window.open(`${url}`, '_blank') | ||
// setTimeout(() => { | ||
// window.open(`${url}`, "_blank"); | ||
// }, 300); | ||
} | ||
}, [router]) | ||
}, [router]); | ||
|
||
return <div> | ||
Redirecting... | ||
return ( | ||
<div> | ||
<a href={redirectUrl} target="_blank">{redirectUrl}</a> | ||
Redirecting... | ||
<div> | ||
<a href={redirectUrl} target="_blank"> | ||
{redirectUrl} | ||
</a> | ||
</div> | ||
</div> | ||
</div> | ||
} | ||
); | ||
}; | ||
|
||
export default ValidatePaymentPage; | ||
export default ValidatePaymentPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const getTdsRetUrl = (orderId: string) => | ||
`${process.env.NEXT_PUBLIC_APP_URL}/api/validate/${orderId}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.