JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_IAPWrapper_nativeOnRequestOwnedProductsResult
        (JNIEnv* env, jobject thiz, jstring className, jint ret, jobjectArray plist)
{
    std::string strClassName = PluginJniHelper::jstring2string(className);
    PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName);
    PluginUtils::outputLog("ProtocolIAP", "onRequestOwnedProductsResult(), Get plugin ptr : %p", pPlugin);

    if (pPlugin != NULL)
    {
        PluginUtils::outputLog("ProtocolIAP", "onRequestOwnedProductsResult(), Get plugin name : %s", pPlugin->getPluginName());
        ProtocolIAP* pIAP = dynamic_cast<ProtocolIAP*>(pPlugin);

        if (pIAP != NULL)
        {
            std::vector<std::string> pplist;

            if(plist != NULL)
            {
                int stringCount = env->GetArrayLength(plist);

                for (int i=0; i<stringCount; i++)
                {
                    jstring string = (jstring) env->GetObjectArrayElement(plist, i);
                    const char* chars = env->GetStringUTFChars(string, NULL);

                    pplist.push_back(chars);
                    env->ReleaseStringUTFChars(string, chars);
                    env->DeleteLocalRef(string);
                }
            }

            pIAP->onRequestOwnedProductsResult((IAPProductRequest)ret, pplist);
        }
    }
}
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_IAPWrapper_nativeOnRequestProductsResult
        (JNIEnv* env, jobject thiz, jstring className, jint ret, jobjectArray stringArray)
{
    std::string strClassName = PluginJniHelper::jstring2string(className);
    PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName);
    PluginUtils::outputLog("ProtocolIAP", "onRequestProductsResult(), Get plugin ptr : %p", pPlugin);

    if (pPlugin != NULL)
    {
        PluginUtils::outputLog("ProtocolIAP", "onRequestProductsResult(), Get plugin name : %s", pPlugin->getPluginName());
        ProtocolIAP* pIAP = dynamic_cast<ProtocolIAP*>(pPlugin);

        if (pIAP != NULL)
        {
            TProductList tplist;

            if(stringArray != NULL)
            {
                int stringCount = env->GetArrayLength(stringArray);

                for (int i=0; i<stringCount; i++)
                {
                    jstring string = (jstring) env->GetObjectArrayElement(stringArray, i);
                    auto map = PluginJniHelper::jsonString2Map(string);

                    tplist.push_back(*map);
                    env->DeleteLocalRef(string);
                }
            }

            pIAP->onRequestProductsResult((IAPProductRequest)ret, tplist);
        }
    }
}
JNIEXPORT jboolean JNICALL Java_org_cocos2dx_plugin_IAPWrapper_nativeIsConsumable
        (JNIEnv* env, jobject thiz, jstring className, jstring productId)
{
    std::string strClassName = PluginJniHelper::jstring2string(className);
    PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName);
    //PluginUtils::outputLog("ProtocolIAP", "isConsumable(), Get plugin ptr : %p", pPlugin);

    if (pPlugin != NULL)
    {
        //PluginUtils::outputLog("ProtocolIAP", "isConsumable(), Get plugin name : %s", pPlugin->getPluginName());
        ProtocolIAP* pIAP = dynamic_cast<ProtocolIAP*>(pPlugin);

        if (pIAP != NULL)
        {
            const char* pid = env->GetStringUTFChars(productId, NULL);
            std::string pidString(pid);
            bool isConsmb = pIAP->isConsumable(pidString);

            env->ReleaseStringUTFChars(productId, pid);

            return isConsmb;
        }
    }

    return false;
}
Exemple #4
0
	JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceIAP_nativeOnPayResult(JNIEnv*  env, jobject thiz, jstring className, jint ret, jstring msg)
	{
		std::string strMsg = PluginJniHelper::jstring2string(msg);
		std::string strClassName = PluginJniHelper::jstring2string(className);
		PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName);
		LOGD("nativeOnPayResult(), Get plugin ptr : %p", pPlugin);
		if (pPlugin != NULL)
		{
			LOGD("nativeOnPayResult(), Get plugin name : %s", pPlugin->getPluginName());
			ProtocolIAP* pIAP = dynamic_cast<ProtocolIAP*>(pPlugin);
			if (pIAP != NULL)
			{
				pIAP->onPayResult((PayResultCode) ret, strMsg.c_str());
			}
		}
	}
static int tolua_anysdk_ProtocolIAP_payForProduct(lua_State* tolua_S)
{
    if (NULL == tolua_S)
        return 0;

    int argc = 0;
    ProtocolIAP* self = nullptr;

#if COCOS2D_DEBUG >= 1
    tolua_Error tolua_err;
    if (!tolua_isusertype(tolua_S,1,"ccanysdk.ProtocolIAP",0,&tolua_err)) goto tolua_lerror;
#endif

    self = static_cast<ProtocolIAP*>(tolua_tousertype(tolua_S,1,0));

#if COCOS2D_DEBUG >= 1
    if (nullptr == self) {
        tolua_error(tolua_S,"invalid 'self' in function 'tolua_anysdk_ProtocolIAP_payForProduct'\n", NULL);
        return 0;
    }
#endif

    argc = lua_gettop(tolua_S) - 1;

    if (1 == argc)
    {
        std::map<std::string, std::string> productInfo;
        luaval_to_stdmap_string_key_string(tolua_S, 2, &productInfo);
        self->payForProduct(productInfo);

        return 0;
    }

    CCLOG("'payForProduct' function of ProtocolIAP has wrong number of arguments: %d, was expecting %d\n", argc, 1);
    return 0;

#if COCOS2D_DEBUG >= 1
tolua_lerror:
    tolua_error(tolua_S,"#ferror in function 'getIAPPlugin'.",&tolua_err);
    return 0;
#endif
}
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_IAPWrapper_nativeOnPayResult(JNIEnv*  env, jobject thiz, jstring className, jint ret, jstring msg)
{
    std::string strMsg = PluginJniHelper::jstring2string(msg);
    std::string strClassName = PluginJniHelper::jstring2string(className);
    PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName);
    PluginUtils::outputLog("ProtocolIAP", "nativeOnPayResult(), Get plugin ptr : %p", pPlugin);
    if (pPlugin != NULL)
    {
        PluginUtils::outputLog("ProtocolIAP", "nativeOnPayResult(), Get plugin name : %s", pPlugin->getPluginName());
        ProtocolIAP* pIAP = dynamic_cast<ProtocolIAP*>(pPlugin);
        if (pIAP != NULL)
        {
            pIAP->onPayResult((PayResultCode) ret, strMsg.c_str());
        }
        else
        {
            ProtocolIAP::ProtocolIAPCallback callback = pIAP->getCallback();
            if(callback)
                callback(ret, strMsg);
        }
    }
}