3

I am trying to implement the Server-to-Server Notifications for IOS subscriptions. I have went through the Server-to-Server Notifications documentation and followed all the necessary steps. My server is in the GCM.

Now when i do a purchase in the app i am getting the notification in my server, but the response is totally different from the which is defined in the above link.

The response which i am getting contains only one field that is latest_receipt . But in the documentation they have mentioned various parameters. So, i thought i have to verify the receipt by send a post message to this endpoint . Now i am getting a json body which contains lot of information, but still i am not getting the json which is mentioned in the documentation.

The response body i am getting after verifying the purchase ( https://sandbox.itunes.apple.com/verifyReceipt)

{
  "auto_renew_status": 1,
  "status": 0,
  "auto_renew_product_id": " ",
  "receipt": {
    "original_purchase_date_pst": "2019-01-09 01:26:35 America/Los_Angeles",
    "quantity": "1",
    "unique_vendor_identifier": " ",
    "bvrs": "56",
    "expires_date_formatted": "2019-07-18 06:19:17 Etc/GMT",
    "is_in_intro_offer_period": "false",
    "purchase_date_ms": "1563430577000",
    "expires_date_formatted_pst": "2019-07-17 23:19:17 America/Los_Angeles",
    "is_trial_period": "false",
    "item_id": "1298435177",
    "unique_identifier": " ",
    "original_transaction_id": "1000000492823158",
    "expires_date": "1563430757000",
    "transaction_id": "1000000548145129",
    "web_order_line_item_id": "1000000045717939",
    "version_external_identifier": "0",
    "bid": " ",
    "product_id": " ",
    "purchase_date": "2019-07-18 06:16:17 Etc/GMT",
    "original_purchase_date": "2019-01-09 09:26:35 Etc/GMT",
    "purchase_date_pst": "2019-07-17 23:16:17 America/Los_Angeles",
    "original_purchase_date_ms": "1547025995000"
  },
  "latest_receipt_info": {
    "original_purchase_date_pst": "2019-01-09 01:26:35 America/Los_Angeles",
    "unique_identifier": " ",
    "original_transaction_id": "1000000492823158",
    "expires_date": "1563430757000",
    "transaction_id": "1000000548145129",
    "quantity": "1",
    "product_id": " ",
    "bvrs": "56",
    "bid": " ",
    "unique_vendor_identifier": " ",
    "web_order_line_item_id": "1000000045717939",
    "original_purchase_date_ms": "1547025995000",
    "expires_date_formatted": "2019-07-18 06:19:17 Etc/GMT",
    "purchase_date": "2019-07-18 06:16:17 Etc/GMT",
    "is_in_intro_offer_period": "false",
    "purchase_date_ms": "1563430577000",
    "expires_date_formatted_pst": "2019-07-17 23:19:17 America/Los_Angeles",
    "is_trial_period": "false",
    "purchase_date_pst": "2019-07-17 23:16:17 America/Los_Angeles",
    "original_purchase_date": "2019-01-09 09:26:35 Etc/GMT",
    "item_id": "1298435177"
  }
}

But in the documentation they have mentioned :

 environment
 notification_type
 password
 cancellation_date
 cancellation_date_pst
 cancellation_date_ms
 web_order_line_item_id
 latest_receipt
 latest_receipt_info
 latest_expired_receipt
 latest_expired_receipt_info
 auto_renew_status
 auto_renew_product_id
 auto_renew_status_change_date
 auto_renew_status_change_date_pst
 auto_renew_status_change_date_ms

I am not getting the main fields such as environment and notification_type.

Whats wrong in it ?

For the first time this is the response i am getting

{ latest_receipt: 'ewoJInNpZ25hdHVyZ'}

The response which i am getting from the server 2 server notification is on the second time (once its renewed):

{ environment: 'Sandbox',
  auto_renew_status: 'false',
  latest_expired_receipt: 'ewoJIn'
}
Welz
  • 236
  • 2
  • 10
  • 21
Kumar KS
  • 521
  • 8
  • 18
  • Hi, I would like to know how you handled and tested the S2S notification in the backend. I'm trying to implement the same in case of non-renewing subscription. I've provided the url in the app store for notification but I'm not getting any response when I try to do a test purchase using sandbox. – Vinay N Oct 28 '20 at 11:22
  • @VinayN S2S notifications are only for auto-renewable subscriptions. Kindly refer to this documentation . https://developer.apple.com/documentation/storekit/in-app_purchase/subscriptions_and_offers/enabling_app_store_server_notifications – Kumar KS Oct 30 '20 at 05:21

1 Answers1

3

The parameters you get when you set up server 2 server notification are not exactly in the same format (or contains the same fields) as when you query verifyReceipt.

For example environment and notification_type are available only in the server 2 server notification and not in verifyReceipt.

Here is an example of the complete params you get when apple send you a notification with the server 2 server notifications -

    {
    "latest_receipt": "ewoXXXXX",
    "latest_receipt_info": {
        "original_purchase_date_pst": "2019-07-29 21:13:18 America/Los_Angeles",
        "quantity": "1",
        "unique_vendor_identifier": "XXX",
        "original_purchase_date_ms": "1564459998000",
        "expires_date_formatted": "2019-08-06 04:13:17 Etc/GMT",
        "is_in_intro_offer_period": "false",
        "purchase_date_ms": "1564459997000",
        "expires_date_formatted_pst": "2019-08-05 21:13:17 America/Los_Angeles",
        "is_trial_period": "true",
        "item_id": "1452171111",
        "unique_identifier": "00000",
        "original_transaction_id": "0000000",
        "expires_date": "00000000",
        "app_item_id": "0000000",
        "transaction_id": "00000000",
        "bvrs": "00000",
        "web_order_line_item_id": "00000000",
        "version_external_identifier": "000000",
        "bid": "com.XXX",
        "product_id": "XXXXX",
        "purchase_date": "2019-07-30 04:13:17 Etc/GMT",
        "purchase_date_pst": "2019-07-29 21:13:17 America/Los_Angeles",
        "original_purchase_date": "2019-07-30 04:13:18 Etc/GMT"
    },
    "environment": "PROD",
    "auto_renew_status": "true",
    "password": "*****",
    "auto_renew_product_id": "com.XXXX",
    "notification_type": "INITIAL_BUY"
}

Your example is from a verifyReceipt response.

The documentation is not that great about server 2 server notification but the latest wwdc video is great - https://developer.apple.com/videos/play/wwdc2019/302/

Note that quite a few of the fields in this payload are considered deprecated by now.

Wilfred Springer
  • 10,869
  • 4
  • 55
  • 69
little
  • 2,927
  • 2
  • 25
  • 36
  • I understand that, but i am not getting the above response as you mentioned. I have edited the question to show what response i am getting in the server 2 server notification – Kumar KS Jul 31 '19 at 07:13
  • So you do get the environment in the S2S notification. Have you tried to look at none sandbox responses? – little Aug 01 '19 at 05:45
  • No, that too i am getting this response once the subscription is renewed. At the first when i purchase the subscription i am getting only the latest_receipt. – Kumar KS Aug 01 '19 at 06:53
  • I don't understand, you clearly say "The response which i am getting from the server 2 server notification is:" and then you have a response that include the environment so why are you saying you don't see the environment field for s2s notifications? – little Aug 01 '19 at 19:09
  • I am sorry for that, that response i am getting for the second time once subscription is getting renewed. – Kumar KS Aug 02 '19 at 06:31
  • Thanks for your response. Finally i have got that working. – Kumar KS Aug 05 '19 at 10:52