#Adrian Moreno

1 messages · Page 1 of 1 (latest)

deep basaltBOT
brazen flame
#

Hi there. What's the issue you're seeing exactly

fringe sleet
#

Hi!

The issue is when I do this:

    paymentHandler.confirmPayment(
      paymentIntentParams,
      with: authContext
    ) { (status, _, _) in
      switch status {
      case .failed:
        self.isLoading.value = false
        self.stripeFailedCallback.fire()
      case .canceled:
        self.isLoading.value = false
        self.stripeCancelledCallback.fire()
      case .succeeded:
        self.addDayToCalendarService()
        self.purchaseService()
      @unknown default:
        self.isLoading.value = false
        self.stripeFailedCallback.fire()
      }
    }```
#

The part inside of the succeeded isn't being executed when the payment with Klarna has been completed

brazen flame
#

Gotcha. What about if the payment fails or is canceled, do those blocks execute?

fringe sleet
#

Yes, they work perfect

brazen flame
#

Does the default case execute on success or nothing happens?

fringe sleet
#

Well, what happen is that the app is redirected because of the deeplink

#
    paymentIntentParams.paymentMethodParams = klarnaMethodParams
    paymentIntentParams.returnURL = deepLink ```
#

That's on top of the previous code I sent you

brazen flame
#

Hm gotcha. Let me see if I can get a colleague who's more familiar with iOS to check this out. Will get back to you

fringe sleet
#

Perfect, thank you

tired snow
#

Hello 👋

#

Just to clarify, when you say the code inside .succeeded isn't getting executed are you seeing any errors in your logs which could indicate something going wrong?

#

Have you tried setting a breakpoint on the switch .succeeded ?
Is it being called or just getting skipped altogether?

fringe sleet
#

Skipped afaik

tired snow
#

Can you double check just in case? I'd also recommend using the stepper to see what case is being followed if not succeeded

Also you mentioned it works fine for other payment methods?

fringe sleet
#

Will check right now and see what happens 100% sure

#

Yes, the other parts work fine

tired snow
#

what happens when you set a breakpoint on the switch status and step through the execution cycle?

fringe sleet
#

I'm executing it right now, it's taking a little bit more than expected to compile

tired snow
#

NP! Take your time 🙂

fringe sleet
#

Weird

#

It ignored the whole switch

#

Just completed the payment and jumped directly to the deeplink

pseudo vapor
#

👋

#

Stepping in as hanzo needed to step away

#

Catching up

fringe sleet
#

Perfect, let me know if there's something you want me to explain

#

Basically as summary:

  • I'm configuring Klarna payment with iOS and the part where I do the switch case isn't working as expected when I complete the payment.
pseudo vapor
#

Hmmm weird

#

The code looks fine as far as I can tell...

#

Can you try commenting out the switch statement completely and just do a really simple print statment?

#

Just see if your callback is getting hit at all without the switch

fringe sleet
#

I'm gonna try

#

I'm testing it

#

It's just taking forever 😂

pseudo vapor
#

All good

fringe sleet
#

If I don't complete the payment at least does the print

#

I'm checking now if completing the payment

#

Okey, completing the payment don't

#

It directly jumps to the deeplink

pseudo vapor
#

Okay so it is indeed the deeplink stopping this next code from running 🤔

#

Wait

#

When you "dont complete the payment"

#

This means you failed it?

#

So it still deep links for this back to your app, no?

fringe sleet
#

Cancelled

#

Not failed, sorry

#

Basically when I close the SVC

pseudo vapor
#

Ah okay so without the deeplink firing

fringe sleet
#

The deeplink gets fired when you fail the payment?

pseudo vapor
#

It should I believe if you attempted to authorize with Klarna but it failed authorization

#

Hmmm maybe not though. I might be misremembering...

fringe sleet
#

Hmmm, then I have another problem because my deeplink is supposed to go to the complete payment screen but that's a different issue 😂

pseudo vapor
#

Right that's why I'm thinking I'm wrong 🙂

fringe sleet
#

First I want to fix the issue with the deeplink not letting the rest of the switch work

#

Do you have any idea what should I start checking first? Because I'm not sure at what point the deeplink gets fired

#

Do you know if there's any option to just don't fire any deeplink?

#

Just complete the switch as usually

pseudo vapor
#

Sure you can just stick any return_url in there to test

#

you don't have to deep link

#

But it is a bad experience and you do want to deep link

#

But that is a good thing to start with

#

In terms of testing

#

Have you confirmed the deep link works in other places?

fringe sleet
#

Yes

pseudo vapor
#

So if you use a different PaymentMethod it deeplinks correctly?

#

Also, are you using PaymentSheet or integrating Klarna directly?

#

Looks like Payment Sheet, right?

fringe sleet
#

I have deeplinks for entering the app from an url and have tested that deeplink itself from outside and does what it's supposed to do

#

It's not exactly a Payment Sheet

pseudo vapor
#

Which guide did you follow?

fringe sleet
pseudo vapor
#

Gotcha so yeah not Payment Sheet

#

Ah wait

#

Nvm you do have handlerStatus set

#

status in your case

#

