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
New Contributor
devin_k
Posts: 6
Registered: ‎08-26-2013
My Device: Blackberry Z10
My Carrier: Telkomsel
Accepted Solution

Need Help Payment Service - Core Native with Cocos2dx

I create games with cocos2dx on blackberry 10 with in app purchase, I sell the virtual money in "Cash" on my game.

I am using the local mode before and then I try to use sanbox mode.

I have successfully upload my games on blackberry world with blackberry sanbox account, already downloaded my game on bb world, and the digital goods is valid..

 

But my problem is:

When the purchase is successful (ID of good, name of good, etc is valid), I do not get the "Cash" money (my cash not increase on my game store).

 

I have already open two link references about cocos2dx, but I can't get the solution:

http://supportforums.blackberry.com/t5/Native-Development/A-Post-Mortem-Supporting-In-App-Purchases-...

http://supportforums.blackberry.com/t5/Native-Development/Is-it-possible-to-use-PaymentService-with-...

 

There is any idea about the validation code when the purchase is successful? Thx

 

This is my code:

 

     CCEGLView* eglView = CCEGLView::sharedOpenGLView();
     eglView->setFrameSize(600, 1024);

 

        bps_initialize();
        paymentservice_request_events(0);
        //paymentservice_set_connection_mode(true);
        purchase_arguments_t *args = NULL;
        paymentservice_purchase_arguments_create(&args);

        paymentservice_purchase_arguments_set_digital_good_id(args, "xxxxxxxx" );
        paymentservice_purchase_arguments_set_digital_good_sku(args, "xxxxxxxx");
        paymentservice_purchase_arguments_set_digital_good_name(args, "100 Cash");
        paymentservice_purchase_arguments_set_metadata(args, "Sample Purchase");
        paymentservice_purchase_arguments_set_app_name(args, "Sample Game");
        paymentservice_purchase_arguments_set_app_icon(args, "http://www.rim.com/products/appworld_3col.jpg");
        paymentservice_purchase_arguments_set_vendor_content_id(args, "xxxxxxxx");
        paymentservice_purchase_arguments_set_vendor_customer_id(args, "ID-vendor-customer");
        paymentservice_purchase_arguments_set_extra_parameter(args, "extrakey1", "extraval1");
        paymentservice_purchase_arguments_set_extra_parameter(args, "extrakey2", "extraval2");
        paymentservice_purchase_arguments_set_extra_parameter(args, "extrakey3", "extraval3");

 

        unsigned request_id = 0;
        if (paymentservice_purchase_request_with_arguments(args)
        != BPS_SUCCESS) {
            fprintf(stderr, "Error: purchase request failed.\n");
        }

 

paymentservice_purchase_arguments_destroy(args);
 
unsigned request_id = 0;
 
bps_event_t *event = NULL;

bps_get_event(&event, -1);

 

if (event) {
    // I try to using the log and the process stop at here
 
    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)) {
                    // Handle a successful purchase here
                    char* digital_good =
                       paymentservice_event_get_digital_good_id(event, 0);
                    char* digital_sku =
                       paymentservice_event_get_digital_good_sku(event, 0);
 
                                           // This is My "Cash" validation code in cocos2dx:
                                             
                                            Cash +=100;
                                            sprintf(  TempCash,"%d",   Cash);
                                            ValueCASHLabel->setString(TempCash);
                                            CCUserDefault::sharedUserDefault()->setIntegerForKey("Cash",Cash);
                                            CCUserDefault::sharedUserDefault()->flush();
                                          / /
 
                } else {
                    // Handle a successful query for past purchases here
                    int numPurchases =
                        paymentservice_event_get_number_purchases(event);
                    // ...
                }
        } else {
            int error_id = paymentservice_event_get_error_id(event);
            const char* error_text =
                paymentservice_event_get_error_text(event);
             
            fprintf(stderr, "Payment System error: ID: %d  Text: %s\n",
                error_id, error_text ? error_text : "N/A");
        }
    }
}
 
 
Please use plain text.
BlackBerry Development Advisor (Retired)
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: Need Help Payment Service - Core Native with Cocos2dx

Does it work as expected in SandBox or Local testing modes?

Garett
@garettBeuk
--
Goodbye everybody!
Please use plain text.
New Contributor
devin_k
Posts: 6
Registered: ‎08-26-2013
My Device: Blackberry Z10
My Carrier: Telkomsel

Re: Need Help Payment Service - Core Native with Cocos2dx

No, my code doesn't work.

When I touch the button  "purchase" on confirm purchase then process the payment, I do not get the virtual Money (cash).

 

 

Please use plain text.
BlackBerry Development Advisor (Retired)
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: Need Help Payment Service - Core Native with Cocos2dx

