-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from r3yc0n1c/main
generate payment url route
- Loading branch information
Showing
5 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
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,12 +1,14 @@ | ||
import { Elysia } from "elysia"; | ||
import authRoutes from "@/routes/auth"; | ||
import machineRoutes from "@/routes/machine"; | ||
import paymentRoutes from "@/routes/payment"; | ||
|
||
const routes = new Elysia(); | ||
|
||
routes | ||
.get("/", () => "Hello from Elysia!") | ||
.group("/auth", (routes) => routes.use(authRoutes)) | ||
.group("/machine", (routes) => routes.use(machineRoutes)); | ||
.group("/machine", (routes) => routes.use(machineRoutes)) | ||
.group("/payment", (routes) => routes.use(paymentRoutes)); | ||
|
||
export default routes; |
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,24 @@ | ||
import { Elysia, t } from "elysia"; | ||
import paymentController from "@/routes/payment/payment.controller"; | ||
|
||
const paymentRoutes = new Elysia(); | ||
|
||
paymentRoutes | ||
.post("/generate", paymentController.GenerateURL, { | ||
body: t.Object( | ||
{ | ||
destinationWallet: t.String(), | ||
cost: t.Number() | ||
}, | ||
{ | ||
description: "Expected Destination Wallet address.", | ||
}, | ||
), | ||
detail: { | ||
summary: "Generate Payment URL", | ||
tags: ["payment"], | ||
}, | ||
}) | ||
|
||
|
||
export default paymentRoutes; |
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,34 @@ | ||
import { Connection, Keypair, PublicKey } from '@solana/web3.js'; | ||
import { encodeURL } from '@solana/pay'; | ||
import BigNumber from 'bignumber.js'; | ||
|
||
|
||
const reference = new Keypair().publicKey; | ||
const label = 'Escrow Contract'; | ||
const message = 'Funding Escrow Contract'; | ||
const memo = 'Solana Pay Public Memo'; | ||
|
||
|
||
const GenerateURL = async ({ body, set, log }) => { | ||
try { | ||
const { destinationWallet, cost } = body; | ||
|
||
const recipient = new PublicKey(destinationWallet); | ||
const amount = new BigNumber(cost); | ||
|
||
const url: URL = encodeURL({ recipient, amount, reference, label, message, memo }); | ||
// console.log('Payment request link:', url); | ||
|
||
set.status = 201; | ||
return url; | ||
} catch (err) { | ||
log.error(err); | ||
set.status = 500; | ||
return { message: "Internal Server Error" }; | ||
} | ||
}; | ||
|
||
|
||
export default { | ||
GenerateURL | ||
}; |