checkout_plugin 0.0.1 checkout_plugin: ^0.0.1 copied to clipboard
A new flutter plugin project.
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:checkout_plugin/checkout_plugin.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
late CheckoutPlugin _obj;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Checkout Plugin Sample App'),
),
body: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(onPressed: openCheckout, child: Text('Pay'))
])),
),
);
}
@override
void initState() {
super.initState();
_obj = CheckoutPlugin();
}
void openCheckout() async {
var options = {
'secureKey': 'bzI93aEQeYDeE50Pa929NiDk3us8XTbU',
'requestParameters': {
'memberId': '10558',
'paymentMode': 'CC',
'terminalId': '',
'merchantTransactionId': '9756',
'amount': '50.00',
'currency': 'USD',
'toType': 'paymentz',
'paymentBrand': 'VISA',
'merchantRedirectUrl': 'https://www.merchantredirecturl.com',
'tmplAmount': '50.00',
'tmplCurrency': 'USD',
'orderDescription': 'Test',
'country': 'IN',
'state': 'MH',
'street': 'Malad',
'city': 'Mumbai',
'email': 'abc@gmail.com',
'postCode': '400064',
'telnocc': '+91',
'phone': '9096831666',
'hostUrl': 'https://preprod.paymentz.com/transaction/Checkout?',
'device': 'ios'
}
};
try {
_obj.clear();
var event_success = CheckoutPlugin.EVENT_SUCCESS;
var event_failed = CheckoutPlugin.EVENT_FAILED;
_obj.on(event_success, _handlePaymentSuccess);
_obj.on(event_failed, _handlePaymentFail);
_obj.payment(options);
} catch (e) {
debugPrint('Error: e');
}
}
@override
void dispose() {
super.dispose();
_obj.clear();
}
void _handlePaymentSuccess(PaymentSuccessResponse response) {
print('In Success Main' + response.response.toString());
_obj.clear();
}
void _handlePaymentFail(PaymentFailureResponse response) {
print('In Fail Main' + response.response.toString());
_obj.clear();
}
}