9 Commits
5.0.0 ... 5.1.1

Author SHA1 Message Date
Alexey Gulev
68ef7f4615 Merge pull request #63 from ekharkunov/emscripten-update
Update js code according to new Emscripten version (3.1.55).
2024-04-10 11:08:22 +02:00
Kharkunov Eugene
1a34582603 Update js code according to new Emscripten version (3.1.55).
Update assets to latest Defold version.
Remove armv7-ios from manifest as unsupported platform.
2024-04-10 11:27:41 +03:00
Björn Ritzl
09f5060d44 Update index.md 2023-10-03 14:40:19 +02:00
Björn Ritzl
649a8a1ebf Merge pull request #58 from defold/Issue-47-index-out-of-bounds-exception
Added product and purchase null checks
2023-02-07 15:53:39 +01:00
Björn Ritzl
5c09447e37 Merge pull request #59 from defold/Issue-56-app-crash-on-slow-purchase
Check that the purchase listener is not null
2023-02-07 15:51:25 +01:00
Björn Ritzl
ad06de7b9c Check purchase listener 2023-02-06 23:11:24 +01:00
Björn Ritzl
d74c97d5c7 Added null checks 2023-02-06 15:56:03 +01:00
Björn Ritzl
f97a7ee6b6 Merge pull request #55 from defold/fix-json-migration-issue
Push nil as last argument if there is no error
2022-11-21 10:30:12 +01:00
Björn Ritzl
5f3f43fb2e Push nil as last argument if there is no error 2022-11-21 10:21:12 +01:00
8 changed files with 148 additions and 27 deletions

View File

@@ -1,6 +1,6 @@
---
title: Defold In-app purchase extension API documentation
brief: This manual covers how to setup and use Google Play Game Services in Defold.
brief: This manual covers how to setup and use In-App Purchases in Defold.
---
# Defold In-app purchase extension API documentation

View File

@@ -1,10 +1,6 @@
name: IAPExt
platforms:
armv7-ios:
context:
weakFrameworks: ['StoreKit', 'UIKit', 'Foundation']
arm64-ios:
context:
weakFrameworks: ['StoreKit', 'UIKit', 'Foundation']

View File

