-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
48 lines (39 loc) · 1.2 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import express from "express"
import { Product } from "./entities/Product"
import { PaymentMethod } from "./paymentpb/payment_service_pb"
import { OrderService } from "./services/OrderService"
function main() {
const server = express()
const orderService = new OrderService()
// buat endpoint post
server.post("/order", (req, res) => {
// fake default order
let p1 = new Product(1, "Mie Indomie", 1500)
let p2 = new Product(2, "Kornet", 5000)
const paymentLink = orderService.placeOrder(
"GT903K",
Array<Product>(p1, p2),
PaymentMethod.GOPAY
).then(paymentLink => {
res.send({
"success": true,
"message": "Order Created",
"data": {
"payment_link": paymentLink
}
})
}).catch(err => {
res.send({
"success": false,
"message": "Order Failed",
"data": {
"payment_link": err
}
})
})
})
server.listen("5000", () => {
console.log("Order Service Started")
})
}
main()