PEGooglePayButton class

A button widget for initiating Google Pay transactions.

The PEGooglePayButton allows users to make payments using Google Pay with a specified PEPaymentRequest. It provides callbacks for handling payment failures, sheet dismissals, and successful token returns.

Example Usage:

final paymentRequest = PEPaymentRequest(
  merchantId: Config.merchantId,
  paymentAmount: 10.00,
  paymentItems: [
    PEPaymentItem(
      label: "Test Item",
      amount: 10.00,
    )
  ],
  platformOptions: PEGooglePayOptions(
    billingAddressRequired: true,
    shippingAddressRequired: true,
  ),
);

PEGooglePayButton(
  paymentRequest: paymentRequest,
  onPaymentFailed: (exception) {
    print("Payment failed: ${exception.toString()}");
  },
  onPaymentSheetDismissed: () {
    print("Payment sheet dismissed");
  },
  onTokenDidReturn: (token, metadata, billingAddress, shippingAddress) {
    // Send the token to your backend to charge it. Don't log it.
    sendToBackend(token, billingAddress);
  },
),
Inheritance

Constructors

PEGooglePayButton({Key? key, required PEPaymentRequest paymentRequest, double width = double.infinity, double height = 50, dynamic onPaymentFailed(Exception)?, VoidCallback? onPaymentSheetDismissed, dynamic onTokenDidReturn(String, dynamic, PEGooglePayAddress?, PEGooglePayAddress?)?})
Creates an instance of PEGooglePayButton.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
height → double
The height of the Google Pay button.
final
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onPaymentFailed → dynamic Function(Exception)?
Callback triggered when the payment fails.
final
onPaymentSheetDismissed → VoidCallback?
Callback triggered when the payment sheet is dismissed.
final
onTokenDidReturn → dynamic Function(String, dynamic, PEGooglePayAddress?, PEGooglePayAddress?)?
Callback triggered when the Google Pay token is successfully returned.
final
paymentRequest → PEPaymentRequest
The payment request details, including merchant ID, amount, and payment items.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
width → double
The width of the Google Pay button.
final

Methods

createElement() → StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → State<PEGooglePayButton>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() → List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) → String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String
Returns a one-line detailed description of the object.
inherited
toStringShort() → String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited