Skip to content
This repository was archived by the owner on Oct 16, 2025. It is now read-only.

Commit 2081fdd

Browse files
authored
fix: corrected transactionReason when a previously cancelled subscription was purchased again (#21)
Hello, I discovered that `transactionReason` was incorrectly set to `RENEW` instead of `PURCHASE`, for iOS purchases that had been previously cancelled and then purchased again in the `purchaseUpdatedListener` callback. This fix restores the previous logic for determining `transactionReason`, consistent with the behavior in react-native-iap versions 12.x.x and 13.x.x and real App Store data encoded in `jsonRepresentation`. hyochan/react-native-iap#3056 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved accuracy in detecting subscription renewals, ensuring renewal events are correctly identified. * Reduces instances where subscriptions might appear incorrectly as new purchases or non-renewals. * Leads to more reliable subscription status, history, and related notifications for users. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent c146f80 commit 2081fdd

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Sources/Helpers/StoreKitTypesBridge.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,10 @@ private extension StoreKitTypesBridge {
333333
let string: String
334334
let uppercased: String
335335
}
336+
337+
struct JSONTransactionReason: Codable {
338+
let transactionReason: String
339+
}
336340

337341
static func transactionReasonDetails(from transaction: StoreKit.Transaction) -> TransactionReason {
338342
if let revocation = transaction.revocationReason {
@@ -358,9 +362,8 @@ private extension StoreKitTypesBridge {
358362
}
359363

360364
// Try to infer renewal for iOS <17
361-
if transaction.productType == .autoRenewable,
362-
let expirationDate = transaction.expirationDate,
363-
expirationDate > transaction.purchaseDate {
365+
if let decodedReason = try? JSONDecoder().decode(JSONTransactionReason.self, from: transaction.jsonRepresentation),
366+
decodedReason.transactionReason == "RENEWAL" {
364367
return TransactionReason(lowercased: "renewal", string: "renewal", uppercased: "RENEWAL")
365368
}
366369

0 commit comments

Comments
 (0)