korapay_flutter 0.3.1
korapay_flutter: ^0.3.1 copied to clipboard
A Flutter SDK for integrating Korapay payments, offering card, bank transfer, and direct bank payment methods with a beautiful UI and easy integration.
Korapay Flutter SDK #
Flutter SDK for integrating Korapay payments into your app.
Features #
- Process payments with card, bank transfer, and direct bank debit
- Clean, modern UI for a seamless payment experience
- Easy integration with minimal code
- Support for test and live environments
- Fully customizable payment flow
Installation #
Add the package to your pubspec.yaml file:
dependencies:
korapay_flutter: ^0.2.0
Then run:
flutter pub get
Basic Usage #
The Korapay Flutter SDK provides an easy way to add payment functionality to your Flutter app.
Simple Integration #
import 'package:flutter/material.dart';
import 'package:korapay_flutter/korapay_flutter.dart';
// Inside your widget...
ElevatedButton(
onPressed: () async {
// Initialize payment configuration
final config = KorapayConfig(
key: 'pk_test_4wrQJedRa2GhJsiHFdtEYBN5EWrDSDviZpmuA1sJ', // Replace with your API key
reference: 'order_${DateTime.now().millisecondsSinceEpoch}',
amount: 1000.0,
currency: 'NGN',
customer: KorapayCustomer(
name: 'John Doe',
email: 'john.doe@example.com',
),
title: 'Payment for Order #123',
description: 'Purchase of items from Your Store',
channels: ['card', 'bank_transfer', 'bank'], // Payment methods to accept
);
// Show the payment form
final response = await KorapayCheckout.checkoutPayment(
context,
config,
closeOnSuccess: true,
);
// Handle the response
if (response.status == KorapayStatus.success) {
print('Payment successful: ${response.reference}');
} else if (response.status == KorapayStatus.failed) {
print('Payment failed: ${response.errorMessage}');
} else if (response.status == KorapayStatus.cancelled) {
print('Payment was cancelled');
}
},
child: Text('Pay Now'),
),
Using the Complete Payment Form #
For an enhanced user experience, you can use the complete payment form that allows users to select currency, payment method, and enter their details:
import 'package:flutter/material.dart';
import 'package:korapay_flutter/korapay_flutter.dart';
// Inside your widget...
ElevatedButton(
onPressed: () async {
// Show the complete payment form
final response = await Korapay.showPaymentForm(
context: context,
apiKey: 'pk_test_4wrQJedRa2GhJsiHFdtEYBN5EWrDSDviZpmuA1sJ', // Replace with your API key
isLiveMode: false, // Set to true for production
title: 'Payment for Order #123',
description: 'Purchase of items from Your Store',
initialAmount: 1000.0,
initialCurrency: 'NGN',
initialCustomerName: 'John Doe',
initialCustomerEmail: 'john.doe@example.com',
primaryColor: Colors.blue, // Customize the primary color
closeOnSuccess: true,
);
// Handle the response
if (response?.status == KorapayStatus.success) {
print('Payment successful: ${response?.reference}');
} else if (response?.status == KorapayStatus.failed) {
print('Payment failed: ${response?.errorMessage}');
} else if (response?.status == KorapayStatus.cancelled) {
print('Payment was cancelled');
}
},
child: Text('Pay Now with Complete Form'),
),
Customization Options #
You can customize the payment experience by providing different options to the SDK:
Available Payment Methods #
Specify which payment methods you want to support:
channels: ['card'], // Only card payments
channels: ['bank_transfer'], // Only bank transfer
channels: ['bank'], // Only direct bank debit
channels: ['card', 'bank_transfer', 'bank'], // All payment methods
Currencies #
The SDK supports multiple currencies:
currency: 'NGN', // Nigerian Naira
currency: 'USD', // US Dollar
currency: 'GHS', // Ghanaian Cedi
UI Customization #
You can customize the UI of the payment form:
// Customize the primary color
primaryColor: Colors.purple,
// Auto-close on successful payment
closeOnSuccess: true,
Test Mode vs Live Mode #
The SDK will automatically detect whether it's in test or live mode based on the API key provided:
// Test mode
key: 'pk_test_4wrQJedRa2GhJsiHFdtEYBN5EWrDSDviZpmuA1sJ',
// Live mode
key: 'pk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxx',
In test mode, you can use the following test card details:
- Card Number: 5188 5133 1538 7486
- Expiry Date: Any future date
- CVV: 123
API Reference #
KorapayConfig #
The KorapayConfig class is used to configure the payment:
KorapayConfig({
required String key, // Your Korapay API key
required String reference, // A unique reference for this transaction
required double amount, // The amount to charge
required String currency, // The currency code (NGN, USD, GHS)
required KorapayCustomer customer, // Customer details
String title = '', // The title of the payment
String description = '', // A description of the payment
List<String> channels = const ['card'], // Payment methods to accept
String? notificationUrl, // URL for webhooks (optional)
});
KorapayCustomer #
The KorapayCustomer class represents the customer's information:
KorapayCustomer({
required String name, // Customer's name
required String email, // Customer's email
});
KorapayResponse #
The KorapayResponse class represents the result of a payment:
KorapayResponse({
required KorapayStatus status, // success, failed, cancelled, pending, or tokenized
String? reference, // The transaction reference
Map<String, dynamic>? data, // Additional data about the transaction
String? errorMessage, // Error message if status is failed
});
License #
This project is licensed under the MIT License - see the LICENSE file for details.