🐛 Fix can repeat using a same order
This commit is contained in:
@@ -43,6 +43,7 @@ class SnCommand(private val sn: SnService, private val eco: Economy?) : CommandE
|
|||||||
val order: SnOrder
|
val order: SnOrder
|
||||||
try {
|
try {
|
||||||
order = orderSrv.getOrder(orderNumber);
|
order = orderSrv.getOrder(orderNumber);
|
||||||
|
orderSrv.cancelOrder(orderNumber);
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
p0.sendMessage(ChatColor.RED.toString() + "An error occurred while pulling transaction. Make sure the order is exists then try again later.")
|
p0.sendMessage(ChatColor.RED.toString() + "An error occurred while pulling transaction. Make sure the order is exists then try again later.")
|
||||||
return true;
|
return true;
|
||||||
|
@@ -19,6 +19,14 @@ data class SnOrderRequest(
|
|||||||
val amount: Double
|
val amount: Double
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class SnOrderCancelRequest(
|
||||||
|
@SerialName("client_id")
|
||||||
|
val clientId: String,
|
||||||
|
@SerialName("client_secret")
|
||||||
|
val clientSecret: String,
|
||||||
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class SnOrder(
|
data class SnOrder(
|
||||||
val id: Long,
|
val id: Long,
|
||||||
@@ -80,4 +88,23 @@ class SnOrderService(private val sn: SnService) {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun cancelOrder(id: Long): SnOrder {
|
||||||
|
val body = SnOrderCancelRequest(
|
||||||
|
sn.clientId,
|
||||||
|
sn.clientSecret,
|
||||||
|
);
|
||||||
|
val request = Request.Builder()
|
||||||
|
.url(sn.getUrl("wa", "/orders/$id/cancel"))
|
||||||
|
.post(Json.encodeToString(body).toRequestBody("application/json".toMediaTypeOrNull()))
|
||||||
|
.build()
|
||||||
|
|
||||||
|
sn.client.newCall(request).execute().use { response ->
|
||||||
|
if (!response.isSuccessful) throw IOException("Unexpected code $response")
|
||||||
|
val responseBody = response.body!!.string()
|
||||||
|
val out = json.decodeFromString<SnOrder>(responseBody)
|
||||||
|
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user