Yrtiop
Yrtiop

Reputation: 51

Expiration notification received a second time after an android subscription purchase

I have a strange behavior with SubscriptionNotification, when we purchase a subscription and cancel it we get in total 4 notifications :

{
  "startTimeMillis": "1680768693830", // 2023-04-06 08:11:33
  "expiryTimeMillis": "1680768987284", // 2023-04-06 08:16:27
  "autoRenewing": true,
  "priceCurrencyCode": "EUR",
  "priceAmountMicros": "12990000",
  "countryCode": "FR",
  "developerPayload": "",
  "paymentState": 1,
  "orderId": "GPA.3318-6319-2574-83983",
  "purchaseType": 0,
  "acknowledgementState": 0,
  "kind": "androidpublisher#subscriptionPurchase",
  "obfuscatedExternalAccountId": "44643664-6333-4338-a666-353162316530",
  "obfuscatedExternalProfileId": "78708a15-b7ab-480d-90bf-84e75c4962eb"
}
{
  "startTimeMillis": "1680768693830", // 2023-04-06 08:11:33
  "expiryTimeMillis": "1680768987284", // 2023-04-06 08:16:27
  "autoRenewing": false,
  "priceCurrencyCode": "EUR",
  "priceAmountMicros": "12990000",
  "countryCode": "FR",
  "developerPayload": "",
  "paymentState": 1,
  "cancelReason": 0,
  "userCancellationTimeMillis": "1680768867438", // 2023-04-06 08:14:27
  "orderId": "GPA.3318-6319-2574-83983",
  "purchaseType": 0,
  "acknowledgementState": 1,
  "kind": "androidpublisher#subscriptionPurchase",
  "obfuscatedExternalAccountId": "44643664-6333-4338-a666-353162316530",
  "obfuscatedExternalProfileId": "78708a15-b7ab-480d-90bf-84e75c4962eb"
}
{
  "startTimeMillis": "1680768693830", // 2023-04-06 08:11:33
  "expiryTimeMillis": "1680768988438", // 2023-04-06 08:16:28
  "autoRenewing": false,
  "priceCurrencyCode": "EUR",
  "priceAmountMicros": "12990000",
  "countryCode": "FR",
  "developerPayload": "",
  "cancelReason": 0,
  "userCancellationTimeMillis": "1680768867438", // 2023-04-06 08:14:27
  "orderId": "GPA.3318-6319-2574-83983",
  "purchaseType": 0,
  "acknowledgementState": 1,
  "kind": "androidpublisher#subscriptionPurchase",
  "obfuscatedExternalAccountId": "44643664-6333-4338-a666-353162316530",
  "obfuscatedExternalProfileId": "78708a15-b7ab-480d-90bf-84e75c4962eb"
}
{
  "startTimeMillis": "1680768693830", // 2023-04-06 08:11:33
  "expiryTimeMillis": "1680768988438", // 2023-04-06 08:16:28
  "autoRenewing": false,
  "priceCurrencyCode": "EUR",
  "priceAmountMicros": "12990000",
  "countryCode": "FR",
  "developerPayload": "",
  "cancelReason": 0,
  "userCancellationTimeMillis": "1680768867438", // 2023-04-06 08:14:27
  "orderId": "GPA.3318-6319-2574-83983",
  "purchaseType": 0,
  "acknowledgementState": 1,
  "kind": "androidpublisher#subscriptionPurchase",
  "obfuscatedExternalAccountId": "44643664-6333-4338-a666-353162316530",
  "obfuscatedExternalProfileId": "78708a15-b7ab-480d-90bf-84e75c4962eb"
}

(I am in test mode so the duration of the subscription is 5 minutes)

I don't understand where this fourth one come from, the problematic thing is it's sent after we make a purchase again.

Here is the notification for the second purchase (received at 08:34:23) :

{
  "startTimeMillis": "1680770058278", // 2023-04-06 08:34:18
  "expiryTimeMillis": "1680770354886", // 2023-04-06 08:39:14
  "autoRenewing": true,
  "priceCurrencyCode": "EUR",
  "priceAmountMicros": "12990000",
  "countryCode": "FR",
  "developerPayload": "",
  "paymentState": 1,
  "orderId": "GPA.3314-6552-0681-64757",
  "purchaseType": 0,
  "acknowledgementState": 0,
  "kind": "androidpublisher#subscriptionPurchase",
  "obfuscatedExternalAccountId": "44643664-6333-4338-a666-353162316530",
  "obfuscatedExternalProfileId": "78708a15-b7ab-480d-90bf-84e75c4962eb"
}

You can see the orderId is different this time as it's a second purchase. Where do this fourth notification from the first purchase comes from ?

Upvotes: 1

Views: 717

Answers (1)

SolessChong
SolessChong

Reputation: 3407

The 3 and 4 notifications have the same information, except for the time at which they were received.

A few possible reasons:

  1. Duplicate notifications: Sometimes, Google Play can send duplicate notifications for the same event. This is a known issue and can occur due to network issues or other technical reasons. You should ensure your server is idempotent, meaning it can handle duplicate notifications without causing any issues.

  2. Real-time Developer Notifications (RTDN) retries: Google Play might retry sending notifications if it doesn't receive a successful acknowledgment (HTTP 200 status code) from your server. Ensure your server is correctly acknowledging the notifications to avoid this issue.

  3. Server-side processing: There might be an issue with your server-side code that processes the notifications. Double-check your code to ensure it's not causing any issues with handling the received notifications.

Andn perhaps some solution:

  1. Make sure your server properly acknowledges the notifications it receives to avoid unnecessary retries from Google Play.

  2. Add logic to your server-side code to deduplicate notifications. You can use the "startTimeMillis", "expiryTimeMillis", and "orderId" fields to uniquely identify a subscription event. If your server receives a notification with the same values for these fields, you can safely ignore the duplicate notification.

  3. Monitor and log the notifications received by your server. This can help you identify any issues or trends with the notifications and aid in debugging if required.

Upvotes: 0

Related Questions