flutter_paypal_package 0.0.5 flutter_paypal_package: ^0.0.5 copied to clipboard
A simple but powerful Paypal SDK for flutter.
import 'package:flutter/material.dart';
import 'package:flutter_paypal_package/flutter_paypal_package.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Paypal',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Paypal Example'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: TextButton(
onPressed: () => {
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) => UsePaypal(
sandboxMode: true,
clientId:
"AftGAHK0xWfNuY6YoVRfU5aH2a3_5f7YYzXZpaNZtrK13C9zhYt4npsq_eq5wZg5E6tK3MMcJWloBUZa",
secretKey: "EB8KdiG-IYyX-Pu5qFokan2EMN-qCtq4wCU6rW8xGBhi4yU553puxcKjIdZakA_MzQAFcfq5dDNmLcH2",
returnURL: "https://samplesite.com/return",
cancelURL: "https://samplesite.com/cancel",
transactions: const [
{
"amount": {
"total": '10.12',
"currency": "USD",
"details": {
"subtotal": '10.12',
"shipping": '0',
"shipping_discount": 0
}
},
"description":
"The payment transaction description.",
// "payment_options": {
// "allowed_payment_method":
// "INSTANT_FUNDING_SOURCE"
// },
"item_list": {
"items": [
{
"name": "A demo product",
"quantity": 1,
"price": '10.12',
"currency": "USD"
}
],
// shipping address is not required though
"shipping_address": {
"recipient_name": "Jane Foster",
"line1": "Travis County",
"line2": "",
"city": "Austin",
"country_code": "US",
"postal_code": "73301",
"phone": "+00000000",
"state": "Texas"
},
}
}
],
note: "Contact us for any questions on your order.",
onSuccess: (Map params) async {
print("onSuccess: $params");
},
onError: (error) {
print("onError: $error");
},
onCancel: (params) {
print('cancelled: $params');
}),
),
)
},
child: const Text("Make Payment")),
));
}
}