Last active
September 28, 2020 23:45
-
-
Save marchbold/bef33d02712479e867371731107e4fd9 to your computer and use it in GitHub Desktop.
InAppBilling product id platform switching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.distriqt.test.inappbilling | |
{ | |
import com.distriqt.extension.inappbilling.InAppBilling; | |
public class Products | |
{ | |
public static const PRODUCT_1:String = "product1"; | |
public static const PRODUCT_2:String = "product2"; | |
public static const SUBSCRIPTION_1:String = "subscription1"; | |
public static const SUBSCRIPTION_2:String = "subscription2"; | |
private static var android_store_product_ids:Object = {}; | |
{ | |
android_store_product_ids[ PRODUCT_1 ] = "com.distriqt.com.distriqt.test.amazingproduct1"; | |
android_store_product_ids[ PRODUCT_2 ] = "com.distriqt.com.distriqt.test.background"; | |
} | |
private static var android_store_subscription_ids:Object = {}; | |
{ | |
android_store_subscription_ids[ SUBSCRIPTION_1 ] = "com.distriqt.com.distriqt.test.subscription1"; | |
android_store_subscription_ids[ SUBSCRIPTION_2 ] = "com.distriqt.com.distriqt.test.subscription2"; | |
} | |
private static var ios_store_product_ids:Object = {}; | |
{ | |
ios_store_product_ids[ PRODUCT_1 ] = "com.distriqt.com.distriqt.test.coins_100"; | |
ios_store_product_ids[ PRODUCT_2 ] = "com.distriqt.com.distriqt.test.pack1"; | |
} | |
private static var ios_store_subscription_ids:Object = {}; | |
{ | |
ios_store_subscription_ids[ SUBSCRIPTION_1 ] = "com.distriqt.com.distriqt.test.subscription1"; | |
ios_store_subscription_ids[ SUBSCRIPTION_2 ] = "com.distriqt.com.distriqt.test.subscription2"; | |
} | |
public function Products() | |
{ | |
} | |
/** | |
* Given an internal product id (eg PRODUCT_1) will search the appropriate data object and return the store product id | |
*/ | |
public function getStoreProductId( product:String ):String | |
{ | |
if (InAppBilling.service.implementation == "Android") | |
{ | |
return android_store_product_ids.hasOwnProperty( product ) ? android_store_product_ids[ product ] : null; | |
} | |
else | |
{ | |
return ios_store_product_ids.hasOwnProperty( product ) ? ios_store_product_ids[ product ] : null; | |
} | |
return null; | |
} | |
/** | |
* Given an store product id will search the appropriate data object and return the internal product id | |
*/ | |
public function getInternalProductId( storeProductId:String ):String | |
{ | |
var productIds:Object; | |
if (InAppBilling.service.implementation == "Android") | |
{ | |
productIds = android_store_product_ids; | |
} | |
else | |
{ | |
productIds = ios_store_product_ids; | |
} | |
for (var internalProductId:String in productIds) | |
{ | |
if (productIds[internalProductId] == storeProductId) | |
return internalProductId; | |
} | |
return null; | |
} | |
// | |
// SUBSCRIPTIONS | |
// | |
/** | |
* Given an internal subscription id (eg SUBSCRIPTION_1) will search the appropriate data object and return the store subscription id | |
*/ | |
public function getStoreSubscriptionId( subscription:String ):String | |
{ | |
if (InAppBilling.service.implementation == "Android") | |
{ | |
return android_store_subscription_ids.hasOwnProperty( subscription ) ? android_store_subscription_ids[ subscription ] : null; | |
} | |
else | |
{ | |
return ios_store_subscription_ids.hasOwnProperty( subscription ) ? ios_store_subscription_ids[ subscription ] : null; | |
} | |
return null; | |
} | |
/** | |
* Given an store subscription id will search the appropriate data object and return the internal subscription id | |
*/ | |
public function getInternalSubscriptionId( storeSubscriptionId:String ):String | |
{ | |
var subscriptionIds:Object; | |
if (InAppBilling.service.implementation == "Android") | |
{ | |
subscriptionIds = android_store_subscription_ids; | |
} | |
else | |
{ | |
subscriptionIds = ios_store_product_ids; | |
} | |
for (var internalProductId:String in subscriptionIds) | |
{ | |
if (subscriptionIds[internalProductId] == storeSubscriptionId) | |
return internalProductId; | |
} | |
return null; | |
} | |
} | |
} | |
// com.distriqt.InAppBilling |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment