aporat / store-receipt-validator

PHP receipt validator for Apple iTunes, Google Play and Amazon App Store
Apache License 2.0
633 stars 153 forks source link

Undefined array key "product_id" Exception #173

Closed freelancefrivas closed 3 weeks ago

freelancefrivas commented 1 year ago

I'm getting this exception while it validates an Apple notification, on PendingRenewalInfo.php, line 140. I'm Printing the payload on the log before validation and it looks like this: [notification_type] => REVOKE [password] => xxxxxxxxxxxxxxxxxxxxxxxx [environment] => PROD [auto_renew_product_id] => com.learnsafari.spanish_safari_monthSub2 [auto_renew_status] => false [unified_receipt] => Array ( [status] => 0 [environment] => Production [latest_receipt_info] => Array ( [0] => Array ( [quantity] => 1 [product_id] => com.learnsafari.spanish_safari_monthSub2 [transaction_id] => 502432905404171488 [purchase_date] => 2023-05-14 23:36:30 Etc/GMT [purchase_date_ms] => 1684107390000 [purchase_date_pst] => 2023-05-14 16:36:30 America/Los_Angeles [original_purchase_date] => 2023-05-14 23:36:31 Etc/GMT [original_purchase_date_ms] => 1684107391000 [original_purchase_date_pst] => 2023-05-14 16:36:31 America/Los_Angeles [expires_date] => 2023-05-28 23:36:30 Etc/GMT [expires_date_ms] => 1685316990000 [expires_date_pst] => 2023-05-28 16:36:30 America/Los_Angeles [web_order_line_item_id] => 502432905404171489 [is_trial_period] => true [is_in_intro_offer_period] => false [original_transaction_id] => 502432905404171488 [cancellation_date] => 2023-06-13 00:32:26 Etc/GMT [cancellation_date_ms] => 1686616346743 [cancellation_date_pst] => 2023-06-12 17:32:26 America/Los_Angeles [cancellation_reason] => 0 [in_app_ownership_type] => FAMILY_SHARED [subscription_group_identifier] => 20619207 )

            )

        [latest_receipt] => MIIU0gYJKoZIhvcNAQcCoIIUwzCCFL8CAQExCzAJBgUrDgMCGgUAMIIEEAYJKoZIhvcNAQcBoIIEAQSCA/0xggP5MAoCARQCAQEEAgwAMAsCARkCAQEEAwIBAzAMAgEKAgEBBAQWAjQrMAwCAQ4CAQEEBAICAIwwDQIBDQIBAQQFAgMCTLIwDgIBAQIBAQQGAgRDIK2UMA4C$
    )

[bid] => com.learnsafari.spanish-safari-v1
[bvrs] => 20221130.1
[original_transaction_id] => 502432905404171488
Stafox commented 1 year ago

hi. you should not try to put notification payload into ProductionResponse constructor. Run validation instead using latest_receipt and password from notification.

The structure looks similar but different.

Stafox commented 1 year ago

In case you get the error on validation stage, could you share Raw validation response from Apple?

freelancefrivas commented 1 year ago

You're right, reviewing this I realize the server is treating V1 notifications as if they were V2, and the payload shouldn't be used to validate. Sorry, should have checked this better before posting.

freelancefrivas commented 1 year ago

Sorry, reviewing this again, I notice the parameters are fine. There is a problem when the response is being processed, and it seems to be because the Pending_renewal_info field has an empty array inside. I wonder why this could happen... I'm attaching a screenshot where the data is displayed. learnsafari

MartinPerry commented 1 year ago

Have you solved this?