Error PaymentService::purchase(Variant p_params) { Dictionary params = p_params; ERR_FAIL_COND_V((!params.has("product_id")) && (!params.has("product_sku")), ERR_INVALID_PARAMETER); char *id = NULL; char *sku = NULL; CharString p_id = params.has("product_id") ? String(params["product_id"]).ascii() : CharString(); CharString p_sku = params.has("product_sku") ? String(params["product_sku"]).ascii() : CharString(); unsigned int request_id; chdir(launch_dir_ptr); int ret = paymentservice_purchase_request(params.has("product_sku") ? NULL : p_id.get_data(), params.has("product_sku") ? p_sku.get_data() : NULL, NULL, NULL, NULL, NULL, get_window_group_id(), &request_id); chdir("app/native"); if (ret != BPS_SUCCESS) { int eret = errno; printf("purchase error %i, %x, %i, %x\n", ret, ret, eret, eret); ERR_FAIL_V((Error)eret); return (Error)eret; }; return OK; };
void create_dialog() { if (main_dialog) { return; } dialog_create_alert(&main_dialog); dialog_set_alert_message_text(main_dialog, "\n"); dialog_set_group_id(main_dialog, get_window_group_id()); dialog_set_cancel_required(main_dialog, true); dialog_add_button(main_dialog, "Query", true, "query", true); dialog_add_button(main_dialog, "Vol Up", true, "double", true); dialog_add_button(main_dialog, "Vol Down", true, "half", true); dialog_add_button(main_dialog, "Toggle Mute", true, "toggle", true); dialog_show(main_dialog); }
/** * Set up a basic screen, so that the navigator will * send window state events when the window state changes. * * @return @c EXIT_SUCCESS or @c EXIT_FAILURE */ int setup_screen() { if (screen_create_context(&screen_ctx, SCREEN_APPLICATION_CONTEXT) != 0) { return EXIT_FAILURE; } if (screen_create_window(&screen_win, screen_ctx) != 0) { screen_destroy_context(screen_ctx); return EXIT_FAILURE; } int usage = SCREEN_USAGE_NATIVE; if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage) != 0) goto fail; if (screen_create_window_buffers(screen_win, 1) != 0) goto fail; if (screen_create_window_group(screen_win, get_window_group_id()) != 0) goto fail; screen_buffer_t buff; if (screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void*)&buff) != 0) goto fail; int buffer_size[2]; if (screen_get_buffer_property_iv(buff, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size) != 0) goto fail; int attribs[1] = {SCREEN_BLIT_END}; if (screen_fill(screen_ctx, buff, attribs) != 0) goto fail; int dirty_rects[4] = {0, 0, buffer_size[0], buffer_size[1]}; if (screen_post_window(screen_win, buff, 1, (const int*)dirty_rects, 0) != 0) goto fail; return EXIT_SUCCESS; fail: screen_destroy_window(screen_win); screen_destroy_context(screen_ctx); return EXIT_FAILURE; }
int setup_screen() { if (screen_create_context(&screen_ctx, SCREEN_APPLICATION_CONTEXT) != 0) { return EXIT_FAILURE; } //Signal BPS library that navigator orientation is to be locked if (BPS_SUCCESS != navigator_rotation_lock(true)) { screen_destroy_context(screen_ctx); return EXIT_FAILURE; } if (screen_create_window(&screen_win, screen_ctx) != 0) { screen_destroy_context(screen_ctx); return EXIT_FAILURE; } if (screen_create_window_group(screen_win, get_window_group_id()) != 0) goto fail; int usage = SCREEN_USAGE_NATIVE; if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage) != 0) goto fail; int size[2]; if (screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size) != 0) goto fail; screen_display_t screen_disp; screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_DISPLAY, (void **)&screen_disp); screen_display_mode_t screen_mode; if (screen_get_display_property_pv(screen_disp, SCREEN_PROPERTY_MODE, (void**)&screen_mode) != 0) goto fail; int buffer_size[2] = {size[0], size[1]}; int angle = atoi(getenv("ORIENTATION")); if ((angle == 0) || (angle == 180)) { if (((screen_mode.width > screen_mode.height) && (size[0] < size[1])) || ((screen_mode.width < screen_mode.height) && (size[0] > size[1]))) { buffer_size[1] = size[0]; buffer_size[0] = size[1]; } } else if ((angle == 90) || (angle == 270)){ if (((screen_mode.width > screen_mode.height) && (size[0] > size[1])) || ((screen_mode.width < screen_mode.height && size[0] < size[1]))) { buffer_size[1] = size[0]; buffer_size[0] = size[1]; } } else { goto fail; } if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size) != 0) goto fail; if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ROTATION, &angle) != 0) goto fail; if (screen_create_window_buffers(screen_win, 1) != 0) goto fail; screen_buffer_t buff; if (screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void*)&buff) != 0) goto fail; int attribs[1] = {SCREEN_BLIT_END}; if (screen_fill(screen_ctx, buff, attribs) != 0) goto fail; int dirty_rects[4] = {0, 0, buffer_size[0], buffer_size[1]}; if (screen_post_window(screen_win, buff, 1, (const int*)dirty_rects, 0) != 0) goto fail; return EXIT_SUCCESS; fail: perror(NULL); cleanup_screen(); return EXIT_FAILURE; }
/** * A sample application that demonstrates the BlackBerry Native APIs for * making in-app purchases. The sample sets the connection mode to local, * allows the purchase of a digital good by using the swipe down gesture, * and displays any existing purchases. */ int main(int argc, char *argv[]) { int exit_application = 0; /* * Before we can listen for events from the BlackBerry Tablet OS platform * services, we need to initialize the BPS infrastructure */ bps_initialize(); /* * Initialize the screen so that the window group Id is properly set, to allow * the Payment Service dialogs to be displayed. */ if (setup_screen() != EXIT_SUCCESS) { fprintf(stderr, "Unable to initialize screen."); exit(0); } /* * Once the BPS infrastructure has been initialized we can register for * events from the various BlackBerry Tablet OS platform services. The * Navigator service manages and delivers application life cycle and * visibility events. * For this sample, we request Navigator events so that we can track when * the system is terminating the application (NAVIGATOR_EXIT event), and as a * convenient way to trigger a purchase request (NAVIGATOR_SWIPE_DOWN). * We request PaymentService events so we can be notified when the payment service * responds to our requests/queries. */ navigator_request_events(0); paymentservice_request_events(0); /* * Set the Payment Service connection mode to local. This allows us to * test the API without the need to contact the AppWorld nor payment servers. */ paymentservice_set_connection_mode(true); /* * Create a set of purchase parameters, which describe the digital good * to be purchased and the application the goods are associated with. */ const char* digital_good_id = "Digital-Good-1-ID"; const char* digital_good_name = "Sample Digital Good 1"; const char* digital_good_sku = "SAMPLE_DIGITAL_GOOD_SKU_1"; const char* metadata = "Sample purchase metadata"; const char* purchase_app_icon = "http://www.rim.com/products/appworld_3col.jpg"; const char* purchase_app_name = "Payment Service Sample App"; /* * Define a request ID to hold the returned value from the purchase request. */ unsigned request_id = 0; /* * initiate the application with a purchase of the sample digital good. */ if (paymentservice_purchase_request(digital_good_id, digital_good_sku, digital_good_name, metadata, purchase_app_name, purchase_app_icon, get_window_group_id(), &request_id) != BPS_SUCCESS) { fprintf(stderr, "Error: purchase request failed.\n"); } /* * Process Payment Service and Navigator events until we receive a NAVIGATOR_EXIT event. */ while (!exit_application) { /* * Using a negative timeout (-1) in the call to bps_get_event(...) * ensures that we don't busy wait by blocking until an event is * available. */ bps_event_t *event = NULL; bps_get_event(&event, -1); if (event) { /* * If it is a Payment Service event, determine the response code * and handle the event accordingly. */ 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)) { onPurchaseSuccess(event); unsigned request_id = 0; if (paymentservice_get_existing_purchases_request(false, get_window_group_id(), &request_id) != BPS_SUCCESS) { fprintf(stderr, "Error: get existing purchases failed.\n"); } } else onGetExistingPurchasesSuccess(event); } else { failureCommon(event); } } /* * If it is a NAVIGATOR_EXIT event then set the exit_application * flag so the application will stop processing events, clean up * and exit. * * If it is a NAVIGATOR_SWIPE_DOWN event, initiate the purchase of * the sample digital good. */ if (bps_event_get_domain(event) == navigator_get_domain()) { if (NAVIGATOR_EXIT == bps_event_get_code(event)) { exit_application = 1; } else if (NAVIGATOR_SWIPE_DOWN == bps_event_get_code(event)) { if (paymentservice_purchase_request(digital_good_id, digital_good_sku, digital_good_name, metadata, purchase_app_name, purchase_app_icon, get_window_group_id(), &request_id) != BPS_SUCCESS) { fprintf(stderr, "Error: purchase request failed.\n"); } } } } } /* * Clean up the BPS infrastructure and exit */ bps_shutdown(); screen_destroy_window(screen_win); screen_destroy_context(screen_ctx); return 0; }