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

Payment Service

Reply
Developer
Posts: 113
Registered: ‎03-23-2011
My Device: Playbook, Z10

Re: Payment service problem after upgrading to BB10

I am working through the process with cocos2d-x-2.0.4, and was able to get the test window to appear.  In this version, there is a problem in CCEGLView.cpp, line 354... here's the context:

 

    // Create the screen window.
    rc = screen_create_window(&m_screenWindow, m_screenContext);
    if (rc)
    {
        perror("screen_create_window");
        return false;
    }

    /****************  ADD THIS BLOCK OF CODE
    // Create the screen window group.
    rc = screen_create_window_group(m_screenWindow, m_windowGroupID);
    if (rc)
    {
        perror("screen_create_window_group");
        return false;
    }
    *****************/ END NEW BLOCK

    // Set/get any window prooperties.
    rc = screen_set_window_property_iv(m_screenWindow, SCREEN_PROPERTY_FORMAT, &screenFormat);
    if (rc)
    {
        perror("screen_set_window_property_iv(SCREEN_PROPERTY_FORMAT)");
        return false;
    }

 

Basically, the screen window group was never created, although an id was already created previously based on the process PID.  The method to retrieve the window group ID was removed in this version, so I get it through the PID:

 

	    char 			 windowGroupID[16];
	    snprintf(windowGroupID, sizeof(windowGroupID), "%d", getpid());

 I have not tested everything fully, but a window does appear, and there's no crashing, so it can't be ALL wrong :smileyhappy:

 

----------------
WIP game: Melodaeum
My graphically bland but very useful Morse Code trainer: Speed CW
My graphically attractive but boring game: The Rainstorm
Developer
Posts: 113
Registered: ‎03-23-2011
My Device: Playbook, Z10

Re: Payment service problem after upgrading to BB10

On a related note, is there any news on live payments?  Are they ready yet?

----------------
WIP game: Melodaeum
My graphically bland but very useful Morse Code trainer: Speed CW
My graphically attractive but boring game: The Rainstorm
Developer
Posts: 113
Registered: ‎03-23-2011
My Device: Playbook, Z10

Re: Payment service problem after upgrading to BB10

After working a bit more on this, I can confirm that it does work, but only with some more modification to CCEGLView.  Specifically, when I put code like this:

	bps_event_t *event = NULL;
	bps_get_event(&event, -1);  

in my own code (outside of cocos2d-x source), I never get a result, even after subscribing to payment events.  When I put code to handle payment events in CCEGLView, it all works as expected.  From a software engineering standpoint, that makes me cringe.  Is there a way to process payments in my own code when cocos2d-x is already handling the other bps event domains? (screen, navigator, etc.)

 

Here's the code that works when placed in the loop in CCEGLView.cpp:

       else if (bps_event_get_domain(event) == paymentservice_get_domain())
	    {
	        if (SUCCESS_RESPONSE == paymentservice_event_get_response_code(event))
	        {
				if (PURCHASE_RESPONSE == bps_event_get_code(event))
				{
				    if (event == NULL)
				    {
				        fprintf(stderr, "Invalid event.\n");
				        break;
				    }

					// Handle a successful purchase here
					const char* digital_good = paymentservice_event_get_digital_good_id(event, 0);
					const char* digital_sku = paymentservice_event_get_digital_good_sku(event, 0);

				    unsigned request_id = paymentservice_event_get_request_id(event);
				    const char* date = paymentservice_event_get_date(event, 0);
				    const char* license_key = paymentservice_event_get_license_key(event, 0);
				    const char* metadata = paymentservice_event_get_metadata(event, 0);
				    const char* purchase_id = paymentservice_event_get_purchase_id(event, 0);

				    fprintf(stderr, "Purchase success. Request Id: %d\n Date: %s\n DigitalGoodID: %s\n SKU: %s\n License: %s\n Metadata: %s\n PurchaseId: %s\n\n",
				        request_id,
				        date ? date : "N/A",
				        digital_good ? digital_good : "N/A",
				        digital_sku ? digital_sku : "N/A",
				        license_key ? license_key : "N/A",
				        metadata ? metadata : "N/A",
				        purchase_id ? purchase_id : "N/A");

					break;
				}
				else
				{
					// Handle a successful query for past purchases here
					int numPurchases = paymentservice_event_get_number_purchases(event);
					fprintf(stderr, "Handle a successful query for past purchases here");

					break;
				}
	        }
	        else
	        {
			    if (event == NULL)
			    {
			        fprintf(stderr, "Invalid event.\n");
			        break;
			    }

			    unsigned request_id = paymentservice_event_get_request_id(event);
			    int error_id = paymentservice_event_get_error_id(event);
			    const char *error_text = paymentservice_event_get_error_text(event);

			    fprintf(stderr, "Payment System error. Request ID: %d  Error ID: %d  Text: %s\n",
			            request_id, error_id, error_text ? error_text : "N/A");
				break;
	        }
	    }

 Adapted from http://bb10pro.com/2012/10/25/blackberry-payment-service-and-cocos2d-x/

----------------
WIP game: Melodaeum
My graphically bland but very useful Morse Code trainer: Speed CW
My graphically attractive but boring game: The Rainstorm
Retired
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10

