Search code examples
iosios7ios8in-app-purchase

How to handle refund/cancellation in-app purchase


I'm trying to handle the refund in-app purchase for iOS. But I couldn't find a clear guidelines to do this.

So I have a membership type in-app purchase feature, where the user credentials is not necessarily ties to the itunes account.

Is there some kind of identifier that I can refer to when someone make a purchase, and have the same identifier when they request a refund through apple?

Also, do we get instant notification when they refund it? I need to cancel the membership immediately.

Thanks!


Solution

  • I ended up storing the receipt string and running cron to go through the transactions and look for cancellation field.

        $url = "https://buy.itunes.apple.com/verifyReceipt"; 
        $data = json_encode(array('receipt-data' => $receipt));
    
        $ch = curl_init($url);
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                $response = curl_exec($ch);
                $errno    = curl_errno($ch);
                $errmsg   = curl_error($ch);
                curl_close($ch);
                if ($errno != 0) {
                    throw new Exception($errmsg, $errno);
                }
                return $response;