Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 632
ordinaryman09 Avatar asked Mar 07 '15 21:03

ordinaryman09


1 Answers

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;
like image 82
ordinaryman09 Avatar answered Sep 25 '22 01:09

ordinaryman09