Skip to content

Commit

Permalink
Ensure Apple receipts with duplicate transaction identifiers are proc…
Browse files Browse the repository at this point in the history
…essed cleanly.
  • Loading branch information
zyro committed Mar 29, 2024
1 parent cd82b6c commit 621c697
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project are documented below.
The format is based on [keep a changelog](http://keepachangelog.com) and this project uses [semantic versioning](http://semver.org).

## [Unreleased]
### Fixed
- Ensure Apple receipts with duplicate transaction identifiers are processed cleanly.

## [3.21.1] - 2024-03-22
### Added
Expand Down
9 changes: 9 additions & 0 deletions server/core_purchase.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,22 @@ func ValidatePurchasesApple(ctx context.Context, logger *zap.Logger, db *sql.DB,
env = api.StoreEnvironment_SANDBOX
}

seenTransactionIDs := make(map[string]struct{}, len(validation.Receipt.InApp)+len(validation.LatestReceiptInfo))
storagePurchases := make([]*storagePurchase, 0, len(validation.Receipt.InApp)+len(validation.LatestReceiptInfo))
for _, purchase := range validation.Receipt.InApp {
if purchase.ExpiresDateMs != "" {
continue
}
if _, seen := seenTransactionIDs[purchase.TransactionId]; seen {
continue
}

purchaseTime, err := strconv.ParseInt(purchase.PurchaseDateMs, 10, 64)
if err != nil {
return nil, err
}

seenTransactionIDs[purchase.TransactionId] = struct{}{}
storagePurchases = append(storagePurchases, &storagePurchase{
userID: userID,
store: api.StoreProvider_APPLE_APP_STORE,
Expand All @@ -94,12 +99,16 @@ func ValidatePurchasesApple(ctx context.Context, logger *zap.Logger, db *sql.DB,
if purchase.ExpiresDateMs != "" {
continue
}
if _, seen := seenTransactionIDs[purchase.TransactionId]; seen {
continue
}

purchaseTime, err := strconv.ParseInt(purchase.PurchaseDateMs, 10, 64)
if err != nil {
return nil, err
}

seenTransactionIDs[purchase.TransactionId] = struct{}{}
storagePurchases = append(storagePurchases, &storagePurchase{
userID: userID,
store: api.StoreProvider_APPLE_APP_STORE,
Expand Down

0 comments on commit 621c697

Please sign in to comment.