Compare commits
7 Commits
e8a39d9fee
...
master
Author | SHA1 | Date | |
---|---|---|---|
788e7b1f96 | |||
322e48e8a7 | |||
b358e0bce4 | |||
6e27d8ad2e | |||
596e210c8a | |||
406a594c8d | |||
8243491de2 |
17
.vscode/c_cpp_properties.json
vendored
Normal file
17
.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Linux",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**",
|
||||
"/home/nick/Workspace/defold/engine/**",
|
||||
],
|
||||
"defines": [],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "c17",
|
||||
"cppStandard": "gnu++17",
|
||||
"intelliSenseMode": "linux-gcc-x64"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
@@ -1,5 +1,10 @@
|
||||
#if defined(DM_PLATFORM_ANDROID)
|
||||
|
||||
#define EXTENSION_NAME IAPExt
|
||||
#define LIB_NAME "IAPExt"
|
||||
#define MODULE_NAME "IAPExt"
|
||||
#define DLIB_LOG_DOMAIN LIB_NAME
|
||||
|
||||
#include <dmsdk/sdk.h>
|
||||
#include <dmsdk/dlib/android.h>
|
||||
|
||||
@@ -8,8 +13,6 @@
|
||||
#include "iap.h"
|
||||
#include "iap_private.h"
|
||||
|
||||
#define LIB_NAME "iap"
|
||||
|
||||
struct IAP
|
||||
{
|
||||
IAP()
|
||||
@@ -210,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);
|
||||
|
||||
@@ -220,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;
|
||||
}
|
||||
|
||||
@@ -267,6 +274,7 @@ JNIEXPORT void JNICALL Java_com_defold_iap_IapJNI_onProductsResult(JNIEnv* env,
|
||||
cmd->m_Data = strdup(pl);
|
||||
env->ReleaseStringUTFChars(productList, pl);
|
||||
}
|
||||
|
||||
IAP_Queue_Push(&g_IAP.m_CommandQueue, cmd);
|
||||
}
|
||||
|
||||
@@ -288,6 +296,7 @@ JNIEXPORT void JNICALL Java_com_defold_iap_IapJNI_onPurchaseResult__ILjava_lang_
|
||||
cmd.m_Data = strdup(pd);
|
||||
env->ReleaseStringUTFChars(purchaseData, pd);
|
||||
}
|
||||
|
||||
IAP_Queue_Push(&g_IAP.m_CommandQueue, &cmd);
|
||||
}
|
||||
|
||||
@@ -343,6 +352,7 @@ static void HandlePurchaseResult(const IAPCommand* cmd)
|
||||
|
||||
if (!dmScript::SetupCallback(cmd->m_Callback))
|
||||
{
|
||||
dmLogError("Failed to setup callback for purchase result!");
|
||||
assert(top == lua_gettop(L));
|
||||
return;
|
||||
}
|
||||
@@ -358,6 +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) {
|
||||
dmLogInfo("User canceled purchase");
|
||||
lua_pushnil(L);
|
||||
IAP_PushError(L, "user canceled purchase", REASON_USER_CANCELED);
|
||||
} else {
|
||||
@@ -367,9 +378,7 @@ static void HandlePurchaseResult(const IAPCommand* cmd)
|
||||
}
|
||||
|
||||
dmScript::PCall(L, 3, 0);
|
||||
|
||||
dmScript::TeardownCallback(cmd->m_Callback);
|
||||
|
||||
assert(top == lua_gettop(L));
|
||||
}
|
||||
|
||||
@@ -380,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");
|
||||
|
||||
@@ -420,6 +427,7 @@ static void IAP_OnCommand(IAPCommand* cmd, void*)
|
||||
case IAP_PRODUCT_RESULT:
|
||||
HandleProductResult(cmd);
|
||||
break;
|
||||
|
||||
case IAP_PURCHASE_RESULT:
|
||||
HandlePurchaseResult(cmd);
|
||||
break;
|
||||
@@ -454,9 +462,10 @@ static dmExtension::Result FinalizeIAP(dmExtension::Params* params)
|
||||
env->DeleteGlobalRef(g_IAP.m_IAP);
|
||||
env->DeleteGlobalRef(g_IAP.m_IAPJNI);
|
||||
g_IAP.m_IAP = NULL;
|
||||
|
||||
return dmExtension::RESULT_OK;
|
||||
}
|
||||
|
||||
DM_DECLARE_EXTENSION(IAPExt, "IAP", 0, 0, InitializeIAP, UpdateIAP, 0, FinalizeIAP)
|
||||
DM_DECLARE_EXTENSION(EXTENSION_NAME, LIB_NAME, 0, 0, InitializeIAP, UpdateIAP, 0, FinalizeIAP)
|
||||
|
||||
#endif //DM_PLATFORM_ANDROID
|
||||
|
@@ -1,5 +1,10 @@
|
||||
#if defined(DM_PLATFORM_IOS)
|
||||
|
||||
#define EXTENSION_NAME IAPExt
|
||||
#define LIB_NAME "IAPExt"
|
||||
#define MODULE_NAME "IAPExt"
|
||||
#define DLIB_LOG_DOMAIN LIB_NAME
|
||||
|
||||
#include <dmsdk/sdk.h>
|
||||
|
||||
#include "iap.h"
|
||||
@@ -9,8 +14,6 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <StoreKit/StoreKit.h>
|
||||
|
||||
#define LIB_NAME "iap"
|
||||
|
||||
struct IAP;
|
||||
|
||||
@interface SKPaymentTransactionObserver : NSObject<SKPaymentTransactionObserver>
|
||||
@@ -258,7 +261,6 @@ static void CopyTransaction(SKPaymentTransaction* transaction, IAPTransaction* o
|
||||
|
||||
out->ident = strdup([transaction.payment.productIdentifier UTF8String]);
|
||||
|
||||
|
||||
if (transaction.transactionDate)
|
||||
out->date = strdup([[dateFormatter stringFromDate: transaction.transactionDate] UTF8String]);
|
||||
out->state = transaction.transactionState;
|
||||
@@ -271,9 +273,15 @@ static void CopyTransaction(SKPaymentTransaction* transaction, IAPTransaction* o
|
||||
if (transaction.transactionState == SKPaymentTransactionStatePurchased) {
|
||||
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
|
||||
NSData *receiptData = [NSData dataWithContentsOfURL:receiptURL];
|
||||
out->receipt_length = receiptData.length;
|
||||
|
||||
NSString *receiptString = [receiptData base64EncodedStringWithOptions:0];
|
||||
out->receipt_length = receiptString.length;
|
||||
out->receipt = (const char*)malloc(out->receipt_length);
|
||||
memcpy((void*)out->receipt, receiptData.bytes, out->receipt_length);
|
||||
memcpy((void*)out->receipt, [receiptString UTF8String], out->receipt_length);
|
||||
|
||||
// out->receipt_length = receiptData.length;
|
||||
// out->receipt = (const char*)malloc(out->receipt_length);
|
||||
// memcpy((void*)out->receipt, receiptData.bytes, out->receipt_length);
|
||||
}
|
||||
|
||||
if (transaction.transactionState == SKPaymentTransactionStateRestored && transaction.originalTransaction) {
|
||||
@@ -322,6 +330,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;
|
||||
}
|
||||
@@ -636,6 +645,5 @@ static dmExtension::Result FinalizeIAP(dmExtension::Params* params)
|
||||
}
|
||||
|
||||
|
||||
DM_DECLARE_EXTENSION(IAPExt, "IAP", 0, 0, InitializeIAP, UpdateIAP, 0, FinalizeIAP)
|
||||
|
||||
DM_DECLARE_EXTENSION(EXTENSION_NAME, LIB_NAME, 0, 0, InitializeIAP, UpdateIAP, 0, FinalizeIAP)
|
||||
#endif // DM_PLATFORM_IOS
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user