Thursday, April 13, 2017

Cancelling in-app subscription on iOS

Is it possible to cancel an App Store subscription the way one can on Google Play (using Google Service AndroidPublisher)?

public function checkPurchases($subscription_id, $receipt_data, $sandbox_receipt = false)
{
    if ($sandbox_receipt) {
        $url = "https://sandbox.itunes.apple.com/verifyReceipt/";
    } else {
        $url = "https://buy.itunes.apple.com/verifyReceipt";
    }
    $ch = curl_init($url);
    $data_string = json_encode(array(
        'receipt-data' => $receipt_data,
        'password' => env(APPSTORE_PASS),
    ));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            'Content-Length: ' . strlen($data_string))
    );
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    if (200 != $httpCode) {
        return false; // Error validating App Store transaction receipt. Response HTTP code $httpCode
    }
    return true;
}



via MikoĊ‚aj Osowski

Advertisement