Yeah hmmm

fringe sleet
#

Yes, it's only status but works too xD

pseudo vapor
#

Also it clearly isn't the switch statement

fringe sleet
#

It's the part inside the confirmPayment

pseudo vapor
#

Can you confirm that that the code afterwards does fire if you use a non-deeplink returnURL?

fringe sleet
#
      paymentIntentParams,
      with: authContext
    ) { (status, _, _) in
    some code that's not being executed when I complete the payment
} ```
pseudo vapor
#

Like can you try just www.example.com?

fringe sleet
#

I'll try

#

Just goes to the status.failed directly

pseudo vapor
#

Hrmmm

#

What if you remove the returnURL completely?

#

Can't remember if it is required here.

fringe sleet
#

I'm trying it right now

#

Same

#

Failed

pseudo vapor
#

Huh I don't think this should be required iirc.

#

I think it should just open a default web view

#

What error are you seeing?

fringe sleet
#

Let me check

pseudo vapor
#

Yeah confirmed that returnURL isn't required

#

So curious why this is failing

#

Only thing required is the clientSecret

fringe sleet
#

It's in spanish but it seems is required

#

Optional("Error Domain=com.stripe.lib Code=50 "Se ha producido un error inesperado. Vuelve a intentarlo en unos segundos" UserInfo={com.stripe.lib:ErrorParameterKey=returnUrl, com.stripe.lib:StripeErrorCodeKey=parameter_invalid_empty, NSLocalizedDescription=Se ha producido un error inesperado. Vuelve a intentarlo en unos segundos, com.stripe.lib:ErrorMessageKey=Especificaste una cadena vacía para 'return_url'. Asumimos que los valores vacíos son un intento de anular un parámetro; no obstante, 'return_url' no se puede anular. Debes eliminar 'return_url' de tu petición o suministrar un valor que no esté vacío.,

It says: return_url can not be null

pseudo vapor
fringe sleet
#

But it's required with Klarna

#

Not with the regular Stripe payments

pseudo vapor
#

Yeah

#

Not Card

#

But still

fringe sleet
#

With card I don't need the returnURL and works perfect

pseudo vapor
#

Right

#

Try https://www.example.com for returnURL and let's look at the error

fringe sleet
#

There's no error with that one

pseudo vapor
#

Also can you add { (handlerStatus, paymentIntent, error) and print("error: ", error) afterward

fringe sleet
#

I get the payment screen

pseudo vapor
#

The payment screen?

#

It works fine you mean?

fringe sleet
#

Yep

pseudo vapor
#

And when you complete authentication what happens?

#

You hit your callback?

fringe sleet
#

Let's see

#

Haven't tested that yet

pseudo vapor
#

kk let me kow

fringe sleet
#

I get the <- Return to Merchant screen

pseudo vapor
#

Yep that's what I expected

#

And your callback code?

fringe sleet
#

Works

pseudo vapor
#

Okay so at least we know the deeplink is indeed the issue and everything else is fine

fringe sleet
#

It goes to .succeded

pseudo vapor
#

Can you show me your deeplink code?

fringe sleet
#
    guard let windowScene = (scene as? UIWindowScene) else { return }
    window = UIWindow(windowScene: windowScene)
    window!.rootViewController = myApp.initialScreen

    guard let url = URLContexts.first?.url else {
      return
    }

    if url.absoluteString.contains("stripe-redirect"), let deeplink = URL(string: url.absoluteString) {
      goToConfirmPayment(deeplink)
    } else if let deeplink = URL(string: url.absoluteString.replacingOccurrences(of: "home/", with: "")) {
      adjustDeeplinkResponse(deeplink)
    }
    window?.makeKeyAndVisible()

    ApplicationDelegate.shared.application(
      UIApplication.shared,
      open: url,
      sourceApplication: nil,
      annotation: [UIApplication.OpenURLOptionsKey.annotation]
    )
  } ```
#

Then the confirmPayment function just goes to the complete payment page with the correct parameters.

#

Not sure if that's what you want to see

pseudo vapor
#

I'm not an iOS expert but that looks fine as far as I can tell....

fringe sleet
#

Is there a way to close the SVC when the payment gets completed?

pseudo vapor
#

Don't think so

#

What version of our iOS SDK are you using?

#

I think the next step here will have to be for us to reproduce this flow and ensure there is nothing bugged on our end. Then play with it in the way you are handling it to find out what is going on. I'm not sure how much more troubleshooting we will be able to do here unfortunately.

fringe sleet
#

Should I update to the last version?

pseudo vapor
#

You can try that... it shouldn't really make a difference

#

But I'm out of ideas so probably worth it.

fringe sleet
#

I'm gonna update and see what happens then

pseudo vapor
#

Sounds good

fringe sleet
#

I updated but on the website it says the last released version is 23.3.1

#

I get the 22.8.4 when I update from XCode, any idea why?

pseudo vapor
#

Minimum iOS version for 23.0.0 is 13.0. Maybe you are still set to 12.0?

fringe sleet
#

My minimum is 14.0

#

What's the minimum for macOS, tvOS and watchOS?

pseudo vapor
#

