Trouble Checking with Shopify Vault Card iOS Mobile App

klaytonerekson
New Member
6 0 0

Here is my code trying to complete a checkout using a TokenizedPaymentInputV3

let query = ClientQuery.queryForShopCardVaultURL()
        let task = self.client.queryGraphWith(query) { (response, error) in
            if let settings = response?.shop.paymentSettings {
                let cardClient = Card.Client()
                let creditCard = Card.CreditCard(
                    firstName:        firstName,
                    middleName:       middleName,
                    lastName:         lastName,
                    number:           number,
                    expiryMonth:      expiryYear,
                    expiryYear:       expiryYear,
                    verificationCode: cvv
                )
                
                let cardVaultURL = settings.cardVaultUrl
                let cardTask = cardClient.vault(creditCard, to: cardVaultURL) { token, error in
                    if let token = token {
                        // proceed to complete checkout with `token`
                        let newCard = CrustCard(token: token, title: "Credit Card - Ending in \(number.suffix(4))", id: "", isPreferred: true, billingAddress: billingAddress)
                        if let id = Auth.auth().currentUser?.uid {
                            let userRef = Firestore.firestore().collection(AccountService.clientKey).document(id)
                            do {
                                let _addressDict = try newCard.asDictionary()
                                userRef.updateData([
                                    "payments": FieldValue.arrayUnion([_addressDict])
                                ])
                                completion(.success(newCard))
                            } catch {
                                completion(.failure(.apiError(error)))
                            }
                        } else {
                            completion(.failure(.noAccount))
                        }
                    } else {
                        // handle error
                        completion(.failure(.queryError))
                    }
                }
                cardTask.resume()
            } else {
                completion(.failure(.queryError))
            }

I use the token to create a payment

let payment = Storefront.TokenizedPaymentInputV3.create(paymentAmount: paymentAmount, idempotencyKey: UUID().uuidString, billingAddress: mailingAddress, paymentData: token, type: .vault)

And then finalize my query

return Storefront.buildMutation { $0
            .checkoutCompleteWithTokenizedPaymentV3(checkoutId: GraphQL.ID(rawValue: checkout.id), payment: payment) { $0
                .payment { $0
                    .id()
                    .ready()
                }
                .checkout { $0
                    .id()
                    .ready()
                }
                .checkoutUserErrors { $0
                    .code()
                    .field()
                    .message()
                }
            }
        }

Then I use that query to get a response from my checkout:

if let payment = response?.checkoutCompleteWithTokenizedPaymentV3?.payment {
     self.fetchCompletedPayment(payment.id.rawValue) { result in
           switch result {
           case .success(let order):
               completion(.success(order))
          case .failure(let error):
               completion(.failure(error))
          }
     }
} else {
     completion(.failure(.queryError))
}

 

I continually get 

Payment error: There was an issue processing your payment. Try again or use a different payment method.

0 Likes
Kevin_A
Shopify Staff
Shopify Staff
310 42 53

Hey @klaytonerekson 

If I had to guess, it appears as though your app doesn't have permissions to write payments at checkout. Can you provide more details about this app (if this is a public or custom app, you can find the app ID in the URL, looks something like partners.shopify.com/<partner id>/apps/<app id>) or perhaps an x-request-id response header from one of the API calls? 

Kevin_A | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes