mirror of
https://github.com/defold/extension-iap
synced 2025-09-28 09:32:19 +02:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
649a8a1ebf | ||
|
5c09447e37 | ||
|
ad06de7b9c | ||
|
d74c97d5c7 | ||
|
f97a7ee6b6 | ||
|
5f3f43fb2e |
@@ -308,6 +308,7 @@ static void HandleProductResult(const IAPCommand* cmd)
|
|||||||
if (cmd->m_ResponseCode == BILLING_RESPONSE_RESULT_OK) {
|
if (cmd->m_ResponseCode == BILLING_RESPONSE_RESULT_OK) {
|
||||||
const char* json = (const char*)cmd->m_Data;
|
const char* json = (const char*)cmd->m_Data;
|
||||||
dmScript::JsonToLua(L, json, strlen(json)); // throws lua error if it fails
|
dmScript::JsonToLua(L, json, strlen(json)); // throws lua error if it fails
|
||||||
|
lua_pushnil(L);
|
||||||
} else {
|
} else {
|
||||||
dmLogError("IAP error %d", cmd->m_ResponseCode);
|
dmLogError("IAP error %d", cmd->m_ResponseCode);
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
@@ -343,6 +344,7 @@ static void HandlePurchaseResult(const IAPCommand* cmd)
|
|||||||
if (cmd->m_Data != 0) {
|
if (cmd->m_Data != 0) {
|
||||||
const char* json = (const char*)cmd->m_Data;
|
const char* json = (const char*)cmd->m_Data;
|
||||||
dmScript::JsonToLua(L, json, strlen(json)); // throws lua error if it fails
|
dmScript::JsonToLua(L, json, strlen(json)); // throws lua error if it fails
|
||||||
|
lua_pushnil(L);
|
||||||
} else {
|
} else {
|
||||||
dmLogError("IAP error, purchase response was null");
|
dmLogError("IAP error, purchase response was null");
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
|
@@ -47,6 +47,7 @@ static void IAPList_Callback(void* luacallback, const char* result_json)
|
|||||||
if(result_json != 0)
|
if(result_json != 0)
|
||||||
{
|
{
|
||||||
dmScript::JsonToLua(L, result_json, strlen(result_json)); // throws lua error if it fails
|
dmScript::JsonToLua(L, result_json, strlen(result_json)); // throws lua error if it fails
|
||||||
|
lua_pushnil(L);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -97,6 +98,7 @@ static void IAPListener_Callback(void* luacallback, const char* result_json, int
|
|||||||
|
|
||||||
if (result_json) {
|
if (result_json) {
|
||||||
dmScript::JsonToLua(L, result_json, strlen(result_json)); // throws lua error if it fails
|
dmScript::JsonToLua(L, result_json, strlen(result_json)); // throws lua error if it fails
|
||||||
|
lua_pushnil(L);
|
||||||
} else {
|
} else {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
switch(error_code)
|
switch(error_code)
|
||||||
|
@@ -243,6 +243,20 @@ public class IapGooglePlay implements PurchasesUpdatedListener {
|
|||||||
return billingResponseCodeToDefoldResponse(result.getResponseCode());
|
return billingResponseCodeToDefoldResponse(result.getResponseCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void invokeOnPurchaseResultListener(IPurchaseListener purchaseListener, int billingResultCode, String purchaseData) {
|
||||||
|
if (purchaseListener == null) {
|
||||||
|
Log.w(TAG, "Received billing result but no listener has been set");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
purchaseListener.onPurchaseResult(billingResultCode, purchaseData);
|
||||||
|
}
|
||||||
|
private void invokeOnPurchaseResultListener(IPurchaseListener purchaseListener, BillingResult billingResult, Purchase purchase) {
|
||||||
|
invokeOnPurchaseResultListener(purchaseListener, billingResultToDefoldResponse(billingResult), convertPurchase(purchase));
|
||||||
|
}
|
||||||
|
private void invokeOnPurchaseResultListener(IPurchaseListener purchaseListener, BillingResult billingResult) {
|
||||||
|
invokeOnPurchaseResultListener(purchaseListener, billingResultToDefoldResponse(billingResult), "");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called either explicitly from Lua or from extension code
|
* This method is called either explicitly from Lua or from extension code
|
||||||
* when "set_listener()" is called from Lua.
|
* when "set_listener()" is called from Lua.
|
||||||
@@ -306,7 +320,7 @@ public class IapGooglePlay implements PurchasesUpdatedListener {
|
|||||||
// note: we only call the purchase listener if an error happens
|
// note: we only call the purchase listener if an error happens
|
||||||
if (billingResult.getResponseCode() != BillingResponseCode.OK) {
|
if (billingResult.getResponseCode() != BillingResponseCode.OK) {
|
||||||
Log.e(TAG, "Unable to consume purchase: " + billingResult.getDebugMessage());
|
Log.e(TAG, "Unable to consume purchase: " + billingResult.getDebugMessage());
|
||||||
purchaseListener.onPurchaseResult(billingResultToDefoldResponse(billingResult), "");
|
invokeOnPurchaseResultListener(purchaseListener, billingResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -329,7 +343,7 @@ public class IapGooglePlay implements PurchasesUpdatedListener {
|
|||||||
// note: we only call the purchase listener if an error happens
|
// note: we only call the purchase listener if an error happens
|
||||||
if (billingResult.getResponseCode() != BillingResponseCode.OK) {
|
if (billingResult.getResponseCode() != BillingResponseCode.OK) {
|
||||||
Log.e(TAG, "Unable to acknowledge purchase: " + billingResult.getDebugMessage());
|
Log.e(TAG, "Unable to acknowledge purchase: " + billingResult.getDebugMessage());
|
||||||
purchaseListener.onPurchaseResult(billingResultToDefoldResponse(billingResult), "");
|
invokeOnPurchaseResultListener(purchaseListener, billingResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -348,12 +362,12 @@ public class IapGooglePlay implements PurchasesUpdatedListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onConsumeResponse(BillingResult billingResult, String purchaseToken) {
|
public void onConsumeResponse(BillingResult billingResult, String purchaseToken) {
|
||||||
Log.d(TAG, "handlePurchase() response code " + billingResult.getResponseCode() + " purchaseToken: " + purchaseToken);
|
Log.d(TAG, "handlePurchase() response code " + billingResult.getResponseCode() + " purchaseToken: " + purchaseToken);
|
||||||
purchaseListener.onPurchaseResult(billingResultToDefoldResponse(billingResult), convertPurchase(purchase));
|
invokeOnPurchaseResultListener(purchaseListener, billingResult, purchase);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
purchaseListener.onPurchaseResult(billingResponseCodeToDefoldResponse(BillingResponseCode.OK), convertPurchase(purchase));
|
invokeOnPurchaseResultListener(purchaseListener, billingResponseCodeToDefoldResponse(BillingResponseCode.OK), convertPurchase(purchase));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,13 +376,17 @@ public class IapGooglePlay implements PurchasesUpdatedListener {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onPurchasesUpdated(BillingResult billingResult, List<Purchase> purchases) {
|
public void onPurchasesUpdated(BillingResult billingResult, List<Purchase> purchases) {
|
||||||
if (billingResult.getResponseCode() == BillingResponseCode.OK && purchases != null) {
|
if (billingResult.getResponseCode() == BillingResponseCode.OK) {
|
||||||
|
if (purchases != null && !purchases.isEmpty()) {
|
||||||
for (Purchase purchase : purchases) {
|
for (Purchase purchase : purchases) {
|
||||||
|
if (purchase != null) {
|
||||||
handlePurchase(purchase, this.purchaseListener);
|
handlePurchase(purchase, this.purchaseListener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
this.purchaseListener.onPurchaseResult(billingResultToDefoldResponse(billingResult), "");
|
invokeOnPurchaseResultListener(this.purchaseListener, billingResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,7 +410,7 @@ public class IapGooglePlay implements PurchasesUpdatedListener {
|
|||||||
BillingResult billingResult = billingClient.launchBillingFlow(this.activity, billingFlowParams);
|
BillingResult billingResult = billingClient.launchBillingFlow(this.activity, billingFlowParams);
|
||||||
if (billingResult.getResponseCode() != BillingResponseCode.OK) {
|
if (billingResult.getResponseCode() != BillingResponseCode.OK) {
|
||||||
Log.e(TAG, "Purchase failed: " + billingResult.getDebugMessage());
|
Log.e(TAG, "Purchase failed: " + billingResult.getDebugMessage());
|
||||||
purchaseListener.onPurchaseResult(billingResultToDefoldResponse(billingResult), "");
|
invokeOnPurchaseResultListener(purchaseListener, billingResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -413,11 +431,16 @@ public class IapGooglePlay implements PurchasesUpdatedListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onProductDetailsResponse(BillingResult billingResult, List<ProductDetails> productDetailsList) {
|
public void onProductDetailsResponse(BillingResult billingResult, List<ProductDetails> productDetailsList) {
|
||||||
if (billingResult.getResponseCode() == BillingResponseCode.OK && (productDetailsList != null) && !productDetailsList.isEmpty()) {
|
if (billingResult.getResponseCode() == BillingResponseCode.OK && (productDetailsList != null) && !productDetailsList.isEmpty()) {
|
||||||
buyProduct(productDetailsList.get(0), token, purchaseListener);
|
for (ProductDetails productDetails : productDetailsList) {
|
||||||
|
if (productDetails != null) {
|
||||||
|
buyProduct(productDetails, token, purchaseListener);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Log.e(TAG, "Unable to get product details before buying: " + billingResult.getDebugMessage());
|
Log.e(TAG, "Unable to get product details before buying: " + billingResult.getDebugMessage());
|
||||||
purchaseListener.onPurchaseResult(billingResultToDefoldResponse(billingResult), "");
|
invokeOnPurchaseResultListener(purchaseListener, billingResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -435,11 +458,13 @@ public class IapGooglePlay implements PurchasesUpdatedListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProductDetailsResponse(BillingResult billingResult, List<ProductDetails> productDetails) {
|
public void onProductDetailsResponse(BillingResult billingResult, List<ProductDetails> productDetails) {
|
||||||
if (productDetails != null) {
|
if (productDetails != null && !productDetails.isEmpty()) {
|
||||||
// cache products (cache will be used to speed up buying)
|
// cache products (cache will be used to speed up buying)
|
||||||
for (ProductDetails pd : productDetails) {
|
for (ProductDetails pd : productDetails) {
|
||||||
|
if (pd != null) {
|
||||||
IapGooglePlay.this.products.put(pd.getProductId(), pd);
|
IapGooglePlay.this.products.put(pd.getProductId(), pd);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// add to list of all product details
|
// add to list of all product details
|
||||||
allProductDetails.addAll(productDetails);
|
allProductDetails.addAll(productDetails);
|
||||||
}
|
}
|
||||||
@@ -485,11 +510,13 @@ public class IapGooglePlay implements PurchasesUpdatedListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onProductDetailsResponse(BillingResult billingResult, List<ProductDetails> productDetails) {
|
public void onProductDetailsResponse(BillingResult billingResult, List<ProductDetails> productDetails) {
|
||||||
JSONArray a = new JSONArray();
|
JSONArray a = new JSONArray();
|
||||||
if (billingResult.getResponseCode() == BillingResponseCode.OK) {
|
if ((billingResult.getResponseCode() == BillingResponseCode.OK) && (productDetails != null) && !productDetails.isEmpty()) {
|
||||||
for (ProductDetails pd : productDetails) {
|
for (ProductDetails pd : productDetails) {
|
||||||
|
if (pd != null) {
|
||||||
a.put(convertProductDetails(pd));
|
a.put(convertProductDetails(pd));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
Log.e(TAG, "Unable to list products: " + billingResult.getDebugMessage());
|
Log.e(TAG, "Unable to list products: " + billingResult.getDebugMessage());
|
||||||
}
|
}
|
||||||
|
@@ -16,7 +16,7 @@ target_sdk_version = 29
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
title = extension-iap
|
title = extension-iap
|
||||||
dependencies = https://github.com/andsve/dirtylarry/archive/master.zip
|
dependencies#0 = https://github.com/andsve/dirtylarry/archive/master.zip
|
||||||
|
|
||||||
[library]
|
[library]
|
||||||
include_dirs = extension-iap
|
include_dirs = extension-iap
|
||||||
|
Reference in New Issue
Block a user