{"_id":"5a6b684793313c005b692e23","category":{"_id":"5a6b684793313c005b692e0a","version":"5a6b684793313c005b692e07","project":"57c87ef85754fa1700b1228d","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-11-05T21:53:37.386Z","from_sync":false,"order":2,"slug":"reference","title":"Reference"},"project":"57c87ef85754fa1700b1228d","parentDoc":null,"user":"57c73a03e6935b1700b15115","version":{"_id":"5a6b684793313c005b692e07","project":"57c87ef85754fa1700b1228d","__v":1,"createdAt":"2018-01-26T17:41:27.297Z","releaseDate":"2018-01-26T17:41:27.297Z","categories":["5a6b684793313c005b692e08","5a6b684793313c005b692e09","5a6b684793313c005b692e0a","5a6b684793313c005b692e0b"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"3.5.3","version":"3.5.3"},"githubsync":"","__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-09-30T22:18:40.806Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":18,"body":"If any screen in your flow contains a purchase SKU, the SDK will verify with google that the SKU exists. If it does, and the user clicks on a button to initiate a purchase, we simply forward you this information by calling the `handlePurchaseRequested` method with the `PrimerPurchase` object.\n\nYou should simply forward the SKU and item type along to your existing purchase implementation. In this example, we forward this work to a new activity that handles purchase info in its intent extras. In order to continue with the primer flow, you must call our purchase completed methods.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"import android.content.Intent;\\nimport android.os.Bundle;\\nimport android.util.Log;\\n\\nimport com.goprimer.AbstractPrimerLaunchActivity;\\nimport com.goprimer.PrimerPurchase;\\nimport com.goprimer.app.ClientPurchaseActivity;\\nimport com.goprimer.callbacks.PrimerPurchaseFinishedCallback;\\n\\npublic class ClientLaunchActivity extends AbstractPrimerLaunchActivity {\\n\\n:::at:::Override\\npublic void handlePurchaseRequested(PrimerPurchase purchaseInfo, PrimerPurchaseFinishedCallback primerCallback) {\\n    mPrimerPurchaseFinishedCallback = primerCallback;\\n\\n    Intent intent = new Intent(this, ClientPurchaseActivity.class);\\n    intent.setAction(ClientPurchaseActivity.ACTION_LAUNCH_PURCHASE);\\n    Bundle extras = new Bundle();\\n    extras.putString(ClientPurchaseActivity.INTENT_EXTRA_KEY_SKU, purchaseInfo.getSku());\\n    extras.putString(ClientPurchaseActivity.INTENT_EXTRA_KEY_ITEM_TYPE, purchaseInfo.getItemType());\\n    Log.d(\\\"Tag\\\", \\\"itemtype: \\\" + purchaseInfo.getItemType() + \\\"sku: \\\" + purchaseInfo.getSku());\\n    intent.putExtras(extras);\\n    startActivityForResult(intent, START_PURCHASE_REQUEST_CODE);\\n}\\n\\n@Override\\nprotected void onActivityResult(int requestCode, int resultCode, Intent data) {\\n    super.onActivityResult(requestCode, resultCode, data);\\n    if (requestCode == START_PURCHASE_REQUEST_CODE) {\\n            if (wasSuccess) {\\n                purchaseComplete();\\n            } else {\\n                if (resultCode == IabHelper.IABHELPER_USER_CANCELLED || resultCode == 1) {\\n                    purchaseCancelled();\\n                } else {\\n                    purchaseFailed(\\\"Error with purchase\\\", resultCode);\\n                }\\n            }\\n    }\\n}\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"handling-purchases","type":"basic","title":"In-App Purchasing"}
If any screen in your flow contains a purchase SKU, the SDK will verify with google that the SKU exists. If it does, and the user clicks on a button to initiate a purchase, we simply forward you this information by calling the `handlePurchaseRequested` method with the `PrimerPurchase` object. You should simply forward the SKU and item type along to your existing purchase implementation. In this example, we forward this work to a new activity that handles purchase info in its intent extras. In order to continue with the primer flow, you must call our purchase completed methods. [block:code] { "codes": [ { "code": "import android.content.Intent;\nimport android.os.Bundle;\nimport android.util.Log;\n\nimport com.goprimer.AbstractPrimerLaunchActivity;\nimport com.goprimer.PrimerPurchase;\nimport com.goprimer.app.ClientPurchaseActivity;\nimport com.goprimer.callbacks.PrimerPurchaseFinishedCallback;\n\npublic class ClientLaunchActivity extends AbstractPrimerLaunchActivity {\n\n@Override\npublic void handlePurchaseRequested(PrimerPurchase purchaseInfo, PrimerPurchaseFinishedCallback primerCallback) {\n mPrimerPurchaseFinishedCallback = primerCallback;\n\n Intent intent = new Intent(this, ClientPurchaseActivity.class);\n intent.setAction(ClientPurchaseActivity.ACTION_LAUNCH_PURCHASE);\n Bundle extras = new Bundle();\n extras.putString(ClientPurchaseActivity.INTENT_EXTRA_KEY_SKU, purchaseInfo.getSku());\n extras.putString(ClientPurchaseActivity.INTENT_EXTRA_KEY_ITEM_TYPE, purchaseInfo.getItemType());\n Log.d(\"Tag\", \"itemtype: \" + purchaseInfo.getItemType() + \"sku: \" + purchaseInfo.getSku());\n intent.putExtras(extras);\n startActivityForResult(intent, START_PURCHASE_REQUEST_CODE);\n}\n\n@Override\nprotected void onActivityResult(int requestCode, int resultCode, Intent data) {\n super.onActivityResult(requestCode, resultCode, data);\n if (requestCode == START_PURCHASE_REQUEST_CODE) {\n if (wasSuccess) {\n purchaseComplete();\n } else {\n if (resultCode == IabHelper.IABHELPER_USER_CANCELLED || resultCode == 1) {\n purchaseCancelled();\n } else {\n purchaseFailed(\"Error with purchase\", resultCode);\n }\n }\n }\n}\n}", "language": "java" } ] } [/block]