Ah

#

I know why

#

In 23.0.0 we split up the modules

fringe sleet
#

Aaaaaah, makes sense

quaint pewter
#

Hello! I'm taking over and catching up...

fringe sleet
#

Hi!

quaint pewter
#

To clarify, the issue is that goToConfirmPayment(deeplink) is not running, correct? If you log url immediately after the guard let url block what URL are you seeing? Is it what you expect?

fringe sleet
#

The issue is that when I go to the SVC to pay with Klarna and complete the payment the deeplink gets fired right as soon as I complete the payment and the paymentHandler.confirmPayment() don't complete the switch .succeded

quaint pewter
#

So goToConfirmPayment(deeplink) is being run?

fringe sleet
#

Yes

#

The deeplink works as expected

quaint pewter
#

In your confirmPayment handler you have (status, _, _) which means you're ignoring the last argument, the error. If you change that to (status, _, error) and then log the error out do you see anything? Or does it not run at all, ever?

fringe sleet
#

It doesn't run at all

#

Just jump directly to the deeplink

quaint pewter
#

Where is paymentHandler coming from?

fringe sleet
#

let paymentHandler = STPPaymentHandler.shared()

#

Not sure if that's what u are asking

quaint pewter
#

Yep, that's what I was asking! Let me think on this for a bit...

fringe sleet
#

Okey, thanks!

fringe sleet
#

Let me know if you have an update 😄

quaint pewter
#

I've got another question: what is authContext and where is it coming from?

fringe sleet
#

STPAuthenticationContext

quaint pewter
#

Right, but where is it coming from? Can you share that code?

fringe sleet
#
    guard klarnaPayRequirementsValidated else { return }
    viewModel.inputs.klarnaPayPurchase(withAuthenticationContext: self)
  } ```
#

Is that what you need?

quaint pewter
#

Where is the authContext variable being set?

fringe sleet
#

In the view model

#
....
} ```
quaint pewter
#

Hm. Yeah, I'm not sure what else to check. Did upgrading the version of the SDK change anything?

fringe sleet
#
    // Billing details
    let billingDetails = STPPaymentMethodBillingDetails()

    guard let clientSecret = stripePI?.clientSecret
    else { return }

    isLoading.value = true
    let klarnaMethodParams = STPPaymentMethodParams(klarna: STPPaymentMethodKlarnaParams(),
                                                    billingDetails: billingDetails,
                                                    metadata: nil)
    let paymentIntentParams = STPPaymentIntentParams(clientSecret: clientSecret)
    paymentIntentParams.paymentMethodParams = klarnaMethodParams

    let deepLink = "com.myapp://stripe-redirect"
    var components = URLComponents(string: deepLink)
    ...
    let finalDeepLink = components?.string

    paymentIntentParams.returnURL = finalDeepLink
    let paymentHandler = STPPaymentHandler.shared()
    paymentHandler.confirmPayment(
      paymentIntentParams,
      with: authContext
    ) { (status, _, _) in
      switch status {
      case .failed:
        self.isLoading.value = false
        self.stripeFailedCallback.fire()
      case .canceled:
        self.isLoading.value = false
        self.stripeCancelledCallback.fire()
      case .succeeded:
        self.addDayToCalendarService()
        self.purchaseService()
      @unknown default:
        self.isLoading.value = false
        self.stripeFailedCallback.fire()
      }
    }
  }
fringe sleet
#

I mean, I have an idea of how to "patch" the issue but it's not what I want to do if I can make the switch work

quaint pewter
#

Hm... I've never seen a deeplink with a . in the first part before. It's a long shot, but can you change com.myapp to com-myapp and see if that has an affect?

fringe sleet
#

I'm gonna try

#

The deeplink didn't work

#

I could go to the switch case but because the deeplink failed 😂

#

Nevermind

#

Forgot to change the URL Schemes on the Info.plist, it did the same with com-myapp

#

No difference with com-myapp and com.myapp

brazen flame
#

Hi again Adrian. Rubeus had to step out, so I'm taking over. I think this is going to be a bit difficult to debug further over discord as we keep changing hands and there are many threads to juggle. At this point, I think the best path forward will be to pick up investigation on this in a ticket, so I recommend writing in to https://support.stripe.com/contact/email to get further help on this. Once you've written in, can you share your account ID and let me know you've written in so I can pick up the support ticket?

fringe sleet
#

Do I have to explain all the case again?

#

And give as much info as possible with all the code parts I shared during the thread?

brazen flame
#

We can reference this discord thread, but it would be great if you could include a summary in the ticket with as much info as possible just to make things easy for folks investigating

fringe sleet
#

Perfect, could you please leave this thread open so I can do it tomorrow? It’s because I need to contact my mate to get access to the account and right now it’s late where I live and he’ll probably be having dinner.

brazen flame
#

Unfortunately we archive threads automatically after about an hour of inactivity. This is to maintain the list of open threads we're working on as that list gets huge. If you post in the main channel, however, someone else can take it up. If you @ me then I can take a look as well

fringe sleet
#

Okey, I'll leave this thread open on my computer then so I can do it tomorrow even if you are not available