The pay plugin provides specialized buttons to trigger payment flows. You must define PaymentItem objects representing the transaction and provide a paymentConfiguration specific to the provider.
Key Components:
PaymentItem: Defines the label, amount, and status (e.g., PaymentItemStatus.final_price) of the transaction.ApplePayButton: Renders the Apple Pay button. Requires paymentConfiguration, paymentItems, and an onPaymentResult callback.GooglePayButton: Renders the Google Pay button. Requires paymentConfiguration, paymentItems, and an onPaymentResult callback.onPaymentResult: A callback function that receives the payment token/result, which you must then send to your server or Payment Service Provider (PSP).
import 'package:pay/pay.dart';
import 'payment_configurations.dart' as payment_configurations;
const _paymentItems = [
PaymentItem(
label: 'Total',
amount: '99.99',
status: PaymentItemStatus.final_price,
)
];
// Apple Pay Button
ApplePayButton(
paymentConfiguration: payment_configurations.defaultApplePayConfig,
paymentItems: _paymentItems,
style: ApplePayButtonStyle.black,
type: ApplePayButtonType.buy,
margin: const EdgeInsets.only(top: 15.0),
onPaymentResult: onApplePayResult,
loadingIndicator: const Center(
child: CircularProgressIndicator(),
),
),
// Google Pay Button
GooglePayButton(
paymentConfiguration: payment_configurations.defaultGooglePayConfig,
paymentItems: _paymentItems,
type: GooglePayButtonType.buy,
margin: const EdgeInsets.only(top: 15.0),
onPaymentResult: onGooglePayResult,
loadingIndicator: const Center(
child: CircularProgressIndicator(),
),
),
void onApplePayResult(paymentResult) {
// Send the resulting Apple Pay token to your server / PSP
}
void onGooglePayResult(paymentResult) {
// Send the resulting Google Pay token to your server / PSP
}