mirror of
https://github.com/defold/extension-iap
synced 2025-09-27 17:12:18 +02:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
1c017cf4ed | ||
|
eda78dda4f | ||
|
8d9ea79d7d | ||
|
c8d2d4e0d8 | ||
|
d2e2a640df | ||
|
aa9448b5e9 | ||
|
ce26b8fdd9 | ||
|
1a778d0e98 |
@@ -11,7 +11,7 @@ To use this library in your Defold project, add the following URL to your <code
|
||||
|
||||
https://github.com/defold/extension-iap/archive/master.zip
|
||||
|
||||
We recommend using a link to a zip file of a [https://github.com/defold/extension-iap/releases](specific release).
|
||||
We recommend using a link to a zip file of a [specific release](https://github.com/defold/extension-iap/releases).
|
||||
|
||||
## Source code
|
||||
|
||||
|
@@ -244,6 +244,12 @@ JNIEXPORT void JNICALL Java_com_defold_iap_IapJNI_onPurchaseResult__ILjava_lang_
|
||||
|
||||
static void HandleProductResult(const IAPCommand* cmd)
|
||||
{
|
||||
if (cmd->m_Callback == 0)
|
||||
{
|
||||
dmLogWarning("Received product list but no listener was set!");
|
||||
return;
|
||||
}
|
||||
|
||||
lua_State* L = dmScript::GetCallbackLuaContext(cmd->m_Callback);
|
||||
int top = lua_gettop(L);
|
||||
|
||||
@@ -277,11 +283,7 @@ static void HandleProductResult(const IAPCommand* cmd)
|
||||
IAP_PushError(L, "failed to fetch product", REASON_UNSPECIFIED);
|
||||
}
|
||||
|
||||
int ret = lua_pcall(L, 3, 0, 0);
|
||||
if (ret != 0) {
|
||||
dmLogError("Error running callback: %s", lua_tostring(L, -1));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
dmScript::PCall(L, 3, 0);
|
||||
|
||||
dmScript::TeardownCallback(cmd->m_Callback);
|
||||
dmScript::DestroyCallback(cmd->m_Callback);
|
||||
@@ -293,6 +295,12 @@ static void HandleProductResult(const IAPCommand* cmd)
|
||||
|
||||
static void HandlePurchaseResult(const IAPCommand* cmd)
|
||||
{
|
||||
if (cmd->m_Callback == 0)
|
||||
{
|
||||
dmLogWarning("Received purchase result but no listener was set!");
|
||||
return;
|
||||
}
|
||||
|
||||
lua_State* L = dmScript::GetCallbackLuaContext(cmd->m_Callback);
|
||||
int top = lua_gettop(L);
|
||||
|
||||
@@ -335,11 +343,7 @@ static void HandlePurchaseResult(const IAPCommand* cmd)
|
||||
IAP_PushError(L, "failed to buy product", REASON_UNSPECIFIED);
|
||||
}
|
||||
|
||||
int ret = dmScript::PCall(L, 3, 0);
|
||||
if (ret != 0) {
|
||||
dmLogError("Error running callback: %s", lua_tostring(L, -1));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
dmScript::PCall(L, 3, 0);
|
||||
|
||||
dmScript::TeardownCallback(cmd->m_Callback);
|
||||
|
||||
|
@@ -71,8 +71,7 @@ static void IAPList_Callback(void* luacallback, const char* result_json)
|
||||
IAP_PushError(L, "Got empty list result.", REASON_UNSPECIFIED);
|
||||
}
|
||||
|
||||
int ret = dmScript::PCall(L, 3, 0);
|
||||
(void)ret;
|
||||
dmScript::PCall(L, 3, 0);
|
||||
|
||||
dmScript::DestroyCallback(callback);
|
||||
dmScript::TeardownCallback(callback);
|
||||
@@ -144,8 +143,7 @@ static void IAPListener_Callback(void* luacallback, const char* result_json, int
|
||||
}
|
||||
}
|
||||
|
||||
int ret = dmScript::PCall(L, 3, 0);
|
||||
(void)ret;
|
||||
dmScript::PCall(L, 3, 0);
|
||||
|
||||
dmScript::TeardownCallback(callback);
|
||||
}
|
||||
|
@@ -186,11 +186,7 @@ static void HandleProductResult(IAPCommand* cmd)
|
||||
}
|
||||
lua_pushnil(L);
|
||||
|
||||
int ret = dmScript::PCall(L, 3, 0);
|
||||
if (ret != 0) {
|
||||
dmLogError("%d: Error running callback: %s", __LINE__, lua_tostring(L, -1));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
dmScript::PCall(L, 3, 0);
|
||||
|
||||
dmScript::TeardownCallback(cmd->m_Callback);
|
||||
dmScript::DestroyCallback(cmd->m_Callback);
|
||||
@@ -237,6 +233,7 @@ static void CopyTransaction(SKPaymentTransaction* transaction, IAPTransaction* o
|
||||
}
|
||||
|
||||
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
|
||||
[dateFormatter setLocale: [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]];
|
||||
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZ"];
|
||||
|
||||
out->ident = strdup([transaction.payment.productIdentifier UTF8String]);
|
||||
@@ -318,11 +315,7 @@ static void HandlePurchaseResult(IAPCommand* cmd)
|
||||
lua_pushnil(L);
|
||||
}
|
||||
|
||||
int ret = dmScript::PCall(L, 3, 0);
|
||||
if (ret != 0) {
|
||||
dmLogError("%d: Error running callback: %s", __LINE__, lua_tostring(L, -1));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
dmScript::PCall(L, 3, 0);
|
||||
|
||||
dmScript::TeardownCallback(cmd->m_Callback);
|
||||
|
||||
|
@@ -67,7 +67,7 @@ public class IapGooglePlay implements Handler.Callback {
|
||||
private boolean autoFinishTransactions;
|
||||
|
||||
private static interface ISkuRequestListener {
|
||||
public void onProducts(int resultCode, JSONObject products);
|
||||
public void onProducts(int resultCode, JSONObject products);
|
||||
}
|
||||
|
||||
private static class SkuRequest {
|
||||
|
@@ -69,8 +69,8 @@ public class IapGooglePlayActivity extends Activity {
|
||||
}
|
||||
|
||||
private void buy(String product, String productType) {
|
||||
// Flush any pending items, in order to be able to buy the same (new) product again
|
||||
processPendingConsumables();
|
||||
// Flush any pending items, in order to be able to buy the same (new) product again
|
||||
processPendingConsumables();
|
||||
|
||||
try {
|
||||
Bundle buyIntentBundle = service.getBuyIntent(3, getPackageName(), product, productType, "");
|
||||
|
11
game.project
11
game.project
@@ -5,12 +5,12 @@ main_collection = /main/main.collectionc
|
||||
shared_state = 1
|
||||
|
||||
[display]
|
||||
width = 960
|
||||
height = 640
|
||||
width = 640
|
||||
height = 1136
|
||||
|
||||
[android]
|
||||
input_method = HiddenInputField
|
||||
package = com.defold.iaprtestapp
|
||||
package = com.defold.extension.iap
|
||||
version_code = 3
|
||||
|
||||
[project]
|
||||
@@ -21,8 +21,11 @@ dependencies = https://github.com/andsve/dirtylarry/archive/master.zip
|
||||
include_dirs = extension-iap
|
||||
|
||||
[ios]
|
||||
bundle_identifier = com.defoldextension.push
|
||||
bundle_identifier = com.defold.extension.iap
|
||||
|
||||
[iap]
|
||||
auto_finish_transactions = 0
|
||||
|
||||
[osx]
|
||||
bundle_identifier = com.defold.extension.iap
|
||||
|
||||
|
883
main/main.gui
883
main/main.gui
@@ -41,7 +41,7 @@ nodes {
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_TEMPLATE
|
||||
id: "consumable"
|
||||
id: "goldbars_small"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
@@ -82,12 +82,12 @@ nodes {
|
||||
type: TYPE_BOX
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
texture: "button/button_normal"
|
||||
id: "consumable/larrybutton"
|
||||
id: "goldbars_small/larrybutton"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
parent: "consumable"
|
||||
parent: "goldbars_small"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
slice9 {
|
||||
@@ -129,16 +129,16 @@ nodes {
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 0.6
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_TEXT
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
text: "consumable"
|
||||
text: "Goldbars - S"
|
||||
font: "larryfont"
|
||||
id: "consumable/larrylabel"
|
||||
id: "goldbars_small/larrylabel"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
@@ -156,172 +156,12 @@ nodes {
|
||||
}
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
line_break: false
|
||||
parent: "consumable/larrybutton"
|
||||
parent: "goldbars_small/larrybutton"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
outline_alpha: 1.0
|
||||
shadow_alpha: 1.0
|
||||
overridden_fields: 5
|
||||
overridden_fields: 8
|
||||
template_node_child: true
|
||||
text_leading: 1.0
|
||||
text_tracking: 0.0
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 171.0
|
||||
y: 449.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 200.0
|
||||
y: 100.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_TEMPLATE
|
||||
id: "nonconsumable"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
template: "/dirtylarry/button.gui"
|
||||
template_node_child: false
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 300.0
|
||||
y: 88.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_BOX
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
texture: "button/button_normal"
|
||||
id: "nonconsumable/larrybutton"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
parent: "nonconsumable"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
slice9 {
|
||||
x: 32.0
|
||||
y: 32.0
|
||||
z: 32.0
|
||||
w: 32.0
|
||||
}
|
||||
clipping_mode: CLIPPING_MODE_NONE
|
||||
clipping_visible: true
|
||||
clipping_inverted: false
|
||||
alpha: 1.0
|
||||
template_node_child: true
|
||||
size_mode: SIZE_MODE_MANUAL
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 200.0
|
||||
y: 100.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 0.6
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_TEXT
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
text: "non-consumable"
|
||||
font: "larryfont"
|
||||
id: "nonconsumable/larrylabel"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
outline {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
shadow {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
line_break: false
|
||||
parent: "nonconsumable/larrybutton"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
outline_alpha: 1.0
|
||||
shadow_alpha: 1.0
|
||||
overridden_fields: 5
|
||||
overridden_fields: 8
|
||||
template_node_child: true
|
||||
text_leading: 1.0
|
||||
@@ -330,7 +170,7 @@ nodes {
|
||||
nodes {
|
||||
position {
|
||||
x: 485.0
|
||||
y: 449.0
|
||||
y: 56.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
@@ -447,14 +287,14 @@ nodes {
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 0.6
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_TEXT
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
text: "<- reset"
|
||||
text: "Reset"
|
||||
font: "larryfont"
|
||||
id: "reset/larrylabel"
|
||||
xanchor: XANCHOR_NONE
|
||||
@@ -480,7 +320,700 @@ nodes {
|
||||
alpha: 1.0
|
||||
outline_alpha: 1.0
|
||||
shadow_alpha: 1.0
|
||||
overridden_fields: 5
|
||||
overridden_fields: 8
|
||||
template_node_child: true
|
||||
text_leading: 1.0
|
||||
text_tracking: 0.0
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 20.0
|
||||
y: 1124.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 600.0
|
||||
y: 450.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_TEXT
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
text: "<text>"
|
||||
font: "system_font"
|
||||
id: "log"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_NW
|
||||
outline {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
shadow {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
line_break: true
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
outline_alpha: 1.0
|
||||
shadow_alpha: 1.0
|
||||
template_node_child: false
|
||||
text_leading: 1.0
|
||||
text_tracking: 0.0
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 171.0
|
||||
y: 465.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 200.0
|
||||
y: 100.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_TEMPLATE
|
||||
id: "goldbars_medium"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
template: "/dirtylarry/button.gui"
|
||||
template_node_child: false
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 300.0
|
||||
y: 88.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_BOX
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
texture: "button/button_normal"
|
||||
id: "goldbars_medium/larrybutton"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
parent: "goldbars_medium"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
slice9 {
|
||||
x: 32.0
|
||||
y: 32.0
|
||||
z: 32.0
|
||||
w: 32.0
|
||||
}
|
||||
clipping_mode: CLIPPING_MODE_NONE
|
||||
clipping_visible: true
|
||||
clipping_inverted: false
|
||||
alpha: 1.0
|
||||
template_node_child: true
|
||||
size_mode: SIZE_MODE_MANUAL
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 200.0
|
||||
y: 100.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_TEXT
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
text: "Goldbars - M"
|
||||
font: "larryfont"
|
||||
id: "goldbars_medium/larrylabel"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
outline {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
shadow {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
line_break: false
|
||||
parent: "goldbars_medium/larrybutton"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
outline_alpha: 1.0
|
||||
shadow_alpha: 1.0
|
||||
overridden_fields: 8
|
||||
template_node_child: true
|
||||
text_leading: 1.0
|
||||
text_tracking: 0.0
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 171.0
|
||||
y: 357.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 200.0
|
||||
y: 100.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_TEMPLATE
|
||||
id: "goldbars_large"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
template: "/dirtylarry/button.gui"
|
||||
template_node_child: false
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 300.0
|
||||
y: 88.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_BOX
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
texture: "button/button_normal"
|
||||
id: "goldbars_large/larrybutton"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
parent: "goldbars_large"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
slice9 {
|
||||
x: 32.0
|
||||
y: 32.0
|
||||
z: 32.0
|
||||
w: 32.0
|
||||
}
|
||||
clipping_mode: CLIPPING_MODE_NONE
|
||||
clipping_visible: true
|
||||
clipping_inverted: false
|
||||
alpha: 1.0
|
||||
template_node_child: true
|
||||
size_mode: SIZE_MODE_MANUAL
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 200.0
|
||||
y: 100.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_TEXT
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
text: "Goldbars - L"
|
||||
font: "larryfont"
|
||||
id: "goldbars_large/larrylabel"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
outline {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
shadow {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
line_break: false
|
||||
parent: "goldbars_large/larrybutton"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
outline_alpha: 1.0
|
||||
shadow_alpha: 1.0
|
||||
overridden_fields: 8
|
||||
template_node_child: true
|
||||
text_leading: 1.0
|
||||
text_tracking: 0.0
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 159.0
|
||||
y: 56.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 200.0
|
||||
y: 100.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_TEMPLATE
|
||||
id: "list"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
template: "/dirtylarry/button.gui"
|
||||
template_node_child: false
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 300.0
|
||||
y: 88.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_BOX
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
texture: "button/button_normal"
|
||||
id: "list/larrybutton"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
parent: "list"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
slice9 {
|
||||
x: 32.0
|
||||
y: 32.0
|
||||
z: 32.0
|
||||
w: 32.0
|
||||
}
|
||||
clipping_mode: CLIPPING_MODE_NONE
|
||||
clipping_visible: true
|
||||
clipping_inverted: false
|
||||
alpha: 1.0
|
||||
template_node_child: true
|
||||
size_mode: SIZE_MODE_MANUAL
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 200.0
|
||||
y: 100.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_TEXT
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
text: "List"
|
||||
font: "larryfont"
|
||||
id: "list/larrylabel"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
outline {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
shadow {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
line_break: false
|
||||
parent: "list/larrybutton"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
outline_alpha: 1.0
|
||||
shadow_alpha: 1.0
|
||||
overridden_fields: 8
|
||||
template_node_child: true
|
||||
text_leading: 1.0
|
||||
text_tracking: 0.0
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 171.0
|
||||
y: 251.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 200.0
|
||||
y: 100.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_TEMPLATE
|
||||
id: "subscription"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
template: "/dirtylarry/button.gui"
|
||||
template_node_child: false
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 300.0
|
||||
y: 88.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_BOX
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
texture: "button/button_normal"
|
||||
id: "subscription/larrybutton"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
parent: "subscription"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
slice9 {
|
||||
x: 32.0
|
||||
y: 32.0
|
||||
z: 32.0
|
||||
w: 32.0
|
||||
}
|
||||
clipping_mode: CLIPPING_MODE_NONE
|
||||
clipping_visible: true
|
||||
clipping_inverted: false
|
||||
alpha: 1.0
|
||||
template_node_child: true
|
||||
size_mode: SIZE_MODE_MANUAL
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 200.0
|
||||
y: 100.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_TEXT
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
text: "Subscription"
|
||||
font: "larryfont"
|
||||
id: "subscription/larrylabel"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
outline {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
shadow {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
line_break: false
|
||||
parent: "subscription/larrybutton"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
outline_alpha: 1.0
|
||||
shadow_alpha: 1.0
|
||||
overridden_fields: 8
|
||||
template_node_child: true
|
||||
text_leading: 1.0
|
||||
|
@@ -1,59 +1,112 @@
|
||||
local dirtylarry = require "dirtylarry/dirtylarry"
|
||||
|
||||
local GOLDBARS_SMALL = "com.defold.iap.goldbar.small"
|
||||
local GOLDBARS_MEDIUM = "com.defold.iap.goldbar.medium"
|
||||
local GOLDBARS_LARGE = "com.defold.iap.goldbar.large"
|
||||
local SUBSCRIPTION = "com.defold.iap.subscription"
|
||||
|
||||
local items = {
|
||||
"consumable",
|
||||
"nonconsumable"
|
||||
GOLDBARS_SMALL,
|
||||
GOLDBARS_MEDIUM,
|
||||
GOLDBARS_LARGE,
|
||||
SUBSCRIPTION,
|
||||
}
|
||||
|
||||
local product_items = {}
|
||||
local item_buttons = {
|
||||
[GOLDBARS_SMALL] = "goldbars_small",
|
||||
[GOLDBARS_MEDIUM] = "goldbars_medium",
|
||||
[GOLDBARS_LARGE] = "goldbars_large",
|
||||
[SUBSCRIPTION] = "subscription",
|
||||
}
|
||||
|
||||
local function list_callback(self, products, error)
|
||||
if error == nil then
|
||||
for k,p in pairs(products) do
|
||||
product_items[p.ident] = p
|
||||
local name = p.ident.."/larrylabel"
|
||||
gui.set_color(gui.get_node(name), vmath.vector4(1,1,1,1))
|
||||
end
|
||||
else
|
||||
print(error.error)
|
||||
local available_items = {}
|
||||
|
||||
local LOG = {}
|
||||
|
||||
local function log(fmt, ...)
|
||||
if not fmt then return end
|
||||
local line = fmt:format(...)
|
||||
print(line)
|
||||
table.insert(LOG, line)
|
||||
if #LOG > 10 then
|
||||
table.remove(LOG, 1)
|
||||
end
|
||||
local s = table.concat(LOG, "\n")
|
||||
gui.set_text(gui.get_node("log"), s)
|
||||
end
|
||||
|
||||
local function buy(id)
|
||||
log("iap.buy() " .. id)
|
||||
iap.buy(id)
|
||||
end
|
||||
|
||||
local function list()
|
||||
log("iap.list()")
|
||||
for item, button in pairs(item_buttons) do
|
||||
gui.set_color(gui.get_node(button.."/larrylabel"), vmath.vector4(1,1,1,0.5))
|
||||
end
|
||||
iap.list(items, function(self, products, error)
|
||||
if error then
|
||||
log(error.error)
|
||||
return
|
||||
end
|
||||
|
||||
for k,p in pairs(products) do
|
||||
available_items[p.ident] = p
|
||||
log("Item %s", p.ident)
|
||||
local button = item_buttons[p.ident]
|
||||
if button then
|
||||
gui.set_color(gui.get_node(button.."/larrylabel"), vmath.vector4(1,1,1,1))
|
||||
else
|
||||
log("Unable to find button for %s", tostring(p.ident))
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
local function buy_listener(self, transaction, error)
|
||||
pprint(transaction, error)
|
||||
if not error and iap.get_provider_id() == iap.PROVIDER_ID_GOOGLE and transaction.ident == "nonconsumable" then
|
||||
local name = "reset/larrylabel"
|
||||
gui.set_color(gui.get_node(name), vmath.vector4(1,1,1,1))
|
||||
if error then
|
||||
log("iap.buy() error %s - %s", tostring(error.error), tostring(error.reason))
|
||||
return
|
||||
end
|
||||
|
||||
if iap.get_provider_id() == iap.PROVIDER_ID_GOOGLE and transaction.ident == NON_CONSUMABLE then
|
||||
log("iap.buy() ok - google")
|
||||
gui.set_color(gui.get_node("reset/larrylabel"), vmath.vector4(1,1,1,1))
|
||||
product_items["reset"] = transaction
|
||||
elseif not error then
|
||||
else
|
||||
log("iap.buy() ok")
|
||||
log("iap.finish()")
|
||||
iap.finish(transaction)
|
||||
end
|
||||
end
|
||||
|
||||
function init(self)
|
||||
self.log = {}
|
||||
log("init()")
|
||||
msg.post(".", "acquire_input_focus")
|
||||
iap.list(items, list_callback)
|
||||
if not iap then
|
||||
log("In-App Purchases not supported")
|
||||
return
|
||||
end
|
||||
|
||||
list()
|
||||
iap.set_listener(buy_listener)
|
||||
end
|
||||
|
||||
function on_input(self, action_id, action)
|
||||
if product_items["consumable"] then
|
||||
dirtylarry:button("consumable", action_id, action, function()
|
||||
iap.buy("consumable")
|
||||
if action_id then
|
||||
for item, button in pairs(item_buttons) do
|
||||
if available_items[item] then
|
||||
dirtylarry:button(button, action_id, action, function()
|
||||
buy(item)
|
||||
end)
|
||||
end
|
||||
end
|
||||
dirtylarry:button("list", action_id, action, function()
|
||||
list()
|
||||
end)
|
||||
end
|
||||
|
||||
if product_items["nonconsumable"] then
|
||||
dirtylarry:button("nonconsumable", action_id, action, function()
|
||||
iap.buy("nonconsumable")
|
||||
end)
|
||||
end
|
||||
|
||||
if product_items["reset"] then
|
||||
dirtylarry:button("reset", action_id, action, function()
|
||||
iap.finish(product_items["reset"])
|
||||
product_items["reset"] = nil
|
||||
gui.set_color(gui.get_node("reset/larrylabel"), vmath.vector4(1,0,0,1))
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user