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

This plugin integrates to oppwa zsw sdk for local zwl payments

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:zsw_ecommerce/zsw_ecommerce.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  String _checkoutIdResult = 'Checkout ID: Not requested yet';
  String _submitTransactionResult = 'Transaction: Not submitted yet';
  String _paymentStatusResult = 'Payment Status: Not requested yet';

  final _zswEcommercePlugin = ZswEcommerce();

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  Future<void> initPlatformState() async {
    String platformVersion;
    try {
      platformVersion = await ZswEcommerce.getPlatformVersion() ?? 'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  Future<void> requestCheckoutId() async {
    try {
      final checkoutId = await ZswEcommerce.requestCheckoutId('https://your-api-url.com') ??
          'Failed to get checkout ID.';
      setState(() {
        _checkoutIdResult = 'Checkout ID: $checkoutId';
      });
    } on PlatformException catch (e) {
      setState(() {
        _checkoutIdResult = 'Error: ${e.message}';
      });
    }
  }

  Future<void> submitTransaction() async {
    try {
      final paymentParams = {
        'checkoutId': '12345',
        'brand': 'Visa',
        'number': '4111111111111111',
        'holder': 'John Doe',
        'expiryMonth': '12',
        'expiryYear': '2023',
        'cvv': '123',
      };

      final isTestMode = true;

      final transactionResult =
          await ZswEcommerce.submitTransaction(paymentParams, isTestMode) ??
              {'transactionId': 'Unknown', 'status': 'Unknown'};
      setState(() {
        _submitTransactionResult = 'Transaction Result: ${transactionResult['status']} (ID: ${transactionResult['transactionId']})';
      });
    } on PlatformException catch (e) {
      setState(() {
        _submitTransactionResult = 'Error: ${e.message}';
      });
    }
  }

  Future<void> requestPaymentStatus() async {
    try {
      final paymentStatus = await ZswEcommerce.requestPaymentStatus('https://your-api-url.com', 'yourCheckoutId') ??
          'Failed to get payment status.';
      setState(() {
        _paymentStatusResult = 'Payment Status: $paymentStatus';
      });
    } on PlatformException catch (e) {
      setState(() {
        _paymentStatusResult = 'Error: ${e.message}';
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text('Running on: $_platformVersion\n'),
              ElevatedButton(
                onPressed: requestCheckoutId,
                child: const Text('Request Checkout ID'),
              ),
              Text(_checkoutIdResult),
              ElevatedButton(
                onPressed: submitTransaction,
                child: const Text('Submit Transaction'),
              ),
              Text(_submitTransactionResult),
              ElevatedButton(
                onPressed: requestPaymentStatus,
                child: const Text('Request Payment Status'),
              ),
              Text(_paymentStatusResult),
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
140
points
0
downloads

Publisher

unverified uploader

Weekly Downloads

This plugin integrates to oppwa zsw sdk for local zwl payments

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on zsw_ecommerce

Packages that implement zsw_ecommerce