arto_sdk 1.0.0 copy "arto_sdk: ^1.0.0" to clipboard
arto_sdk: ^1.0.0 copied to clipboard

Flutter SDK for Arto Pay payment gateway integration.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:arto_sdk/arto/arto.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Payment SDK Config',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigo),
        useMaterial3: true,
      ),
      home: const PaymentSetupScreen(),
    );
  }
}

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

  @override
  State<PaymentSetupScreen> createState() => _PaymentSetupScreenState();
}

class _PaymentSetupScreenState extends State<PaymentSetupScreen> {
  final TextEditingController _publicKeyTokenController = TextEditingController();
  final TextEditingController _customerTokenController = TextEditingController();
  final TextEditingController _paymentSecretTokenController = TextEditingController();
  final TextEditingController _paymentIntentIdController = TextEditingController();
  
  bool _isSandbox = false;

  @override
  void dispose() {
    _publicKeyTokenController.dispose();
    _customerTokenController.dispose();
    _paymentSecretTokenController.dispose();
    _paymentIntentIdController.dispose();
    super.dispose();
  }

  void _onProcess() {
    final publicKey = _publicKeyTokenController.text;
    final customerToken = _customerTokenController.text;
    final secretToken = _paymentSecretTokenController.text;
    final intentId = _paymentIntentIdController.text;
    
    if (publicKey.isEmpty || secretToken.isEmpty || intentId.isEmpty) {
       ScaffoldMessenger.of(context).showSnackBar(
         const SnackBar(content: Text('Please enter public key, secret, and intent ID.')),
       );
       return;
    }

    Arto.configure(sandbox: _isSandbox, publicKey: publicKey);

    final options = OpenPaymentOptions(
      clientSecret: secretToken,
      paymentId: intentId,
      token: customerToken.isNotEmpty ? customerToken : null,
      sandbox: _isSandbox,
      onSuccess: (result) {
        debugPrint('PAYMENT SUCCESS: ${result.rawData}');
        ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Payment Successful!')));
      },
      onPending: (result) {
        debugPrint('PAYMENT PENDING: ${result.rawData}');
        ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Payment Pending...')));
      },
      onError: (result) {
        debugPrint('PAYMENT ERROR: ${result.rawData}');
        ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Payment Error!')));
      },
    );

    try {
      Arto.openPayment(context, options);
    } catch(e) {
      ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(e.toString())));
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('SDK Configuration'),
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: SafeArea(
        child: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Column(
            children: [
              Expanded(
                child: SingleChildScrollView(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    children: [
                      const Text(
                        'Please enter the required credentials to proceed.',
                        style: TextStyle(
                          fontSize: 16, 
                          fontWeight: FontWeight.w500,
                        ),
                      ),
                      const SizedBox(height: 24),
                      TextField(
                        controller: _publicKeyTokenController,
                        decoration: const InputDecoration(
                          labelText: 'Public Key Token',
                          border: OutlineInputBorder(),
                          prefixIcon: Icon(Icons.vpn_key),
                        ),
                      ),
                      const SizedBox(height: 16),
                      TextField(
                        controller: _customerTokenController,
                        decoration: const InputDecoration(
                          labelText: 'Customer Token (Optional)',
                          border: OutlineInputBorder(),
                          prefixIcon: Icon(Icons.person),
                        ),
                      ),
                      const SizedBox(height: 16),
                      TextField(
                        controller: _paymentSecretTokenController,
                        decoration: const InputDecoration(
                          labelText: 'Payment Secret Token',
                          border: OutlineInputBorder(),
                          prefixIcon: Icon(Icons.security),
                        ),
                      ),
                      const SizedBox(height: 16),
                      TextField(
                        controller: _paymentIntentIdController,
                        decoration: const InputDecoration(
                          labelText: 'Payment Intent Id',
                          border: OutlineInputBorder(),
                          prefixIcon: Icon(Icons.payment),
                        ),
                      ),
                      const SizedBox(height: 24),
                      Container(
                        decoration: BoxDecoration(
                          border: Border.all(color: Colors.grey.shade400),
                          borderRadius: BorderRadius.circular(4),
                        ),
                        child: SwitchListTile(
                          title: const Text('Sandbox Environment'),
                          subtitle: Text('Selected: ${_isSandbox ? 'true' : 'false'}'),
                          value: _isSandbox,
                          onChanged: (bool value) {
                            setState(() {
                              _isSandbox = value;
                            });
                          },
                          activeThumbColor: Theme.of(context).colorScheme.primary,
                        ),
                      ),
                    ],
                  ),
                ),
              ),
              const SizedBox(height: 16),
              SizedBox(
                width: double.infinity,
                height: 52,
                child: ElevatedButton(
                  onPressed: _onProcess,
                  style: ElevatedButton.styleFrom(
                    backgroundColor: Theme.of(context).colorScheme.primary,
                    foregroundColor: Theme.of(context).colorScheme.onPrimary,
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(8),
                    ),
                    elevation: 2,
                  ),
                  child: const Text(
                    'Process',
                    style: TextStyle(
                      fontSize: 18, 
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
150
points
110
downloads

Documentation

API reference

Publisher

verified publisherarto-pay.com

Weekly Downloads

Flutter SDK for Arto Pay payment gateway integration.

Homepage

License

MIT (license)

Dependencies

cupertino_icons, flutter, webview_flutter

More

Packages that depend on arto_sdk