I tried making payment to my flutterwave account using Flutterwave_standard flutter's dependency. Transactons I made using test card while isTestMode
set to true
was successful but after I changed the bool value to false
and my publicKey
to my live dashboard PublicKey I got failure message that states "only testcards are allowed in testmode".
Please I need help?
See my code below:
import 'package:flutter/material.dart';
import 'package:flutterwave_standard/flutterwave.dart';
import 'apikey.dart';
import 'constants.dart';
void main() {
runApp(
const MaterialApp(
debugShowCheckedModeBanner: false,
title: 'PayApp',
home: Home(),
),
);
}
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
@override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ElevatedButton(
onPressed: handlePayment,
child: const Text('Go to PayPage'),
),
),
);
}
void handlePayment() async {
// assign values to flutterwaveStyle object's properties
final style = FlutterwaveStyle(
buttonColor: Util.myPrimaryColor,
buttonTextStyle:
const TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
appBarText: 'Proceed to Flutterwave',
appBarColor: Util.myPrimaryColor,
appBarIcon: const Icon(Icons.card_travel),
appBarTitleTextStyle:
const TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
mainBackgroundColor: Colors.white,
mainTextStyle: const TextStyle(color: Colors.black45),
dialogBackgroundColor: Colors.white,
dialogCancelTextStyle:
const TextStyle(color: Colors.black54, fontWeight: FontWeight.bold),
dialogContinueTextStyle:
const TextStyle(color: Colors.black, fontWeight: FontWeight.bold),
buttonText: 'Go to CheckOut',
);
//assign values to customer object
final customer = Customer(
name: 'Paschal',
phoneNumber: '***********',
email: '***************',
);
//assign values to flutterwave object
final flutterwave = Flutterwave(
context: context,
// publicKey: ApiKey.testPublicKey,
publicKey: ApiKey.livePublicKey,
txRef: Util.txtRefKeys,
// amount: Util.testAmount300,
amount: Util.liveAmount5,
customer: customer,
paymentOptions: 'card',
// customization: Customization(title: Util.customizationTitleTest),
customization: Customization(title: Util.customizationTitleLive),
// isTestMode: Util.yesItsTestMode,
// isTestMode: Util.noItsNotTestMode,
isTestMode: false,
currency: Util.nairaAsCurrency,
redirectUrl: 'https://www.google.com',
meta: {
'payment for:': '\n\tmobile app development',
'PhoneNumber:': '************',
'email:': '**************',
},
style: style,
);
//call Flutterwave's ChargeResponse method
final ChargeResponse response = await flutterwave.charge();
if (response.success != null) {
debugPrint(response.status);
return showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text(
'Success',
textAlign: TextAlign.center,
),
content: const SizedBox(
height: 100,
width: 50,
child: Text('Dear customer,\nYour transaction was successful.'),
),
actions: [
ElevatedButton(
onPressed: () {
return Navigator.pop(context);
},
child: const Text('Close'),
),
],
);
},
);
} else {
debugPrint(response.status);
return showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text(
'Failed',
textAlign: TextAlign.center,
),
content: const SizedBox(
height: 100,
width: 50,
child: Text(
'Dear customer,\nSorry your transaction was not successful.'),
),
actions: [
ElevatedButton(
onPressed: () {
return Navigator.pop(context);
},
child: const Text('Close'),
),
],
);
},
);
}
}
}