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: 78
Registered: ‎12-12-2012
My Device: playbook
My Carrier: free

paymentservice_get_existing_purchases_request CRASH

Hello, I open a new thread to solve my issue with this function: paymentservice_get_existing_purchases_request

 

I have implemented the process of purchasing a virtual good. All works in local test, sandbox and live. Today I want to add managed item and then I add the possibility to restore past purchases.

 

Then in a callback of button restore in my game I call

 


void* Callback_RestoreTransactions(const char* _params, const char* _callerName)
{

    unsigned request_id = 0;
        if(paymentservice_get_existing_purchases_request(false, get_window_group_id(), &request_id) != BPS_SUCCESS)
        {
            STD_Printf("Error: restore transaction failed.\n");
        }
        STD_Printf("Purchase restore request ID %d\n", request_id);
    #endif


  return NULL;
}

 

 

I have checked the documentation: https://developer.blackberry.com/native/documentation/core/check_past_purchases_native.html

 

And now what?

 

This function continue to crash in sandbox mode, even if I set refresh param to true or false. If I set to true my game crash every time. If I set to false (means that payment service look for a cache purchase). Then if I bought an item and after try to restore: ok it works. If I bought nothing then this crash.

 

Where can I be wrong? thank you

Retired
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: paymentservice_get_existing_purchases_request CRASH

Do you know which line exactly is causing the crash? It could be an issue with the response logic, could you post that as well?

Garett
@garettBeuk
--
Goodbye everybody!
Developer
Posts: 78
Registered: ‎12-12-2012
My Device: playbook
My Carrier: free

Re: paymentservice_get_existing_purchases_request CRASH

Hello,

 

I will look into response code.

 

 

My code is:

 

In my update logic:

 

...

else if (domain == payment_domain)
          {
              handlePurchaseEvent(event);
          }

...

 

 

then

 

static void handlePurchaseEvent(bps_event_t *event)
{
  cPersistantDatasManager* pPDM = cPersistantDatasManager::GetInstancePtr();

  mPurchaseCalled = FALSE;

  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);
                // ...
        pPDM->GetUserDatasManager()->Purchase(digital_sku);

    }
    else // GET_EXISTING_PURCHASES_RESPONSE
    {    // Handle a successful query for past purchases here

         onGetExistingPurchasesSuccess(event);

    }
  }
  else
  {

      failureCommon(event);


  }



}

 

 

 

/////////////////


static void onGetExistingPurchasesSuccess(bps_event_t *event)
{
    if (event == NULL)
    {
         STD_Printf("Invalid event.\n");
        return;
    }

    unsigned request_id = paymentservice_event_get_request_id(event);
    int purchases = paymentservice_event_get_number_purchases(event);

    STD_Printf("Get existing purchases success. Request ID: %d\n", request_id);
    STD_Printf("Number of existing purchases: %d\n", purchases);
    STD_Printf("Existing purchases:\n");

    int i = 0;
    for (i = 0; i<purchases; i++)
    {
        const char* date = paymentservice_event_get_date(event, i);
        const char* digital_good = paymentservice_event_get_digital_good_id(event, i);
        const char* digital_sku = paymentservice_event_get_digital_good_sku(event, i);
        const char* license_key = paymentservice_event_get_license_key(event, i);
        const char* metadata = paymentservice_event_get_metadata(event, i);
        const char* purchase_id = paymentservice_event_get_purchase_id(event, i);

        STD_Printf("  Date: %s  PurchaseID: %s  DigitalGoodID: %s  SKU: %s  License: %s  Metadata&colon; %s\n",
            date ? date : "N/A",
            purchase_id ? purchase_id : "N/A",
            digital_good ? digital_good : "N/A",
            digital_sku ? digital_sku : "N/A",
            license_key ? license_key : "N/A",
            metadata ? metadata &colon; "N/A");

        cPersistantDatasManager* pPDM = cPersistantDatasManager::GetInstancePtr();
        // on unlock l'item acheté
        pPDM->GetUserDatasManager()->Purchase(digital_sku);
    }
}

 

 

 

This code works with cached purchases.

Retired
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: paymentservice_get_existing_purchases_request CRASH

Do you know which line causes the crash? Or in general how far your app gets before crashing? 

 

Nothing is immediately jumping out at me from the app as a possible cause for the crash.

Garett
@garettBeuk
--
Goodbye everybody!
Developer
Posts: 78
Registered: ‎12-12-2012
My Device: playbook
My Carrier: free

Re: paymentservice_get_existing_purchases_request CRASH

I will launch it with more verbose logs and send you report. Thank you.

 

 

Retired
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: paymentservice_get_existing_purchases_request CRASH

I tested the NDK PaymentService sample, which it looks like you may have borrowed logic from, and in sandbox mode I cannot replicate any sort of crash when trying to restore purchases.

 

Could you provide your app's content ID?

 

I tested against a Dev Alpha B running 10.2.0.1445

Garett
@garettBeuk
--
Goodbye everybody!
Developer
Posts: 78
Registered: ‎12-12-2012
My Device: playbook
My Carrier: free

Re: paymentservice_get_existing_purchases_request CRASH

The sample works fine because the function  paymentservice_get_existing_purchases_request  is only call after a purchase response.

 

Then payment  service use cache.

 

in the sample instead of calling purchase event, start by calling  paymentservice_get_existing_purchases_request . And I am sure that sample will crash.

 

If I made a purchase and call  paymentservice_get_existing_purchases_request with first param to false, all is ok and I retrieve past purchase.

 

I use Dev Alpha C with 10.2.

 

Retired
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: paymentservice_get_existing_purchases_request CRASH

I modified the sample to call:

paymentservice_get_existing_purchases_request(true, get_window_group_id(), &request_id) 

 

When the app first starts. Still no crash.

Garett
@garettBeuk
--
Goodbye everybody!
Developer
Posts: 78
Registered: ‎12-12-2012
My Device: playbook
My Carrier: free

Re: paymentservice_get_existing_purchases_request CRASH

Ok, I will try and debug my code. I recontact you here after, thank you
Developer
Posts: 78
Registered: ‎12-12-2012
My Device: playbook
My Carrier: free

Re: paymentservice_get_existing_purchases_request CRASH

I forgot to ask you if you test in sandbox?

 

My app never crash in local debug mode, even in release. But in sandbox and production crash