How can I integrate a PayPal payment gateway in flutter framework. I tried with web view but not get success. What is the best way for it.
First I tried with access token and RSET API, but there is problem that no user login for payment. My code is below and this code run with Tryit Editor successfully
import 'package:flutter/material.dart';
import'package:flutter_webview_plugin/flutter_webview_plugin.dart';
class PayPalPayment extends StatefulWidget {
@override
_PayPalPaymentState createState() => _PayPalPaymentState();
}
class _PayPalPaymentState extends State<PayPalPayment> {
String test = "Test Charge";
int amount = 100;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: WebviewScaffold(
url: new Uri.dataFromString('''
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>
<body>
<script
src="https://www.paypal.com/sdk/js?client-id=SB_CLIENT_ID">
</script>
<script>paypal.Buttons().render('body');</script>
</body>
</html>
''', mimeType: 'text/html').toString(), ),
);
}
}
SB_CLIENT_ID = My client id
2
Answers
If you’re planning to handle responses from inside a WebView, you can use webview_flutter plugin and follow this similar approach.
However, if you’re looking for an easier approach, I suggest using Flutter’s
pay
package for handling payment transactions. The package has support for Apple Pay and Google Pay – both of which supports Paypal.PayPal doesn’t support ‘WebViews’. Ref: https://developer.paypal.com/docs/api/info-security-guidelines/#secure-applications