cocos2d-x / plugin-x

Plugin-x is the plugin repository for cocos2d-x, it also provides a unified API for plugins.
71 stars 92 forks source link

Wrong callback code in IAPWrapper.mm (for iOS) and in ProtocolIAP.cpp (for Android) #168

Open shkatulo opened 9 years ago

shkatulo commented 9 years ago

Current callback code in onPayResult:withRet:withMsg method is next:

...
if (iapPlugin) {
        iapPlugin->onPayResult(cRet, chMsg);
}else if(callback){
        std::string stdmsg(chMsg);
        callback(cRet,stdmsg);
} else {
        PluginUtilsIOS::outputLog("Can't find the C++ object of the IAP plugin");
}
...

So, if plugin was successfully instantiated callback(cRet,stdmsg); will be newer called. I think, code should be equivalent to other plugins, where all works properly:

...
if (iapPlugin) {
        PayResultListener *listener = iapPlugin->getResultListener();
        if(listener) {
            iapPlugin->onPayResult(cRet, chMsg);
        }
        else if(callback) {
            std::string stdmsg(chMsg);
            callback(cRet,stdmsg);
        }
}
else {
        PluginUtilsIOS::outputLog("Can't find the C++ object of the IAP plugin");
}
...

The same problem on Android - in file ProtocolIAP.cpp