Home > database >  <SKPaymentQueue: 0x281194d90>: Payment completed with error: Error Domain=ASDErrorDomain Code=
<SKPaymentQueue: 0x281194d90>: Payment completed with error: Error Domain=ASDErrorDomain Code=

Time:09-16

I'm trying to make an in app purchase inside my app but for some reason when i enter my apple ID and my password i'm getting an error on the log and nothing happens on UI. I nedd to upload my app on test flight or something like this to be able to purchase items from my app?. I have added the payment methods and the tax info.

I'm just calling the purchase product method from my view.

The error:

2021-09-14 19:06:01.857244 0300 iGrow Goals[697:72415] <SKPaymentQueue: 0x2802709f0>: Payment completed with error: Error Domain=ASDErrorDomain Code=500 "Unhandled exception" UserInfo={NSUnderlyingError=0x280ec2610 {Error Domain=AMSErrorDomain Code=100 "Authentication Failed" UserInfo={NSLocalizedFailureReason=The verify credentials call failed., NSLocalizedDescription=Authentication Failed, NSUnderlyingError=0x280ec2700 {Error Domain=AMSServerErrorDomain Code=-5000 "The operation couldn’t be completed. (AMSServerErrorDomain error -5000.)" UserInfo={NSLocalizedDescription=The operation couldn’t be completed. (AMSServerErrorDomain error -5000.)}}}}, NSLocalizedFailureReason=An unknown error occurred, NSLocalizedDescription=Unhandled exception}

StoreManager.swift:

//
//  StoreManager.swift
//  iGrow Goals
//
//  Created by George Sepetadelis on 30/8/21.
//

import Foundation
import StoreKit

class StoreManager: NSObject, ObservableObject, SKProductsRequestDelegate {
    
    @Published var myProducts = [SKProduct]()
    var request: SKProductsRequest!
    
    @Published var transactionState: SKPaymentTransactionState?
    
    func enablePremiumPlan() {
        
    }
    
    func purchaseProduct(product: SKProduct) {
        if SKPaymentQueue.canMakePayments() {
            let payment = SKPayment(product: product)
            SKPaymentQueue.default().add(payment)
        } else {
            print("User can't make payment.")
        }
    }
    
    
    func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
        for transaction in transactions {
            switch transaction.transactionState {
            case .purchasing:
                transactionState = .purchasing
            case .purchased:
                UserDefaults.standard.setValue(true, forKey: transaction.payment.productIdentifier)
                queue.finishTransaction(transaction)
                print("payment success")
                transactionState = .purchased
                enablePremiumPlan()
            case .restored:
                UserDefaults.standard.setValue(true, forKey: transaction.payment.productIdentifier)
                queue.finishTransaction(transaction)
                transactionState = .restored
                enablePremiumPlan()
            case .failed, .deferred:
                queue.finishTransaction(transaction)
                transactionState = .failed
                print("payment failed")
            default:
                queue.finishTransaction(transaction)
                print("default")
                
            }
        }
    }
    
    func getProducts(productIDs: [String]) {
        print("Start requesting products ...")
        let request = SKProductsRequest(productIdentifiers: Set(productIDs))
        request.delegate = self
        request.start()
    }
    
    
    func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
        print("Did receive response")
        
        if !response.products.isEmpty {
            for fetchedProduct in response.products {
                DispatchQueue.main.async {
                    self.myProducts.append(fetchedProduct)
                }
            }
        }
        
        for invalidIdentifier in response.invalidProductIdentifiers {
            print("Invalid identifiers found: \(invalidIdentifier)")
        }
    }
    
    func request(_ request: SKRequest, didFailWithError error: Error) {
        print("Request did fail: \(error)")
    }
    
}

CodePudding user response:

Try a sandbox account when testing in app purchases straight out of Xcode.

Your regular account will work on Test Flight and when in the App Store.

https://developer.apple.com/documentation/storekit/original_api_for_in-app_purchase/testing_in-app_purchases_with_sandbox

  • Related