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

[IOS/ANDROID] store.utils.ajax does not POST data object #733

Closed kallewangstedt closed 6 years ago

kallewangstedt commented 6 years ago

system info

Cordova 8.1.1
Device: iPhone iOS 12.0.1 // Android 8.0.0
Plugin Version: 7.2.0

Expected behavior

When using the store.utils.ajax() method for server side verification of subscription a JS object with the subscription receipt and signature are sent via the data object in the ajax request.

Observed behavior

The data object is not sent via POST. Therefore the server never receives the data for processing, and cannot verify the subscription.

Steps to reproduce

store.validator = function(subscription, callback){
    store.utils.ajax({
        url: config.backend + "purchase/verify/" + os,
        method: "POST",
        data: {"subscription":subscription},
        success: function(data) {
            console.log(data);
        }
    });
});

If the server in the example above just returns the $_REQUEST['subscription'] the logged data object is null.

Dexus commented 6 years ago

@kallewangstedt The data is sending with application/json content type here. So you need to use in your php script: $data = file_get_contents('php://input'); for getting post variables instead $_POST.

Have fun and working scripts :-)