#Adrian Moreno
1 messages · Page 1 of 1 (latest)
hi! well you would use a clientSecret yes. It's no different from just using the PaymentSheet, so there shouldn't be anything different or any changes you need to make to billing detail collection, you just pass a PaymentIntent client_secret to the PaymentSheet as normal, if you have klarna in the payment_method_types of the PaymentIntent it should just show up as an option in the sheet.
I've done this but I'm not sure if it's correct since it's my first time using Klarna with Stripe:
let klarnaMethodParams = STPPaymentMethodParams(
klarna: STPPaymentMethodKlarnaParams(), billingDetails: billingDetails, metadata: nil)
let paymentIntentParams = STPPaymentIntentParams(clientSecret: clientSecret)
paymentIntentParams.paymentMethodParams = klarnaMethodParams
let paymentHandler = STPPaymentHandler.shared()
paymentHandler.confirmPayment(
paymentIntentParams,
with: authContext
I'd really recommend using the PaymentSheet component here instead, so there's no need to create your own PaymentMethod and manually confirm the PaymentIntent
https://stripe.com/docs/payments/accept-a-payment?platform=ios&ui=payment-sheet
what you have there might work, was there an error when you tried?
I'm trying to get again the error so I can send you. It'll take me 1 minute
Do I need to complete the STPPaymentCardTextField to use Klarna? Because I think that was the issue
you wouldn't need that no, since Klarna doesn't use card details, it's a redirect to Klarna's website(the redirect would happen when you confirm the PaymentIntent)
Okey, then it's another issue. I'll continue searching and will ask you better when I have more info, thanks
Oh, do I need StripeIsReady value?
I'm not familiar with that value
Do I need to add the payment_method_type? Or it's automatically selected with the type of params I use?
that doc seems completely unrelated to what you were asking about
it's for Checkout(hosted payment page), but you were talking about a mobile integration using iOS components and a directly-created PaymentIntent
Hmmmm, so I don't need it at all, good to know, thanks
Sorry for the noob questions, still trying to understand it all to know the best way to develop this. Thank you for your patience.
Okey, I updated the backend and now it's "working" but when I click on Klarna pay I always arrive to switch case Failed.
can you share some code/screenshot of the UI/the PaymentIntent pi_xxx ?
also look in XCode for any errors in the logs for the app
I can try to help but again my advice here is to use the PaymentSheet, looks like maybe you're doing this in some custom way that I'm not too familiar with
This?
I may change to PaymentSheet, but I had it like this and just wanted to add Klarna and it seems is more complicated than I initially though
That's the log I get:
2022-12-12 14:38:18.242734+0100 xxxx[81067:6386558] LOG ANALYTICS: ["device_type": "iPhone14,5", "app_name": "Sporttips", "source_type": "klarna", "apple_pay_enabled": 1, "required_shipping_address_fields": "none", "ui_usage_level": "card_text_field", "required_billing_address_fields": "zip", "analytics_ua": "analytics.stripeios-1.0", "product_usage": ["STPPaymentCardTextField"], "app_version": "2.1.9", "install": "S", "bindings_version": "22.6.0", "os_version": "16.1.1", "company_name": "xxxx", "event": "stripeios.payment_intent_confirmation", "additional_payment_methods": "none", "pay_var": "legacy", "shipping_type": "shipping", "apple_merchant_identifier": "unknown", "additional_info": [], "ocr_type": "none", "publishable_key": "pk_....."]
can you capture and log the error?
in confirmPayment, don't just use _ to ignore the arguments , you can do
(status, paymentIntent, error) in
...
case .failed:
if let error = error {
print("Payment failed: \n\(error.localizedDescription)")
let fullError = error as NSError
print(fullError.code)
print(fullError.description)
dump(fullError.userInfo)
}
for example
Yep, will do right now
and again, share the PaymentIntent ID pi_xxx
if you used the PaymentSheet for card payments it is extremely easy to add Klarna to it
I had already this custom way, that's why I didn't want to change it.
But if I can't get it to work then I'll change to PaymentSheet
It seems I have to add klarna to the payment_method_type.
Error Domain=com.stripe.lib Code=50 "Se ha producido un error inesperado. Vuelve a intentarlo en unos segundos" UserInfo={com.stripe.lib:StripeErrorTypeKey=invalid_request_error, com.stripe.lib:ErrorMessageKey=No se admite el PaymentMethod provisto (klarna) para este PaymentIntent. Adjunta un PaymentMethod de uno de los siguientes tipos: card. También puedes actualizar los payment _method _types permitidos para este PaymentIntent a fin de incluir "klarna"., NSLocalizedDescription=Se ha producido un error inesperado. Vuelve a intentarlo en unos segundos, com.stripe.lib:StripeErrorCodeKey=}
▿ 4 key/value pairs
▿ (2 elements)
- key: "com.stripe.lib:StripeErrorTypeKey"
- value: "invalid_request_error"
▿ (2 elements)
- key: "com.stripe.lib:ErrorMessageKey"
- value: "No se admite el PaymentMethod provisto (klarna) para este PaymentIntent. Adjunta un PaymentMethod de uno de los siguientes tipos: card. También puedes actualizar los payment _method _types permitidos para este PaymentIntent a fin de incluir "klarna"."
I'm trying to get the paymentIntent id but it's always nil which is weird
yes you need to add "klarna" in the payment_method_types of the PaymentIntent you create on the backend server
$paymentIntent = $stripe->paymentIntents->create([
'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);
So this should work right?
Hey karllekko had to step out but I can help out here.
No problem, thanks for your help
Like they said, you need to add klarna to the payment_method_types argument when creating that payment intent
I think that would look like
'payment_method_types' => ['card','klarna'],
'amount' => $finalPrice*100,
'currency' => 'eur',
'setup_future_usage' => 'off_session',
'customer' => $userExist->getStripeCustomerId(),
'payment_method_types' => ['klarna']
]);```
I need payment_method_types twice?
One at the beginning and another one at the end?
Whoops sorry I don't know how I missed that in your code
You only need it one
My bad. Need more coffee
So my code should be fine, right?
Correct, should work as far as I can see
Okey, will try then with that new part, thanks!