Wizcorp / node-iap

In-app purchase validation for Apple, Google, Amazon, Roku
262 stars 92 forks source link

Not sure sorting by `transaction_id` works with family sharing #90

Open ricsantos opened 2 years ago

ricsantos commented 2 years ago

Noticed that a iOS user who was having receipt validation issues had two items in the latest receipt info array:

  "latest_receipt_info": [
    {
      "quantity": "1",
      "product_id": "yearly",
      "transaction_id": "501136461303889853",
      "original_transaction_id": "501136461303889853",
      "purchase_date": "2022-02-10 17:59:20 Etc/GMT",
      "purchase_date_ms": "1644515960000",
      "purchase_date_pst": "2022-02-10 09:59:20 America/Los_Angeles",
      "original_purchase_date": "2022-02-10 17:59:21 Etc/GMT",
      "original_purchase_date_ms": "1644515961000",
      "original_purchase_date_pst": "2022-02-10 09:59:21 America/Los_Angeles",
      "expires_date": "2022-02-17 17:59:20 Etc/GMT",
      "expires_date_ms": "1645120760000",
      "expires_date_pst": "2022-02-17 09:59:20 America/Los_Angeles",
      "cancellation_date": "2022-03-10 20:57:06 Etc/GMT",
      "cancellation_date_ms": "1646945826586",
      "cancellation_date_pst": "2022-03-10 12:57:06 America/Los_Angeles",
      "is_trial_period": "true",
      "is_in_intro_offer_period": "false",
      "cancellation_reason": "0",
      "in_app_ownership_type": "FAMILY_SHARED"
    },
    {
      "quantity": "1",
      "product_id": "monthly",
      "transaction_id": "150001161180179",
      "original_transaction_id": "150001161180179",
      "purchase_date": "2022-08-12 19:06:35 Etc/GMT",
      "purchase_date_ms": "1660331195000",
      "purchase_date_pst": "2022-08-12 12:06:35 America/Los_Angeles",
      "original_purchase_date": "2022-08-12 19:06:35 Etc/GMT",
      "original_purchase_date_ms": "1660331195000",
      "original_purchase_date_pst": "2022-08-12 12:06:35 America/Los_Angeles",
      "expires_date": "2022-09-12 19:06:35 Etc/GMT",
      "expires_date_ms": "1663009595000",
      "expires_date_pst": "2022-09-12 12:06:35 America/Los_Angeles",
      "is_trial_period": "false",
      "is_in_intro_offer_period": "false",
      "in_app_ownership_type": "PURCHASED"
    }
  ]

Our tactic of grabbing the last item in the array failed, because iap sorts the items before returning them:

https://github.com/Wizcorp/node-iap/blob/4ac0e22a54008a8396599190ea75a80b038ae407/lib/apple/index.js#L76

However the sorting is via transaction_id and in this case the first transaction has a much larger id than the second. Not sure if related to family sharing, or a red herring.

Perhaps don't sort the array when parsing?

ayano-opendna commented 10 months ago

I have same problem too. In case of family sharing, transaction_id is larger than new one of purchase. So I cant get latest receipt. How can I get latest receipt in anyway ?

ronkorving commented 9 months ago

Years ago, I maintained this project, but I've since moved on. I'm getting the impression this project is no longer maintained and you may be better off using an alternative.

adamk22 commented 9 months ago

@ronkorving do you have any recommendations? I'm currently in the process of refactoring a project where this is used for iap verification, but have yet to look for an alternative.

ronkorving commented 9 months ago

I'm sorry to say I do not. I hardly use Node.js these days. But I do know there is more than one IAP related package on NPM.

ayano-opendna commented 8 months ago

@ronkorving Thank you to reply! I will try other NPMs.