· 4 years ago · Apr 22, 2021, 03:08 PM
1import 'dart:convert';
2
3import 'package:http/http.dart' as http;
4
5class PaystackService {
6 // secret key
7 static final String secretKey = 'YOUR_SECRET_KEY';
8 // public key
9 static final String publicKey = 'YOUR_PUBLIC_KEY';
10
11 // initialize transaction url
12 static final String initTransactionUrl =
13 'https://api.paystack.co/transaction/initialize';
14
15 // initialize transaction connection
16 static Future initTransaction(String secretKey) async {
17 // headers
18 Map<String, String> headers = {
19 'Content-Type': 'application/json',
20 'Accept': 'application/json',
21 'Authorization': 'Bearer $secretKey'
22 };
23
24 // body
25 Map<String, String> body = {
26 "amount": '9000',
27 "email": "johnsonoye34@gmail.com"
28 };
29
30 // api connection
31 var response = await http.post(APIService.initTransactionUrl,
32 headers: headers, body: jsonEncode(body));
33 var values = jsonDecode(response.body);
34 return values;
35 }
36}
37