@@ -71,7 +71,7 @@ var LibraryFacebookIAP = {
if(url_index == product_count-1) {
var productsJSON = JSON.stringify(products);
var res_buf = allocate(intArrayFromString(productsJSON), 'i8', ALLOC_STACK);
var res_buf = stringToUTF8OnStack(productsJSON);
{{{ makeDynCall('vii', 'callback')}}}(lua_callback, res_buf);
} else {
var xmlhttp = new XMLHttpRequest();
@@ -143,7 +143,7 @@ var LibraryFacebookIAP = {
}
var productsJSON = JSON.stringify(result)
var res_buf = allocate(intArrayFromString(productsJSON), 'i8', ALLOC_STACK);
var res_buf = stringToUTF8OnStack(productsJSON);
{{{ makeDynCall('viii', 'callback')}}}(lua_callback, res_buf, 0);
} else {
@@ -166,4 +166,4 @@ var LibraryFacebookIAP = {
}
autoAddDeps(LibraryFacebookIAP, '$FBinner');
mergeInto(LibraryManager.library, LibraryFacebookIAP);
addToLibrary(LibraryFacebookIAP);

View File

@@ -308,6 +308,7 @@ static void HandleProductResult(const IAPCommand* cmd)
if (cmd->m_ResponseCode == BILLING_RESPONSE_RESULT_OK) {
const char* json = (const char*)cmd->m_Data;
dmScript::JsonToLua(L, json, strlen(json)); // throws lua error if it fails
lua_pushnil(L);
} else {
dmLogError("IAP error %d", cmd->m_ResponseCode);
lua_pushnil(L);
@@ -343,6 +344,7 @@ static void HandlePurchaseResult(const IAPCommand* cmd)
if (cmd->m_Data != 0) {
const char* json = (const char*)cmd->m_Data;
dmScript::JsonToLua(L, json, strlen(json)); // throws lua error if it fails
lua_pushnil(L);
} else {
dmLogError("IAP error, purchase response was null");
lua_pushnil(L);

View File

@@ -47,6 +47,7 @@ static void IAPList_Callback(void* luacallback, const char* result_json)
if(result_json != 0)
{
dmScript::JsonToLua(L, result_json, strlen(result_json)); // throws lua error if it fails
lua_pushnil(L);
}
else
{
@@ -97,6 +98,7 @@ static void IAPListener_Callback(void* luacallback, const char* result_json, int
if (result_json) {
dmScript::JsonToLua(L, result_json, strlen(result_json)); // throws lua error if it fails
lua_pushnil(L);
} else {
lua_pushnil(L);
switch(error_code)

View File

@@ -243,6 +243,20 @@ public class IapGooglePlay implements PurchasesUpdatedListener {
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
* 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
if (billingResult.getResponseCode() != BillingResponseCode.OK) {
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
if (billingResult.getResponseCode() != BillingResponseCode.OK) {
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
public void onConsumeResponse(BillingResult billingResult, String purchaseToken) {
Log.d(TAG, "handlePurchase() response code " + billingResult.getResponseCode() + " purchaseToken: " + purchaseToken);
purchaseListener.onPurchaseResult(billingResultToDefoldResponse(billingResult), convertPurchase(purchase));
invokeOnPurchaseResultListener(purchaseListener, billingResult, purchase);
}
});
}
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
public void onPurchasesUpdated(BillingResult billingResult, List<Purchase> purchases) {
if (billingResult.getResponseCode() == BillingResponseCode.OK && purchases != null) {
for (Purchase purchase : purchases) {
handlePurchase(purchase, this.purchaseListener);
if (billingResult.getResponseCode() == BillingResponseCode.OK) {
if (purchases != null && !purchases.isEmpty()) {
for (Purchase purchase : purchases) {
if (purchase != null) {
handlePurchase(purchase, this.purchaseListener);
}
}
}
}
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);
if (billingResult.getResponseCode() != BillingResponseCode.OK) {
Log.e(TAG, "Purchase failed: " + billingResult.getDebugMessage());
purchaseListener.onPurchaseResult(billingResultToDefoldResponse(billingResult), "");
invokeOnPurchaseResultListener(purchaseListener, billingResult);
}
}
@@ -413,11 +431,16 @@ public class IapGooglePlay implements PurchasesUpdatedListener {
@Override
public void onProductDetailsResponse(BillingResult billingResult, List<ProductDetails> productDetailsList) {
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 {
Log.e(TAG, "Unable to get product details before buying: " + billingResult.getDebugMessage());
purchaseListener.onPurchaseResult(billingResultToDefoldResponse(billingResult), "");
invokeOnPurchaseResultListener(purchaseListener, billingResult);
}
}
});
@@ -435,10 +458,12 @@ public class IapGooglePlay implements PurchasesUpdatedListener {
@Override
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)
for (ProductDetails pd : productDetails) {
IapGooglePlay.this.products.put(pd.getProductId(), pd);
if (pd != null) {
IapGooglePlay.this.products.put(pd.getProductId(), pd);
}
}
// add to list of all product details
allProductDetails.addAll(productDetails);
@@ -485,9 +510,11 @@ public class IapGooglePlay implements PurchasesUpdatedListener {
@Override
public void onProductDetailsResponse(BillingResult billingResult, List<ProductDetails> productDetails) {
JSONArray a = new JSONArray();
if (billingResult.getResponseCode() == BillingResponseCode.OK) {
if ((billingResult.getResponseCode() == BillingResponseCode.OK) && (productDetails != null) && !productDetails.isEmpty()) {
for (ProductDetails pd : productDetails) {
a.put(convertProductDetails(pd));
if (pd != null) {
a.put(convertProductDetails(pd));
}
}
}
else {

View File

@@ -16,7 +16,7 @@ target_sdk_version = 29
[project]
title = extension-iap
dependencies = https://github.com/andsve/dirtylarry/archive/master.zip
dependencies#0 = https://github.com/andsve/dirtylarry/archive/master.zip
[library]
include_dirs = extension-iap

View File

@@ -1,7 +1,7 @@
script: "/main/main.gui_script"
fonts {
name: "system_font"
font: "/builtins/fonts/system_font.font"
name: "default"
font: "/builtins/fonts/default.font"
}
background_color {
x: 0.0
@@ -47,6 +47,8 @@ nodes {
alpha: 1.0
template: "/dirtylarry/button.gui"
template_node_child: false
custom_type: 0
enabled: true
}
nodes {
position {
@@ -102,6 +104,10 @@ nodes {
alpha: 1.0
template_node_child: true
size_mode: SIZE_MODE_MANUAL
custom_type: 0
enabled: true
visible: true
material: ""
}
nodes {
position {
@@ -166,6 +172,10 @@ nodes {
template_node_child: true
text_leading: 1.0
text_tracking: 0.0
custom_type: 0
enabled: true
visible: true
material: ""
}
nodes {
position {
@@ -205,6 +215,8 @@ nodes {
alpha: 1.0
template: "/dirtylarry/button.gui"
template_node_child: false
custom_type: 0
enabled: true
}
nodes {
position {
@@ -261,6 +273,10 @@ nodes {
overridden_fields: 4
template_node_child: true
size_mode: SIZE_MODE_MANUAL
custom_type: 0
enabled: true
visible: true
material: ""
}
nodes {
position {
@@ -325,6 +341,10 @@ nodes {
template_node_child: true
text_leading: 1.0
text_tracking: 0.0
custom_type: 0
enabled: true
visible: true
material: ""
}
nodes {
position {
@@ -360,7 +380,7 @@ nodes {
type: TYPE_TEXT
blend_mode: BLEND_MODE_ALPHA
text: "<text>"
font: "system_font"
font: "default"
id: "log"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
@@ -387,6 +407,10 @@ nodes {
template_node_child: false
text_leading: 1.0
text_tracking: 0.0
custom_type: 0
enabled: true
visible: true
material: ""
}
nodes {
position {
@@ -426,6 +450,8 @@ nodes {
alpha: 1.0
template: "/dirtylarry/button.gui"
template_node_child: false
custom_type: 0
enabled: true
}
nodes {
position {
@@ -481,6 +507,10 @@ nodes {
alpha: 1.0
template_node_child: true
size_mode: SIZE_MODE_MANUAL
custom_type: 0
enabled: true
visible: true
material: ""
}
nodes {
position {
@@ -545,6 +575,10 @@ nodes {
template_node_child: true
text_leading: 1.0
text_tracking: 0.0
custom_type: 0
enabled: true
visible: true
material: ""
}
nodes {
position {
@@ -584,6 +618,8 @@ nodes {
alpha: 1.0
template: "/dirtylarry/button.gui"
template_node_child: false
custom_type: 0
enabled: true
}
nodes {
position {
@@ -639,6 +675,10 @@ nodes {
alpha: 1.0
template_node_child: true
size_mode: SIZE_MODE_MANUAL
custom_type: 0
enabled: true
visible: true
material: ""
}
nodes {
position {
@@ -703,6 +743,10 @@ nodes {
template_node_child: true
text_leading: 1.0
text_tracking: 0.0
custom_type: 0
enabled: true
visible: true
material: ""
}
nodes {
position {
@@ -742,6 +786,8 @@ nodes {
alpha: 1.0
template: "/dirtylarry/button.gui"
template_node_child: false
custom_type: 0
enabled: true
}
nodes {
position {
@@ -798,6 +844,10 @@ nodes {
overridden_fields: 4
template_node_child: true
size_mode: SIZE_MODE_MANUAL
custom_type: 0
enabled: true
visible: true
material: ""
}
nodes {
position {
@@ -862,6 +912,10 @@ nodes {
template_node_child: true
text_leading: 1.0
text_tracking: 0.0
custom_type: 0
enabled: true
visible: true
material: ""
}
nodes {
position {
@@ -901,6 +955,8 @@ nodes {
alpha: 1.0
template: "/dirtylarry/button.gui"
template_node_child: false
custom_type: 0
enabled: true
}
nodes {
position {
@@ -956,6 +1012,10 @@ nodes {
alpha: 1.0
template_node_child: true
size_mode: SIZE_MODE_MANUAL
custom_type: 0
enabled: true
visible: true
material: ""
}
nodes {
position {
@@ -1020,6 +1080,10 @@ nodes {
template_node_child: true
text_leading: 1.0
text_tracking: 0.0
custom_type: 0
enabled: true
visible: true
material: ""
}
nodes {
position {
@@ -1059,6 +1123,8 @@ nodes {
alpha: 1.0
template: "/dirtylarry/button.gui"
template_node_child: false
custom_type: 0
enabled: true
}
nodes {
position {
@@ -1115,6 +1181,10 @@ nodes {
overridden_fields: 4
template_node_child: true
size_mode: SIZE_MODE_MANUAL
custom_type: 0
enabled: true
visible: true
material: ""
}
nodes {
position {
@@ -1179,6 +1249,10 @@ nodes {
template_node_child: true
text_leading: 1.0
text_tracking: 0.0
custom_type: 0
enabled: true
visible: true
material: ""
}
nodes {
position {
@@ -1218,6 +1292,8 @@ nodes {
alpha: 1.0
template: "/dirtylarry/checkbox_label.gui"
template_node_child: false
custom_type: 0
enabled: true
}
nodes {
position {
@@ -1273,6 +1349,10 @@ nodes {
alpha: 1.0
template_node_child: true
size_mode: SIZE_MODE_MANUAL
custom_type: 0
enabled: true
visible: true
material: ""
}
nodes {
position {
@@ -1337,6 +1417,10 @@ nodes {
template_node_child: true
text_leading: 1.0
text_tracking: 0.0
custom_type: 0
enabled: true
visible: true
material: ""
}
nodes {
position {
@@ -1376,6 +1460,8 @@ nodes {
alpha: 1.0
template: "/dirtylarry/checkbox_label.gui"
template_node_child: false
custom_type: 0
enabled: true
}
nodes {
position {
@@ -1431,6 +1517,10 @@ nodes {
alpha: 1.0
template_node_child: true
size_mode: SIZE_MODE_MANUAL
custom_type: 0
enabled: true
visible: true
material: ""
}
nodes {
position {
@@ -1495,6 +1585,10 @@ nodes {
template_node_child: true
text_leading: 1.0
text_tracking: 0.0
custom_type: 0
enabled: true
visible: true
material: ""
}
material: "/builtins/materials/gui.material"
adjust_reference: ADJUST_REFERENCE_PARENT