generated from alpas/starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.kt
53 lines (37 loc) · 1.3 KB
/
start.kt
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
49
50
51
52
53
package com.stripe.example
import com.stripe.Stripe
import com.stripe.example.configs.MailConfig
import com.stripe.model.PaymentIntent
import com.stripe.param.PaymentIntentCreateParams
import dev.alpas.Alpas
import dev.alpas.JsonSerializer
import dev.alpas.config
import dev.alpas.http.HttpCall
import dev.alpas.mailing.MailMessage
fun main(args: Array<String>) = Alpas(args).routes {
group {
get{ render("welcome")}
post("create-payment-intent") {
Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"
val createParams = PaymentIntentCreateParams.Builder()
.setCurrency("usd")
.setAmount(1400)
.build()
val intent = PaymentIntent.create(createParams)
val paymentResponse = CreatePaymentResponse(intent.clientSecret)
reply(JsonSerializer.serialize(paymentResponse))
}
post("payment-success") {
send(this)
}
}.middlewareGroup("web")
}.ignite()
class CreatePaymentResponse(val clientSecret: String)
fun send(call: HttpCall) {
val mail = MailMessage().apply {
to = call.body
subject = "Order Confirmed"
message = "Here is your order receipt!"
}
call.config<MailConfig>().driver("sparkpost").send(mail)
}