busha_commerce_flutter 0.0.2 copy "busha_commerce_flutter: ^0.0.2" to clipboard
busha_commerce_flutter: ^0.0.2 copied to clipboard

Accept bitcoin and other cryptocurrencies from anywhere in the world.

example/lib/main.dart

import 'dart:developer';

import 'package:busha_commerce_flutter/busha_commerce_flutter.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        scaffoldBackgroundColor: Colors.white,
        primarySwatch: Colors.blue,
      ),
      home: Builder(
        builder: (BuildContext context) {
          return const SetupView();
        },
      ),
    );
  }
}

class SetupView extends StatefulWidget {
  const SetupView({super.key});

  @override
  State<SetupView> createState() => _SetupViewState();
}

class _SetupViewState extends State<SetupView> {
  late BushaCommerce bushaCommerce;

  @override
  void initState() {
    /// The sdk must be instantiated before use.
    bushaCommerce = BushaCommerce(
        context: context,
        //url:'https://staging.commerce.busha.co/invoices/93605804-e6de-4718-8ade-a71a17cbdef0?support=rexford%40busha.co&mode=live',
        url:
            'https://staging.commerce.busha.co/checkouts/59f48a7c-9b7d-4f9d-84b5-0037950b0921?support=rexford%40busha.co&mode=live',
        businessToken: 'live_6ISPvNAszyayzyZvpP9q7ysQbsz0jvVs',
        paymentType: PaymentType.checkout,
        customerEmail: 'zoluwatobi@gmail.com',
        customerName: 'Oluwatobi');

    super.initState();
  }

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Busha Commerce',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        scaffoldBackgroundColor: Colors.white,
        primarySwatch: Colors.blue,
      ),
      home: Builder(builder: (context) {
        return Scaffold(
          body: Center(
            child: InkWell(
              onTap: () async {
                /// This will open the UI to start payment and will only work if the sdk is instantiated
                bushaCommerce.startPayment(
                  onCompleted: (data) {
                  /// Returns any charge action after an payment attempt.
                  log(data!.toJson().toString());
                }, onClose: (data) {
                  /// Returns closed event message before any charge takes place.
                  log(data.toString());
                });
              },
              child: Container(
                alignment: Alignment.center,
                margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 0),
                width: 240,
                height: 65,
                decoration: BoxDecoration(
                  color: const Color(0xFF12A633),
                  borderRadius: BorderRadius.circular(12),
                ),
                child: const Text(
                  'Make payment',
                  style: TextStyle(
                      fontSize: 14,
                      color: Colors.white,
                      fontWeight: FontWeight.w700),
                ),
              ),
            ),
          ),
        );
      }),
    );
  }
}