-
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.
feat: do once billing checkin callback
- Loading branch information
1 parent
f79e76e
commit 5e62cf9
Showing
4 changed files
with
56 additions
and
2 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
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,43 @@ | ||
package biz | ||
|
||
import config.Props | ||
import io.vertx.core.Vertx | ||
import io.vertx.core.http.HttpClient | ||
import okhttp3.MediaType.Companion.toMediaType | ||
import okhttp3.OkHttpClient | ||
import okhttp3.Request | ||
import okhttp3.RequestBody.Companion.toRequestBody | ||
import org.slf4j.LoggerFactory | ||
|
||
private val log = LoggerFactory.getLogger("RpcKt")!! | ||
|
||
val C: OkHttpClient = OkHttpClient.Builder() | ||
.build() | ||
|
||
private val JSON_MT = "application/json; charset=utf-8".toMediaType() | ||
|
||
private lateinit var client: HttpClient | ||
|
||
fun setupClient(v: Vertx) { | ||
client = v.createHttpClient() | ||
} | ||
|
||
fun doSendBillingCheckIn(cdk: String, resource: String, ua: String) { | ||
val body = """ | ||
{ | ||
"cdk": "$cdk", | ||
"application": "$resource", | ||
"user_agent": "$ua", | ||
"module": "", | ||
} | ||
""".trimIndent().toRequestBody(contentType = JSON_MT) | ||
val resp = Request.Builder() | ||
.url(Props.Extra.billingCheckInUrl) | ||
.post(body) | ||
.build().let { | ||
C.newCall(it).execute() | ||
} | ||
if (resp.code != 200) { | ||
log.error("BillingCheckIn response {}", resp.body?.string()) | ||
} | ||
} |
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