flutter_paypal_payment_plus 1.1.0 copy "flutter_paypal_payment_plus: ^1.1.0" to clipboard
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 #

Pub Version Pub Points License: MIT Flutter

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 #

  1. Go to PayPal Developer Dashboard
  2. Log in or create a PayPal account
  3. Navigate to Apps & Credentials
  4. Click Create App (or use the default sandbox app)
  5. 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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“ฎ Support #


Made with โค๏ธ by Yaseen Hussein

4
likes
150
points
103
downloads

Publisher

unverified uploader

Weekly Downloads

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.

Repository (GitHub)
View/report issues

Topics

#paypal #payment #checkout #e-commerce #in-app-purchase

Documentation

API reference

Funding

Consider supporting this project:

github.com

License

MIT (license)

Dependencies

dio, equatable, flutter, flutter_inappwebview

More

Packages that depend on flutter_paypal_payment_plus