paylink_payment 1.0.0
paylink_payment: ^1.0.0 copied to clipboard
A Flutter SDK 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.
example/lib/main.dart
import 'package:example/body_content.dart';
import 'package:flutter/material.dart';
import 'package:paylink_payment/paylink_payment.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Payment Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Payment Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String? errorMessage;
onPaymentComplete(Map<String, dynamic> orderDetails) {
setState(() => errorMessage = 'Order Amount: ${orderDetails['amount']}, order Status: ${orderDetails['orderStatus']}');
}
onErrorPayment(Object error) {
setState(() => errorMessage = error.toString());
}
@override
Widget build(BuildContext context) {
return Scaffold(
/// -- Screen App Bar
appBar: AppBar(
centerTitle: true,
backgroundColor: Colors.blue,
title: Text(widget.title, style: const TextStyle(color: Colors.white)),
),
/// -- Checkout Action
bottomNavigationBar: GestureDetector(
onTap: () {
setState(() => errorMessage = null);
PaylinkPayment(
context: context,
isTestMode: true,
webViewTitle: 'Payment Screen',
).openPaymentForm(
transactionNo: '1713690519134',
onPaymentComplete: onPaymentComplete,
onError: onErrorPayment,
);
},
child: Container(
height: 60,
color: Colors.blue,
child: const Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Checkout', style: TextStyle(color: Colors.white, fontWeight: FontWeight.w700, fontSize: 24.0)),
SizedBox(width: 5),
Icon(Icons.add, color: Colors.white),
],
),
),
),
/// -- Body content
body: Column(
children: [
const Expanded(child: CartItems()),
const SizedBox(height: 20),
if (errorMessage != null)
Container(
color: Colors.amber,
padding: const EdgeInsets.all(10.0),
child: Text(errorMessage!, style: const TextStyle(fontSize: 16.0, fontWeight: FontWeight.bold)),
),
const SizedBox(height: 20),
],
),
);
}
}