payengine 2.0.9
payengine: ^2.0.9 copied to clipboard
The PayEngine Flutter SDK allows you to build delightful payment experiences in your native Android and iOS apps using Flutter
PayEngine SDK for Flutter #
The PayEngine Flutter SDK allows you to build delightful payment experiences in your native Android and iOS apps using Flutter. We provide powerful and customizable UI screens and elements that can be used out-of-the-box to collect your users' payment details
Installation #
Add PayEngine registry to your project:
allprojects {
repositories {
...your repositories
maven {
name = "pe-maven"
url = uri("https://maven.payengine.co/payengine")
credentials {
username = "<username>"
password = "<password>"
}
}
}
}
copied to clipboard
Contact PayEngine support for username and password
Prerequisites #
Android
To use secure fields components, you need to install and configure the Material Components theme in your app.
- Add the following dependency to your
app/build.gradle
file with the specified version:
implementation 'com.google.android.material:material:<version>'
copied to clipboard
- Set the appropriate style in your
styles.xml
file:
<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- ... -->
</style>
copied to clipboard
iOS
cd ios && pod install --repo-update && cd ..
copied to clipboard
Usage #
PayEngine config
final PayEngineConfig config = const PayEngineConfig(
publicKey: "pk_test_xxx",
scriptURL: "https://console.payengine.dev");
final String merchantId = "<your-merchant-id>";
copied to clipboard
Wrap the config in a Provider
PayEngineProvider(
config: Config.config,
child: const MyApp()
)
copied to clipboard
Credit Card Form
var additionalFields = List<PayEngineField>.from([
PayEngineField('address_zip', 'text', 'Zip Code', true,
keyboardType: PayEngineKeyboardType.number,
pattern:
r"^(?:\d{5}(?:-\d{4})?|[ABCEGHJKLMNPRSTVXY]\d[A-Z] ?\d[A-Z]\d)$"),
]);
final creditCardForm = CreditCardForm(additionalFields: additionalFields);
Container(padding: const EdgeInsets.all(10), child: creditCardForm),
OutlinedButton(
onPressed: () async {
final additionalData = <String, String>{
"address_street": "123 My Street"
};
final response = await creditCardForm.tokenize(
merchantId, // optional,
additionalData // optional
);
setState(() {
result = response;
});
},
child: const Text('Tokenize')),
copied to clipboard
Bank Account Form
final bankAccountForm = BankAccountForm();
Container(padding: const EdgeInsets.all(10), child: bankAccountForm),
OutlinedButton(
onPressed: () async {
final additionalData = <String, String>{};
final response = await bankAccountForm.tokenize(
merchantId, // optional,
additionalData // optional
);
setState(() {
result = response;
});
},
child: const Text('Tokenize')),
copied to clipboard
Google Pay and Apple Pay #
Check whether is supported or not:
final isSupported = PayEngineNative.userCanPay(PayProvider.applePay, Config.merchantId)
copied to clipboard
Always call this method before rendering the pay button, see the example below.
Google Pay
final paymentRequest = PEPaymentRequest(
merchantId: Config.merchantId,
paymentAmount: 10.00,
paymentItems: [
PEPaymentItem(
label: "Test Item",
amount: 10.00,
)
],
platformOptions: PEGooglePayOptions(billingAddressRequired: true, shippingAddressRequired: true)
);
// render button
FutureBuilder<bool>(
future: PayEngineNative.userCanPay(
PayProvider.googlePay, Config.merchantId),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasError) {
return Center(
child: Text(
'${snapshot.error}',
),
);
} else if (snapshot.data == true) {
return PEGooglePayButton(
paymentRequest: paymentRequest,
onPaymentFailed: (error) {
debugPrint("onPaymentFailed $error");
result = error.toString();
},
onPaymentSheetDismissed: () {
debugPrint("onPaymentSheetDismissed");
},
onTokenDidReturn: (token, metadata, billingAddress, shippingAddress) {
debugPrint("onTokenDidReturn $token $metadata ${billingAddress?.toJson()} ${shippingAddress?.toJson()}");
result = token;
},
);
} else {
return const Text("Google Pay is not supported");
}
} else {
return const SizedBox.shrink();
}
})
copied to clipboard
Apple Pay
final paymentRequest = PEPaymentRequest(
merchantId: Config.merchantId,
paymentAmount: 10.00,
paymentItems: [
PEPaymentItem(
label: "Test Item",
amount: 10.00,
)
],
platformOptions: PEApplePayOptions(
requiredBillingContactFields: [PEContactField.postalAddress],
requiredShippingContactFields: [PEContactField.name])
);
// render button
FutureBuilder<bool>(
future: PayEngineNative.userCanPay(
PayProvider.applePay, Config.merchantId),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasError) {
return Center(
child: Text(
'${snapshot.error}',
),
);
} else if (snapshot.data == true) {
return PEApplePayButton(
paymentRequest: paymentRequest,
onPaymentFailed: (error) {
debugPrint("onPaymentFailed $error");
result = error.toString();
},
onPaymentSheetDismissed: () {
debugPrint("onPaymentSheetDismissed");
},
onTokenDidReturn: (token, metadata, billingContact, shippingContact) {
debugPrint("onTokenDidReturn $token $metadata ${billingContact?.toJson()} ${shippingContact?.toJson()}");
result = token;
},
);
} else {
return const Text("Apple Pay is not supported");
}
} else {
return const SizedBox.shrink();
}
})
copied to clipboard