j3k0 / cordova-plugin-purchase

In-App Purchase for Cordova on iOS, Android and Windows
https://purchase.cordova.fovea.cc
1.3k stars 537 forks source link

Verify problem #508

Closed malloc32 closed 7 years ago

malloc32 commented 8 years ago

I m trying to verify a receipt using my own server. When response is successful it works ok, but when there is an error I can't see how it works... In _validator store.utils.ajax({ url: store.validator, method: 'POST', data: product, success: function(data) { callback(data && data.ok, data.data); }, error: function(status, message) { callback(false, "Error " + status + ": " + message); } });

We can see that error callback use a boolean and a string, but in callback function:

    store._validator(that, function(success, data) {
        store.log.debug("verify -> " + JSON.stringify(success));
        if (success) {
            store.log.debug("verify -> success: " + JSON.stringify(data));
            store.utils.callExternal('verify.success', successCb, that, data);
            store.utils.callExternal('verify.done', doneCb, that);
            that.trigger("verified");
        }
        else {
            store.log.debug("verify -> error: " + JSON.stringify(data));
            var msg = (data && data.error && data.error.message ? data.error.message : '');
            var err = new store.Error({
                code: store.ERR_VERIFICATION_FAILED,
                message: "Transaction verification failed: " + msg
            });
            if (data.code === store.PURCHASE_EXPIRED) {
                err = new store.Error({
                    code: store.ERR_PAYMENT_EXPIRED,
                    message: "Transaction expired: " + msg

we can see that it works with an object....

Thank you.

jcornic commented 7 years ago

Indeed, I'm struggling with the same problem.

I've tried to implement my own callback in case of error: callback(false, { code: 6778003, error : {message: "Expired"}}) But it doesn't seem to work.

Is it working for anyone?