Skip to content

Commit

Permalink
FIX: Check all subscriptions to use latest expiring one
Browse files Browse the repository at this point in the history
  • Loading branch information
hijohnnylin committed Apr 21, 2020
1 parent 9151b60 commit 24662f8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion models/receipt-model.js
Expand Up @@ -170,7 +170,16 @@ class Receipt {
if (!body.hasOwnProperty("latest_receipt_info") || body.latest_receipt_info.length == 0) {
throw new ConfirmedError(400, 9, "No subscription found in iOS receipt", body);
}
var latestReceiptInfo = body.latest_receipt_info[0];
// choose the receipt with the latest expiration date
var latestExpirationIndex = 0
var latestExpirationMs = 0;
for (var index = 0; index < body.latest_receipt_info.length; index++) {
if (body.latest_receipt_info[index].hasOwnProperty("expires_date_ms") && body.latest_receipt_info[index].expires_date_ms > latestExpirationMs) {
latestExpirationIndex = index;
latestExpirationMs = body.latest_receipt_info[index].expires_date_ms
}
}
var latestReceiptInfo = body.latest_receipt_info[latestExpirationIndex];

if (!body.hasOwnProperty("pending_renewal_info") || body.pending_renewal_info.length == 0) {
throw new ConfirmedError(400, 9, "iOS subscription receipt missing pending_renewal_info", body);
Expand Down

0 comments on commit 24662f8

Please sign in to comment.