sucrose 0.0.5 sucrose: ^0.0.5 copied to clipboard
A Bridge Payment Gateway for Xendit, Midtrans and any other payment gateway.
import 'package:sucrose/sucrose.dart';
import 'package:flutter/material.dart';
import 'package:logger/logger.dart';
void main() async {
final sucrose = Sucrose.initMidtrans(
midtransApiKey: "SB-Mid-server-9OwPRJdQERWtpPL5xAOdzARo",
environment: MidtransEnvironment.SANDBOX,
debug: true,
);
Logger logger = Logger(
printer: PrettyPrinter(),
);
try {
final response = await sucrose.midtrans.chargeKredivo(
request: MidtransKredivoRequest(
customerDetails: MidtransCustomerDetails(
email: "test@mail.com",
firstName: "Test",
lastName: "Test",
phone: "08123456789",
shippingAddress: MidtransShippingAddress(
address: "Jalan Teknologi Indonesia",
city: "Jakarta",
countryCode: "IDN",
firstName: "Test",
lastName: "Test",
phone: "08123456789",
postalCode: "12345",
),
billingAddress: MidtransBillingAddress(
address: "Jalan Teknologi Indonesia",
city: "Jakarta",
countryCode: "IDN",
firstName: "Test",
lastName: "Test",
phone: "08123456789",
postalCode: "12345",
),
),
itemDetails: [
MidtransItemDetail(
name: "Steam Wallet Code",
price: 10000,
quantity: 1,
)
],
sellerDetails: [
MidtransSellerDetail(
id: "str-123",
name: "Store 123",
url: "https://www.store123.com",
email: "store123@mail.com",
address: MidtransAddress(
address: "Jalan Teknologi Indonesia",
city: "Jakarta",
countryCode: "IDN",
firstName: "Test",
lastName: "Test",
phone: "08123456789",
postalCode: "12345",
),
),
],
customExpiry: MidtransCustomExpiry(
expiryDuration: 60,
unit: "minute",
),
transactionDetails: MidtransTransactionDetail(
orderId: "inv-${DateTime.now().millisecondsSinceEpoch}",
grossAmount: 10000,
),
),
);
// final response = await sucrose.midtrans.registerCard(
// clientKey: "SB-Mid-client-AkJUcZx3FXE7K0hY",
// cardNumber: "5211 1111 1111 1117",
// cardExpMonth: "12",
// cardExpYear: "2024",
// cardCvv: "123",
// );
logger.i(response.toJson());
} catch (e) {
if (e is MidtransException) {
logger.e(e.statusCode);
logger.e(e.statusMessage);
logger.e(e.validationMessages);
} else {
logger.e(e.toString());
}
}
runApp(const MainApp());
}
class MainApp extends StatefulWidget {
const MainApp({super.key});
@override
State<MainApp> createState() => _MainAppState();
}
class _MainAppState extends State<MainApp> {
// final controller = WebViewController()
// ..setJavaScriptMode(JavaScriptMode.unrestricted)
// ..setBackgroundColor(const Color(0x00000000))
// ..setNavigationDelegate(
// NavigationDelegate(
// onProgress: (int progress) {
// // Update loading bar.
// },
// onPageStarted: (String url) {},
// onPageFinished: (String url) {},
// onWebResourceError: (WebResourceError error) {},
// onNavigationRequest: (NavigationRequest request) {
// if (request.url.startsWith('https://www.youtube.com/')) {
// return NavigationDecision.prevent;
// }
// return NavigationDecision.navigate;
// },
// ),
// )
// ..loadRequest(Uri.parse(
// 'https://app.sandbox.midtrans.com/snap/v3/redirection/31ccb075-2c7e-4af8-a0b1-1f8ac1dea6a6'));
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(body: Center(child: Text("Hello"))),
);
}
}