#Adrian Moreno

1 messages ยท Page 1 of 1 (latest)

upbeat havenBOT
kindred minnow
#

Hi! I opened a thread before because I was having issues adding Klarna with Stripe

worldly haven
#

Hi there. Are you using Payment Intents with Elements? Or Checkout? Or something else

kindred minnow
#

I'm using Card Element

#

I wanted to add Klarna to my iOS app so I added the button but it seems the backend isn't working as expected.

#
            'payment_method_types' => ['card','klarna'],
            'amount' => $finalPrice*100,
            'currency' => 'eur',
            'setup_future_usage' => 'off_session',
            'customer' => $userExist->getStripeCustomerId(),
        ]);

        $paymentIntentDTO = new StripePaymentIntentDTO();
        $paymentIntentDTO->setId($paymentIntent->id);
        $paymentIntentDTO->setClientSecret($paymentIntent->client_secret);
        $paymentIntentDTO->setAmount($paymentIntent->amount);```
#

That's the code I have, and that's the response I get

#

But if i remove the 'payment_method_types' part then I get this other response:

#

So I'm a little bit lost on what am I doing wrong

worldly haven
#

So that 500 is coming from your server. Did you check your logs to see where it's breaking?

kindred minnow
#

I'm looking at it right now?

#

That's what I get:

[2022-12-12T16:01:13.591474+00:00] request.CRITICAL: Uncaught PHP Exception Stripe\Exception\InvalidRequestException: "`setup_future_usage` cannot be used with one or more of the values you specified in `payment_method_types`. Please remove `setup_future_usage` or remove these types from `payment_method_types`: ["klarna"]." at /var/www/project/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php line 38 {"exception":"[object] (Stripe\\Exception\\InvalidRequestException(code: 0): `setup_future_usage` cannot be used with one or more of the values you specified in `payment_method_types`. Please remove `setup_future_usage` or remove these types from `payment_method_types`: [\"klarna\"]. at /var/www/project/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php:38)"}

#

Do I need setup_future_usage for anything? Is it important?

#

Without the setup... it works but I'm not sure if it's something I need to have at some point to don't break payments.

worldly haven
#

Klarna is single use so it isn't compatible with setup_future_usage

#

What that does is allows some payment methods to be re-used and charged in the future with the customer offline

kindred minnow
#

What payment methods?

worldly haven
kindred minnow
#

From what I understand, if I don't have this setup_future_usage it will bug the user a little bit with the experience when paying but at the same time will help me with security, right?

worldly haven
#

Well you can't use it with Klarna at all, so the experience shouldn't be impacted at all

kindred minnow
#

Perfect, will try changing it and seeing if it works perfect now.
Thank you so much guys, you are amazing.

worldly haven
#

No problem!

kindred minnow
#

I'm getting this error when trying to use Klarna now:

    - value: "You must provide a `return_url` when confirming a PaymentIntent with the payment method type klarna."```
#

Do I have to provide the return_url from backend or how should it work?

worldly haven
#

Are you confirming on the backend?

kindred minnow
#

Yes, I'm using confirmPayment with the paymentHandler

worldly haven
#

Ideally you'd pass it at confirmation, but AFAIK with klarna you'd want to confirm client-side not server-side so the customer can complete payment on Klarna

#

How are you redirecting them currently?

kindred minnow
#

When paying with a card I just use this:

      card: cardParams, billingDetails: nil, metadata: nil)
    let paymentIntentParams = STPPaymentIntentParams(clientSecret: clientSecret)
    paymentIntentParams.paymentMethodParams = paymentMethodParams
    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()
      }
    }```
#

But not sure if that's what u are asking me

torpid panther
#

Hi ๐Ÿ‘‹

This looks like a front-end confirmation (in iOS). But Klarna requires a redirect to their own interface so you must provide a return_url in the payment intent confirmation parameters.

kindred minnow
#

Oh, so it means I need a Klarna account and they'll give me the url I have to add, right?

torpid panther
#

No

#

It means you need to provide a URL that will redirect your users back to your app. A "deep link" in the case of an iOS app

kindred minnow
#

Hmmmm, gotcha

#

Thank you!