32 lines
611 B
GDScript
32 lines
611 B
GDScript
class_name PayApi
|
|
extends RefCounted
|
|
|
|
var _api_client: ApiClient
|
|
|
|
|
|
func _init(api_client: ApiClient = null) -> void:
|
|
_api_client = api_client
|
|
|
|
|
|
func set_api_client(api_client: ApiClient) -> void:
|
|
_api_client = api_client
|
|
|
|
|
|
func buy(token: String, pay_id: int) -> Dictionary:
|
|
return await _post("pay/pay", {
|
|
"token": token,
|
|
"pay_id": pay_id
|
|
})
|
|
|
|
|
|
func _post(path: String, payload: Dictionary) -> Dictionary:
|
|
if _api_client == null:
|
|
return {
|
|
"ok": false,
|
|
"offline": true,
|
|
"status": 0,
|
|
"body": {},
|
|
"text": "PayApi missing ApiClient."
|
|
}
|
|
return await _api_client.post_json(path, payload)
|