Presentation is loading. Please wait.

Presentation is loading. Please wait.

Android In-App Purchases 7 Аппсторов за полчаса Настя Каримова Разработчик мобильных приложений.

Similar presentations


Presentation on theme: "Android In-App Purchases 7 Аппсторов за полчаса Настя Каримова Разработчик мобильных приложений."— Presentation transcript:

1 Android In-App Purchases 7 Аппсторов за полчаса Настя Каримова Разработчик мобильных приложений

2 Топ приложений в Google Play

3 Рекламные баннеры

4 Покупки внутри приложений

5 5 контент функциональность сервисы Можно продавать

6 6 сonsumable (заклинания, жизни, время) non-consumable (уровни, текст книги) subscriptions (подписки на контент) Виды инаппов

7 7 Вот так выглядит инапп com.game.SKU_THE_BEST_SWORD_EVER

8 8

9 9 Permission

10 10 IabHelper helper = new IabHelper(context, "your_base_64_public_key"); helper.startSetup(new IabHelper.OnIabSetupFinishedListener() public void onIabSetupFinished(IabResult result) { if (result.isSuccess()) { //query inventory } else { complain("Billing is not supported."); } }); Настройка

11 11 helper.queryInventoryAsync(true, new IabHelper.QueryInventoryFinishedListener() public void onQueryInventoryFinished(IabResult result, Inventory inventory) { if (result.isFailure()) { complain(String.format("queryInventory failed:%s", result)); } else { //consume if not consumed //update UI } }); Запрашиваем инвентарь

12 12 final Purchase tipPurchase = inventory.getPurchase(IN_APP_SKU_TIP); if (tipPurchase != null) { helper.consumeAsync(tipPurchase, new IabHelper.OnConsumeFinishedListener() public void onConsumeFinished(Purchase purchase, IabResult result) { if (result.isSuccess()) { if (purchase.getSku().equals(IN_APP_SKU_TIP)) { //process it //update UI } }); } Выполняем consume

13 13 helper.launchPurchaseFlow(this, sku, REQUEST_CODE_PURCHASE_CODE, new IabHelper.OnIabPurchaseFinishedListener() public void onIabPurchaseFinished(IabResult result, Purchase info) { if (result.isSuccess() && info.getSku().equals(IN_APP_SKU_TIP)) { //consume //update UI } }); // your code protected void onActivityResult(int reqCode, int resCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); helper.handleActivityResult(requestCode, resultCode, data); } Покупка

14 14 Аппсторы

15 15

16 16... ... В манифесте

17 17 public class MyPurchasingObserver extends BasePurchasingObserver { private static final String TAG = "IAPPurchasingObserver"; public MyPurchasingObserver(Activity iapActivity) { super(iapActivity); } public void onSdkAvailable(final boolean isSandboxMode) {} public void onGetUserIdResponse(final GetUserIdResponse response) {} public void onItemDataResponse(final ItemDataResponse response) {} public void onPurchaseResponse(final PurchaseResponse response) {} public void onPurchaseUpdatesResponse( final PurchaseUpdatesResponse response) {} } Purchasing observer

18 18 public class IAPActivity extends Activity {... protected void onCreate(Bundle savedInstanceState) {... PurchasingManager.registerObserver(new MyPurchasingObserver(this)); }... } Регистрируем observer

19 19 PurchasingManager.initiatePurchaseUpdatesRequest(getPersistedOffset()); public class MyPurchasingObserver extends BasePurchasingObserver {... public void onPurchaseUpdatesResponse( final PurchaseUpdatesResponse response) { // No implementation required when dealing solely // with consumables. }... } Запрашиваем инвентарь

20 20 public class IAPActivity extends Activity { //... private void initiatePurchase() { String requestId = PurchasingManager.initiatePurchaseRequest ("com.amazon.example.iap.consumable"); } //... } public class MyPurchasingObserver extends BasePurchasingObserver {... public void onPurchaseResponse(PurchaseResponse response) { final PurchaseRequestStatus status = response.getPurchaseRequestStatus(); if (status == PurchaseResponse.PurchaseRequestStatus.SUCCESSFUL) { }... } Процесс покупки

21 21

22 22 Permissions

23 23 Маппинг SKU OpenIabHelper.mapSku(SKU_PREMIUM, OpenIabHelper.NAME_AMAZON, "org.onepf.trivialdrive.amazon.premium"); OpenIabHelper.mapSku(SKU_PREMIUM, OpenIabHelper.NAME_TSTORE, "tstore_sku_premium"); OpenIabHelper.mapSku(SKU_PREMIUM, OpenIabHelper.NAME_SAMSUNG, " / "); OpenIabHelper.mapSku(SKU_PREMIUM, "com.yandex.store", "org.onepf.trivialdrive.premium"); OpenIabHelper.mapSku(SKU_GAS, OpenIabHelper.NAME_AMAZON, "org.onepf.trivialdrive.amazon.gas"); OpenIabHelper.mapSku(SKU_GAS, OpenIabHelper.NAME_SAMSUNG, " / "); OpenIabHelper.mapSku(SKU_GAS, "com.yandex.store", "org.onepf.trivialdrive.gas"); OpenIabHelper.mapSku(SKU_INFINITE_GAS, OpenIabHelper.NAME_AMAZON, "org.onepf.trivialdrive.amazon.infinite_gas"); OpenIabHelper.mapSku(SKU_INFINITE_GAS, OpenIabHelper.NAME_SAMSUNG, " / "); OpenIabHelper.mapSku(SKU_INFINITE_GAS, "com.yandex.store", "org.onepf.trivialdrive.infinite_gas");

24 24 OpenIabHelper.Options options = new OpenIabHelper.Options(); Map storeKeys = new HashMap (); storeKeys.put(OpenIabHelper.NAME_GOOGLE, googleBase64EncodedPublicKey); /* storeKeys.put(OpenIabHelper.NAME_AMAZON, "Unavailable. Amazon doesn't support RSA verification. So this mapping is not needed"); */ /* storeKeys.put(OpenIabHelper.NAME_SAMSUNG,"Unavailable. SamsungApps doesn't support RSA verification. So this mapping is not needed"); */ storeKeys.put(OpenIabHelper.NAME_YANDEX, YANDEX_PUBLIC_KEY); options.storeKeys = storeKeys; options.checkInventory = true; options.prefferedStoreNames =... options.availableStores =... Опции

25 25 OpenIabHelper helper = new OpenIabHelper(context, options); helper.startSetup(new IabHelper.OnIabSetupFinishedListener() public void onIabSetupFinished(IabResult result) { if (result.isSuccess()) { //query inventory } else { complain("Billing is not supported."); } }); Настройка

26 26 helper.queryInventoryAsync(true, new IabHelper.QueryInventoryFinishedListener() public void onQueryInventoryFinished(IabResult result, Inventory inventory) { if (result.isFailure()) { complain(String.format("queryInventory failed: %s”, result)); } else { //consume if not consumed //update UI } }); Запрашиваем инвентарь

27 27 final Purchase tipPurchase = inventory.getPurchase(IN_APP_SKU_TIP); if (tipPurchase != null) { helper.consumeAsync(tipPurchase, newIabHelper.OnConsumeFinishedListener() public void onConsumeFinished(Purchase purchase, IabResult result) { if (result.isSuccess()) { if (purchase.getSku().equals(IN_APP_SKU_TIP)) { //process it //update UI } }); } Выполняем consume

28 28 helper.launchPurchaseFlow(this, sku, REQUEST_CODE_PURCHASE_CODE, new IabHelper.OnIabPurchaseFinishedListener() public void onIabPurchaseFinished(IabResult result, Purchase info) { if (result.isSuccess() && info.getSku().equals(IN_APP_SKU_TIP)) { //consume //update UI } }); // your code protected void onActivityResult(int reqCode, int resCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); helper.handleActivityResult(requestCode, resultCode, data); } Покупка

29 29 Верификация Server-2-Server

30 30 public static boolean verifyPurchase(String base64PublicKey, String signedData, String signature) { if (TextUtils.isEmpty(signedData) || TextUtils.isEmpty(base64PublicKey) || TextUtils.isEmpty(signature)) { Log.e(TAG, "Purchase verification failed: missing data."); return false; } PublicKey key = Security.generatePublicKey(base64PublicKey); return Security.verify(key, signedData, signature); } // Unique OpenIAB feature =) Options opts = new Options(); opts.verifyMode = Options.VERIFY_SKIP; mHelper = new OpenIabHelper(context, opts); Код верификации

31 31 One Platform Foundation github.com/onepf/OpenIAB github.com/onepf/AppDF


Download ppt "Android In-App Purchases 7 Аппсторов за полчаса Настя Каримова Разработчик мобильных приложений."

Similar presentations


Ads by Google