Have you debugged? Does your payment logic get called? Do you see the purchase dialog appear?

Garett
@garettBeuk
--
Goodbye everybody!
Please use plain text.
New Contributor
devin_k
Posts: 6
Registered: ‎08-26-2013
My Device: Blackberry Z10
My Carrier: Telkomsel

Re: Need Help Payment Service - Core Native with Cocos2dx

I use the Log (in cocos2dx called "CCLog" library) to get information about event on every line, the example: to get information whether  "if" condition true or false.

 

I get the codes from documentation of developer blackberry site, I don't understand about :

"if (bps_event_get_domain(event) == paymentservice_get_domain()) { }"

 

I think the domain of the BPS Event not same with Domain of payment service, so the condition of code:

"if (SUCCESS_RESPONSE == paymentservice_event_get_response_code(event)) { }"

never called because the BPS domain and Payment Domain never get same value.

 

How to handle or setting the BPS Domain to make connecting to the Payment Domain?

Please use plain text.
New Contributor
devin_k
Posts: 6
Registered: ‎08-26-2013
My Device: Blackberry Z10
My Carrier: Telkomsel

Re: Need Help Payment Service - Core Native with Cocos2dx

Yes, when I use the local mode, sandbox, or network, Getting payment success and the purchase dialog always appear (the Dialog of information about name of digital goods, price in US $ , my Visa number, etc). When I touch the button "Purchase" and the Purchase finished, there is nothing happen. My virtual money not increase :smileysad:

Please use plain text.
BlackBerry Development Advisor (Retired)
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: Need Help Payment Service - Core Native with Cocos2dx

Does your code loop infinitely to read events? The purchase response may not be the first one back, so if you one read the event once after the purchase is attempted then it would make sense that the event is lost.

 

What you need in the code is a loop to continually listen for BPS events.

Garett
@garettBeuk
--
Goodbye everybody!
Please use plain text.
New Contributor
devin_k
Posts: 6
Registered: ‎08-26-2013
My Device: Blackberry Z10
My Carrier: Telkomsel

Re: Need Help Payment Service - Core Native with Cocos2dx

That's the good solution from you, thank you very much :smileyhappy:

After get the idea from you, I use the boolean and loop the events with do-while validation until the BPS event to get events code success or failed, and it's working! 

 

Using the Local mode and get the Log from console and I see the events code success or failed.


This is the final code:

 

        FlagPayment = true;

        do{
            bps_event_t *event = NULL;
            bps_get_event(&event, -1);


            if(event){
                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)) {
                            // Handle a successful purchase here
                            const char* digital_good_id =
                            paymentservice_event_get_digital_good_id(event, 0);
                            const char* digital_good_sku =
                            paymentservice_event_get_digital_good_sku(event,0);
                            const char* metadata =
                            paymentservice_event_get_metadata(event,0);

                            FlagPayment = false;


                            Cash +=100;
                            sprintf(  TempCash,"%d",   Cash);
                            ValueCASHLabel->setString(TempCash);
                            CCUserDefault::sharedUserDefault()->setIntegerForKey("Cash",Cash);
                            CCUserDefault::sharedUserDefault()->flush();
                            GetCash();

                            menuDetail3->setTouchEnabled(false);
                            CCActionInterval* Delay = CCDelayTime::create(2.0);
                            CCCallFunc* callFunction =    CCCallFunc::create(this,callfunc_selector(Shop::RemoveGetPurchase));

                            LayerOpacity->setVisible(true);
                            Get100Cash = CCLabelTTF::create("Purchase Success!\nGet 100 Cash",
                                    "fonts/walibi-holland.ttf",30);
                            Get100Cash->setPosition(ccp(300,512));
                            Get100Cash->setColor(ccc3(0,0,0));
                            Get100Cash->setHorizontalAlignment(kCCTextAlignmentCenter);
                            Get100Cash->setVerticalAlignment(kCCVerticalTextAlignmentCenter);
                            LayerDetail3->addChild(Get100Cash,3);
                            Get100Cash->runAction(CCSequence::create(Delay,callFunction,NULL));
                            CCLog("Success Purchase");
                            // ...

                        } else {
                            // Handle a successful query for past purchases here
                            int numPurchases =
                                paymentservice_event_get_number_purchases(event);
                            CCLog("Test Payment3");
                            // ...
                        }
                }else{
                    FlagPayment = false;
                    int error_id = paymentservice_event_get_error_id(event);
                    CCLog("Test Payment4");
                    const char* error_text =
                        paymentservice_event_get_error_text(event);

                    fprintf(stderr, "Payment System error: ID: %d  Text: %s\n",
                        error_id, error_text ? error_text : "N/A");
                    CCLog("Test Payment6");
                    }
                }
            }
        }while(FlagPayment == true);

 

Please use plain text.