Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Android™ Runtime Development

Reply
Contributor
varunagp1988
Posts: 42
Registered: ‎11-11-2013
My Device: Black berry Play book
Accepted Solution

Android - Inapp purchase sending request fails.

[ Edited ]

  I'm using Playbook (OS Version is 2.1.0.1526).IAP working fine with Android market but nothing happen when click on buy button in playbook version of ported app. I remove signature verfiication code. My inapp purchase code is same as inapp purchase sample application in android developer site and i'm using android in-app billing v2.

 

I have downloaded using sandbox test account. But nothing happened. 

  

 When i sending request itseft fails, my request code is

Bundle response = mService.sendBillingRequest(request); // mservice - IMarketBillingService
PendingIntent pendingIntent  = response.getParcelable(Consts.BILLING_RESPONSE_PURCHASE_INTENT);
        if (pendingIntent == null) {
              Log.e(TAG, "Error with requestPurchase");
              return Consts.BILLING_RESPONSE_INVALID_REQUEST_ID;
        }

 

I checked the responsecode, that return value 5 (i.e) developer_error. and pendingIntent object become null. After that i can't proceed the next step. Even When i checked the support for IAP through code, code return false value.

 

I have also looked into here : http://supportforums.blackberry.com/t5/Android-Runtime-Development/Android-Inapp-purchase-response/t...

 

But i couldnt find any soultion, please help me to solve this.

Regular Contributor
jcentricity
Posts: 62
Registered: ‎09-28-2012
My Device: BlackBerry Bold

Re: Android - Inapp purchase sending request fails.

ensure inapp code is correct.  my code worked after I removed signature.  jJcentricity

 

 

 

 

 

 

 

Contributor
varunagp1988
Posts: 42
Registered: ‎11-11-2013
My Device: Black berry Play book

Re: Android - Inapp purchase sending request fails.

[ Edited ]

Thanks for your concern.

 

Yes i have commented the condition in Security class.

 

//        if (!TextUtils.isEmpty(signature)) {
//            /**
//             * Compute your public key (that you got from the Android Market publisher site).
//             *
//             * Instead of just storing the entire literal string here embedded in the
//             * program,  construct the key at runtime from pieces or
//             * use bit manipulation (for example, XOR with some other string) to hide
//             * the actual key.  The key itself is not secret information, but we don't
//             * want to make it easy for an adversary to replace the public key with one
//             * of their own and then fake messages from the server.
//             *
//             * Generally, encryption keys / passwords should only be kept in memory
//             * long enough to perform the operation they need to perform.
//             */
//            String base64EncodedPublicKey = "your public key here";
//            PublicKey key = Security.generatePublicKey(base64EncodedPublicKey);
//            verified = Security.verify(key, signedData, signature);
//            if (!verified) {
//                Log.w(TAG, "signature does not match data.");
//                return null;
//            }
//        }

 

If you have a sample example that is working, please share with me.

Regular Contributor
jcentricity
Posts: 62
Registered: ‎09-28-2012
My Device: BlackBerry Bold

Re: Android - Inapp purchase sending request fails.

Are you getting blackberry payment window?
Contributor
varunagp1988
Posts: 42
Registered: ‎11-11-2013
My Device: Black berry Play book

Re: Android - Inapp purchase sending request fails.

 No I am not getting Blackberry payemnt window.

 

When i click on buy button, nothing happens, i have added some toast messages to get to know what is happening,
in that it will call run() inside that it enters this if statement.

 

Bundle response = mService.sendBillingRequest(request);
        PendingIntent pendingIntent = response.getParcelable(Consts.BILLING_RESPONSE_PURCHASE_INTENT);
        if (pendingIntent == null) {
        Log.e(TAG, "Error with requestPurchase");
        Toast.makeText(getApplicationContext(), "Errors: Error with requestPurchase " + Consts.BILLING_RESPONSE_INVALID_REQUEST_ID, 2000)
            .show();
        return Consts.BILLING_RESPONSE_INVALID_REQUEST_ID;
        }

 

