我在收到 SKPaymentTransactionStatePurchased
后使用收据来验证购买通知,除其他外,获取用户刚刚购买的订阅的到期日期。
为了正确识别收据中刚刚发生的交易,我通过 transaction.transactionIdentifier
匹配它。和 transaction_id
.我遇到的问题是事务标识符永远不会匹配。
通过手动检查 purchase_date
,我已经能够识别收据中的正确交易。和 product_id
,但 transaction_id
与交易完全不同。
我也看过 transaction.originalTransaction.transactionIdentifier
和 original_transaction_id
,但这四个值似乎在任何时候都不匹配。
这里发生了什么?在沙盒中测试时有人遇到过类似的问题吗?该文档明确指出 transaction_id
应该匹配 transactionIdentifier
交易的属性(property)。这可能是一个错误吗?
编辑 1:
这是单次购买订阅(之前已过期)的不同交易标识符
transaction.transactionIdentifier = 1000000325087359
transaction.originalTransaction.transactionIdentifier = 1000000297785006
transaction_id = 1000000325087377
original_transaction_id = 1000000297785006
似乎原始交易标识符匹配(为什么他们会,这是一个新购买?),但其他两个不匹配。它们来自哪里,它们匹配什么?我不明白两者之间的关系及其重要性。
最佳答案
SKPaymentTransaction.transactionIdentifier
的文档笔记:
This value has the same format as the transaction’s
transaction_id
in the receipt; however, the values may not be the same.
以及
transaction_id
的文档笔记:This value has the same format as the transaction’s
transactionIdentifier
property; however, the values may not be the same.You can use this value to:
• Manage subscribers in your account database. Store the
transaction_id
,original_transaction_id
, andproduct_id
for each transaction, as a best practice to store transaction records for each customer. App Store generates a new value fortransaction_id
every time the subscription automatically renews or is restored on a new device.• Differentiate a purchase transaction from a restore or a renewal transaction. In a purchase transaction, the
transaction_id
always matches theoriginal_transaction_id
. For subscriptions, it indicates the first subscription purchase. For a restore or renewal, thetransaction_id
does not match theoriginal_transaction_id
. If a user restores or renews the same purchase multiple times, each restore or renewal has a differenttransaction_id
.
我还会注意到 Receipt Validation Programming Guide (来自文档文件)在交易标识符下说明:
This value corresponds to the transaction’s
transactionIdentifier
property.
除了记录的场景外,我不清楚这两个字段在哪些场景中相同或不同。
关于iOS StoreKit 交易标识符与收据不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45705069/