Managing subscriptions

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

Request the terms of a digital good subscription

Not available

Check the status of a subscription

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

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: 2014-09-30



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

comments powered by Disqus