Compare commits
4 Commits
596e210c8a
...
master
Author | SHA1 | Date | |
---|---|---|---|
788e7b1f96 | |||
322e48e8a7 | |||
b358e0bce4 | |||
6e27d8ad2e |
@@ -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");
|
||||||
|
|
||||||
@@ -422,15 +424,16 @@ static void IAP_OnCommand(IAPCommand* cmd, void*)
|
|||||||
{
|
{
|
||||||
switch (cmd->m_Command)
|
switch (cmd->m_Command)
|
||||||
{
|
{
|
||||||
case IAP_PRODUCT_RESULT:
|
case IAP_PRODUCT_RESULT:
|
||||||
HandleProductResult(cmd);
|
HandleProductResult(cmd);
|
||||||
break;
|
break;
|
||||||
case IAP_PURCHASE_RESULT:
|
|
||||||
HandlePurchaseResult(cmd);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
case IAP_PURCHASE_RESULT:
|
||||||
assert(false);
|
HandlePurchaseResult(cmd);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd->m_Data) {
|
if (cmd->m_Data) {
|
||||||
|
@@ -261,7 +261,6 @@ static void CopyTransaction(SKPaymentTransaction* transaction, IAPTransaction* o
|
|||||||
|
|
||||||
out->ident = strdup([transaction.payment.productIdentifier UTF8String]);
|
out->ident = strdup([transaction.payment.productIdentifier UTF8String]);
|
||||||
|
|
||||||
|
|
||||||
if (transaction.transactionDate)
|
if (transaction.transactionDate)
|
||||||
out->date = strdup([[dateFormatter stringFromDate: transaction.transactionDate] UTF8String]);
|
out->date = strdup([[dateFormatter stringFromDate: transaction.transactionDate] UTF8String]);
|
||||||
out->state = transaction.transactionState;
|
out->state = transaction.transactionState;
|
||||||
@@ -274,9 +273,15 @@ static void CopyTransaction(SKPaymentTransaction* transaction, IAPTransaction* o
|
|||||||
if (transaction.transactionState == SKPaymentTransactionStatePurchased) {
|
if (transaction.transactionState == SKPaymentTransactionStatePurchased) {
|
||||||
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
|
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
|
||||||
NSData *receiptData = [NSData dataWithContentsOfURL:receiptURL];
|
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);
|
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) {
|
if (transaction.transactionState == SKPaymentTransactionStateRestored && transaction.originalTransaction) {
|
||||||
@@ -325,6 +330,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;
|
||||||
}
|
}
|
||||||
|
@@ -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()
|
||||||
{
|
{
|
||||||
|
@@ -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>
|
||||||
|
|
||||||
|
@@ -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
|
||||||
|
Reference in New Issue
Block a user