Flutter Package
Flutter Package designed to simplify the integration of Paylink's payment gateway into Flutter applications. It provides a streamlined way to handle payments within your Flutter app.
Package Link
https://pub.dev/packages/paylink_payment
Usage
To integrate Paylink's payment gateway into your Flutter application using the paylink_payment
package, follow these steps:
-
Install the Package:
Add
paylink_payment
to yourpubspec.yaml
file under dependencies:dependencies: paylink_payment: ^2.0.0 # Use the latest version
-
Import the Package:
Import the
paylink_payment
package in your Dart file:import 'package:paylink_payment/paylink_payment.dart';
-
Initialize Paylink instance
-
For Testing
paylink = PaylinkPayment.test( context: context, webViewTitle: 'Payment Screen', // optional textColor: Colors.white, // optional themeColor: Colors.blue, // optional )
-
For Production
paylink = PaylinkPayment.production( context: context, apiId: '**************', secretKey: '**************', webViewTitle: 'Payment Screen', // optional textColor: Colors.white, // optional themeColor: Colors.blue, // optional )
Package Functionalities
1. Open Payment Form:
Use the PaylinkPayment
class to open the payment form when a button or action is triggered. Here's an example of how to do this:
// paylink instance initialized in previous step
paylink.openPaymentForm(
transactionNo: '1713690519134',
onPaymentComplete: (PaylinkInvoice orderDetails) {
/// Handle payment completion
},
onError: (Object error) {
/// Handle payment error
},
);
- Implement the
onPaymentComplete
andonError
callbacks to handle the payment completion and any errors that occur during the payment process. Customize these callbacks based on your app's requirements.
2. Add Invoice:
paylink.addInvoice(
amount: 220.0,
clientMobile: '0512345678',
clientName: 'Mohammed',
orderNumber: '123456789',
callBackUrl: 'https://example.com',
products: [
PaylinkProduct(title: 'Book', price: 100, qty: 2),
PaylinkProduct(title: 'Pen', price: 2, qty: 10),
],
cancelUrl: 'https://example.com',
clientEmail: '[email protected]',
currency: 'SAR',
displayPending: true,
note: 'Test invoice',
smsMessage: 'URL: [SHORT_URL], Amount: [AMOUNT]',
supportedCardBrands: ['mada', 'visaMastercard', 'amex', 'tabby', 'tamara', 'stcpay', 'urpay'],
)
.then((PaylinkInvoice orderDetails) {
/// Handle success response
})
.onError((error, stackTrace) {
/// Handle error response
});
3. Retrieve Invoice Details:
paylink.getInvoice('1713690519134')
.then((PaylinkInvoice orderDetails) {
/// Handle success response
})
.onError((error, stackTrace) {
/// Handle error response
});
4. Cancel Invoice:
paylink.cancelInvoice('1713690519134')
.then((bool result) {
/// Handle success response
})
.onError((error, stackTrace) {
/// Handle error response
});
By following these steps, you can easily integrate Paylink's payment gateway into your Flutter application using the paylink_payment
package.
Updated about 2 months ago