Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PaymentTransaction.transactionIdentifier is different from ReceiptItem.transactionId #302

Closed
6 tasks
NandhakumarHCL opened this issue Nov 17, 2017 · 2 comments

Comments

@NandhakumarHCL
Copy link

Platform

  • [#] iOS
  • macOS
  • tvOS

In app purchase type

  • Consumable
  • Non-consumable
  • [#] Auto-Renewable Subscription
  • Non-Renewing Subscription

Environment

  • [#] Sandbox
  • Production

For Analytics i need to track the Auto-Renewable Subscription.
Method: purchaseProduct(_ productId: String, quantity: Int = 1, atomically: Bool = true, applicationUsername: String = "", completion: @escaping (PurchaseResult) -> Void)

  • purchaseProduct returning the PurchaseResult in completion and the PurchaseResult.PurchaseDetails.transaction.transactionIdentifier is different from the ReceiptItem.transactionId.

Please provide me solution to track the Auto-Renewable Subscription in completeTransactions(atomically: Bool = true, completion: @escaping ([Purchase]) -> Void)

@bizz84
Copy link
Owner

bizz84 commented Dec 22, 2017

@NandhakumarHCL Apologies for the late reply.

The problem lies in the difference between transaction and originalTransaction.

For auto-renewable subscriptions, ReceiptItem.transactionId refers to the payment's originalTransaction.

The originalTransaction has been available in completeTransactions() and restorePurchases() since version 0.9.0. Example:

SwiftyStoreKit.completeTransactions(atomically: true) { purchases in

    for purchase in purchases {
        switch purchase.transaction.transactionState {
        case .purchased, .restored:
            if purchase.needsFinishTransaction {
                // Deliver content from server, then:
                SwiftyStoreKit.finishTransaction(purchase.transaction)
            }
            // this will match ReceiptItem.transactionId
            print("\(purchase.originalTransaction?.transactionIdentifier)")
        case .failed, .purchasing, .deferred:
            break // do nothing
        }
    }
}

originalTransaction is not available in purchaseProduct(). For consistency, it would make sense to add it, right?

@bizz84
Copy link
Owner

bizz84 commented Dec 23, 2017

Available on version 0.11.3.

Closing this issue for now, feel free to comment or reopen if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants