Skip to content

Commit

Permalink
Merge pull request #59 from r3yc0n1c/main
Browse files Browse the repository at this point in the history
generate payment url route
  • Loading branch information
zeitgeistxx authored Jun 29, 2024
2 parents 4c081d6 + 3e095fa commit 0647324
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 1 deletion.
Binary file modified backend/bun.lockb
Binary file not shown.
3 changes: 3 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"@elysiajs/swagger": "^1.0.5",
"@lucia-auth/adapter-prisma": "^4.0.1",
"@prisma/client": "^5.16.1",
"@solana/pay": "^0.2.5",
"@solana/web3.js": "^1.94.0",
"bignumber.js": "^9.1.2",
"elysia": "latest",
"lucia": "^3.2.0",
"pino-pretty": "^11.2.1",
Expand Down
4 changes: 3 additions & 1 deletion backend/src/routes/index.ts
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;
24 changes: 24 additions & 0 deletions backend/src/routes/payment/index.ts
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;
34 changes: 34 additions & 0 deletions backend/src/routes/payment/payment.controller.ts
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
};

0 comments on commit 0647324

Please sign in to comment.