Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PaymentSheet not working with klarna for IOS #1487

Closed
sunmeetsingh2606 opened this issue Nov 17, 2023 · 3 comments
Closed

PaymentSheet not working with klarna for IOS #1487

sunmeetsingh2606 opened this issue Nov 17, 2023 · 3 comments
Assignees
Labels
blocked This issue is blocked by an external dependency issue bug Something isn't working iOS Issue related to iOS native bindings

Comments

@sunmeetsingh2606
Copy link

sunmeetsingh2606 commented Nov 17, 2023

Describe the bug
I am using Flutter: 3.0, IOS: 13.0, flutter_stripe: 9.5.0+1. When I am trying to open a PaymentSheet for klarna it is not working in IOS but it is properly working on android devices.

To Reproduce
Below is the sample code of my project

import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_stripe/flutter_stripe.dart';
import 'package:http/http.dart';

void main() {
  runApp(const MainApp());
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  void onPayWithKlarna() async {
    Stripe.publishableKey = 'STRIPE PUBLIC KEY';
    Stripe.merchantIdentifier = 'merchant.flutter.stripe.test';
    await Stripe.instance.applySettings().catchError((e) {
      throw e.toString();
    });

    Request request =
        Request('POST', Uri.parse('https://api.stripe.com/v1/payment_intents'));

    request.bodyFields = {
      'payment_method_types[0]': 'klarna',
      'amount': '100',
      'currency': 'USD'
    };

    request.headers.addAll({'Authorization': 'Bearer STRIPE SECRET KEY'});

    request.send().then((value) {
      Response.fromStream(value).then((response) {
        dynamic body = jsonDecode(response.body);

        SetupPaymentSheetParameters setupPaymentSheetParameters =
            SetupPaymentSheetParameters(
                paymentIntentClientSecret: body['client_secret'],
                setupIntentClientSecret: body['client_secret'],
                merchantDisplayName: 'Newlime Tech',
                allowsDelayedPaymentMethods: true);

        Stripe.instance
            .initPaymentSheet(
                paymentSheetParameters: setupPaymentSheetParameters)
            .then((value) {
          Stripe.instance.presentPaymentSheet().then((value) {});
        });
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: OutlinedButton(
              onPressed: onPayWithKlarna, child: const Text('Pay With Klarna')),
        ),
      ),
    );
  }
}

Expected behavior
This code will also open a PaymentSheet for klarna in IOS but it isn't, not sure if I am missing something...

Any guidance would be really helpful, thanks :)

@sunmeetsingh2606 sunmeetsingh2606 added the needs triage Needs triage label Nov 17, 2023
@remonh87 remonh87 self-assigned this Nov 26, 2023
@remonh87
Copy link
Member

yes you are correct I can reproduce this issue. I raised a ticket in Stripe stripe/stripe-react-native#1572

@remonh87 remonh87 added bug Something isn't working iOS Issue related to iOS native bindings blocked This issue is blocked by an external dependency issue and removed needs triage Needs triage labels Nov 26, 2023
@remonh87
Copy link
Member

ok I found the issue returnUrl is required in initpaymentSheet. For example:
returnURL: 'flutterstripe://redirect'

@sunmeetsingh2606
Copy link
Author

Tried this returnURL: 'flutterstripe://redirect' but after successful payment it is not closing the payment web window as it usually close without returnURL.

Do you have any ideas for that ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked This issue is blocked by an external dependency issue bug Something isn't working iOS Issue related to iOS native bindings
Projects
None yet
Development

No branches or pull requests

2 participants