πͺ Flutter Pay Buttons
A modern, customizable Flutter plugin that provides ready-made Pay buttons β including Apple Pay, Google Pay, and more β using a simple, developer-friendly API.
β¨ Features
β
Prebuilt buttons for Apple Pay, Google Pay, etc.
β
Fully customizable UI (color, radius, text, child widget).
β
Built on top of the official pay package.
β
Simple callback for handling payment results.
β
Scalable and responsive with pr, sp, and ScaledEdgeInsets.
π¦ Installation
Add the dependency in your pubspec.yaml:
dependencies:
flutter_pay_buttons: ^0.0.4
Then, import it:
import 'package:flutter_pay_buttons/flutter_pay_buttons.dart';
π Quick Start (Apple Pay Example)
ApplePayButton(
merchantId: 'merchant.YOUR_MERCHANT_ID',
merchantName: 'Example Merchant',
amount: '49.99',
paymentItems: const [
PaymentItem(label: 'Product', amount: '49.99', status: PaymentItemStatus.final_price, type: PaymentItemType.item),
PaymentItem(label: 'Total', amount: '49.99', status: PaymentItemStatus.final_price),
],
onPaymentResult: (result) {
print('Payment result: $result');
},
)
π Quick Start (Google Pay Example)
GooglePayButton(
totalPrice: '10.00',
merchantId: 'YOUR_MERCHANT_ID',
merchantName: 'Example Merchant',
publicKey: 'YOUR_PUBLIC_KEY_HERE',
tokenizationSpecificationType: TokenizationSpecificationType.direct,
isTesting: true,
paymentItems: [PaymentItem(label: 'Total', amount: '99.99', status: PaymentItemStatus.final_price)],
onPaymentResult: (result) {
debugPrint('Payment Result: $result');
},
)
βοΈ Parameters (Apple Pay)
| Parameter | Type | Required | Description |
|---|---|---|---|
merchantId |
String |
β | The Apple Pay merchant ID. |
merchantName |
String |
β | The display name shown in the Apple Pay sheet. |
amount |
String |
β | The total payment amount for the transaction. |
paymentItems |
List<PaymentItem> |
β | List of payment items displayed in the Apple Pay sheet. |
onPaymentResult |
Function(Map<String, dynamic>) |
β | Callback triggered after receiving the Apple Pay result. |
height |
double? |
β | Custom height of the button. |
width |
double? |
β | Custom width of the button (must be at least 220). |
margin |
EdgeInsets? |
β | External padding around the button. |
backgroundColor |
Color? |
β | Background color of the Apple Pay button. |
cornersRadius |
double? |
β | Corner radius of the button for rounded edges. |
merchantCapabilities |
List<MerchantCapability>? |
β | Supported merchant capabilities (e.g. 3DS, Credit, Debit). |
supportedNetworks |
List<ApplePaySupportedNetwork>? |
β | Supported card networks for Apple Pay (e.g. visa, masterCard). |
countryCode |
String? |
β | The ISO country code (e.g. US, PK). |
currencyCode |
String? |
β | The currency code used for the transaction (e.g. USD, PKR). |
requiredBillingContactFields |
List<ApplePayContactFields>? |
β | Fields required for billing contact information. |
requiredShippingContactFields |
List<ApplePayContactFields>? |
β | Fields required for shipping contact information. |
mainAxisAlignment |
MainAxisAlignment |
β | Alignment of content inside the button row. |
mainAxisSize |
MainAxisSize |
β | Layout size behavior of the button (default: MainAxisSize.min). |
child |
Widget? |
β | Custom widget to replace the default Apple Pay button UI. |
βοΈ Parameters (Google Pay)
| Parameter | Type | Required | Description |
|---|---|---|---|
merchantId |
String |
β | The Google Pay merchant ID. |
merchantName |
String |
β | The merchant name displayed in the payment sheet. |
totalPrice |
String |
β | The total transaction amount. |
paymentItems |
List<PaymentItem> |
β | List of payment items shown in the Google Pay sheet. |
onPaymentResult |
Function(Map<String, dynamic>) |
β | Callback triggered when the payment result is received. |
height |
double? |
β | Custom height of the button. |
width |
double? |
β | Custom width of the button (must be at least 220). |
margin |
EdgeInsets? |
β | External padding around the button. |
backgroundColor |
Color? |
β | Background color of the button. |
cornersRadius |
double? |
β | Corner radius for rounded edges. |
isTesting |
bool |
β | Enable testing mode for Google Pay. |
checkoutOption |
CheckoutOption |
β | Determines when payment is processed (e.g. CheckoutOption.lazy). |
apiVersion |
int? |
β | Google Pay API version (optional). |
apiVersionMinor |
int? |
β | Minor API version for Google Pay. |
allowedCardNetworks |
List<CardNetwork>? |
β | List of supported card networks (e.g. VISA, MASTERCARD). |
billingAddressRequired |
bool |
β | Whether billing address is required. |
billingAddressFormat |
BillingAddressFormat? |
β | Format of the billing address (e.g. FULL, MIN). |
phoneNumberRequired |
bool |
β | Whether phone number collection is required. |
tokenizationSpecificationType |
TokenizationSpecificationType |
β | Defines how payment data is tokenized (direct or paymentGateway). |
tokenizationSpecificationParameters |
Map<String, dynamic>? |
β | Parameters required when using paymentGateway tokenization. |
publicKey |
String? |
β | Public key used for direct tokenization. |
currencyCode |
String? |
β | Currency code (e.g. USD, PKR). |
transactionInfoStatus |
TransactionInfoStatus? |
β | Status type for the transaction (e.g. FINAL, ESTIMATED). |
child |
Widget? |
β | Custom child widget to override the default button content. |
mainAxisAlignment |
MainAxisAlignment |
β | Alignment of content inside the button row. |
mainAxisSize |
MainAxisSize |
β | Layout size behavior of the button (default: MainAxisSize.min). |
π§ How It Works
- Internally,
ApplePayButtonbuilds a configuration JSON for thepaypackage. - When tapped, it calls
showPaymentSelector()to display the Apple Pay sheet. - The result (success, error, or cancellation) is returned via the
onPaymentResultcallback.
π¨ Customizing the Button
You can replace the default layout with your own widget:
ApplePayButton(
merchantId: 'merchant.com.example',
merchantName: 'Custom Shop',
amount: '29.99',
paymentItems: const [
PaymentItem(label: 'Shoes', amount: '29.99'),
],
onPaymentResult: (result) => print(result),
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(12),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Icon(Icons.apple, color: Colors.white),
SizedBox(width: 8),
Text('Buy with Apple Pay', style: TextStyle(color: Colors.white)),
],
),
),
)
π Author
M-Tayyab-Mustafa
π§ m.tayyabmustafa.joiya@gmail.com
π github.com/M-Tayyab-Mustafa
π‘ Notes
- Make sure to configure your Merchant ID.
- Always test on a real device (Apple Pay is not supported in simulators).
Made with β€οΈ in Flutter
Libraries
- Copyright 2024 M-Tayyab-Mustafa