Implemented support for account identifiers for Google Play and StoreKit.
This commit is contained in:
parent
68ef7f4615
commit
609071876c
@ -38,6 +38,21 @@ struct IAP
|
||||
|
||||
static IAP g_IAP;
|
||||
|
||||
static int IAP_SetAccountId(lua_State* L)
|
||||
{
|
||||
DM_LUA_STACK_CHECK(L, 0);
|
||||
|
||||
const char* account_id = luaL_checkstring(L, 1);
|
||||
|
||||
dmAndroid::ThreadAttacher threadAttacher;
|
||||
JNIEnv* env = threadAttacher.GetEnv();
|
||||
jstring account_id_utf = env->NewStringUTF(account_id);
|
||||
env->CallVoidMethod(g_IAP.m_IAP, g_IAP.m_SetAccountId, account_id_utf);
|
||||
env->DeleteLocalRef(account_id_utf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int IAP_ProcessPendingTransactions(lua_State* L)
|
||||
{
|
||||
DM_LUA_STACK_CHECK(L, 0);
|
||||
@ -236,6 +251,7 @@ static const luaL_reg IAP_methods[] =
|
||||
{"set_listener", IAP_SetListener},
|
||||
{"get_provider_id", IAP_GetProviderId},
|
||||
{"process_pending_transactions", IAP_ProcessPendingTransactions},
|
||||
{"set_account_id", IAP_SetAccountId},
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
|
@ -62,6 +62,12 @@ static void IAPList_Callback(void* luacallback, const char* result_json)
|
||||
dmScript::TeardownCallback(callback);
|
||||
}
|
||||
|
||||
static int IAP_SetAccountId(lua_State* L)
|
||||
{
|
||||
dmLogError("iap.set_account_id is not supported on this platform.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int IAP_ProcessPendingTransactions(lua_State* L)
|
||||
{
|
||||
return 0;
|
||||
|
@ -31,6 +31,7 @@ struct IAP
|
||||
IAPCommandQueue m_CommandQueue;
|
||||
IAPCommandQueue m_ObservableQueue;
|
||||
SKPaymentTransactionObserver* m_Observer;
|
||||
char * m_AccountId;
|
||||
};
|
||||
|
||||
IAP g_IAP;
|
||||
@ -383,6 +384,19 @@ static void processTransactions(IAP* iap, NSArray* transactions) {
|
||||
}
|
||||
}
|
||||
|
||||
static int IAP_SetAccountId(lua_State* L)
|
||||
{
|
||||
int top = lua_gettop(L);
|
||||
|
||||
const char *account_id = luaL_checkstring(L, 1);
|
||||
if (g_IAP.m_AccountId) {
|
||||
free(g_IAP.m_AccountId);
|
||||
}
|
||||
|
||||
g_IAP.m_AccountId = strdup(account_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int IAP_ProcessPendingTransactions(lua_State* L)
|
||||
{
|
||||
processTransactions(&g_IAP, [SKPaymentQueue defaultQueue].transactions);
|
||||
@ -431,6 +445,9 @@ static int IAP_Buy(lua_State* L)
|
||||
SKMutablePayment* payment = [[SKMutablePayment alloc] init];
|
||||
payment.productIdentifier = [NSString stringWithUTF8String: id];
|
||||
payment.quantity = 1;
|
||||
if (g_IAP.m_AccountId) {
|
||||
payment.applicationUsername = [NSString stringWithUTF8String: g_IAP.m_AccountId];
|
||||
}
|
||||
|
||||
[[SKPaymentQueue defaultQueue] addPayment:payment];
|
||||
[payment release];
|
||||
@ -531,6 +548,7 @@ static const luaL_reg IAP_methods[] =
|
||||
{"set_listener", IAP_SetListener},
|
||||
{"get_provider_id", IAP_GetProviderId},
|
||||
{"process_pending_transactions", IAP_ProcessPendingTransactions},
|
||||
{"set_account_id", IAP_SetAccountId},
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
|
@ -51,6 +51,7 @@ public class IapGooglePlay implements PurchasesUpdatedListener {
|
||||
private IPurchaseListener purchaseListener;
|
||||
private boolean autoFinishTransactions;
|
||||
private Activity activity;
|
||||
private String accountId;
|
||||
|
||||
public IapGooglePlay(Activity activity, boolean autoFinishTransactions) {
|
||||
this.activity = activity;
|
||||
@ -257,6 +258,11 @@ public class IapGooglePlay implements PurchasesUpdatedListener {
|
||||
invokeOnPurchaseResultListener(purchaseListener, billingResultToDefoldResponse(billingResult), "");
|
||||
}
|
||||
|
||||
public void setAccountId(String accountId) {
|
||||
Log.d(TAG, "setAccountId() " + accountId);
|
||||
this.accountId = accountId;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called either explicitly from Lua or from extension code
|
||||
* when "set_listener()" is called from Lua.
|
||||
@ -405,7 +411,11 @@ public class IapGooglePlay implements PurchasesUpdatedListener {
|
||||
productDetailsParams.add(ProductDetailsParams.newBuilder().setProductDetails(pd).build());
|
||||
}
|
||||
|
||||
final BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder().setProductDetailsParamsList(productDetailsParams).build();
|
||||
final BillingFlowParams.Builder billingFlowBuilder = BillingFlowParams.newBuilder().setProductDetailsParamsList(productDetailsParams);
|
||||
if (this.accountId != null) {
|
||||
billingFlowBuilder.setObfuscatedAccountId(this.accountId);
|
||||
}
|
||||
final BillingFlowParams billingFlowParams = billingFlowBuilder.build();
|
||||
|
||||
BillingResult billingResult = billingClient.launchBillingFlow(this.activity, billingFlowParams);
|
||||
if (billingResult.getResponseCode() != BillingResponseCode.OK) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user