From 0473ac6cb4f940635a9981f065395e4277540c5b Mon Sep 17 00:00:00 2001 From: AmmarElgml Date: Mon, 15 Jan 2024 17:12:22 +0200 Subject: [PATCH 1/5] Feat-Unify all imports --- example/lib/main.dart | 9 +-------- example/pubspec.lock | 2 +- lib/paytabs_payment.dart | 8 ++++++++ 3 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 lib/paytabs_payment.dart diff --git a/example/lib/main.dart b/example/lib/main.dart index 5a5d606..da1a423 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -2,14 +2,7 @@ import 'dart:async'; import 'dart:io' show Platform; import 'package:flutter/material.dart'; -import 'package:flutter_paytabs_bridge/BaseBillingShippingInfo.dart'; -import 'package:flutter_paytabs_bridge/IOSThemeConfiguration.dart'; -import 'package:flutter_paytabs_bridge/PaymentSDKQueryConfiguration.dart'; -import 'package:flutter_paytabs_bridge/PaymentSDKSavedCardInfo.dart'; -import 'package:flutter_paytabs_bridge/PaymentSdkApms.dart'; -import 'package:flutter_paytabs_bridge/PaymentSdkConfigurationDetails.dart'; -import 'package:flutter_paytabs_bridge/PaymentSdkTokeniseType.dart'; -import 'package:flutter_paytabs_bridge/flutter_paytabs_bridge.dart'; +import 'package:flutter_paytabs_bridge/paytabs_payment.dart'; void main() { runApp(MyApp()); diff --git a/example/pubspec.lock b/example/pubspec.lock index bfba408..3dea411 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -76,7 +76,7 @@ packages: path: ".." relative: true source: path - version: "2.6.5" + version: "2.6.7" flutter_test: dependency: "direct dev" description: flutter diff --git a/lib/paytabs_payment.dart b/lib/paytabs_payment.dart new file mode 100644 index 0000000..52cd064 --- /dev/null +++ b/lib/paytabs_payment.dart @@ -0,0 +1,8 @@ +export 'BaseBillingShippingInfo.dart'; +export 'IOSThemeConfiguration.dart'; +export 'PaymentSDKQueryConfiguration.dart'; +export 'PaymentSDKSavedCardInfo.dart'; +export 'PaymentSdkApms.dart'; +export 'PaymentSdkConfigurationDetails.dart'; +export 'PaymentSdkTokeniseType.dart'; +export 'flutter_paytabs_bridge.dart'; From b71107416b6e6c5ecac068b48371c2980370d4f9 Mon Sep 17 00:00:00 2001 From: AmmarElgml Date: Mon, 15 Jan 2024 17:13:32 +0200 Subject: [PATCH 2/5] Feat-Added named params for shipping and billing details models --- .idea/codeStyles/Project.xml | 129 +++++++++++++++++++++++++++ .idea/codeStyles/codeStyleConfig.xml | 5 ++ .idea/libraries/Dart_SDK.xml | 42 ++++----- .idea/libraries/Flutter_Plugins.xml | 6 +- example/lib/main.dart | 25 +++++- lib/BaseBillingShippingInfo.dart | 47 +++++----- 6 files changed, 200 insertions(+), 54 deletions(-) create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..9f62527 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml index e5a15c2..fcbce96 100644 --- a/.idea/libraries/Dart_SDK.xml +++ b/.idea/libraries/Dart_SDK.xml @@ -1,27 +1,27 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + diff --git a/.idea/libraries/Flutter_Plugins.xml b/.idea/libraries/Flutter_Plugins.xml index 8314cce..831e2b7 100644 --- a/.idea/libraries/Flutter_Plugins.xml +++ b/.idea/libraries/Flutter_Plugins.xml @@ -1,12 +1,12 @@ - - + - + + diff --git a/example/lib/main.dart b/example/lib/main.dart index da1a423..30b38eb 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -22,10 +22,27 @@ class _MyAppState extends State { } PaymentSdkConfigurationDetails generateConfig() { - var billingDetails = BillingDetails("John Smith", "email@domain.com", - "+97311111111", "st. 12", "eg", "dubai", "dubai", "12345"); - var shippingDetails = ShippingDetails("John Smith", "email@domain.com", - "+97311111111", "st. 12", "eg", "dubai", "dubai", "12345"); + var billingDetails = BillingDetails( + name: "John Smith", + email: "email@domain.com", + phone: "+97311111111", + addressLine: "st. 12", + country: "eg", + city: "dubai", + state: "dubai", + zipCode: "12345", + ); + var shippingDetails = ShippingDetails( + name: "John Smith", + email: "email@domain.com", + phone: "+97311111111", + addressLine: "st. 12", + country: "eg", + city: "dubai", + state: "dubai", + zipCode: "12345", + ); + List apms = []; apms.add(PaymentSdkAPms.AMAN); final configuration = PaymentSdkConfigurationDetails( diff --git a/lib/BaseBillingShippingInfo.dart b/lib/BaseBillingShippingInfo.dart index 6cd6e19..55d863a 100644 --- a/lib/BaseBillingShippingInfo.dart +++ b/lib/BaseBillingShippingInfo.dart @@ -3,16 +3,16 @@ import 'flutter_paytabs_bridge.dart'; class BillingDetails { String name, email, phone, addressLine, country, city, state, zipCode; - BillingDetails( - this.name, - this.email, - this.phone, - this.addressLine, - this.country, - this.city, - this.state, - this.zipCode, - ); + BillingDetails({ + required this.name, + required this.email, + required this.phone, + required this.addressLine, + required this.country, + required this.city, + required this.state, + required this.zipCode, + }); } extension BillingDetailsExtension on BillingDetails { @@ -31,23 +31,18 @@ extension BillingDetailsExtension on BillingDetails { } class ShippingDetails { - String name; - String email; - String phone; - String addressLine; - String country; - String city, state, zipCode; + String name, email, phone, addressLine, country, city, state, zipCode; - ShippingDetails( - this.name, - this.email, - this.phone, - this.addressLine, - this.country, - this.city, - this.state, - this.zipCode, - ); + ShippingDetails({ + required this.name, + required this.email, + required this.phone, + required this.addressLine, + required this.country, + required this.city, + required this.state, + required this.zipCode, + }); } extension ShippingDetailsExtension on ShippingDetails { From da28966df0b3a961a81db409897446241a737467 Mon Sep 17 00:00:00 2001 From: AmmarElgml Date: Mon, 22 Jan 2024 16:30:18 +0200 Subject: [PATCH 3/5] Fix-Comment unused variable --- lib/flutter_paytabs_bridge.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/flutter_paytabs_bridge.dart b/lib/flutter_paytabs_bridge.dart index bdd0b06..07f19c2 100644 --- a/lib/flutter_paytabs_bridge.dart +++ b/lib/flutter_paytabs_bridge.dart @@ -236,8 +236,8 @@ class FlutterPaytabsBridge { static Future clearSavedCards() async { MethodChannel localChannel = MethodChannel('flutter_paytabs_bridge'); - EventChannel localStream = - const EventChannel('flutter_paytabs_bridge_stream'); + // EventChannel localStream = + // const EventChannel('flutter_paytabs_bridge_stream'); return await localChannel.invokeMethod('clearSavedCards'); } From 05ccd686df5422baef55cf99c652119a6190b402 Mon Sep 17 00:00:00 2001 From: AmmarElgml Date: Wed, 31 Jan 2024 12:43:41 +0200 Subject: [PATCH 4/5] Fix-add a create constructor for both shipping and billing details for more readability --- example/lib/main.dart | 171 +++++++++++++++---------------- lib/BaseBillingShippingInfo.dart | 34 +++++- 2 files changed, 113 insertions(+), 92 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 30b38eb..a64c0ff 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -23,24 +23,24 @@ class _MyAppState extends State { PaymentSdkConfigurationDetails generateConfig() { var billingDetails = BillingDetails( - name: "John Smith", - email: "email@domain.com", - phone: "+97311111111", - addressLine: "st. 12", - country: "eg", - city: "dubai", - state: "dubai", - zipCode: "12345", + "John Smith", + "email@domain.com", + "+97311111111", + "st. 12", + "eg", + "dubai", + "dubai", + "12345", ); var shippingDetails = ShippingDetails( - name: "John Smith", - email: "email@domain.com", - phone: "+97311111111", - addressLine: "st. 12", - country: "eg", - city: "dubai", - state: "dubai", - zipCode: "12345", + "John Smith", + "email@domain.com", + "+97311111111", + "st. 12", + "eg", + "dubai", + "dubai", + "12345", ); List apms = []; @@ -98,8 +98,7 @@ class _MyAppState extends State { } Future payWithTokenPressed() async { - FlutterPaytabsBridge.startTokenizedCardPayment( - generateConfig(), "*Token*", "*TransactionReference*", (event) { + FlutterPaytabsBridge.startTokenizedCardPayment(generateConfig(), "*Token*", "*TransactionReference*", (event) { setState(() { if (event["status"] == "success") { // Handle transaction details here. @@ -126,9 +125,7 @@ class _MyAppState extends State { Future payWith3ds() async { FlutterPaytabsBridge.start3DSecureTokenizedCardPayment( - generateConfig(), - PaymentSDKSavedCardInfo("4111 11## #### 1111", "visa"), - "*Token*", (event) { + generateConfig(), PaymentSDKSavedCardInfo("4111 11## #### 1111", "visa"), "*Token*", (event) { setState(() { if (event["status"] == "success") { // Handle transaction details here. @@ -154,8 +151,7 @@ class _MyAppState extends State { } Future payWithSavedCards() async { - FlutterPaytabsBridge.startPaymentWithSavedCards(generateConfig(), false, - (event) { + FlutterPaytabsBridge.startPaymentWithSavedCards(generateConfig(), false, (event) { setState(() { if (event["status"] == "success") { // Handle transaction details here. @@ -181,8 +177,7 @@ class _MyAppState extends State { } Future apmsPayPressed() async { - FlutterPaytabsBridge.startAlternativePaymentMethod(generateConfig(), - (event) { + FlutterPaytabsBridge.startAlternativePaymentMethod(generateConfig(), (event) { setState(() { if (event["status"] == "success") { // Handle transaction details here. @@ -198,8 +193,7 @@ class _MyAppState extends State { } Future queryPressed() async { - FlutterPaytabsBridge.queryTransaction( - generateConfig(), generateQueryConfig(), (event) { + FlutterPaytabsBridge.queryTransaction(generateConfig(), generateQueryConfig(), (event) { setState(() { if (event["status"] == "success") { // Handle transaction details here. @@ -262,67 +256,64 @@ class _MyAppState extends State { title: const Text('PayTabs Plugin Example App'), ), body: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text('$_instructions'), - SizedBox(height: 16), - TextButton( - onPressed: () { - payPressed(); - }, - child: Text('Pay with Card'), - ), - TextButton( - onPressed: () { - Future.delayed(const Duration(seconds: 20)).then( - (value) => FlutterPaytabsBridge.cancelPayment((dynamic) { - debugPrint("cancel payment $dynamic"); - })); - }, - child: Text('Cancel Payment After 20 sec'), - ), - TextButton( - onPressed: () { - payWithTokenPressed(); - }, - child: Text('Pay with Token'), - ), - TextButton( - onPressed: () { - payWith3ds(); - }, - child: Text('Pay with 3ds'), - ), - TextButton( - onPressed: () { - payWithSavedCards(); - }, - child: Text('Pay with saved cards'), - ), - SizedBox(height: 16), - TextButton( - onPressed: () { - apmsPayPressed(); - }, - child: Text('Pay with Alternative payment methods'), - ), - SizedBox(height: 16), - TextButton( - onPressed: () { - queryPressed(); - }, - child: Text('Query transaction'), - ), - TextButton( - onPressed: () { - _clearSavedCards(); - }, - child: Text('Clear saved cards'), - ), - SizedBox(height: 16), - applePayButton() - ])), + child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [ + Text('$_instructions'), + SizedBox(height: 16), + TextButton( + onPressed: () { + payPressed(); + }, + child: Text('Pay with Card'), + ), + TextButton( + onPressed: () { + Future.delayed(const Duration(seconds: 20)).then((value) => FlutterPaytabsBridge.cancelPayment((dynamic) { + debugPrint("cancel payment $dynamic"); + })); + }, + child: Text('Cancel Payment After 20 sec'), + ), + TextButton( + onPressed: () { + payWithTokenPressed(); + }, + child: Text('Pay with Token'), + ), + TextButton( + onPressed: () { + payWith3ds(); + }, + child: Text('Pay with 3ds'), + ), + TextButton( + onPressed: () { + payWithSavedCards(); + }, + child: Text('Pay with saved cards'), + ), + SizedBox(height: 16), + TextButton( + onPressed: () { + apmsPayPressed(); + }, + child: Text('Pay with Alternative payment methods'), + ), + SizedBox(height: 16), + TextButton( + onPressed: () { + queryPressed(); + }, + child: Text('Query transaction'), + ), + TextButton( + onPressed: () { + _clearSavedCards(); + }, + child: Text('Clear saved cards'), + ), + SizedBox(height: 16), + applePayButton() + ])), ), ); } @@ -333,7 +324,7 @@ class _MyAppState extends State { } PaymentSDKQueryConfiguration generateQueryConfig() { - return new PaymentSDKQueryConfiguration("ServerKey", "ClientKey", - "Country Iso 2", "Profile Id", "Transaction Reference"); + return new PaymentSDKQueryConfiguration( + "ServerKey", "ClientKey", "Country Iso 2", "Profile Id", "Transaction Reference"); } } diff --git a/lib/BaseBillingShippingInfo.dart b/lib/BaseBillingShippingInfo.dart index 55d863a..596b18b 100644 --- a/lib/BaseBillingShippingInfo.dart +++ b/lib/BaseBillingShippingInfo.dart @@ -3,7 +3,22 @@ import 'flutter_paytabs_bridge.dart'; class BillingDetails { String name, email, phone, addressLine, country, city, state, zipCode; - BillingDetails({ + @Deprecated(""" + This constructor is deprecated for general usage in favor of the `create` constructor with named parameters. Please migrate to the `create` constructor for more readable and user-friendly syntax. + Example usage: BillingDetails.create(name: "John", email: "john@example.com", ...); + """) + BillingDetails( + this.name, + this.email, + this.phone, + this.addressLine, + this.country, + this.city, + this.state, + this.zipCode, + ); + + BillingDetails.create({ required this.name, required this.email, required this.phone, @@ -33,7 +48,22 @@ extension BillingDetailsExtension on BillingDetails { class ShippingDetails { String name, email, phone, addressLine, country, city, state, zipCode; - ShippingDetails({ + @Deprecated(""" + This constructor is deprecated for general usage in favor of the `create` constructor with named parameters. Please migrate to the `create` constructor for more readable and user-friendly syntax. + Example usage: ShippingDetails.create(name: "John", email: "john@example.com", ...); + """) + ShippingDetails( + this.name, + this.email, + this.phone, + this.addressLine, + this.country, + this.city, + this.state, + this.zipCode, + ); + + ShippingDetails.create({ required this.name, required this.email, required this.phone, From dc44c520ed4328aca58ca99226b7740aca14c121 Mon Sep 17 00:00:00 2001 From: AmmarElgml Date: Wed, 31 Jan 2024 16:47:42 +0200 Subject: [PATCH 5/5] Update README --- README.md | 49 +++++++++++++++++++------------------------ example/lib/main.dart | 37 ++++++++++++++++---------------- 2 files changed, 41 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index bd0f8b9..b3aa2e8 100644 --- a/README.md +++ b/README.md @@ -18,16 +18,7 @@ dependencies: ## Usage ```dart -import 'package:flutter_paytabs_bridge/BaseBillingShippingInfo.dart'; -import 'package:flutter_paytabs_bridge/PaymentSdkConfigurationDetails.dart'; -import 'package:flutter_paytabs_bridge/PaymentSdkLocale.dart'; -import 'package:flutter_paytabs_bridge/PaymentSdkTokenFormat.dart'; -import 'package:flutter_paytabs_bridge/PaymentSdkTokeniseType.dart'; -import 'package:flutter_paytabs_bridge/flutter_paytabs_bridge.dart'; -import 'package:flutter_paytabs_bridge/IOSThemeConfiguration.dart'; -import 'package:flutter_paytabs_bridge/PaymentSDKSavedCardInfo.dart'; -import 'package:flutter_paytabs_bridge/PaymentSdkTransactionClass.dart'; -import 'package:flutter_paytabs_bridge/PaymentSDKQueryConfiguration.dart'; +import 'package:flutter_paytabs_bridge/paytabs_payment.dart'; ``` ### Pay with Card @@ -35,23 +26,27 @@ import 'package:flutter_paytabs_bridge/PaymentSDKQueryConfiguration.dart'; 1. Configure the billing & shipping info, the shipping info is optional ```dart - var billingDetails = new BillingDetails("billing name", - "billing email", - "billing phone", - "address line", - "country", - "city", - "state", - "zip code"); - -var shippingDetails = new ShippingDetails("shipping name", - "shipping email", - "shipping phone", - "address line", - "country", - "city", - "state", - "zip code"); + var billingDetails = BillingDetails.create( + name: "John Smith", + email: "email@domain.com", + phone: "+97311111111", + addressLine: "st. 12", + country: "eg", + city: "dubai", + state: "dubai", + zipCode: "12345", +); + +var shippingDetails = ShippingDetails.create( + name: "John Smith", + email: "email@domain.com", + phone: "+97311111111", + addressLine: "st. 12", + country: "eg", + city: "dubai", + state: "dubai", + zipCode: "12345", +); ``` diff --git a/example/lib/main.dart b/example/lib/main.dart index a64c0ff..6702220 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -22,25 +22,26 @@ class _MyAppState extends State { } PaymentSdkConfigurationDetails generateConfig() { - var billingDetails = BillingDetails( - "John Smith", - "email@domain.com", - "+97311111111", - "st. 12", - "eg", - "dubai", - "dubai", - "12345", + var billingDetails = BillingDetails.create( + name: "John Smith", + email: "email@domain.com", + phone: "+97311111111", + addressLine: "st. 12", + country: "eg", + city: "dubai", + state: "dubai", + zipCode: "12345", ); - var shippingDetails = ShippingDetails( - "John Smith", - "email@domain.com", - "+97311111111", - "st. 12", - "eg", - "dubai", - "dubai", - "12345", + + var shippingDetails = ShippingDetails.create( + name: "John Smith", + email: "email@domain.com", + phone: "+97311111111", + addressLine: "st. 12", + country: "eg", + city: "dubai", + state: "dubai", + zipCode: "12345", ); List apms = [];