8

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!

ordinaryman09
  • 2,761
  • 4
  • 26
  • 32
  • Refer to [How does Apple notify iOS apps of refunds of in-app purchases (IAP)?](https://stackoverflow.com/q/6439482/6521116) – LF00 Aug 20 '19 at 07:01

2 Answers2

5

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;
ordinaryman09
  • 2,761
  • 4
  • 26
  • 32
  • Can I use the original receipt to check for the refund? Or does the iOS app need to fetch a new receipt after the refund and then check that receipt for the refund? Basically, will the old receipt contain the cancellation_date field? – cbartel Jan 14 '16 at 19:49
  • According to Apple docs (https://developer.apple.com/library/content/technotes/tn2413/_index.html#//apple_ref/doc/uid/DTS40016228-CH1-RECEIPT-HOW_DO_I_USE_THE_CANCELLATION_DATE_FIELD_), there is no cancellation_date for consumables and non-renewing subscriptions. – Renatus Sep 25 '17 at 07:42
1

You can use various elements of the receipt to track... most of which are discussed in the In-App Purchase Programming Guide. https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Introduction.html#//apple_ref/doc/uid/TP40008267-CH1-SW1

As far as canceling, it depends. If the subscription is terminated, it is active until the end of the currently subscribed term. If it's an actual refund, there doesn't appear to be an externally documented "formal answer". See this question for someone else having the same situation... How does Apple notify iOS apps of refunds of in-app purchases (IAP)?

Community
  • 1
  • 1
Brad Brighton
  • 2,179
  • 1
  • 13
  • 15
  • 1
    thanks, but it seems that I can only check if they refund and still uses the same itunes account? It won't work in my case because the user credentials is not ties to the itunes account. So they technically can buy and ask for refund, and never login with the same itunes account, and I won't be able to track it. – ordinaryman09 Mar 08 '15 at 18:40
  • First, the scenario you describe is not common in the general case (though you may have reason to believe it will be worth the effort in your specific use). Be sure you're not wasting time chasing a phantom problem. Second, you can give Apple information about your server-based username (see "Detecting Irregular Activity" in the In-App Purchase Programming Guide previously linked). Third, based on the linked answer, you won't be able to be certain, but when you _do_ note something suspicious, you could always adjust your in-app purchase code to look for membership state from your server. – Brad Brighton Mar 08 '15 at 19:08
  • Thanks. I see that you can add applicationUsername to the payment. Do you know if this will show up under the iTunes Connect for refund section? I only see the fields for content, content type, id, and units. – ordinaryman09 Mar 08 '15 at 23:53
  • Glad you got a solution. I didn't mean to leave you hanging there -- for some reason, I never saw your question. – Brad Brighton May 11 '15 at 22:41