and i get the toast as Errors: Error with requestPurchase

 

what am i doing wrong here, stuck from long time.

 

Thanks again.

Regular Contributor
jcentricity
Posts: 62
Registered: ‎09-28-2012
My Device: BlackBerry Bold

Re: Android - Inapp purchase sending request fails.

Bundle request = makeRequestBundle("REQUEST_PURCHASE");

//Item ID of INapp purchase
        request.putString("ITEM_ID", itemId);

    Bundle response = mService.sendBillingRequest(request);

//The RESPONSE_CODE key provides you with the status of the request
            Integer responseCodeIndex     = (Integer) response.get("RESPONSE_CODE");
            //The PURCHASE_INTENT key provides you with a PendingIntent, which you can use to launch the checkout UI
            PendingIntent pendingIntent = (PendingIntent) response.get("PURCHASE_INTENT");
            //The REQUEST_ID key provides you with a unique request identifier for the request
            Long requestIndentifier     = (Long) response.get("REQUEST_ID");
            
//            Log.i(TAG, "current request is:" + requestIndentifier);
//            Toast.makeText(mContext, "current request is:" + requestIndentifier, Toast.LENGTH_LONG).show();
            
            C.ResponseCode responseCode = C.ResponseCode.valueOf(responseCodeIndex);
            
//            Log.i(TAG, "REQUEST_PURCHASE Sync Response code: "+responseCode.toString());
//            Toast.makeText(mContext, "REQUEST_PURCHASE Sync Response code: "+responseCode.toString(), Toast.LENGTH_LONG).show();
            
            startBuyPageActivity(pendingIntent, new Intent(), activityContext);

 

 

private static Bundle makeRequestBundle(String method)
    {
        Bundle request = new Bundle();
        request.putString("BILLING_REQUEST", method);
        request.putInt("API_VERSION", 1);
        request.putString("PACKAGE_NAME", mContext.getPackageName());
        return request;
    }

 

private static void startBuyPageActivity(PendingIntent pendingIntent, Intent intent, Context context)
    {
        //TODO add above 2.0 implementation with reflection, for now just using 1.6 implem
        
        // This is on Android 1.6. The in-app checkout page activity will be on its
        // own separate activity stack instead of on the activity stack of
        // the application.
        try
        {
            pendingIntent.send(context, 0, intent);    
        }
        catch (CanceledException e)
        {
//            Log.e(TAG, "startBuyPageActivity CanceledException");
//            Toast.makeText(mContext, "startBuyPageActivity CanceledException", Toast.LENGTH_LONG).show();
        }
    }

Contributor
varunagp1988
Posts: 42
Registered: ‎11-11-2013
My Device: Black berry Play book

Re: Android - Inapp purchase sending request fails.

[ Edited ]

Hello jcentricity,

 

Thanks for giving me the code:

 

I tried with your code, on click of buy button the app crashes.

 

This is my OLD CODE :

 

Please correct me if i am doing wrong anywhere.

 

