Responding to a purchase

Your app can listen for a Payment Service event by calling bps_get_event(). After an event is received, you should determine whether it's a Payment Service event by calling bps_event_get_domain() and paymentservice_get_domain() .

You can determine event codes by calling bps_get_event_code(). The PURCHASE_RESPONSE response code indicates that the event was generated in response to a purchase request. The GET_EXISTING_PURCHASES_RESPONSE reponse code indicates that the event was generated in response to a request for the past purchases that the user made in the app (a call to paymentservice_get_existing_purchases_request() ).

A response code of FAILURE_RESPONSE indicates that the request was unsuccessful. If an error is thrown, you can use the following functions to get more information on the error:

You can use two functions to find the ID and SKU of the digital good.

You can use the paymentservice_purchase_arguments_get_metadata() function to present information about the successful purchase to the user.

The following code sample requests a purchase, passing in an ID and a SKU to paymentservice_purchase_request().

.do_purchase(int selected_index, char** result_str)
{
    unsigned request_id = 0;
    purchase_params_t params = *available_purchase_info[selected_index];

    paymentservice_purchase_request(params.digital_good_id, params.digital_good_sku, params.digital_good_name,
            params.metadata, params.purchase_app_name, params.purchase_app_icon, get_window_group_id(), &request_id);

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

Last modified: 2014-05-14



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

comments powered by Disqus