2
I am implementing the purchase of Subscriptions in an Android application.
So far, payment orders are already configured in the 'Google Play Developer Console' and I can debit the amount set in each of the SKU on the credit card.
At the end of this, I want to get the JSON data that should come "INAPP_PURCHASE_DATA"
within the onActivityResult
of the application.
However, when making the call on bundle
, returns nothing.
All places of the code where the purchase data should return always return a Null value.
But even so the purchase is charged from my card. Which brings me to the process of running to the console of 'Google Wallet
' and cancel the billing.
Here’s what I’m doing at the moment:
I set the service before Oncreate.
ServiceConnection mServiceConn = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
mService = null;
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mService = IInAppBillingService.Stub.asInterface(service);
}
};
In onCreate I define the SKU that comes from another Activity, I start the Service and configuration of Iabhelper.
@Override
public void onCreate(Bundle savedInstanceState) {
.
.
.
skuSubs = getIntent().getExtras().getString("SKU_TYPE");
bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"), mServiceConn, Context.BIND_AUTO_CREATE);
mHelper = new IabHelper(this, base64EncodedPublicKey);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
Log.d(TAG, "In-app Billing setup failed: " result);
}else{
Log.d(TAG, "In-app Billing is set up OK");
}
}
});
}
here I define the method that will be used in
onClick
of my Activity to open the signature dialog. (developerPayload is generated elsewhere in the code)
public void buyClick(View view) {
mHelper.launchPurchaseFlow(this, skuSubs, 10001, mPurchaseFinishedListener, developerPayload);
}
In the 'onActivityResult' method I capture the return of the 'INAPP_PURCHASE_DATA' by 'Bundle'.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
}
if(data.getExtras()!=null){
Bundle bundle = data.getExtras();
editText.setText(bundle.getString("INAPP_PURCHASE_DATA"));
}else{
editText.setText("null");
}
}
Here the 'mPurchaseFinishedListener' treats the purchase data. In tests I tried to capture the data by the 'Purchase' class, but without success.
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
if (result.isFailure()) {
return;
}else
if (purchase.getSku().equals(skuSubs)) {
mHelper.queryInventoryAsync(mReceivedInventoryListener);
}
}
};
IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
StringBuffer sb = new StringBuffer();
if (result.isFailure()) {
// Handle failure
return;
} else {
mHelper.consumeAsync(inventory.getPurchase(skuSubs), mConsumeFinishedListener);
}
}
};
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase, IabResult result) {
if (result.isSuccess()) {
//ok msg
} else {
//fail msg
}
}
};
In onDestroy I end with 'Service' and 'Iabhelper''.
@Override
public void onDestroy() {
super.onDestroy();
if (mService != null) unbindService(mServiceConn);
if (mHelper != null) {
mHelper.dispose();
mHelper = null;
}
}
In my 'Androidmanifest.xml' are defined:
<uses-permission android:name="com.android.vending.BILLING" />
...
<service android:name="com.android.vending.billing.IInAppBillingService" />
When I set this up, depending on the SKU that is sent in the previous Activity I get the purchase data correctly.
When I make the purchase, it is determined as completed and then I do not receive the purchase result.
I open the Developer Console and immediately after I log into Wallet to cancel the debited Subscription.
How do I make this request within the application? I can’t get the return on purchase so far.