1) RequestPurchase extends BillingRequest

 

 

 /**
     * Wrapper class that requests a purchase.
     */
    class RequestPurchase extends BillingRequest {
	public final String mProductId;
	public final String mDeveloperPayload;
	public final String mProductType;

	/** Legacy constructor
	 *
	 * @param itemId  The ID of the item to be purchased. Will be assumed to be a one-time
	 *                purchase.
	 */
	@Deprecated
	public RequestPurchase(String itemId) {
	    this(itemId, null, null);
	}

	/** Legacy constructor
	 *
	 * @param itemId  The ID of the item to be purchased. Will be assumed to be a one-time
	 *                purchase.
	 * @param developerPayload Optional data.
	 */
	@Deprecated
	public RequestPurchase(String itemId, String developerPayload) {
	    this(itemId, null, developerPayload);
	}

	/** Constructor
	 *
	 * @param itemId  The ID of the item to be purchased. Will be assumed to be a one-time
	 *                purchase.
	 * @param itemType  Either Consts.ITEM_TYPE_INAPP or Consts.ITEM_TYPE_SUBSCRIPTION,
	 *                  indicating the type of item type support is being checked for.
	 * @param developerPayload Optional data.
	 */
	public RequestPurchase(String itemId, String itemType, String developerPayload) {
	    // This object is never created as a side effect of starting this
	    // service so we pass -1 as the startId to indicate that we should
	    // not stop this service after executing this request.
	    super(-1);
	    mProductId = itemId;
	    mDeveloperPayload = developerPayload;
	    mProductType = itemType;
	}

	@Override
	protected long run() throws RemoteException {
	    Toast.makeText(getApplicationContext(), "requestpurchase()", 2000).show();
	    Bundle request = makeRequestBundle("REQUEST_PURCHASE");
	    request.putString(Consts.BILLING_REQUEST_ITEM_ID, mProductId);
	    request.putString(Consts.BILLING_REQUEST_ITEM_TYPE, mProductType);
	    // Note that the developer payload is optional.
	    if (mDeveloperPayload != null) {
		request.putString(Consts.BILLING_REQUEST_DEVELOPER_PAYLOAD, mDeveloperPayload);
	    }
	    Bundle response = mService.sendBillingRequest(request);
	    PendingIntent pendingIntent = response.getParcelable(Consts.BILLING_RESPONSE_PURCHASE_INTENT);
	    if (pendingIntent == null) {
		Log.e(TAG, "Error with requestPurchase");
		Toast.makeText(getApplicationContext(), "Errors: Error with requestPurchase " + Consts.BILLING_RESPONSE_INVALID_REQUEST_ID, 2000)
			.show();
		return Consts.BILLING_RESPONSE_INVALID_REQUEST_ID;
	    }
	    Toast.makeText(getApplicationContext(), "requestPurchase successfull " + Consts.BILLING_RESPONSE_REQUEST_ID, 2000).show();
	    Intent intent = new Intent();
	    ResponseHandler.buyPageIntentResponse(pendingIntent, intent);
	    return response.getLong(Consts.BILLING_RESPONSE_REQUEST_ID, Consts.BILLING_RESPONSE_INVALID_REQUEST_ID);
	}

	@Override
	protected void responseCodeReceived(ResponseCode responseCode) {
	    ResponseHandler.responseCodeReceived(BillingService.this, this, responseCode);
	}

 

2)  In ResponseHandler

 

/**
     * Starts a new activity for the user to buy an item for sale. This method
     * forwards the intent on to the PurchaseObserver (if it exists) because
     * we need to start the activity on the activity stack of the application.
     *
     * @param pendingIntent a PendingIntent that we received from Android Market that
     *     will create the new buy page activity
     * @param intent an intent containing a request id in an extra field that
     *     will be passed to the buy page activity when it is created
     */
    public static void buyPageIntentResponse(PendingIntent pendingIntent, Intent intent) {
        if (sPurchaseObserver == null) {
            if (Consts.DEBUG) {
                Log.d(TAG, "UI is not running");
            }
            return;
        }
        sPurchaseObserver.startBuyPageActivity(pendingIntent, intent);
    }

 

3) In PurchaseObserver

 

 void startBuyPageActivity(PendingIntent pendingIntent, Intent intent) {
	if (mStartIntentSender != null) {
	    // This is on Android 2.0 and beyond.  The in-app buy page activity
	    // must be on the activity stack of the application.
	    try {
		// This implements the method call:
		// mActivity.startIntentSender(pendingIntent.getIntentSender(),
		//     intent, 0, 0, 0);
		mStartIntentSenderArgs[0] = pendingIntent.getIntentSender();
		mStartIntentSenderArgs[1] = intent;
		mStartIntentSenderArgs[2] = Integer.valueOf(0);
		mStartIntentSenderArgs[3] = Integer.valueOf(0);
		mStartIntentSenderArgs[4] = Integer.valueOf(0);
		mStartIntentSender.invoke(mActivity, mStartIntentSenderArgs);
	    } catch (Exception e) {
		Log.e(TAG, "error starting activity", e);
	    }
	} else {
	    // This is on Android version 1.6. The in-app buy page activity must be on its
	    // own separate activity stack instead of on the activity stack of
	    // the application.
	    try {
		pendingIntent.send(mActivity, 0 /* code */, intent);
	    } catch (CanceledException e) {
		Log.e(TAG, "error starting activity", e);
	    }
	}
    }

 

