//----------------------------------------------------------------// void MOAIApp::HandleStoreMessage ( std::string & message ) { if ( message.find( "STORE:PaymentSuccess:" ) != std::string::npos ) { //change to queue for bckgrd thread NACL_LOG ( "STORE:OnLoginSuccess!\n" ); //g_SocialConnect->OnLoginSuccess (); int responseStartIndex = strlen ( "STORE:PaymentSuccess:" ); MOAIApp::Get ().PaymentQueueUpdatedTransactions ( TRANSACTION_STATE_PURCHASED, message.c_str () + responseStartIndex ); } else if ( message.find( "STORE:PaymentFailed:" ) != std::string::npos ) { //change to queue for bckgrd thread /*int responseStartIndex = strlen ( "STORE:OnRequestSuccess:" ); int responseEndIndex = message.find( "&" ); int responseSize = responseEndIndex - responseStartIndex + 1; char *responseText = new char [ responseSize ]; memset ( responseText, 0, responseSize ); memcpy ( responseText, message.c_str () + responseStartIndex, responseSize - 1 ); int responseId = atoi ( message.c_str () + responseEndIndex + 1 ); NACL_LOG ( "MOAIApp->PaymentFailed ( %d, %s )\n", responseId, responseText );*/ //g_SocialConnect->OnRequestSuccess ( responseId, responseText ); int responseStartIndex = strlen ( "STORE:PaymentFailed:" ); MOAIApp::Get ().PaymentQueueUpdatedTransactions ( TRANSACTION_STATE_CANCELLED, message.c_str () + responseStartIndex ); //delete [] responseText; } else if ( message.find( "STORE:PaymentClientDone:" ) != std::string::npos ) { int responseStartIndex = strlen ( "STORE:PaymentClientDone:" ); //const char *openId = message.c_str () + responseStartIndex; std::string params = message.substr ( responseStartIndex, message.length () - responseStartIndex ); int midIndex = params.find ( ":" ); g_openID = params.substr ( 0, midIndex ) ; g_productID = params.substr ( midIndex + 1, params.length () - midIndex ); NACL_LOG ( "Client payment done with Id %s, product %s\n", g_openID.c_str (), g_productID.c_str ()); pp::CompletionCallback cc ( VerifyPaymentMainThread, NULL ); g_core->CallOnMainThread ( 0, cc , 0 ); } }
/** @name restoreCompletedTransactions @text Request a restore of all purchased non-consumables from the App Store. Use this to retrieve a list of all previously purchased items (for example after reinstalling the app on a different device). @out nil */ int MOAIApp::_restoreCompletedTransactions( lua_State* L ) { NACL_LOG ( "_restoreCompletedTransactions Not implemented\n" ); //[[SKPaymentQueue defaultQueue] restoreCompletedTransactions]; return 0; }
/** @name requestProductIdentifiers @text Verify the validity of a set of products. @in table productIdentifiers A table of product identifiers. @out nil */ int MOAIApp::_requestProductIdentifiers ( lua_State* L ) { MOAILuaState state ( L ); NACL_LOG ( "_requestProductIdentifiers Not implemented\n" ); /*NSMutableSet* productSet = [[[ NSMutableSet alloc ] init ] autorelease ]; int top = state.GetTop (); for ( int i = 1; i <= top; ++i ) { if ( state.IsType ( i, LUA_TSTRING )) { cc8* identifier = state.GetValue < cc8* >( i, "" ); [ productSet addObject :[ NSString stringWithUTF8String:identifier ]]; } if ( state.IsType ( i, LUA_TTABLE )) { int itr = state.PushTableItr ( i ); while ( state.TableItrNext ( itr )) { cc8* identifier = state.GetValue < cc8* >( -1, "" ); [ productSet addObject :[ NSString stringWithUTF8String:identifier ]]; } } }*/ return 0; }
//----------------------------------------------------------------// void MOAIHttpTaskNaCl::NaClFinish () { NACL_LOG ("MOAIHttpTaskNaCl::Finish %p\n", this ); if ( this->mStream == &this->mMemStream ) { u32 size = this->mMemStream.GetLength (); NACL_LOG ("MOAIHttpTaskNaCl::Finish get size %d\n", size ); if ( size ) { this->mData.Init ( size ); this->mStream->Seek ( 0, SEEK_SET ); this->mStream->ReadBytes ( this->mData, size ); } this->mMemStream.Clear (); } this->Finish (); }
/** @name alert @text Display a modal style dialog box with one or more buttons, including a cancel button. This will not halt execution (this function returns immediately), so if you need to respond to the user's selection, pass a callback. @in string title The title of the dialog box. @in string message The message to display. @in function callback The function that will receive an integer index as which button was pressed. @in string cancelTitle The title of the cancel button. @in string... buttons Other buttons to add to the alert box. @out nil */ int MOAIApp::_alert( lua_State* L ) { MOAILuaState state ( L ); //cc8* title = state.GetValue< cc8* >(1, "Alert"); cc8* message = state.GetValue< cc8* >(2, ""); //cc8* cancelTitle = state.GetValue< cc8*>(4, NULL); NACL_LOG ( "ALERT: %s\n", message ); return 0; }
void MOAIApp::HttpLoaded ( GetURLHandler *handler, const char *buffer, int32_t size ) { NACL_LOG ( "MOAIApp_HttpLoaded code %d, data %s\n", handler->GetStatusCode (), buffer ); if ( handler->GetStatusCode () == 200 ) { NACL_LOG ( "payment success\n" ); g_MessageQueue->Push ( "STORE:PaymentSuccess:" ); RedeemProduct ( ); } else if ( handler->GetStatusCode () == 404 ) { NACL_LOG ( "User Did not purchse\n" ); g_instance->PostMessage ( "ALERT:STORE" ); g_MessageQueue->Push ( "STORE:PaymentFailed:" ); } else { NACL_LOG ( "???\n" ); g_instance->PostMessage ( "ALERT:STORE" ); g_MessageQueue->Push ( "STORE:PaymentFailed:" ); } }
int MOAIApp::_openURLPOP ( lua_State* L ) { MOAILuaState state ( L ); cc8* url = state.GetValue < cc8* >( 1, "" ); NACL_LOG ("MOAIApp should open popup url: %s\n", url ); char message[2048]; memset ( message, 0, 2048 ); sprintf ( message, "URL:OpenPop:%s", url ); NaClPostMessage ( message ); return 0; }
//----------------------------------------------------------------// void MOAIHttpTaskNaCl::HttpGetMainThread ( void* userData, int32_t result ) { MOAIHttpTaskNaCl * taskInfo = static_cast < MOAIHttpTaskNaCl * > ( userData ); GetURLHandler* handler = GetURLHandler::Create( g_instance, taskInfo->mUrl ); if ( handler != NULL ) { handler->SetMethod ( taskInfo->mMethod ); handler->SetUserData ( taskInfo ); if ( taskInfo->mBody.Size () > 0 ) { NACL_LOG ( "\nSet Body: %s\n", taskInfo->mBody.Data ()); handler->SetBody ( taskInfo->mBody.Data (), taskInfo->mBody.Size ()); } taskInfo->Prepare ( handler ); handler->Start( HttpLoaded ); } taskInfo->mLock = false; }