adalovelacer
adalovelacer

Reputation: 11

Stripe Client intent error swift: No such payment_intent

I am having issues utilizing a pay function given by the stripe documentation

Stripe documentation: https://stripe.com/docs/payments/accept-a-payment

All my server side & client side keys are the same testing keys.

I have successfully retrieved a payment intent with the value

pi_1ITiM3KCSIKL5fqUAMGk32Do_secret_cJfvlRxtnnTuU8VIScj8NCz12

Error message:

No such payment_intent: \ 'pi_1ITiM3KCSIKL5fqUAMGk32Do \ '

Not sure why the error message includes: (possibly json issue)

\ '

Any help would be much appreciated on why this is happening.

var paymentIntentClientSecret: String?

func pay() {
            guard let paymentIntentClientSecret = paymentIntentClientSecret else {
                return;
            }
        print(paymentIntentClientSecret) // pi_1ITiM3KCSIKL5fqUAMGk32Do_secret_cJfvlRxtnnTuU8VIScj8NCz12
        
            // Collect card details
        let cardParams = creditCardField.cardParams//cardTextField.cardParams
            let paymentMethodParams = STPPaymentMethodParams(card: cardParams, billingDetails: nil, metadata: nil)
            let paymentIntentParams = STPPaymentIntentParams(clientSecret: paymentIntentClientSecret)
            print(paymentIntentParams)
            paymentIntentParams.paymentMethodParams = paymentMethodParams

            // Submit the payment
            let paymentHandler = STPPaymentHandler.shared()
        paymentHandler.confirmPayment(paymentIntentParams, with: self) { (status, paymentIntent, error) in
                switch (status) {
                case .failed:
                    //self.displayAlert(title: "Payment failed", message: error?.localizedDescription ?? "")
                    print("failed: \(String(describing: error?.localizedDescription))")
                    break
                case .canceled:
                    //self.displayAlert(title: "Payment canceled", message: error?.localizedDescription ?? "")
                    print("cancled: \(String(describing: error?.localizedDescription))")
                    break
                case .succeeded:
                    //self.displayAlert(title: "Payment succeeded", message: paymentIntent?.description ?? "", restartDemo: true)
                    print("succeeded: \(String(describing: error?.localizedDescription))")
                    break
                @unknown default:
                    fatalError()
                    break
                }
            }
        }

Response body:

{
  "error": {
    "code": "resource_missing",
    "doc_url": "https://stripe.com/docs/error-codes/resource-missing",
    "message": "No such payment_intent: 'pi_1ITh8QKCSIKL5fqU7VjJqHH0'",
    "param": "intent",
    "type": "invalid_request_error"
  }
}

Upvotes: 1

Views: 1201

Answers (1)

floatingLomas
floatingLomas

Reputation: 8727

“No such...” errors are usually caused by either a mismatch in API keys (e.g. using a mixture of your test plus live keys) or by trying to access objects that exist on a different account (e.g. trying to perform an operation from your platform account on an object that was created on a connected account).

Most likely you're using a publishable key from one account and a secret key from another (assuming you're not using Connect).

Upvotes: 1

Related Questions