如何在 inAppPurchase 中获取交易 ID

Posted

技术标签:

【中文标题】如何在 inAppPurchase 中获取交易 ID【英文标题】:how to get transaction id in inAppPurchase 【发布时间】:2016-05-10 08:13:57 【问题描述】:

在我的应用程序中,我正在实施 inAppPurchase。 问题:在测试帐户中测试应用程序时,我显示交易完成的弹出窗口。但我不知道如何获取交易 ID。

这是我的代码

-(void)paymentQueue:(SKPaymentQueue *)queue

updatedTransactions:(NSArray *)transactions for (SKPaymentTransaction *transaction in transactions)

    switch (transaction.transactionState) 
        case SKPaymentTransactionStatePurchasing:
            NSLog(@"Purchasing");
            break;
        case SKPaymentTransactionStatePurchased:
            if ([transaction.payment.productIdentifier
                 isEqualToString:kTutorialPointProductID]) 
                NSLog(@"Purchased ");
                UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
                                          @"Purchase is completed succesfully" message:nil delegate:
                                          self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
                [alertView show];
                _shipbutton.hidden=FALSE;
            

            if ([transaction.payment.productIdentifier
                 isEqualToString:kTutorialPointProductID45]) 
                NSLog(@"Purchased ");
                UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
                                          @"Purchase is completed succesfully" message:nil delegate:
                                          self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
                [alertView show];
                _shipbuttonPremium.hidden=FALSE;
            


            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
            break;
        case SKPaymentTransactionStateRestored:
            NSLog(@"Restored ");
            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
            break;
        case SKPaymentTransactionStateFailed:
            NSLog(@"Purchase failed ");
            break;
        default:
            break;
    

我正在请求产品并获取该产品标识符甚至交易也给出了成功消息。那么我怎样才能获得交易ID?

【问题讨论】:

这是接收产品请求结果的代码,但这与购买交易无关。您想在哪里使用交易 ID? 【参考方案1】:

// 我觉得对你有帮助

        for (SKPaymentTransaction * transaction in transactions) 
    switch (transaction.transactionState)
    

        case SKPaymentTransactionStatePurchased:
           NSLog(@"id ===> %@",transaction.transactionIdentifier);
            break;
        case SKPaymentTransactionStateFailed:
            break;
        case SKPaymentTransactionStateRestored:
            NSLog(@"id ===> %@",transaction.transactionIdentifier);
        default:
           NSLog(@"Deafault");
            break;
    
;

【讨论】:

以上是关于如何在 inAppPurchase 中获取交易 ID的主要内容,如果未能解决你的问题,请参考以下文章

支付交易状态失败

如何将 inapppurchase 中的数据转换为 Fabric Answers 所需的格式

InAppPurchases 不适用于 PhoneGap 应用程序

IOS InAppPurchase 内容从我自己的服务器下载

如何在Apple Connect中获取ProductID?(在App中购买)

如何在 NodeJS 中获取 Paypal 交易