refactor/extension #2
@ -213,8 +213,9 @@ static int IAP_SetListener(lua_State* L)
|
||||
|
||||
bool had_previous = iap->m_Listener != 0;
|
||||
|
||||
if (iap->m_Listener)
|
||||
if (iap->m_Listener) {
|
||||
dmScript::DestroyCallback(iap->m_Listener);
|
||||
}
|
||||
|
||||
iap->m_Listener = dmScript::CreateCallback(L, 1);
|
||||
|
||||
@ -223,7 +224,10 @@ static int IAP_SetListener(lua_State* L)
|
||||
dmAndroid::ThreadAttacher threadAttacher;
|
||||
JNIEnv* env = threadAttacher.GetEnv();
|
||||
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;
|
||||
}
|
||||
|
||||
@ -348,7 +352,7 @@ static void HandlePurchaseResult(const IAPCommand* cmd)
|
||||
|
||||
if (!dmScript::SetupCallback(cmd->m_Callback))
|
||||
{
|
||||
dmLogError("Failed to setup callback");
|
||||
dmLogError("Failed to setup callback for purchase result!");
|
||||
assert(top == lua_gettop(L));
|
||||
return;
|
||||
}
|
||||
@ -364,7 +368,7 @@ static void HandlePurchaseResult(const IAPCommand* cmd)
|
||||
IAP_PushError(L, "purchase response was null", REASON_UNSPECIFIED);
|
||||
}
|
||||
} else if (cmd->m_ResponseCode == BILLING_RESPONSE_RESULT_USER_CANCELED) {
|
||||
dmLogError("User canceled purchase");
|
||||
dmLogInfo("User canceled purchase");
|
||||
lua_pushnil(L);
|
||||
IAP_PushError(L, "user canceled purchase", REASON_USER_CANCELED);
|
||||
} else {
|
||||
@ -385,9 +389,7 @@ static dmExtension::Result InitializeIAP(dmExtension::Params* params)
|
||||
dmAndroid::ThreadAttacher threadAttacher;
|
||||
JNIEnv* env = threadAttacher.GetEnv();
|
||||
|
||||
const char* provider = dmConfigFile::GetString(params->m_ConfigFile, "android.iap_provider", "GooglePlay");
|
||||
const char* class_name = "com.defold.iap.IapGooglePlay";
|
||||
|
||||
jclass iap_class = dmAndroid::LoadClass(env, class_name);
|
||||
jclass iap_jni_class = dmAndroid::LoadClass(env, "com.defold.iap.IapJNI");
|
||||
|
||||
@ -422,15 +424,16 @@ static void IAP_OnCommand(IAPCommand* cmd, void*)
|
||||
{
|
||||
switch (cmd->m_Command)
|
||||
{
|
||||
case IAP_PRODUCT_RESULT:
|
||||
HandleProductResult(cmd);
|
||||
break;
|
||||
case IAP_PURCHASE_RESULT:
|
||||
HandlePurchaseResult(cmd);
|
||||
break;
|
||||
case IAP_PRODUCT_RESULT:
|
||||
HandleProductResult(cmd);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
case IAP_PURCHASE_RESULT:
|
||||
HandlePurchaseResult(cmd);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
||||
if (cmd->m_Data) {
|
||||
|
@ -325,6 +325,7 @@ static void HandlePurchaseResult(IAPCommand* cmd)
|
||||
|
||||
if (!dmScript::SetupCallback(cmd->m_Callback))
|
||||
{
|
||||
dmLogError("Failed to setup callback for purchase result");
|
||||
assert(top == lua_gettop(L));
|
||||
return;
|
||||
}
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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
|
||||
#define IAP_PRIVATE_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user