flutter_paypal_payment_plus 1.1.0
flutter_paypal_payment_plus: ^1.1.0 copied to clipboard
A powerful and easy-to-use PayPal payment integration package for Flutter. Features seamless in-app checkout, sandbox/production mode support, customizable UI, and comprehensive transaction callbacks.
Flutter PayPal Payment Plus #
A powerful and easy-to-use PayPal payment integration package for Flutter. Seamlessly integrate PayPal Checkout into your mobile applications with support for both sandbox testing and live production environments.
โจ Features #
| Feature | Description |
|---|---|
| ๐ Easy Integration | Simple setup with just a few lines of code |
| ๐งช Sandbox Mode | Toggle between sandbox and production environments |
| ๐ณ Full Transaction Support | Define items, amounts, shipping, and discounts |
| ๐จ Customizable UI | Custom AppBar and loading indicators |
| ๐ฑ Type-Safe Callbacks | Strongly typed success, error, and cancel handlers |
| ๐ Secure | Built on PayPal's official REST API |
๐ฆ Installation #
Add the dependency to your pubspec.yaml:
dependencies:
flutter_paypal_payment_plus: ^1.1.0
Then run:
flutter pub get
๐ Quick Start #
1. Import the package #
import 'package:flutter_paypal_payment_plus/flutter_paypal_payment_plus.dart';
2. Navigate to PaypalCheckoutView #
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => PaypalCheckoutView(
sandboxMode: true, // Set to false for production
clientId: 'YOUR_CLIENT_ID',
secretKey: 'YOUR_SECRET_KEY',
returnURL: 'https://yourapp.com/success',
cancelURL: 'https://yourapp.com/cancel',
transactions: const TransactionOption(
payPalAmount: PayPalAmount(
total: '100.00',
currency: 'USD',
details: PaymentDetails(
subtotal: '100.00',
shipping: '0',
shippingDiscount: 0,
),
),
description: 'Purchase from MyApp',
itemList: ItemList(
items: [
Item(name: 'Product 1', quantity: 2, price: '50.00', currency: 'USD'),
],
),
),
onSuccess: (PaymentSuccessModel model) {
log('Payment successful: ${model.toJson()}');
Navigator.pop(context);
},
onError: (error) {
log('Payment error: $error');
Navigator.pop(context);
},
onCancel: () {
log('Payment cancelled');
Navigator.pop(context);
},
),
),
);
๐ Complete Example #
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:flutter_paypal_payment_plus/flutter_paypal_payment_plus.dart';
void main() {
runApp(const PaypalPaymentDemo());
}
class PaypalPaymentDemo extends StatelessWidget {
const PaypalPaymentDemo({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'PayPal Payment Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
useMaterial3: true,
),
home: const HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('My Shop'),
centerTitle: true,
),
body: Center(
child: ElevatedButton.icon(
icon: const Icon(Icons.payment),
label: const Text('Pay with PayPal'),
onPressed: () => _startPayment(context),
),
),
);
}
void _startPayment(BuildContext context) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => PaypalCheckoutView(
sandboxMode: true,
clientId: 'YOUR_CLIENT_ID',
secretKey: 'YOUR_SECRET_KEY',
returnURL: 'https://yourapp.com/success',
cancelURL: 'https://yourapp.com/cancel',
transactions: const TransactionOption(
payPalAmount: PayPalAmount(
total: '100',
currency: 'USD',
details: PaymentDetails(
subtotal: '100',
shipping: '0',
shippingDiscount: 0,
),
),
description: 'Order from My Shop',
itemList: ItemList(
items: [
Item(name: 'Apple', quantity: 1, price: '50', currency: 'USD'),
Item(name: 'Pineapple', quantity: 5, price: '10', currency: 'USD'),
],
),
),
note: 'Contact us for any questions on your order.',
onSuccess: (PaymentSuccessModel model) {
log('Success: ${model.toJson()}');
Navigator.pop(context);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Payment successful!')),
);
},
onError: (error) {
log('Error: $error');
Navigator.pop(context);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Payment failed: $error')),
);
},
onCancel: () {
log('Cancelled');
Navigator.pop(context);
},
),
),
);
}
}
โ๏ธ Configuration #
PaypalCheckoutView Parameters #
| Parameter | Type | Required | Description |
|---|---|---|---|
clientId |
String |
โ | Your PayPal REST API Client ID |
secretKey |
String |
โ | Your PayPal REST API Secret Key |
returnURL |
String |
โ | Redirect URL for successful payment |
cancelURL |
String |
โ | Redirect URL for cancelled payment |
transactions |
TransactionOption |
โ | Transaction details (amount, items, etc.) |
onSuccess |
Function(PaymentSuccessModel) |
โ | Callback for successful payment |
onError |
Function(dynamic) |
โ | Callback for payment errors |
onCancel |
Function() |
โ | Callback for cancelled payment |
sandboxMode |
bool |
โ | Use sandbox environment (default: false) |
note |
String? |
โ | Optional note to display to payer |
appBar |
AppBar? |
โ | Custom AppBar for checkout screen |
loadingIndicator |
Widget? |
โ | Custom loading widget |
TransactionOption Structure #
TransactionOption(
payPalAmount: PayPalAmount(
total: '150.00', // Must equal subtotal + shipping - discount
currency: 'USD',
details: PaymentDetails(
subtotal: '140.00', // Sum of item prices ร quantities
shipping: '10.00',
shippingDiscount: 0,
),
),
description: 'Order description',
itemList: ItemList(
items: [
Item(name: 'Item 1', quantity: 2, price: '50.00', currency: 'USD'),
Item(name: 'Item 2', quantity: 1, price: '40.00', currency: 'USD'),
],
shippingAddress: ShippingAddress( // Optional
recipientName: 'John Doe',
line1: '123 Main St',
city: 'San Jose',
state: 'CA',
postalCode: '95131',
countryCode: 'US',
),
),
paymentOptions: PaymentOptions( // Optional
allowedPaymentMethod: PaymentMethodEnum.instantFundingSource,
),
)
๐ Getting PayPal Credentials #
- Go to PayPal Developer Dashboard
- Log in or create a PayPal account
- Navigate to Apps & Credentials
- Click Create App (or use the default sandbox app)
- Copy your Client ID and Secret Key
โ ๏ธ Important: Never hardcode production credentials in your app. Use environment variables or secure storage.
๐งช Testing #
Use sandbox mode for testing:
PaypalCheckoutView(
sandboxMode: true, // Enable sandbox mode
clientId: 'SANDBOX_CLIENT_ID',
secretKey: 'SANDBOX_SECRET_KEY',
// ...
)
Sandbox Test Accounts #
Create test accounts in the PayPal Developer Dashboard to simulate buyer and seller transactions.
๐ Requirements #
| Requirement | Version |
|---|---|
| Flutter | โฅ 3.10.0 |
| Dart SDK | โฅ 3.1.3 |
| Android | minSdkVersion 19 |
| iOS | iOS 11.0+ |
๐ Troubleshooting #
Common Issues #
| Issue | Solution |
|---|---|
| "Your PayPal credentials seem incorrect" | Verify your Client ID and Secret Key |
| WebView not loading | Check internet connection and WebView dependencies |
| Amount mismatch error | Ensure total equals subtotal + shipping - shippingDiscount |
๐ License #
This project is licensed under the MIT License.
๐ค Contributing #
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ฎ Support #
- ๐ Bug Reports: Open an issue
- ๐ก Feature Requests: Open an issue
- โญ Like this package? Give it a star on GitHub!
Made with โค๏ธ by Yaseen Hussein