Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit bdd469f

Browse files
committed
Added livecode command for setting the type of the item (inapp or subs)
1 parent 85e084a commit bdd469f

File tree

10 files changed

+92
-53
lines changed

10 files changed

+92
-53
lines changed

engine/src/java/com/runrev/android/Engine.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,6 +1952,12 @@ public boolean storeConsumePurchase(String productID)
19521952

19531953
return mBillingProvider.consumePurchase(productID);
19541954
}
1955+
1956+
public boolean storeProductSetType(String productId, String productType)
1957+
{
1958+
Log.d(TAG, "Setting type for productId" + productId + ", type is : " + productType);
1959+
return mBillingProvider.productSetType(productId, productType);
1960+
}
19551961

19561962
public boolean purchaseConfirmDelivery(int purchaseId, String notificationId)
19571963
{

engine/src/java/com/runrev/android/billing/BillingProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public interface BillingProvider
4343
// Consume a purchased item -- only for Google API
4444
boolean consumePurchase(String productId);
4545

46+
// type is subscription or non-subscription
47+
boolean productSetType(String productId, String productType);
48+
4649
// Return the set of properties for the given id. These should be updated with any information returned by the store (receipt, etc.)
4750
Map<String, String> getPurchaseProperties(int purchaseId);
4851

engine/src/java/com/runrev/android/billing/amazon/AmazonBillingProvider.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ public boolean sendRequest(int purchaseId, String productId, String developerPay
8080
return true;
8181
}
8282

83+
public boolean productSetType(String productId, String productType)
84+
{
85+
return true;
86+
}
87+
8388
public boolean consumePurchase(String productID)
8489
{
8590
return true;

engine/src/java/com/runrev/android/billing/google/GoogleBillingProvider.java

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class GoogleBillingProvider implements BillingProvider
2121
private Activity mActivity;
2222
private Boolean started = false;
2323
private PurchaseObserver mPurchaseObserver;
24+
private Map<String,String> types = new HashMap<String,String>();
2425

2526
// (arbitrary) request code for the purchase flow
2627
static final int RC_REQUEST = 10001;
@@ -120,11 +121,38 @@ public boolean sendRequest(int purchaseId, String productId, String developerPay
120121
if (mHelper == null)
121122
return false;
122123

123-
Log.i(TAG, "purchaseSendRequest(" + purchaseId + ", " + productId + ")");
124-
mHelper.launchPurchaseFlow(getActivity(), productId, RC_REQUEST, mPurchaseFinishedListener, "");
124+
String type = productGetType(productId);
125+
126+
Log.i(TAG, "purchaseSendRequest(" + purchaseId + ", " + productId + ", " + type + ")");
127+
128+
if (type.equals("SUBS"))
129+
{
130+
Log.i(TAG, "mHelper.launchSubscriptionPurchaseFlow is called!!!!");
131+
mHelper.launchSubscriptionPurchaseFlow(getActivity(), productId, RC_REQUEST, mPurchaseFinishedListener, "");
132+
}
133+
else
134+
{
135+
Log.i(TAG, "Ohh Nooo !!!! mHelper.launchSubscriptionPurchaseFlow is NOT called!!!!");
136+
mHelper.launchPurchaseFlow(getActivity(), productId, RC_REQUEST, mPurchaseFinishedListener, "");
137+
}
138+
return true;
139+
}
140+
141+
public boolean productSetType(String productId, String productType)
142+
{
143+
//TODO
144+
Log.d(TAG, "Setting type for productId" + productId + ", type is : " + productType);
145+
types.put(productId, productType);
146+
Log.d(TAG, "Querying HashMap, type is " + types.get(productId));
125147
return true;
126148
}
127149

150+
private String productGetType(String productId)
151+
{
152+
//TODO
153+
return types.get(productId);
154+
}
155+
128156
public boolean consumePurchase(final String productId)
129157
{
130158
mHelper.queryInventoryAsync(new IabHelper.QueryInventoryFinishedListener()
@@ -248,29 +276,7 @@ public void onIabPurchaseFinished(IabResult result, Purchase purchase)
248276
void offerPurchasedItems(Purchase purchase)
249277
{
250278
mPurchaseObserver.onPurchaseStateChanged(purchase.getSku(), purchase.getPurchaseState());
251-
/*
252-
final boolean tVerified = true;
253-
final int tPurchaseState = purchase.getPurchaseState();
254-
final String tNotificationId = purchase.getSku();
255-
final String tProductId = purchase.getSku();
256-
final String tOrderId = purchase.getOrderId();
257-
final long tPurchaseTime = purchase.getPurchaseTime();
258-
final String tDeveloperPayload = purchase.getDeveloperPayload();
259-
final String tSignedData = "";
260-
final String tSignature = purchase.getSignature();
261279

262-
post(new Runnable()
263-
{
264-
public void run()
265-
{
266-
doPurchaseStateChanged(tVerified, tPurchaseState,
267-
tNotificationId, tProductId, tOrderId,
268-
tPurchaseTime, tDeveloperPayload, tSignedData, tSignature);
269-
if (m_wake_on_event)
270-
doProcess(false);
271-
}
272-
});
273-
*/
274280
}
275281

276282
// Called when consumption is complete

engine/src/java/com/runrev/android/billing/samsung/SamsungBillingProvider.java

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -250,31 +250,6 @@ else if (resultCode == Activity.RESULT_CANCELED)
250250
//mPurchaseObserver.onPurchaseStateChanged(1, statusCode);
251251
mPurchaseObserver.onPurchaseStateChanged(itemId, statusCode);
252252

253-
// TODO : Move this to EnginePurchaseObserver
254-
/*
255-
final boolean tVerified = true;
256-
//TODO : Check status code in accordance with the purchase state in mblandroidstore.cpp
257-
final int tPurchaseState = statusCode;
258-
final String tNotificationId = "";
259-
final String tProductId = itemId;
260-
final String tOrderId = "";
261-
final long tPurchaseTime = 1;
262-
final String tDeveloperPayload = "";
263-
final String tSignedData = "";
264-
final String tSignature = "";
265-
266-
post(new Runnable()
267-
{
268-
public void run()
269-
{
270-
doPurchaseStateChanged(tVerified, tPurchaseState,
271-
tNotificationId, tProductId, tOrderId,
272-
tPurchaseTime, tDeveloperPayload, tSignedData, tSignature);
273-
if (m_wake_on_event)
274-
doProcess(false);
275-
}
276-
});
277-
*/
278253
}
279254

280255
/////////////////
@@ -357,6 +332,11 @@ public boolean sendRequest(int purchaseId, String productId, String developerPay
357332
return true;
358333
}
359334

335+
public boolean productSetType(String productId, String productType)
336+
{
337+
return true;
338+
}
339+
360340
public boolean consumePurchase(String productID)
361341
{
362342
return true;

engine/src/java/com/sec/android/iap/sample/helper/SamsungIapHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ public class SamsungIapHelper
8686
// IAP 호출시 onActivityResult 에서 받기 위한 요청 코드
8787
// define request code for IAPService.
8888
// ========================================================================
89-
public static final int REQUEST_CODE_IS_IAP_PAYMENT = 1;
90-
public static final int REQUEST_CODE_IS_ACCOUNT_CERTIFICATION = 2;
89+
public static final int REQUEST_CODE_IS_IAP_PAYMENT = 100;
90+
public static final int REQUEST_CODE_IS_ACCOUNT_CERTIFICATION = 101;
9191
// ========================================================================
9292

9393
// 3rd party 에 전달되는 코드 정의

engine/src/mblandroidmisc.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,7 @@ extern Exec_stat MCHandleDisablePurchaseUpdates(void *context, MCParameter *p_pa
943943
extern Exec_stat MCHandleRestorePurchases(void *context, MCParameter *p_parameters);
944944
extern Exec_stat MCHandlePurchaseList(void *context, MCParameter *p_parameters);
945945
extern Exec_stat MCHandleConsumePurchase(void *context, MCParameter *p_parameters);
946+
extern Exec_stat MCHandleProductSetType(void *context, MCParameter *p_parameters);
946947
extern Exec_stat MCHandlePurchaseCreate(void *context, MCParameter *p_parameters);
947948
extern Exec_stat MCHandlePurchaseState(void *context, MCParameter *p_parameters);
948949
extern Exec_stat MCHandlePurchaseError(void *context, MCParameter *p_parameters);
@@ -1172,6 +1173,7 @@ static MCPlatformMessageSpec s_platform_messages[] =
11721173
{"mobilePurchaseSet", MCHandlePurchaseSet, nil},
11731174
{"mobilePurchaseSendRequest", MCHandlePurchaseSendRequest, nil},
11741175
{"mobileConsumePurchase", MCHandleConsumePurchase, nil},
1176+
{"mobileProductSetType", MCHandleProductSetType, nil},
11751177
{"mobilePurchaseConfirmDelivery", MCHandlePurchaseConfirmDelivery, nil},
11761178
{"mobilePurchaseVerify", MCHandlePurchaseVerify, nil},
11771179

engine/src/mblandroidstore.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ typedef enum
5151
CANCELED, //FAILED for Amazon
5252
INVALID_SKU,
5353
ALREADY_ENTITLED,
54+
IAP_ERROR_ALREADY_PURCHASED = -1003,
5455
REFUNDED,
5556
} MCAndroidPurchaseState;
5657

@@ -115,6 +116,17 @@ bool MCStoreRestorePurchases()
115116
return t_result;
116117
}
117118

119+
bool MCStoreProductSetType(const char *p_purchase_id, const char *p_product_type)
120+
{
121+
122+
bool t_result;
123+
124+
MCAndroidEngineRemoteCall("storeProductSetType", "bss", &t_result, p_purchase_id, p_product_type);
125+
126+
return t_result;
127+
128+
}
129+
118130
bool MCStoreConsumePurchase(const char *p_purchase_id)
119131
{
120132

@@ -339,9 +351,16 @@ void MCPurchaseVerify(MCPurchase *p_purchase, bool p_verified)
339351
purchase_confirm(p_purchase);
340352
break;
341353
}
342-
354+
355+
case IAP_ERROR_ALREADY_PURCHASED:
356+
{
357+
MCLog("found ALREADY_PURCHASED purchase", nil);
358+
p_purchase->state = kMCPurchaseStateAlreadyEntitled;
359+
break;
360+
}
343361
case ALREADY_ENTITLED:
344362
{
363+
MCLog("found ALREADY_ENTITLED purchase", nil);
345364
p_purchase->state = kMCPurchaseStateAlreadyEntitled;
346365
break;
347366
}
@@ -373,11 +392,12 @@ void MCPurchaseVerify(MCPurchase *p_purchase, bool p_verified)
373392

374393
void update_purchase_state(MCPurchase *p_purchase, int32_t p_state, bool p_verified)
375394
{
395+
MCLog("State is " + p_state, nil);
376396
if (!p_verified)
377397
p_purchase->state = kMCPurchaseStateUnverified;
378398
else if (p_state == PURCHASED)
379399
p_purchase->state = kMCPurchaseStatePaymentReceived;
380-
else if (p_state == ALREADY_ENTITLED)
400+
else if (p_state == ALREADY_ENTITLED || p_state == IAP_ERROR_ALREADY_PURCHASED)
381401
p_purchase->state = kMCPurchaseStateAlreadyEntitled;
382402
else if (p_state == INVALID_SKU)
383403
p_purchase->state = kMCPurchaseStateInvalidSKU;

engine/src/mblstore.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,22 @@ Exec_stat MCHandleDisablePurchaseUpdates(void *context, MCParameter *p_parameter
333333
return ES_NORMAL;
334334
}
335335

336+
Exec_stat MCHandleProductSetType(void *context, MCParameter *p_parameters)
337+
{
338+
bool t_success = true;
339+
char *t_product_id = nil;
340+
char *t_product_type;
341+
if (t_success)
342+
t_success = MCParseParameters(p_parameters, "ss", &t_product_id, &t_product_type);
343+
if (t_success)
344+
t_success = MCStoreProductSetType(t_product_id, t_product_type);
345+
346+
MCCStringFree(t_product_id);
347+
MCCStringFree(t_product_type);
348+
349+
return ES_NORMAL;
350+
}
351+
336352
Exec_stat MCHandleConsumePurchase(void *context, MCParameter *p_parameters)
337353
{
338354
bool t_success = true;

engine/src/mblstore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ bool MCStoreCanMakePurchase();
9999

100100
bool MCStoreEnablePurchaseUpdates();
101101
bool MCStoreDisablePurchaseUpdates();
102+
bool MCStoreProductSetType(const char *p_purchase_id, const char *p_product_type);
102103
bool MCStoreConsumePurchase(const char *p_product_id);
103104

104105
bool MCStoreRestorePurchases();

0 commit comments

Comments
 (0)