Managing subscriptions

See C++

You can use the following functions in PaymentManager to manage subscriptions in your app:

You can use the following functions to manage subscriptions in your app:

Request the terms of a digital good subscription

See C++

You can use the SubscriptionTermsReply class to interpret the results of a call to requestSubscriptionTerms(). The requestSubscriptionTerms() function is similar to all other PaymentManager requests. You can check that the requestSubscriptionTerms call finished using the SubscriptionTermsReply::finished() signal or the PaymentManager::subscriptionTermsFinished() signal.

When you call the requestSubscriptionTerms() function, only the ID or SKU of the digital good to be purchased is required; you don't need to provide both. If the ID and SKU are both provided, then the ID is used. To use the SKU, you must pass an empty string for the digitalGoodId.

void MyPaymentApp::getSubscriptionTerms(
    const QString &id, const QString &sku)
{
    if (id.isEmpty())
        return;

    const SubscriptionTermsReply *reply = 
        m_paymentManager->requestSubscriptionTerms(id, sku);

    bool success = QObject::connect(reply, 
         SIGNAL(finished()),
         this, 
         SLOT(subscriptionTermsReply()));

    if (success) {
       // Signal was successfully connected.

    } else {
       // Failed to connect to signal.
    } 
}

Here's a code sample that shows how you can handle the SubscriptionTermsReply. You can display the subscription terms in your UI when the subscriptionTermsResponseSuccess() signal is emitted or you can display an error with the error code and text in your UI when the infoResponseError() signal is emitted.

void MyPaymentApp::subscriptionTermsReply()
{
    bb::platform::SubscriptionTermsReply *reply = 
       qobject_cast<bb::platform::SubscriptionTermsReply*>(sender());
    Q_ASSERT(reply);

    // Emit an error signal if there were errors.

    if (reply->isError()) {

        emit infoResponseError(reply->errorCode(), 
            reply->errorText());

    // Emit a success signal if the request succeeded.

    } else {

       emit subscriptionTermsResponseSuccess(reply->price(), 
        reply->initialPeriod(), 
        reply->renewalPrice(), 
        reply->renewalPeriod());
    }

    reply->deleteLater();
}

Coming soon

Check the status of a subscription

See C++

You can use the SubscriptionStatusReply class to interpret the results of your call to requestSubscriptionStatus().

When you call the requestSubscriptionStatus() function, only the ID or SKU of the digital good to be purchased is required; you don't need to provide both. If you do provide both, the ID takes precedence.

You can use the constant PaymentManager::Subscription_App as the digitalGoodId in a call to the requestSubscriptionStatus() function to check the status of an app that is registered as a subscription in BlackBerry World.

void MyPaymentApp::checkSubscriptionStatus(const QString &id, 
                                           const QString &sku)
{
    if (id.isEmpty())
        return;

    const SubscriptionStatusReply *reply =
        m_paymentManager->requestSubscriptionStatus(id, sku);

    bool success = QObject::connect(reply,
         SIGNAL(finished()),
         this,
         SLOT(subscriptionStatusResponse()));

    if (success) {
       // Signal was successfully connected.

    } else {
       // Failed to connect to signal.
    }
}

Here's a code sample that shows how you can handle the SubscriptionStatusReply:

void MyPaymentApp::subscriptionStatusResponse()
{
    bb::platform::SubscriptionStatusReply *reply = 
      qobject_cast<bb::platform::SubscriptionStatusReply*>(sender());
    Q_ASSERT(reply);

    // Emit an error signal if there were errors.

    if (reply->isError()) {

       emit infoResponseError(reply->errorCode(), 
            reply->errorText());

    // Emit a success signal if the request succeeded.

    } else {

       emit checkStatusResponseSuccess(reply->isActive());
    }

    reply->deleteLater();
}
You can use the paymentservice_check_existing() function to check the status of a subscription.

When you call the paymentservice_check_existing() function, only the ID or SKU of the digital good to be purchased is required; you don't need to provide both. If you do provide both, the ID will take precedence.

static void
do_check_existing(int selected_index, char** result_str)
{
    unsigned request_id = 0;

    if(selected_index == CHECK_EXISTING_APP) {

        paymentservice_check_existing(
            PAYMENTSERVICE_APP_SUBSCRIPTION, 
            0, 
            get_window_group_id(), 
            &request_id);

    } else {

        char* good_sku = get_input_field(get_window_group_id(), 
            "Enter Digital Good SKU", 
            params1.digital_good_sku);

        if (good_sku)
            paymentservice_check_existing(0, 
                good_sku, 
                get_window_group_id(), 
                &request_id);
    }
    
    sprintf(*result_str, 
        "Sent checkExisting request. ID: %d\n", 
        request_id);
}

Cancel a subscription

See C++

To cancel a subscription to a digital good, use the ID of the subscription from the receipt of the purchase or from the list of previous successful purchases. You can retrieve previous purchases using PaymentManager::RequestExistingPurchases(). You can use the CancelSubscriptionReply class to interpret the results of your call to RequestCancelSubscription().

void MyPaymentApp::cancelSubscription(const QString &purchaseId)
{
    if (purchaseId.isEmpty())
        return;

    const CancelSubscriptionReply *reply = 
        m_paymentManager->requestCancelSubscription(purchaseId);

    bool success = QObject::connect(reply, 
         SIGNAL(finished()),
         this, 
         SLOT(cancelSubscriptionResponse()));

    if (success) {
       // Signal was successfully connected.

    } else {
       // Failed to connect to signal.
    }
}

Here's a code sample that shows how you can handle the CancelSubscriptionReply:

void MyPaymentApp::cancelSubscriptionResponse()
{
    bb::platform::CancelSubscriptionReply *reply = 
      qobject_cast<bb::platform::CancelSubscriptionReply*>(sender());
    Q_ASSERT(reply);

    // Emit an error signal if there were errors.

    if (reply->isError()) {

       emit infoResponseError(reply->errorCode(), 
            reply->errorText());

    // Emit a success signal if the request succeeded.
    } else {

       emit cancelSubscriptionResponseSuccess(reply->isCanceled());
    }

    reply->deleteLater();
}

To cancel a subscription to a digital good, use the ID of the subscription from the receipt of the purchase or from the list of previous successful purchases. You can retrieve previous purchases using paymentservice_get_existing_purchases_request(). You can use the paymentservice_event_get_cancelled() class to interpret the results of your call to paymentservice_cancel_subscription().

static void
do_get_existing(int selected_index, char** result_str)
{
    unsigned request_id = 0;

    if (selected_index == GET_EXISTING_REFRESH_FALSE) {

        paymentservice_get_existing_purchases_request(false,
            get_window_group_id(), 
            &request_id);

    } else if (selected_index == GET_EXISTING_REFRESH_TRUE) {

        paymentservice_get_existing_purchases_request(true, 
            get_window_group_id(), 
            &request_id);
    }

    sprintf(*result_str, 
        "Sent getExistingPurchases request. ID: %d\n", 
        request_id);
}

Here's a code sample that shows how you can handle the paymentservice_cancel_subscription():

static void
do_cancel(int selected_index, char** result_str)
{
    unsigned request_id = 0;

    char* purch_id = get_input_field(get_window_group_id(), 
        "Enter Purchase ID", 
        "");

    if (purch_id)
        paymentservice_cancel_subscription(purch_id, 
            get_window_group_id(), 
            &request_id);

    sprintf(*result_str, 
        "Sent cancelSubscription request. ID: %d\n", 
        request_id);
}

Last modified: 2015-05-07



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus