refactor/extension #2

Merged
Frozenverse merged 2 commits from refactor/extension into master 2024-05-04 17:40:22 +02:00
5 changed files with 20 additions and 16 deletions

View File

@ -213,8 +213,9 @@ static int IAP_SetListener(lua_State* L)
bool had_previous = iap->m_Listener != 0; bool had_previous = iap->m_Listener != 0;
if (iap->m_Listener) if (iap->m_Listener) {
dmScript::DestroyCallback(iap->m_Listener); dmScript::DestroyCallback(iap->m_Listener);
}
iap->m_Listener = dmScript::CreateCallback(L, 1); iap->m_Listener = dmScript::CreateCallback(L, 1);
@ -223,7 +224,10 @@ static int IAP_SetListener(lua_State* L)
dmAndroid::ThreadAttacher threadAttacher; dmAndroid::ThreadAttacher threadAttacher;
JNIEnv* env = threadAttacher.GetEnv(); JNIEnv* env = threadAttacher.GetEnv();
env->CallVoidMethod(g_IAP.m_IAP, g_IAP.m_ProcessPendingConsumables, g_IAP.m_IAPJNI); env->CallVoidMethod(g_IAP.m_IAP, g_IAP.m_ProcessPendingConsumables, g_IAP.m_IAPJNI);
dmLogInfo("IAP: Processing pending transactions");
} }
dmLogInfo("IAP listener set");
return 0; return 0;
} }
@ -348,7 +352,7 @@ static void HandlePurchaseResult(const IAPCommand* cmd)
if (!dmScript::SetupCallback(cmd->m_Callback)) if (!dmScript::SetupCallback(cmd->m_Callback))
{ {
dmLogError("Failed to setup callback"); dmLogError("Failed to setup callback for purchase result!");
assert(top == lua_gettop(L)); assert(top == lua_gettop(L));
return; return;
} }
@ -364,7 +368,7 @@ static void HandlePurchaseResult(const IAPCommand* cmd)
IAP_PushError(L, "purchase response was null", REASON_UNSPECIFIED); IAP_PushError(L, "purchase response was null", REASON_UNSPECIFIED);
} }
} else if (cmd->m_ResponseCode == BILLING_RESPONSE_RESULT_USER_CANCELED) { } else if (cmd->m_ResponseCode == BILLING_RESPONSE_RESULT_USER_CANCELED) {
dmLogError("User canceled purchase"); dmLogInfo("User canceled purchase");
lua_pushnil(L); lua_pushnil(L);
IAP_PushError(L, "user canceled purchase", REASON_USER_CANCELED); IAP_PushError(L, "user canceled purchase", REASON_USER_CANCELED);
} else { } else {
@ -385,9 +389,7 @@ static dmExtension::Result InitializeIAP(dmExtension::Params* params)
dmAndroid::ThreadAttacher threadAttacher; dmAndroid::ThreadAttacher threadAttacher;
JNIEnv* env = threadAttacher.GetEnv(); JNIEnv* env = threadAttacher.GetEnv();
const char* provider = dmConfigFile::GetString(params->m_ConfigFile, "android.iap_provider", "GooglePlay");
const char* class_name = "com.defold.iap.IapGooglePlay"; const char* class_name = "com.defold.iap.IapGooglePlay";
jclass iap_class = dmAndroid::LoadClass(env, class_name); jclass iap_class = dmAndroid::LoadClass(env, class_name);
jclass iap_jni_class = dmAndroid::LoadClass(env, "com.defold.iap.IapJNI"); jclass iap_jni_class = dmAndroid::LoadClass(env, "com.defold.iap.IapJNI");
@ -425,6 +427,7 @@ static void IAP_OnCommand(IAPCommand* cmd, void*)
case IAP_PRODUCT_RESULT: case IAP_PRODUCT_RESULT:
HandleProductResult(cmd); HandleProductResult(cmd);
break; break;
case IAP_PURCHASE_RESULT: case IAP_PURCHASE_RESULT:
HandlePurchaseResult(cmd); HandlePurchaseResult(cmd);
break; break;

View File

@ -325,6 +325,7 @@ static void HandlePurchaseResult(IAPCommand* cmd)
if (!dmScript::SetupCallback(cmd->m_Callback)) if (!dmScript::SetupCallback(cmd->m_Callback))
{ {
dmLogError("Failed to setup callback for purchase result");
assert(top == lua_gettop(L)); assert(top == lua_gettop(L));
return; return;
} }

View File

@ -1,4 +1,4 @@
#if !defined(DM_PLATFORM_HTML5) && !defined(DM_PLATFORM_ANDROID) && !defined(DM_PLATFORM_IOS) #if !defined(DM_PLATFORM_ANDROID) && !defined(DM_PLATFORM_IOS)
extern "C" void IAPExt() extern "C" void IAPExt()
{ {

View File

@ -1,4 +1,4 @@
#if defined(DM_PLATFORM_HTML5) || defined(DM_PLATFORM_ANDROID) || defined(DM_PLATFORM_IOS) #if defined(DM_PLATFORM_ANDROID) || defined(DM_PLATFORM_IOS)
#include <dmsdk/sdk.h> #include <dmsdk/sdk.h>

View File

@ -1,4 +1,4 @@
#if defined(DM_PLATFORM_HTML5) || defined(DM_PLATFORM_ANDROID) || defined(DM_PLATFORM_IOS) #if defined(DM_PLATFORM_ANDROID) || defined(DM_PLATFORM_IOS)
#ifndef IAP_PRIVATE_H #ifndef IAP_PRIVATE_H
#define IAP_PRIVATE_H #define IAP_PRIVATE_H