#Adrian Moreno
1 messages ยท Page 1 of 1 (latest)
Hi! I opened a thread before because I was having issues adding Klarna with Stripe
Hi there. Are you using Payment Intents with Elements? Or Checkout? Or something else
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
So that 500 is coming from your server. Did you check your logs to see where it's breaking?
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.
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
What payment methods?
It's the list here: https://stripe.com/docs/api/setup_intents/create#create_setup_intent-payment_method_types
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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?
Well you can't use it with Klarna at all, so the experience shouldn't be impacted at all
Perfect, will try changing it and seeing if it works perfect now.
Thank you so much guys, you are amazing.
No problem!
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?
Are you confirming on the backend?
Yes, I'm using confirmPayment with the paymentHandler
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?
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
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.
Oh, so it means I need a Klarna account and they'll give me the url I have to add, right?