diff --git a/.flutter-plugins b/.flutter-plugins index 3b48a2b..fdea085 100644 --- a/.flutter-plugins +++ b/.flutter-plugins @@ -1,8 +1,8 @@ # This is a generated file; do not edit or check into version control. -connectivity_plus=C:\\Users\\Hp\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dartlang.org\\connectivity_plus-2.3.9\\ -connectivity_plus_linux=C:\\Users\\Hp\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dartlang.org\\connectivity_plus_linux-1.3.1\\ -connectivity_plus_macos=C:\\Users\\Hp\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dartlang.org\\connectivity_plus_macos-1.2.6\\ -connectivity_plus_web=C:\\Users\\Hp\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dartlang.org\\connectivity_plus_web-1.2.5\\ -connectivity_plus_windows=C:\\Users\\Hp\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dartlang.org\\connectivity_plus_windows-1.2.2\\ -flutter_inappwebview=C:\\Users\\Hp\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dartlang.org\\flutter_inappwebview-5.7.2+3\\ -fluttertoast=C:\\Users\\Hp\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dartlang.org\\fluttertoast-8.1.2\\ +connectivity_plus=C:\\Users\\User\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\connectivity_plus-5.0.2\\ +flutter_inappwebview=C:\\Users\\User\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\flutter_inappwebview-6.0.0\\ +flutter_inappwebview_android=C:\\Users\\User\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\flutter_inappwebview_android-1.0.13\\ +flutter_inappwebview_ios=C:\\Users\\User\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\flutter_inappwebview_ios-1.0.13\\ +flutter_inappwebview_macos=C:\\Users\\User\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\flutter_inappwebview_macos-1.0.11\\ +flutter_inappwebview_web=C:\\Users\\User\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\flutter_inappwebview_web-1.0.8\\ +fluttertoast=C:\\Users\\User\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\fluttertoast-8.2.4\\ diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index 2cf840f..8c09f13 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"connectivity_plus","path":"C:\\\\Users\\\\Hp\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\connectivity_plus-2.3.9\\\\","native_build":true,"dependencies":[]},{"name":"flutter_inappwebview","path":"C:\\\\Users\\\\Hp\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_inappwebview-5.7.2+3\\\\","native_build":true,"dependencies":[]},{"name":"fluttertoast","path":"C:\\\\Users\\\\Hp\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\fluttertoast-8.1.2\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"connectivity_plus","path":"C:\\\\Users\\\\Hp\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\connectivity_plus-2.3.9\\\\","native_build":true,"dependencies":[]},{"name":"flutter_inappwebview","path":"C:\\\\Users\\\\Hp\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_inappwebview-5.7.2+3\\\\","native_build":true,"dependencies":[]},{"name":"fluttertoast","path":"C:\\\\Users\\\\Hp\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\fluttertoast-8.1.2\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"connectivity_plus_macos","path":"C:\\\\Users\\\\Hp\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\connectivity_plus_macos-1.2.6\\\\","native_build":true,"dependencies":[]}],"linux":[{"name":"connectivity_plus_linux","path":"C:\\\\Users\\\\Hp\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\connectivity_plus_linux-1.3.1\\\\","native_build":false,"dependencies":[]}],"windows":[{"name":"connectivity_plus_windows","path":"C:\\\\Users\\\\Hp\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\connectivity_plus_windows-1.2.2\\\\","native_build":true,"dependencies":[]}],"web":[{"name":"connectivity_plus_web","path":"C:\\\\Users\\\\Hp\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\connectivity_plus_web-1.2.5\\\\","dependencies":[]},{"name":"fluttertoast","path":"C:\\\\Users\\\\Hp\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\fluttertoast-8.1.2\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"connectivity_plus","dependencies":["connectivity_plus_linux","connectivity_plus_macos","connectivity_plus_web","connectivity_plus_windows"]},{"name":"connectivity_plus_linux","dependencies":[]},{"name":"connectivity_plus_macos","dependencies":[]},{"name":"connectivity_plus_web","dependencies":[]},{"name":"connectivity_plus_windows","dependencies":[]},{"name":"flutter_inappwebview","dependencies":[]},{"name":"fluttertoast","dependencies":[]}],"date_created":"2023-01-25 18:26:27.856179","version":"3.3.5"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"connectivity_plus","path":"C:\\\\Users\\\\User\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\connectivity_plus-5.0.2\\\\","native_build":true,"dependencies":[]},{"name":"flutter_inappwebview_ios","path":"C:\\\\Users\\\\User\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_inappwebview_ios-1.0.13\\\\","native_build":true,"dependencies":[]},{"name":"fluttertoast","path":"C:\\\\Users\\\\User\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\fluttertoast-8.2.4\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"connectivity_plus","path":"C:\\\\Users\\\\User\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\connectivity_plus-5.0.2\\\\","native_build":true,"dependencies":[]},{"name":"flutter_inappwebview_android","path":"C:\\\\Users\\\\User\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_inappwebview_android-1.0.13\\\\","native_build":true,"dependencies":[]},{"name":"fluttertoast","path":"C:\\\\Users\\\\User\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\fluttertoast-8.2.4\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"connectivity_plus","path":"C:\\\\Users\\\\User\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\connectivity_plus-5.0.2\\\\","native_build":true,"dependencies":[]},{"name":"flutter_inappwebview_macos","path":"C:\\\\Users\\\\User\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_inappwebview_macos-1.0.11\\\\","native_build":true,"dependencies":[]}],"linux":[{"name":"connectivity_plus","path":"C:\\\\Users\\\\User\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\connectivity_plus-5.0.2\\\\","native_build":false,"dependencies":[]}],"windows":[{"name":"connectivity_plus","path":"C:\\\\Users\\\\User\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\connectivity_plus-5.0.2\\\\","native_build":true,"dependencies":[]}],"web":[{"name":"connectivity_plus","path":"C:\\\\Users\\\\User\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\connectivity_plus-5.0.2\\\\","dependencies":[]},{"name":"flutter_inappwebview_web","path":"C:\\\\Users\\\\User\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_inappwebview_web-1.0.8\\\\","dependencies":[]},{"name":"fluttertoast","path":"C:\\\\Users\\\\User\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\fluttertoast-8.2.4\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"connectivity_plus","dependencies":[]},{"name":"flutter_inappwebview","dependencies":["flutter_inappwebview_android","flutter_inappwebview_ios","flutter_inappwebview_macos","flutter_inappwebview_web"]},{"name":"flutter_inappwebview_android","dependencies":[]},{"name":"flutter_inappwebview_ios","dependencies":[]},{"name":"flutter_inappwebview_macos","dependencies":[]},{"name":"flutter_inappwebview_web","dependencies":[]},{"name":"fluttertoast","dependencies":[]}],"date_created":"2024-03-09 15:03:15.240380","version":"3.16.9"} \ No newline at end of file diff --git a/README.md b/README.md index b72e58f..d41ece0 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ Chapa.paymentParameters( email: 'xyz@gmail.com', firstName: 'fullName', lastName: 'lastName', - txRef: '34TXTHHgb', + companyName: 'XYZCrop', title: 'title', desc:'desc', namedRouteFallBack: '/second', // fall back route name @@ -71,6 +71,20 @@ Chapa.paymentParameters( #### Should my fallBack route should be named route? -Answer Yes, the fallBackRoute comes with an information such as payment is successfull, user cancelled payment and connectivity issue messages. Those informations will help you to update your backend, to generate new transaction refrence. +Answer Yes, the fallBackRoute comes with an information such as payment is successfully, user cancelled payment and connectivity issue messages. Those informations will help you to update your backend, to generate new transaction refrence. +#### what is invalid key mean? +Answer If you get an invalid key error try to generate new key or use test secrete key while testing. + +#### why company name is required? + +Answer in the old version ttx will be handled by developer and this version supports automatic generation of ttx reference for company name. + +## Demo + +screen shots + +https://ethiomappsgebeta.com/image_one.jpg +https://ethiomappsgebeta.com/image_two.jpg +https://ethiomappsgebeta.com/image_three.jpg diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index f4e1f9d..9bdd09f 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -26,13 +26,22 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion flutter.compileSdkVersion + compileSdkVersion 34 compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } + kotlinOptions { + jvmTarget = '1.8' + } + + sourceSets { + + main.java.srcDirs += 'src/main/kotlin' + } + defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.shopping_cart_app" diff --git a/example/android/build.gradle b/example/android/build.gradle index 4256f91..1e139d8 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,12 +1,12 @@ buildscript { - ext.kotlin_version = '1.6.10' + ext.kotlin_version = '1.8.20' repositories { google() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.1.0' + classpath 'com.android.tools.build:gradle:7.0.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } @@ -26,6 +26,6 @@ subprojects { project.evaluationDependsOn(':app') } -task clean(type: Delete) { +tasks.register("clean", Delete) { delete rootProject.buildDir } diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index bc6a58a..6b66533 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip diff --git a/example/lib/screens/cart_screen.dart b/example/lib/screens/cart_screen.dart index 3128096..9d1ba87 100644 --- a/example/lib/screens/cart_screen.dart +++ b/example/lib/screens/cart_screen.dart @@ -1,4 +1,4 @@ -import 'package:badges/badges.dart'; +import 'package:badges/badges.dart' as badges; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:shopping_cart_app/database/db_helper.dart'; @@ -21,8 +21,6 @@ class _CartScreenState extends State { @override void initState() { - - // get data after payment charm update your database now Future.delayed(Duration.zero,(){ setState(() { if(ModalRoute.of(context)?.settings.arguments!= null) @@ -30,8 +28,7 @@ class _CartScreenState extends State { args=ModalRoute.of(context)?.settings.arguments; print('message after payment'); print(args['message']); - print(args['transactionReference']); - print(args['paidAmount']); + print(args['ttx']); } }); @@ -50,8 +47,8 @@ class _CartScreenState extends State { centerTitle: true, title: const Text('My Shopping Cart'), actions: [ - Badge( - badgeContent: Consumer( + badges.Badge( + badgeContent: Consumer( builder: (context, value, child) { return Text( value.getCounter().toString(), @@ -60,7 +57,7 @@ class _CartScreenState extends State { ); }, ), - position: const BadgePosition(start: 30, bottom: 30), + position: badges.BadgePosition.topEnd(), child: IconButton( onPressed: () {}, icon: const Icon(Icons.shopping_cart), @@ -257,13 +254,13 @@ class _CartScreenState extends State { /// Chapa.paymentParameters( context: context, // context - publicKey: 'CHASECK_TEST-', + publicKey: 'CHASECK_TEST-7LNY26k8aIcWkgsoHoPgZhNjiYhnOMQ9', currency: 'etb', amount: '300', email: 'xyz@gmail.com', firstName: 'testname', lastName: 'lastName', - txRef: '55ttyyy', + companyName: 'LeyuCars', title: 'title', desc:'desc', namedRouteFallBack: '/checkoutPage', // fall back route name diff --git a/example/lib/screens/product_list.dart b/example/lib/screens/product_list.dart index bb2a36b..3390589 100644 --- a/example/lib/screens/product_list.dart +++ b/example/lib/screens/product_list.dart @@ -6,6 +6,7 @@ import 'package:shopping_cart_app/provider/cart_provider.dart'; import 'package:shopping_cart_app/database/db_helper.dart'; import 'package:shopping_cart_app/model/cart_model.dart'; import 'package:shopping_cart_app/screens/cart_screen.dart'; +import 'package:badges/badges.dart' as badges; class ProductList extends StatefulWidget { const ProductList({Key? key}) : super(key: key); @@ -80,9 +81,7 @@ class _ProductListState extends State { .then((value) { cart.addTotalPrice(products[index].price.toDouble()); cart.addCounter(); - print('Product Added to cart'); }).onError((error, stackTrace) { - print(error.toString()); }); } @@ -91,7 +90,7 @@ class _ProductListState extends State { centerTitle: true, title: const Text('Product List'), actions: [ - Badge( + badges.Badge( badgeContent: Consumer( builder: (context, value, child) { return Text( @@ -101,7 +100,7 @@ class _ProductListState extends State { ); }, ), - position: const BadgePosition(start: 30, bottom: 30), + position: badges.BadgePosition.topEnd(), child: IconButton( onPressed: () { Navigator.push( diff --git a/example/pubspec.lock b/example/pubspec.lock index 882d183..8dce017 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -1,146 +1,205 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + sha256: eb376e9acf6938204f90eb3b1f00b578640d3188b4c8a8ec054f9f479af8d051 + url: "https://pub.dev" + source: hosted + version: "64.0.0" + analyzer: + dependency: transitive + description: + name: analyzer + sha256: "69f54f967773f6c26c7dcb13e93d7ccee8b17a641689da39e878d5cf13b06893" + url: "https://pub.dev" + source: hosted + version: "6.2.0" args: dependency: transitive description: name: args - url: "https://pub.dartlang.org" + sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596 + url: "https://pub.dev" source: hosted - version: "2.3.1" + version: "2.4.2" async: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" source: hosted - version: "2.8.2" + version: "2.11.0" badges: dependency: "direct main" description: name: badges - url: "https://pub.dartlang.org" + sha256: a7b6bbd60dce418df0db3058b53f9d083c22cdb5132a052145dc267494df0b84 + url: "https://pub.dev" source: hosted - version: "2.0.2" + version: "3.1.2" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" + build: + dependency: transitive + description: + name: build + sha256: "80184af8b6cb3e5c1c4ec6d8544d27711700bc3e6d2efad04238c7b5290889f0" + url: "https://pub.dev" + source: hosted + version: "2.4.1" + built_collection: + dependency: transitive + description: + name: built_collection + sha256: "376e3dd27b51ea877c28d525560790aee2e6fbb5f20e2f85d5081027d94e2100" + url: "https://pub.dev" + source: hosted + version: "5.1.1" + built_value: + dependency: transitive + description: + name: built_value + sha256: fedde275e0a6b798c3296963c5cd224e3e1b55d0e478d5b7e65e6b540f363a0e + url: "https://pub.dev" + source: hosted + version: "8.9.1" chapasdk: dependency: "direct main" description: path: ".." relative: true source: path - version: "0.0.1" + version: "0.0.5" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" source: hosted - version: "1.2.0" - charcode: + version: "1.3.0" + clock: dependency: transitive description: - name: charcode - url: "https://pub.dartlang.org" + name: clock + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted - version: "1.3.1" - clock: + version: "1.1.1" + code_builder: dependency: transitive description: - name: clock - url: "https://pub.dartlang.org" + name: code_builder + sha256: f692079e25e7869c14132d39f223f8eec9830eb76131925143b2129c4bb01b37 + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "4.10.0" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" source: hosted - version: "1.16.0" + version: "1.18.0" connectivity_plus: dependency: transitive description: name: connectivity_plus - url: "https://pub.dartlang.org" + sha256: "224a77051d52a11fbad53dd57827594d3bd24f945af28bd70bab376d68d437f0" + url: "https://pub.dev" source: hosted - version: "2.3.6+1" - connectivity_plus_linux: - dependency: transitive - description: - name: connectivity_plus_linux - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" - connectivity_plus_macos: - dependency: transitive - description: - name: connectivity_plus_macos - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.4" + version: "5.0.2" connectivity_plus_platform_interface: dependency: transitive description: name: connectivity_plus_platform_interface - url: "https://pub.dartlang.org" + sha256: cf1d1c28f4416f8c654d7dc3cd638ec586076255d407cef3ddbdaf178272a71a + url: "https://pub.dev" source: hosted - version: "1.2.1" - connectivity_plus_web: + version: "1.2.4" + convert: dependency: transitive description: - name: connectivity_plus_web - url: "https://pub.dartlang.org" + name: convert + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" + url: "https://pub.dev" source: hosted - version: "1.2.3" - connectivity_plus_windows: + version: "3.1.1" + crypto: dependency: transitive description: - name: connectivity_plus_windows - url: "https://pub.dartlang.org" + name: crypto + sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab + url: "https://pub.dev" source: hosted - version: "1.2.2" + version: "3.0.3" cupertino_icons: dependency: "direct main" description: name: cupertino_icons - url: "https://pub.dartlang.org" + sha256: d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d + url: "https://pub.dev" source: hosted - version: "1.0.4" + version: "1.0.6" + dart_style: + dependency: transitive + description: + name: dart_style + sha256: "99e066ce75c89d6b29903d788a7bb9369cf754f7b24bf70bf4b6d6d6b26853b9" + url: "https://pub.dev" + source: hosted + version: "2.3.6" dbus: dependency: transitive description: name: dbus - url: "https://pub.dartlang.org" + sha256: "365c771ac3b0e58845f39ec6deebc76e3276aa9922b0cc60840712094d9047ac" + url: "https://pub.dev" source: hosted - version: "0.7.4" + version: "0.7.10" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" source: hosted - version: "1.3.0" + version: "1.3.1" ffi: dependency: transitive description: name: ffi - url: "https://pub.dartlang.org" + sha256: "7bf0adc28a23d395f19f3f1eb21dd7cfd1dd9f8e1c50051c069122e6853bc878" + url: "https://pub.dev" source: hosted - version: "1.2.1" + version: "2.1.0" file: dependency: transitive description: name: file - url: "https://pub.dartlang.org" + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" + url: "https://pub.dev" source: hosted - version: "6.1.2" + version: "7.0.0" + fixnum: + dependency: transitive + description: + name: fixnum + sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1" + url: "https://pub.dev" + source: hosted + version: "1.1.0" flutter: dependency: "direct main" description: flutter @@ -150,16 +209,66 @@ packages: dependency: transitive description: name: flutter_inappwebview - url: "https://pub.dartlang.org" + sha256: "3e9a443a18ecef966fb930c3a76ca5ab6a7aafc0c7b5e14a4a850cf107b09959" + url: "https://pub.dev" + source: hosted + version: "6.0.0" + flutter_inappwebview_android: + dependency: transitive + description: + name: flutter_inappwebview_android + sha256: d247f6ed417f1f8c364612fa05a2ecba7f775c8d0c044c1d3b9ee33a6515c421 + url: "https://pub.dev" source: hosted - version: "5.4.3+7" + version: "1.0.13" + flutter_inappwebview_internal_annotations: + dependency: transitive + description: + name: flutter_inappwebview_internal_annotations + sha256: "5f80fd30e208ddded7dbbcd0d569e7995f9f63d45ea3f548d8dd4c0b473fb4c8" + url: "https://pub.dev" + source: hosted + version: "1.1.1" + flutter_inappwebview_ios: + dependency: transitive + description: + name: flutter_inappwebview_ios + sha256: f363577208b97b10b319cd0c428555cd8493e88b468019a8c5635a0e4312bd0f + url: "https://pub.dev" + source: hosted + version: "1.0.13" + flutter_inappwebview_macos: + dependency: transitive + description: + name: flutter_inappwebview_macos + sha256: b55b9e506c549ce88e26580351d2c71d54f4825901666bd6cfa4be9415bb2636 + url: "https://pub.dev" + source: hosted + version: "1.0.11" + flutter_inappwebview_platform_interface: + dependency: transitive + description: + name: flutter_inappwebview_platform_interface + sha256: "545fd4c25a07d2775f7d5af05a979b2cac4fbf79393b0a7f5d33ba39ba4f6187" + url: "https://pub.dev" + source: hosted + version: "1.0.10" + flutter_inappwebview_web: + dependency: transitive + description: + name: flutter_inappwebview_web + sha256: d8c680abfb6fec71609a700199635d38a744df0febd5544c5a020bd73de8ee07 + url: "https://pub.dev" + source: hosted + version: "1.0.8" flutter_lints: dependency: "direct dev" description: name: flutter_lints - url: "https://pub.dartlang.org" + sha256: e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7 + url: "https://pub.dev" source: hosted - version: "1.0.4" + version: "3.0.1" flutter_test: dependency: "direct dev" description: flutter @@ -174,322 +283,431 @@ packages: dependency: transitive description: name: fluttertoast - url: "https://pub.dartlang.org" + sha256: dfdde255317af381bfc1c486ed968d5a43a2ded9c931e87cbecd88767d6a71c1 + url: "https://pub.dev" source: hosted - version: "8.0.9" + version: "8.2.4" + glob: + dependency: transitive + description: + name: glob + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" + url: "https://pub.dev" + source: hosted + version: "2.1.2" http: dependency: transitive description: name: http - url: "https://pub.dartlang.org" + sha256: a2bbf9d017fcced29139daa8ed2bba4ece450ab222871df93ca9eec6f80c34ba + url: "https://pub.dev" source: hosted - version: "0.13.5" + version: "1.2.0" http_parser: dependency: transitive description: name: http_parser - url: "https://pub.dartlang.org" + sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" + url: "https://pub.dev" source: hosted - version: "4.0.1" + version: "4.0.2" js: dependency: transitive description: name: js - url: "https://pub.dartlang.org" + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" source: hosted - version: "0.6.4" + version: "0.6.7" lints: dependency: transitive description: name: lints - url: "https://pub.dartlang.org" + sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290 + url: "https://pub.dev" source: hosted - version: "1.0.1" + version: "3.0.0" + logging: + dependency: transitive + description: + name: logging + sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + url: "https://pub.dev" + source: hosted + version: "1.2.0" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + url: "https://pub.dev" source: hosted - version: "0.12.11" + version: "0.12.16" material_color_utilities: dependency: transitive description: name: material_color_utilities - url: "https://pub.dartlang.org" + sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + url: "https://pub.dev" source: hosted - version: "0.1.4" + version: "0.5.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e + url: "https://pub.dev" + source: hosted + version: "1.10.0" + mockito: + dependency: transitive + description: + name: mockito + sha256: "6841eed20a7befac0ce07df8116c8b8233ed1f4486a7647c7fc5a02ae6163917" + url: "https://pub.dev" source: hosted - version: "1.7.0" + version: "5.4.4" nested: dependency: transitive description: name: nested - url: "https://pub.dartlang.org" + sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20" + url: "https://pub.dev" source: hosted version: "1.0.0" nm: dependency: transitive description: name: nm - url: "https://pub.dartlang.org" + sha256: "2c9aae4127bdc8993206464fcc063611e0e36e72018696cd9631023a31b24254" + url: "https://pub.dev" source: hosted version: "0.5.0" + package_config: + dependency: transitive + description: + name: package_config + sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" + url: "https://pub.dev" + source: hosted + version: "2.1.0" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + url: "https://pub.dev" source: hosted - version: "1.8.1" + version: "1.8.3" path_provider: dependency: "direct main" description: name: path_provider - url: "https://pub.dartlang.org" + sha256: b27217933eeeba8ff24845c34003b003b2b22151de3c908d0e679e8fe1aa078b + url: "https://pub.dev" source: hosted - version: "2.0.10" + version: "2.1.2" path_provider_android: dependency: transitive description: name: path_provider_android - url: "https://pub.dartlang.org" + sha256: "477184d672607c0a3bf68fbbf601805f92ef79c82b64b4d6eb318cbca4c48668" + url: "https://pub.dev" source: hosted - version: "2.0.14" - path_provider_ios: + version: "2.2.2" + path_provider_foundation: dependency: transitive description: - name: path_provider_ios - url: "https://pub.dartlang.org" + name: path_provider_foundation + sha256: "5a7999be66e000916500be4f15a3633ebceb8302719b47b9cc49ce924125350f" + url: "https://pub.dev" source: hosted - version: "2.0.9" + version: "2.3.2" path_provider_linux: dependency: transitive description: name: path_provider_linux - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.6" - path_provider_macos: - dependency: transitive - description: - name: path_provider_macos - url: "https://pub.dartlang.org" + sha256: f7a1fe3a634fe7734c8d3f2766ad746ae2a2884abe22e241a8b301bf5cac3279 + url: "https://pub.dev" source: hosted - version: "2.0.6" + version: "2.2.1" path_provider_platform_interface: dependency: transitive description: name: path_provider_platform_interface - url: "https://pub.dartlang.org" + sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334" + url: "https://pub.dev" source: hosted - version: "2.0.4" + version: "2.1.2" path_provider_windows: dependency: transitive description: name: path_provider_windows - url: "https://pub.dartlang.org" + sha256: "8bc9f22eee8690981c22aa7fc602f5c85b497a6fb2ceb35ee5a5e5ed85ad8170" + url: "https://pub.dev" source: hosted - version: "2.0.6" + version: "2.2.1" petitparser: dependency: transitive description: name: petitparser - url: "https://pub.dartlang.org" + sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27 + url: "https://pub.dev" source: hosted - version: "5.0.0" + version: "6.0.2" platform: dependency: transitive description: name: platform - url: "https://pub.dartlang.org" + sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec" + url: "https://pub.dev" source: hosted - version: "3.1.0" + version: "3.1.4" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface - url: "https://pub.dartlang.org" + sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02" + url: "https://pub.dev" source: hosted - version: "2.1.2" - process: - dependency: transitive - description: - name: process - url: "https://pub.dartlang.org" - source: hosted - version: "4.2.4" + version: "2.1.8" provider: dependency: "direct main" description: name: provider - url: "https://pub.dartlang.org" + sha256: c8a055ee5ce3fd98d6fc872478b03823ffdb448699c6ebdbbc71d59b596fd48c + url: "https://pub.dev" + source: hosted + version: "6.1.2" + pub_semver: + dependency: transitive + description: + name: pub_semver + sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" + url: "https://pub.dev" source: hosted - version: "6.0.3" + version: "2.1.4" shared_preferences: dependency: "direct main" description: name: shared_preferences - url: "https://pub.dartlang.org" + sha256: "81429e4481e1ccfb51ede496e916348668fd0921627779233bd24cc3ff6abd02" + url: "https://pub.dev" source: hosted - version: "2.0.15" + version: "2.2.2" shared_preferences_android: dependency: transitive description: name: shared_preferences_android - url: "https://pub.dartlang.org" + sha256: "8568a389334b6e83415b6aae55378e158fbc2314e074983362d20c562780fb06" + url: "https://pub.dev" source: hosted - version: "2.0.12" - shared_preferences_ios: + version: "2.2.1" + shared_preferences_foundation: dependency: transitive description: - name: shared_preferences_ios - url: "https://pub.dartlang.org" + name: shared_preferences_foundation + sha256: "7708d83064f38060c7b39db12aefe449cb8cdc031d6062280087bc4cdb988f5c" + url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.3.5" shared_preferences_linux: dependency: transitive description: name: shared_preferences_linux - url: "https://pub.dartlang.org" + sha256: "9f2cbcf46d4270ea8be39fa156d86379077c8a5228d9dfdb1164ae0bb93f1faa" + url: "https://pub.dev" source: hosted - version: "2.1.1" - shared_preferences_macos: - dependency: transitive - description: - name: shared_preferences_macos - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.4" + version: "2.3.2" shared_preferences_platform_interface: dependency: transitive description: name: shared_preferences_platform_interface - url: "https://pub.dartlang.org" + sha256: "22e2ecac9419b4246d7c22bfbbda589e3acf5c0351137d87dd2939d984d37c3b" + url: "https://pub.dev" source: hosted - version: "2.0.0" + version: "2.3.2" shared_preferences_web: dependency: transitive description: name: shared_preferences_web - url: "https://pub.dartlang.org" + sha256: "7b15ffb9387ea3e237bb7a66b8a23d2147663d391cafc5c8f37b2e7b4bde5d21" + url: "https://pub.dev" source: hosted - version: "2.0.4" + version: "2.2.2" shared_preferences_windows: dependency: transitive description: name: shared_preferences_windows - url: "https://pub.dartlang.org" + sha256: "841ad54f3c8381c480d0c9b508b89a34036f512482c407e6df7a9c4aa2ef8f59" + url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.3.2" sky_engine: dependency: transitive description: flutter source: sdk version: "0.0.99" + source_gen: + dependency: transitive + description: + name: source_gen + sha256: "14658ba5f669685cd3d63701d01b31ea748310f7ab854e471962670abcf57832" + url: "https://pub.dev" + source: hosted + version: "1.5.0" source_span: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" source: hosted - version: "1.8.2" + version: "1.10.0" + sprintf: + dependency: transitive + description: + name: sprintf + sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23" + url: "https://pub.dev" + source: hosted + version: "7.0.0" sqflite: dependency: "direct main" description: name: sqflite - url: "https://pub.dartlang.org" + sha256: a9016f495c927cb90557c909ff26a6d92d9bd54fc42ba92e19d4e79d61e798c6 + url: "https://pub.dev" source: hosted - version: "2.0.2+1" + version: "2.3.2" sqflite_common: dependency: transitive description: name: sqflite_common - url: "https://pub.dartlang.org" + sha256: "28d8c66baee4968519fb8bd6cdbedad982d6e53359091f0b74544a9f32ec72d5" + url: "https://pub.dev" source: hosted - version: "2.2.1+1" + version: "2.5.3" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.2" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.2.0" synchronized: dependency: transitive description: name: synchronized - url: "https://pub.dartlang.org" + sha256: "539ef412b170d65ecdafd780f924e5be3f60032a1128df156adad6c5b373d558" + url: "https://pub.dev" source: hosted - version: "3.0.0+2" + version: "3.1.0+1" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + url: "https://pub.dev" source: hosted - version: "0.4.9" + version: "0.6.1" typed_data: dependency: transitive description: name: typed_data - url: "https://pub.dartlang.org" + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + url: "https://pub.dev" source: hosted - version: "1.3.1" + version: "1.3.2" + uuid: + dependency: transitive + description: + name: uuid + sha256: cd210a09f7c18cbe5a02511718e0334de6559871052c90a90c0cca46a4aa81c8 + url: "https://pub.dev" + source: hosted + version: "4.3.3" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.4" + watcher: + dependency: transitive + description: + name: watcher + sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8" + url: "https://pub.dev" + source: hosted + version: "1.1.0" + web: + dependency: transitive + description: + name: web + sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 + url: "https://pub.dev" + source: hosted + version: "0.3.0" win32: dependency: transitive description: name: win32 - url: "https://pub.dartlang.org" + sha256: "464f5674532865248444b4c3daca12bd9bf2d7c47f759ce2617986e7229494a8" + url: "https://pub.dev" source: hosted - version: "2.5.2" + version: "5.2.0" xdg_directories: dependency: transitive description: name: xdg_directories - url: "https://pub.dartlang.org" + sha256: faea9dee56b520b55a566385b84f2e8de55e7496104adada9962e0bd11bcff1d + url: "https://pub.dev" source: hosted - version: "0.2.0+1" + version: "1.0.4" xml: dependency: transitive description: name: xml - url: "https://pub.dartlang.org" + sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226 + url: "https://pub.dev" + source: hosted + version: "6.5.0" + yaml: + dependency: transitive + description: + name: yaml + sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" + url: "https://pub.dev" source: hosted - version: "6.1.0" + version: "3.1.2" sdks: - dart: ">=2.17.0 <3.0.0" - flutter: ">=2.8.1" + dart: ">=3.2.0 <4.0.0" + flutter: ">=3.16.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 83d202d..504ff76 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev version: 1.0.0+1 environment: - sdk: ">=2.16.1 <3.0.0" + sdk: ">=2.19.0 <4.0.0" # Dependencies specify other packages that your package needs in order to work. # To automatically upgrade your package dependencies to the latest versions @@ -33,12 +33,12 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^1.0.4 - shared_preferences: ^2.0.15 - path_provider: ^2.0.10 - sqflite: ^2.0.2+1 - badges: ^2.0.2 - provider: ^6.0.3 + cupertino_icons: + shared_preferences: + path_provider: + sqflite: + badges: + provider: chapasdk: path: ../ @@ -52,7 +52,7 @@ dev_dependencies: # activated in the `analysis_options.yaml` file located at the root of your # package. See that file for information about deactivating specific lint # rules and activating additional ones. - flutter_lints: ^1.0.0 + flutter_lints: ^3.0.1 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/lib/chapa_payment initializer.dart b/lib/chapa_payment initializer.dart index fb0fe39..9a709dd 100644 --- a/lib/chapa_payment initializer.dart +++ b/lib/chapa_payment initializer.dart @@ -1,6 +1,6 @@ +import 'package:chapasdk/service/web_service.dart'; import 'package:flutter/material.dart'; import 'constants/common.dart'; -import 'constants/requests.dart'; import 'constants/strings.dart'; class Chapa { @@ -11,7 +11,7 @@ class Chapa { String email; String firstName; String lastName; - String txRef; + String companyName; String title; String desc; String namedRouteFallBack; @@ -24,21 +24,21 @@ class Chapa { required this.email, required this.firstName, required this.lastName, - required this.txRef, + required this.companyName, required this.title, required this.desc, required this.namedRouteFallBack, }) { - _validateKeys(); + validateKeys(); currency = currency.toUpperCase(); - if(_validateKeys()) + if(validateKeys()) { - initatePayment(); + initPayment(); } } - bool _validateKeys() { + bool validateKeys() { if (publicKey.trim().isEmpty) { showErrorToast(ChapaStrings.publicKeyRequired); return false; @@ -64,7 +64,7 @@ class Chapa { showErrorToast(ChapaStrings.lastNameRequired); return false; } - if (txRef.trim().isEmpty) { + if (companyName.trim().isEmpty) { showErrorToast(ChapaStrings.transactionRefrenceRequired); return false; } @@ -72,8 +72,8 @@ class Chapa { return true; } - void initatePayment() async{ - intilizeMyPayment(context, publicKey, email, amount, currency, firstName, - lastName, txRef, title, desc, namedRouteFallBack); + void initPayment() async{ + intilizeMyPayment(context, publicKey, email, amount, currency, firstName, + lastName, companyName, title, desc, namedRouteFallBack); } } diff --git a/lib/chapawebview.dart b/lib/chapawebview.dart index 94dd916..8533bba 100644 --- a/lib/chapawebview.dart +++ b/lib/chapawebview.dart @@ -8,16 +8,10 @@ import 'constants/common.dart'; class ChapaWebView extends StatefulWidget { final String url; final String fallBackNamedUrl; - final String transactionReference; - final String amountPaid; - - //ttx - //amount - //description - // + final String ttx; const ChapaWebView( - {Key? key, required this.url, required this.fallBackNamedUrl, required this.transactionReference, required this.amountPaid}) + {Key? key, required this.url, required this.fallBackNamedUrl, required this.ttx}) : super(key: key); @override @@ -48,7 +42,7 @@ class _ChapaWebViewState extends State { }); showErrorToast(ChapaStrings.connectionError); - exitPaymentPage(ChapaStrings.connectionError); + exitPaymentPage(ChapaStrings.connectionError, widget.ttx); } else if (result == ConnectivityResult.mobile) { setState(() { isOffline = false; @@ -65,16 +59,16 @@ class _ChapaWebViewState extends State { setState(() { isOffline = false; }); - exitPaymentPage(ChapaStrings.connectionError); + exitPaymentPage(ChapaStrings.connectionError, widget.ttx); } }); } - void exitPaymentPage(String message) { + void exitPaymentPage(String message, String ttx) { Navigator.pushNamed( context, widget.fallBackNamedUrl, - arguments: {'message': message, 'transactionReference':widget.transactionReference,'paidAmount':widget.amountPaid}, + arguments: {'message': message,'ttx':ttx}, ); } @@ -91,18 +85,18 @@ class _ChapaWebViewState extends State { body: Column(children: [ Expanded( child: InAppWebView( - initialUrlRequest: URLRequest(url: Uri.parse(widget.url)), + initialUrlRequest: URLRequest(url:WebUri(widget.url)), onWebViewCreated: (controller) { setState(() { webViewController = controller; }); controller.addJavaScriptHandler( - handlerName: "buttonState", + handlerName: ChapaStrings.buttonHandler, callback: (args) async { webViewController = controller; - if (args[2][1] == 'CancelbuttonClicked') { - exitPaymentPage('paymentCancelled'); + if (args[2][1] == ChapaStrings.cancelClicked) { + exitPaymentPage(ChapaStrings.paymentCancelled, ""); } return args.reduce((curr, next) => curr + next); @@ -110,35 +104,42 @@ class _ChapaWebViewState extends State { }, onUpdateVisitedHistory: (InAppWebViewController controller, Uri? uri, androidIsReload) async { + if (uri.toString() == 'https://chapa.co') { - exitPaymentPage('paymentSuccessful'); + exitPaymentPage(ChapaStrings.paymentSuccessful, widget.ttx); } if (uri.toString().contains('checkout/payment-receipt/')) { - await delay(); - exitPaymentPage('paymentSuccessful'); - } + await delay(); + exitPaymentPage(ChapaStrings.paymentSuccessful, widget.ttx); + } + if(uri.toString().contains('checkout/test-payment-receipt/')){ + await delay(); + exitPaymentPage(ChapaStrings.paymentSuccessful, widget.ttx); + + } controller.addJavaScriptHandler( - handlerName: "handlerFooWithArgs", + handlerName: ChapaStrings.handlerArgs, callback: (args) async { webViewController = controller; - if (args[2][1] == 'failed') { + + if (args[2][1] == ChapaStrings.failed) { await delay(); - exitPaymentPage('paymentFailed'); + exitPaymentPage(ChapaStrings.payementFailed,""); } - if (args[2][1] == 'success') { + if (args[2][1] == ChapaStrings.success) { await delay(); - exitPaymentPage('paymentSuccessful'); + exitPaymentPage(ChapaStrings.paymentSuccessful, widget.ttx); } return args.reduce((curr, next) => curr + next); }); controller.addJavaScriptHandler( - handlerName: "buttonState", + handlerName: ChapaStrings.buttonHandler, callback: (args) async { webViewController = controller; - if (args[2][1] == 'CancelbuttonClicked') { - exitPaymentPage('paymentCancelled'); + if (args[2][1] == ChapaStrings.cancelClicked) { + exitPaymentPage(ChapaStrings.paymentCancelled,""); } return args.reduce((curr, next) => curr + next); diff --git a/lib/constants/strings.dart b/lib/constants/strings.dart index bcb2e79..e1751cc 100644 --- a/lib/constants/strings.dart +++ b/lib/constants/strings.dart @@ -7,4 +7,12 @@ class ChapaStrings { static const lastNameRequired = 'First Name is required'; static const transactionRefrenceRequired = 'Transaction is required'; static const connectionError='Connectivity Issue'; + static const buttonHandler ='buttonState'; + static const cancelClicked ='CancelbuttonClicked'; + static const paymentCancelled='paymentCancelled'; + static const paymentSuccessful='paymentSuccessful'; + static const handlerArgs='handlerFooWithArgs'; + static const failed='failed'; + static const payementFailed='paymentFailed'; + static const success='Success'; } diff --git a/lib/constants/url.dart b/lib/constants/url.dart index 04b2a4e..814c545 100644 --- a/lib/constants/url.dart +++ b/lib/constants/url.dart @@ -4,9 +4,7 @@ class ChapaUrl { static const String chargeCardUrl = "charges?type=card"; static const String validateCharge = "validate-charge"; static const String defaultRedirectUrl = "https://chapa.co/"; - static const String verifyTransaction = - "https://api.chapa.co/v1/transaction/verify/"; - + static const String verifyTransaction ="https://api.chapa.co/v1/transaction/verify/"; static String getBaseUrl(final bool isDebugMode) { return baseUrl; } diff --git a/lib/constants/utils.dart b/lib/constants/utils.dart new file mode 100644 index 0000000..6b9ce5f --- /dev/null +++ b/lib/constants/utils.dart @@ -0,0 +1,24 @@ +import 'package:fluttertoast/fluttertoast.dart'; +import 'package:flutter/material.dart'; +import 'package:uuid/uuid.dart'; + +Future showToast(jsonResponse) { + return Fluttertoast.showToast( + msg: jsonResponse, + toastLength: Toast.LENGTH_SHORT, + gravity: ToastGravity.CENTER, + timeInSecForIosWeb: 1, + backgroundColor: Colors.red, + textColor: Colors.white, + fontSize: 16.0); +} + +String generateTransactionReference(String companyName) { + var uuid = Uuid(); + String uniqueId = uuid.v4(); + DateTime now = DateTime.now(); + String timestamp = now.millisecondsSinceEpoch.toString(); + String transactionReference = '$companyName-$uniqueId-$timestamp'; + return transactionReference; +} + diff --git a/lib/constants/requests.dart b/lib/service/web_service.dart similarity index 66% rename from lib/constants/requests.dart rename to lib/service/web_service.dart index a5aa475..666c58c 100644 --- a/lib/constants/requests.dart +++ b/lib/service/web_service.dart @@ -1,13 +1,13 @@ import 'dart:convert'; +import 'package:chapasdk/chapawebview.dart'; import 'package:chapasdk/constants/url.dart'; +import 'package:chapasdk/constants/utils.dart'; +import 'package:chapasdk/model/data.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:fluttertoast/fluttertoast.dart'; import 'package:http/http.dart' as http; -import '../chapawebview.dart'; -import '../model/data.dart'; - -Future intilizeMyPayment( +import 'dart:async'; +Future intilizeMyPayment( BuildContext context, String authorization, String email, @@ -15,57 +15,49 @@ Future intilizeMyPayment( String currency, String firstName, String lastName, - String transactionReference, + String companyName, String customTitle, String customDescription, String fallBackNamedRoute, ) async { + String generatedTransactionRef=generateTransactionReference(companyName); + final http.Response response = await http.post( Uri.parse(ChapaUrl.baseUrl), headers: { 'Authorization': 'Bearer $authorization', }, + body: { 'email': email, 'amount': amount, 'currency': currency.toUpperCase(), 'first_name': firstName, 'last_name': lastName, - 'tx_ref': transactionReference, + 'tx_ref':generatedTransactionRef, 'customization[title]': customTitle, 'customization[description]': customDescription }, ); + var jsonResponse = json.decode(response.body); if (response.statusCode == 400) { - showToast(jsonResponse); + showToast(jsonResponse['message']); } else if (response.statusCode == 200) { ResponseData res = ResponseData.fromJson(jsonResponse); - Navigator.push( context, MaterialPageRoute( builder: (context) => ChapaWebView( url: res.data.checkoutUrl.toString(), fallBackNamedUrl: fallBackNamedRoute, - transactionReference: transactionReference, - amountPaid: amount, + ttx: generatedTransactionRef, )), ); return res.data.checkoutUrl.toString(); } - return ''; + return showToast(jsonResponse.toString()); } -Future showToast(jsonResponse) { - return Fluttertoast.showToast( - msg: jsonResponse['message'], - toastLength: Toast.LENGTH_SHORT, - gravity: ToastGravity.CENTER, - timeInSecForIosWeb: 1, - backgroundColor: Colors.red, - textColor: Colors.white, - fontSize: 16.0); -} diff --git a/pubspec.yaml b/pubspec.yaml index 9f03584..e5c503b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,22 +1,23 @@ name: chapasdk description: Chapa flutter library to accept payment via Card, Bank or telebirr etc. -version: 0.0.3 +version: 0.0.5 homepage: https://github.com/chapa-et/chapa-flutter environment: - sdk: ">=2.15.0<3.0.0" + sdk: '>=2.19.3 <4.0.0' flutter: ">=1.17.0" - dependencies: flutter: sdk: flutter - http: ^0.13.0 - flutter_inappwebview: ^5.4.3+7 - connectivity_plus: ^2.3.6+1 - fluttertoast: ^8.0.9 + http: ^1.2.0 + flutter_inappwebview: ^6.0.0 + connectivity_plus: any + fluttertoast: any + mockito: ^5.4.3 + uuid: any dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^1.0.0 + flutter_lints: ^3.0.1 diff --git a/test/chapasdk_test.dart b/test/chapasdk_test.dart index c85760c..bf3218b 100644 --- a/test/chapasdk_test.dart +++ b/test/chapasdk_test.dart @@ -1,7 +1,98 @@ +import 'package:chapasdk/constants/strings.dart'; +import 'package:chapasdk/constants/url.dart'; +import 'package:chapasdk/service/web_service.dart'; +import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; - import 'package:chapasdk/chapasdk.dart'; +import 'package:http/testing.dart'; +import 'package:mockito/mockito.dart'; +import 'package:http/http.dart' as http; +class MockClient extends Mock implements http.Client {} void main() { + WidgetsFlutterBinding.ensureInitialized(); + + group('Chapa', () { + late BuildContext context; + late String publicKey; + late String amount; + late String currency; + late String email; + late String firstName; + late String lastName; + late String txRef; + late String title; + late String desc; + late String namedRouteFallBack; + + setUp(() { + context = MockBuildContext(); + publicKey = 'your_public_key'; + amount = '10.0'; + currency = 'USD'; + email = 'test@example.com'; + firstName = 'John'; + lastName = 'Doe'; + txRef = '1234567890'; + title = 'Payment'; + desc = 'Payment description'; + namedRouteFallBack = '/fallback'; + }); + + test('paymentParameters - valid keys', () { + final chapa = Chapa.paymentParameters( + context: context, + publicKey: publicKey, + currency: currency, + amount: amount, + email: email, + firstName: firstName, + lastName: lastName, + companyName: txRef, + title: title, + desc: desc, + namedRouteFallBack: namedRouteFallBack, + ); + + expect(chapa, isNotNull); + expect(chapa.validateKeys(), isTrue); + }); + + test('paymentParameters - invalid public key', () { + final invalidPublicKey = ''; + final chapa = Chapa.paymentParameters( + context: context, + publicKey: invalidPublicKey, + currency: currency, + amount: amount, + email: email, + firstName: firstName, + lastName: lastName, + companyName: txRef, + title: title, + desc: desc, + namedRouteFallBack: namedRouteFallBack, + ); + + expect(chapa, isNotNull); + expect(chapa.validateKeys(), isFalse); + expect(showErrorToastCalled, isFalse); + expect(showErrorToastMessage, equals('')); + }); + + + }); + +} +class MockBuildContext extends Mock implements BuildContext { + +} + +bool showErrorToastCalled = false; +String showErrorToastMessage = ''; +void showErrorToast(String message) { + showErrorToastCalled = true; + showErrorToastMessage = message; } +void showToast(dynamic message) {}