mirror of
https://github.com/defold/extension-iap
synced 2025-06-27 02:17:51 +02:00
Updated to use dmScript::LuaToJson()
This commit is contained in:
parent
961a43f732
commit
501af9c90d
@ -306,23 +306,8 @@ static void HandleProductResult(const IAPCommand* cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cmd->m_ResponseCode == BILLING_RESPONSE_RESULT_OK) {
|
if (cmd->m_ResponseCode == BILLING_RESPONSE_RESULT_OK) {
|
||||||
dmJson::Document doc;
|
const char* json = (const char*)cmd->m_Data;
|
||||||
dmJson::Result r = dmJson::Parse((const char*) cmd->m_Data, &doc);
|
dmScript::JsonToLua(L, json, strlen(json)); // throws lua error if it fails
|
||||||
if (r == dmJson::RESULT_OK && doc.m_NodeCount > 0) {
|
|
||||||
char err_str[128];
|
|
||||||
if (dmScript::JsonToLua(L, &doc, 0, err_str, sizeof(err_str)) < 0) {
|
|
||||||
dmLogError("Failed converting product result JSON to Lua; %s", err_str);
|
|
||||||
lua_pushnil(L);
|
|
||||||
IAP_PushError(L, "failed to convert JSON to Lua for product response", REASON_UNSPECIFIED);
|
|
||||||
} else {
|
|
||||||
lua_pushnil(L);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dmLogError("Failed to parse product response (%d)", r);
|
|
||||||
lua_pushnil(L);
|
|
||||||
IAP_PushError(L, "failed to parse product response", REASON_UNSPECIFIED);
|
|
||||||
}
|
|
||||||
dmJson::Free(&doc);
|
|
||||||
} else {
|
} else {
|
||||||
dmLogError("IAP error %d", cmd->m_ResponseCode);
|
dmLogError("IAP error %d", cmd->m_ResponseCode);
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
@ -356,23 +341,8 @@ static void HandlePurchaseResult(const IAPCommand* cmd)
|
|||||||
|
|
||||||
if (cmd->m_ResponseCode == BILLING_RESPONSE_RESULT_OK) {
|
if (cmd->m_ResponseCode == BILLING_RESPONSE_RESULT_OK) {
|
||||||
if (cmd->m_Data != 0) {
|
if (cmd->m_Data != 0) {
|
||||||
dmJson::Document doc;
|
const char* json = (const char*)cmd->m_Data;
|
||||||
dmJson::Result r = dmJson::Parse((const char*) cmd->m_Data, &doc);
|
dmScript::JsonToLua(L, json, strlen(json)); // throws lua error if it fails
|
||||||
if (r == dmJson::RESULT_OK && doc.m_NodeCount > 0) {
|
|
||||||
char err_str[128];
|
|
||||||
if (dmScript::JsonToLua(L, &doc, 0, err_str, sizeof(err_str)) < 0) {
|
|
||||||
dmLogError("Failed converting purchase JSON result to Lua; %s", err_str);
|
|
||||||
lua_pushnil(L);
|
|
||||||
IAP_PushError(L, "failed to convert purchase response JSON to Lua", REASON_UNSPECIFIED);
|
|
||||||
} else {
|
|
||||||
lua_pushnil(L);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dmLogError("Failed to parse purchase response (%d)", r);
|
|
||||||
lua_pushnil(L);
|
|
||||||
IAP_PushError(L, "failed to parse purchase response", REASON_UNSPECIFIED);
|
|
||||||
}
|
|
||||||
dmJson::Free(&doc);
|
|
||||||
} else {
|
} else {
|
||||||
dmLogError("IAP error, purchase response was null");
|
dmLogError("IAP error, purchase response was null");
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
|
@ -46,23 +46,7 @@ static void IAPList_Callback(void* luacallback, const char* result_json)
|
|||||||
|
|
||||||
if(result_json != 0)
|
if(result_json != 0)
|
||||||
{
|
{
|
||||||
dmJson::Document doc;
|
dmScript::JsonToLua(L, result_json, strlen(result_json)); // throws lua error if it fails
|
||||||
dmJson::Result r = dmJson::Parse(result_json, &doc);
|
|
||||||
if (r == dmJson::RESULT_OK && doc.m_NodeCount > 0) {
|
|
||||||
char err_str[128];
|
|
||||||
if (dmScript::JsonToLua(L, &doc, 0, err_str, sizeof(err_str)) < 0) {
|
|
||||||
dmLogError("Failed converting list result JSON to Lua; %s", err_str);
|
|
||||||
lua_pushnil(L);
|
|
||||||
IAP_PushError(L, "Failed converting list result JSON to Lua", REASON_UNSPECIFIED);
|
|
||||||
} else {
|
|
||||||
lua_pushnil(L);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dmLogError("Failed to parse list result JSON (%d)", r);
|
|
||||||
lua_pushnil(L);
|
|
||||||
IAP_PushError(L, "Failed to parse list result JSON", REASON_UNSPECIFIED);
|
|
||||||
}
|
|
||||||
dmJson::Free(&doc);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -112,23 +96,7 @@ static void IAPListener_Callback(void* luacallback, const char* result_json, int
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (result_json) {
|
if (result_json) {
|
||||||
dmJson::Document doc;
|
dmScript::JsonToLua(L, result_json, strlen(result_json)); // throws lua error if it fails
|
||||||
dmJson::Result r = dmJson::Parse(result_json, &doc);
|
|
||||||
if (r == dmJson::RESULT_OK && doc.m_NodeCount > 0) {
|
|
||||||
char err_str[128];
|
|
||||||
if (dmScript::JsonToLua(L, &doc, 0, err_str, sizeof(err_str)) < 0) {
|
|
||||||
dmLogError("Failed converting purchase result JSON to Lua; %s", err_str);
|
|
||||||
lua_pushnil(L);
|
|
||||||
IAP_PushError(L, "failed converting purchase result JSON to Lua", REASON_UNSPECIFIED);
|
|
||||||
} else {
|
|
||||||
lua_pushnil(L);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dmLogError("Failed to parse purchase response (%d)", r);
|
|
||||||
lua_pushnil(L);
|
|
||||||
IAP_PushError(L, "failed to parse purchase response", REASON_UNSPECIFIED);
|
|
||||||
}
|
|
||||||
dmJson::Free(&doc);
|
|
||||||
} else {
|
} else {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
switch(error_code)
|
switch(error_code)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user