Re: Payment service problem after upgrading to BB10

I took a look at PHelper.cpp from the site you referenced and noticed a few issues which may contribute to this not working:

1) In your code you should use a BPS event loop, if BPS is initialized already on the same thread then there is no guarantee that the first event that gets read in will be a Payment event, it could be a touch event, accelerometer etc. Using a loop will let you read in each of these events and filter out the events related to Payment

 

2) In the MakePurchase method BPS gets initialized and you register for payment events every time this is called, it should only be called once and then the loop started, the purchase request should really be the only thing called from this method.

 

Take a look at the handleEvents() method of CCEGLView.cpp to see the loop. You can handle payment events in a separate class but need to follow the same sort of conventions.

Garett
@garettBeuk
--
Goodbye everybody!
Developer
Posts: 113
Registered: ‎03-23-2011
My Device: Playbook, Z10

Re: Payment service problem after upgrading to BB10

Thank you, that's just what I needed.

 

I got things working better, just one small problem now.  paymentservice_event_get_error_id always returns 0, no matter what failure mode I choose with the payment simulator popup.  The paymentservice_event_get_error_text gives correct information (so I could compare strings as a workaround), just the error_id is always 0.  When a successful payment happens, everything works as expected.  

 

Here's the code now:

int MakePurchase(char* good_id, char* good_name, char* good_sku, char* mdata, char* app_icon, char* appname)
{

	const char* digital_good_id = good_id;
	const char* digital_good_name = good_name;
	const char* digital_good_sku = good_sku;
	const char* metadata = mdata;
	const char* purchase_app_icon = app_icon;
	const char* purchase_app_name = appname;

	unsigned request_id = 0;

    // Changed CCEGLView to create a window group with ID of getPID
char windowGroupID[16]; snprintf(windowGroupID, sizeof(windowGroupID), "%d", getpid()); if (paymentservice_purchase_request(digital_good_id, digital_good_sku, digital_good_name, metadata, purchase_app_name, purchase_app_icon, windowGroupID, &request_id) != BPS_SUCCESS) { fprintf(stderr, "Error: purchase request failed.\n"); } bps_event_t *event = NULL; while(true) { bps_get_event(&event, 1); if (event) { if (bps_event_get_domain(event) == paymentservice_get_domain()) { if (SUCCESS_RESPONSE == paymentservice_event_get_response_code(event)) { if (PURCHASE_RESPONSE == bps_event_get_code(event)) { // Handle a successful purchase here const char* digital_good = paymentservice_event_get_digital_good_id(event, 0); const char* digital_sku = paymentservice_event_get_digital_good_sku(event, 0); onPurchaseSuccess(event); //comment this one if you don't want to put all info in console int result = atoi(digital_good); return result; } else { // Handle a successful query for past purchases here int numPurchases = paymentservice_event_get_number_purchases(event); fprintf(stderr, "Handle a successful query for past purchases here"); return numPurchases; } } else { int error_id = paymentservice_event_get_error_id(event); const char* error_text = paymentservice_event_get_error_text(event); failureCommon(event); //comment this one if you don't want to put all info in console return error_id; } } } } return -1; }

 

 

 

----------------
WIP game: Melodaeum
My graphically bland but very useful Morse Code trainer: Speed CW
My graphically attractive but boring game: The Rainstorm
Retired
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10

Re: Payment service problem after upgrading to BB10

Which OS are you using to test? Sim or real device?

Does this work as expected on the PlayBook?

Garett
@garettBeuk
--
Goodbye everybody!
Developer
Posts: 113
Registered: ‎03-23-2011
My Device: Playbook, Z10

Re: Payment service problem after upgrading to BB10

I'm developing on Linux (Mint and Fedora). This is on a Dev Alpha B device.  

 

I have not tested with the PlayBook, and I may test it later, or maybe not, since I'm trying to hurry and get this game done before Friday for Built for Blackberry :smileyhappy:

 

I'm not working on this at the moment, but when I do in a few hours I'll try opening the payment service test sample to see if the same problem happens, or maybe try the playbook.

----------------
WIP game: Melodaeum
My graphically bland but very useful Morse Code trainer: Speed CW
My graphically attractive but boring game: The Rainstorm
Retired
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10

Re: Payment service problem after upgrading to BB10

I meant which OS is the device :smileyhappy:
Garett
@garettBeuk
--
Goodbye everybody!
Developer
Posts: 113
Registered: ‎03-23-2011
My Device: Playbook, Z10

Re: Payment service problem after upgrading to BB10

:smileyhappy:  I just wanted to be sure I had all the bases covered.  In case you missed it, it is a Dev Alpha B, oh and I guess maybe you want to know the version.  It's 10.0.9.1675

----------------
WIP game: Melodaeum
My graphically bland but very useful Morse Code trainer: Speed CW
My graphically attractive but boring game: The Rainstorm
Retired
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10

Re: Payment service problem after upgrading to BB10

I just tested in Cascades and I received the correct error response (which was 4) but then I tried a few other errors and I am only ever receiving 4 in a response. So it seems we have a bug. I will let the payment folks internally know.

 

Thanks!

Garett
@garettBeuk
--
Goodbye everybody!