Last updated:
0 purchases
midtrans plugin
Table of Contents generated with DocToc
Midtrans Plugin
Introduction
Features
Installation
Usage
1. Import the package
2. Initialize Midtrans
3. Make transaction
4. Handle Payment Result
Midtrans Plugin #
This plugin is a unofficial implementation for integrating Midtrans payment gateway into your Flutter applications. Midtrans is tech-based finance that offers a payment gateway in Indonesia. Supports many online payment methods and transfers funds (disbursement) to make it easier for customers in business transactions and to focus on growing your business with the option of managing all payment processes.
Introduction #
This Flutter plugin aims to streamline the process of integrating Midtrans into your Flutter apps, providing developers with an easy-to-use interface for handling payments. With this plugin, you can facilitate secure transactions within your app, offering users a smooth payment experience.
Features #
Seamless integration of Midtrans payment gateway.
Customizable options for payment methods and configurations.
Secure transaction handling to protect sensitive user data.
Easy-to-use API for initiating and managing transactions.
Installation #
to use this plugin, follow these steps:
Add dependency: Add the following line to your pubspec.yaml file:
dependencies:
midtrans_plugin: <latest_version>
copied to clipboard
Install packages: Run the following command in your terminal:
flutter pub get
copied to clipboard
Usage #
1. Import the package #
import 'package:midtrans_plugin/midtrans_plugin.dart';
copied to clipboard
2. Initialize Midtrans #
String merchantClientKey = 'clientKeySandbox';
String merchantUrl = 'merchantUrlSandbox';
if (!kDebugMode && !kProfileMode) {
merchantClientKey = 'clientKeyProd';
merchantUrl = 'merchantUrlProd';
}
final config = MidtransConfig(
merchantClientKey: merchantClientKey,
merchantUrl: merchantUrl,
);
await MidtransPlugin.initialize(config);
copied to clipboard
3. Make transaction #
try {
final transactionDetails = TransactionDetails(
orderId: 'ORDER-${DateTime.now().millisecondsSinceEpoch}',
grossAmount: 10.0,
);
final itemDetails = [
ItemDetail(
id: 'product_a',
price: 10.0,
quantity: 1,
name: 'Product A',
)
];
final customerDetails = CustomerDetails(
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
phone: '08123456789',
billingAddress: BillingAddress(
firstName: 'John',
lastName: 'Doe',
address: 'Jl. Buntu No. 2',
city: 'Jakarta',
phone: '08123456789',
postalCode: '112233',
),
);
await MidtransPlugin.instance.startPayment(
MidtransPayload(
transactionDetails: transactionDetails,
itemDetails: itemDetails,
customerDetails: customerDetails,
),
);
} catch (e) {
print('an error occured $e');
}
copied to clipboard
4. Handle Payment Result #
MidtransPlugin.onTransactionResult.listen((result) {
print('[transactionResult] $result');
});
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.