4) In Dungeons class onClick on buy button

 

if (!mBillingService.requestPurchase(mSku, Consts.ITEM_TYPE_INAPP, null)) {
		showDialog(DIALOG_BILLING_NOT_SUPPORTED_ID);
	    }

 

I have removed the signature verification part.

 

 

 

 

Contributor
varunagp1988
Posts: 42
Registered: ‎11-11-2013
My Device: Black berry Play book

Re: Android - Inapp purchase sending request fails.

Ok,

 

After searching a lot i got the example where i saw the code which you had posted earlier is exactly same.

 

Example Code Link :

http://www.anddev.org/advanced-tutorials-f21/simple-inapp-billing-payment-t52060.html

 

Now i had checked with this app and it was crashing for some reason and i was not able to find out why it was crashing,so i have added toast and tried to check what is the response.

 

when i click on BUY button these are the following responses:

 

1)Toast.makeText(mContext, "isBillingSupported " + ResponseCode.RESULT_OK.equals(code), 2000).show();

response: isBillingSupported true

 

2)Toast.makeText(mContext, "current request is:" + requestIndentifier, Toast.LENGTH_LONG).show();

response : current request -1

 

3)Toast.makeText(mContext, "REQUEST_PURCHASE Sync Response code: " + responseCode.toString(), Toast.LENGTH_LONG).show();

response: "REQUEST_PURCHASE Sync Response code: RESULT ERROR

 

How i am testing:

 

1) I have already uploaded the bar and made it as draft with the item id.

2) Now for this example i am just replacing the package name,version code,version name and the item id that i have used the app(that i have made it as draft).

3) create bar and install the bar in the Blackberry Playbook.

 

Is the the proper way to test ? or if i make any changes to my code, each time do i need to upload the bar to the portal and install it from the portal?

 

 

 

Regular Contributor
jcentricity
Posts: 62
Registered: ‎09-28-2012
My Device: BlackBerry Bold

Re: Android - Inapp purchase sending request fails.

you must install bar from store while it's in draft state. add a version number to your main page somewhere so when u download draft you will know it's the right version. follow steps http://supportforums.blackberry.com/t5/BlackBerry-World-Development/How-To-Live-Testing-the-Payment-...

ensure you follow these steps

On the home screen of the BlackBerry PlayBook tablet, tap the BlackBerry World icon.
Swipe your finger from the bottom left corner of the screen toward the center of the screen to display the keyboard.
Type tst. Tap Return.
Open the browser on the tablet.
In the address bar, type the location of the application that you want to test (for example, you can type http://appworld.blackberry.com/webstore/content/xxxxx, where xxxxx is the ID of the application).
On the Details screen for your application, click Purchase.
Complete the instructions on the screen to download the application.
Contributor
varunagp1988
Posts: 42
Registered: ‎11-11-2013
My Device: Black berry Play book

Re: Android - Inapp purchase sending request fails.

[ Edited ]

Yes, i have done these steps.

 

when i click on BUY button these are the following responses:

 

1)Toast.makeText(mContext, "isBillingSupported " + ResponseCode.RESULT_OK.equals(code), 2000).show();

response: isBillingSupported true

 

2)Toast.makeText(mContext, "current request is:" + requestIndentifier, Toast.LENGTH_LONG).show();

response : current request -1

 

3)Toast.makeText(mContext, "REQUEST_PURCHASE Sync Response code: " + responseCode.toString(), Toast.LENGTH_LONG).show();

response: "REQUEST_PURCHASE Sync Response code: RESULT ERROR(6)

 

The app crashes,what i am missing here ?