Home > Mobile >  Stripe iOS SDK - Value of type 'STPPaymentResult' has no member 'source'
Stripe iOS SDK - Value of type 'STPPaymentResult' has no member 'source'

Time:06-11

I am having an issue with my project that is causing it to fail it's build. The error is:

Value of type 'STPPaymentResult' has no member 'source'

And my code is:

  func paymentContext(_ paymentContext: STPPaymentContext, didCreatePaymentResult paymentResult: STPPaymentResult, completion: @escaping STPErrorBlock) {
    // Create charge using payment result
    let source = paymentResult.source.stripeID
    
    // call api to process payment
    apiTask?.cancel()
    showLoading()
    apiTask = PaymentService.topUpBalance(paymentContext.paymentAmount, stripeSource: source, completion: { (error) in
      completion(error)
    })
  }

This used to work but works no longer which is making me wonder if Stripe has changed something with the latest version. I have looked everywhere and haven't found an answer.

Help would be much appreciated!

enter image description here

CodePudding user response:

As per the Stripe iOS SDK migration guide, Source/Token was migrated to PaymentMethod from version 16.0.0 and up for STPPaymentResult and other classes.

As such the line should be changed to:

let source = paymentResult.paymentMethod.stripeID

You should check out the docs for STPPaymentResult and the 'Migrating to the Payment Intents API' guide.

  • Related