diff --git a/android/src/main/java/tap/company/go_sell_sdk_flutter/GoSellSdKDelegate.java b/android/src/main/java/tap/company/go_sell_sdk_flutter/GoSellSdKDelegate.java index 2b93465..fe06bd2 100644 --- a/android/src/main/java/tap/company/go_sell_sdk_flutter/GoSellSdKDelegate.java +++ b/android/src/main/java/tap/company/go_sell_sdk_flutter/GoSellSdKDelegate.java @@ -195,7 +195,7 @@ private void configureSDKSession(HashMap sessionParameters, Meth sdkSession.setPaymentDescription(sessionParameters.get("paymentDescription").toString()); // ** Optional ** // Payment Extra Info - sdkSession.setPaymentMetadata(DeserializationUtil.getMetaData(sessionParameters.get("paymenMetaData")));// ** + sdkSession.setPaymentMetadata(DeserializationUtil.getMetaData(sessionParameters.get("paymentMetadata")));// ** // Optional // ** // you diff --git a/example/lib/main.dart b/example/lib/main.dart index 58c9e66..3775f89 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -89,7 +89,7 @@ class _MyAppState extends State { // Payment description paymentDescription: "paymentDescription", // Payment Metadata - paymentMetaData: { + paymentMetadata: { "a": "a meta", "b": "b meta", }, diff --git a/example/pubspec.lock b/example/pubspec.lock index 476d078..d94c56b 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,42 +7,42 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety.1" + version: "2.6.1" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.3" + version: "1.15.0" cupertino_icons: dependency: "direct main" description: @@ -56,7 +56,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -73,28 +73,28 @@ packages: path: ".." relative: true source: path - version: "2.0.5" + version: "2.0.7" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10-nullsafety.1" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.1" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -106,56 +106,56 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.2" + version: "1.8.1" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.1" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19-nullsafety.2" + version: "0.3.0" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" sdks: - dart: ">=2.10.0-110 <2.11.0" + dart: ">=2.12.0 <3.0.0" flutter: ">=1.10.0" diff --git a/ios/Classes/SwiftGoSellSdkFlutterPlugin.swift b/ios/Classes/SwiftGoSellSdkFlutterPlugin.swift index a05d781..2ffb8d6 100644 --- a/ios/Classes/SwiftGoSellSdkFlutterPlugin.swift +++ b/ios/Classes/SwiftGoSellSdkFlutterPlugin.swift @@ -261,6 +261,25 @@ extension SwiftGoSellSdkFlutterPlugin: SessionDataSource { } return nil } + + + public var paymentMetadata: Metadata? { + if let paymentMetadataString:String = argsSessionParameters?["paymentMetadata"] as? String { + if let data = paymentMetadataString.data(using: .utf8) { + do { + let decoder = JSONDecoder() + let paymentMetadataObject:Metadata = try decoder.decode(Metadata.self, from: data) + return paymentMetadataObject + } catch { + print(error.localizedDescription) + } + } + } + return nil + } + + + public var receiptSettings: Receipt? { if let receiptSettingsString:String = argsSessionParameters?["receiptSettings"] as? String { if let data = receiptSettingsString.data(using: .utf8) { diff --git a/lib/go_sell_sdk_flutter.dart b/lib/go_sell_sdk_flutter.dart index 845aef6..87bbed2 100644 --- a/lib/go_sell_sdk_flutter.dart +++ b/lib/go_sell_sdk_flutter.dart @@ -9,16 +9,21 @@ class GoSellSdkFlutter { static const String ERROR_CODE_INVALID_APP_CONFIGURATION = "501"; static Map _tapSDKResult = Map(); - static const MethodChannel _channel = const MethodChannel('go_sell_sdk_flutter'); + static const MethodChannel _channel = + const MethodChannel('go_sell_sdk_flutter'); static Future get startPaymentSDK async { if (!_validateSessionArge() || _validateAppConfig()) return _tapSDKResult; /// prepare sdk configurations - sdkConfigurations = {"appCredentials": appCredentials, "sessionParameters": sessionParameters}; + sdkConfigurations = { + "appCredentials": appCredentials, + "sessionParameters": sessionParameters + }; // /forward call to channel - dynamic result = await _channel.invokeMethod('start_sdk', sdkConfigurations); + dynamic result = + await _channel.invokeMethod('start_sdk', sdkConfigurations); print('result in dart : $result'); return result; } @@ -27,12 +32,17 @@ class GoSellSdkFlutter { _channel.invokeMethod('terminate_session'); } - static Map sdkConfigurations; - static Map appCredentials; - static Map sessionParameters; + static late Map sdkConfigurations; + static late Map appCredentials; + static late Map sessionParameters; /// App configurations - static void configureApp({String productionSecreteKey, String sandBoxsecretKey, String bundleId, String lang}) { + static void configureApp({ + required String productionSecreteKey, + required String sandBoxsecretKey, + required String bundleId, + required String lang, + }) { appCredentials = { "production_secrete_key": productionSecreteKey, "sandbox_secrete_key": sandBoxsecretKey, @@ -43,31 +53,31 @@ class GoSellSdkFlutter { /// session configurations static void sessionConfigurations({ - TransactionMode trxMode, - String transactionCurrency, - String amount, - Customer customer, - List paymentItems, - List taxes, - List shippings, - String postURL, - String paymentDescription, - Map paymentMetaData, - Reference paymentReference, - String paymentStatementDescriptor, - bool isUserAllowedToSaveCard, - bool isRequires3DSecure, - Receipt receipt, - AuthorizeAction authorizeAction, - Destinations destinations, - String merchantID, - CardType allowedCadTypes, - String applePayMerchantID, - SDKMode sdkMode, - PaymentType paymentType, - bool allowsToSaveSameCardMoreThanOnce, - String cardHolderName, - bool allowsToEditCardHolderName, + required TransactionMode trxMode, + required String transactionCurrency, + required String amount, + required Customer customer, + required List paymentItems, + List? taxes, + List? shippings, + required String postURL, + required String paymentDescription, + required Map paymentMetadata, + required Reference paymentReference, + required String paymentStatementDescriptor, + required bool isUserAllowedToSaveCard, + required bool isRequires3DSecure, + required Receipt receipt, + required AuthorizeAction authorizeAction, + Destinations? destinations, + required String merchantID, + CardType? allowedCadTypes, + required String applePayMerchantID, + required SDKMode sdkMode, + required PaymentType paymentType, + required bool allowsToSaveSameCardMoreThanOnce, + String? cardHolderName, + bool? allowsToEditCardHolderName, }) { sessionParameters = { 'trxMode': trxMode.toString(), @@ -79,7 +89,7 @@ class GoSellSdkFlutter { "shipping": jsonEncode(shippings), "postURL": postURL, "paymentDescription": paymentDescription, - "paymenMetaData": jsonEncode(paymentMetaData), + "paymentMetadata": jsonEncode(paymentMetadata), "paymentReference": jsonEncode(paymentReference), "paymentStatementDescriptor": paymentStatementDescriptor, "isUserAllowedToSaveCard": isUserAllowedToSaveCard, @@ -100,9 +110,13 @@ class GoSellSdkFlutter { /// validate app configurations static bool _validateAppConfig() { - if (appCredentials["bundleId"] == "" || appCredentials["bundleId"] == "null" || appCredentials["bundleId"] == null) { + if (appCredentials["bundleId"] == "" || + appCredentials["bundleId"] == "null" || + appCredentials["bundleId"] == null) { _prepareConfigurationsErrorMap( - errorCode: ERROR_CODE_INVALID_APP_CONFIGURATION, errorMsg: 'Invalid Bundle ID', errorDescription: 'Bundle ID can not be empty or null'); + errorCode: ERROR_CODE_INVALID_APP_CONFIGURATION, + errorMsg: 'Invalid Bundle ID', + errorDescription: 'Bundle ID can not be empty or null'); return false; } @@ -126,9 +140,13 @@ class GoSellSdkFlutter { return false; } - if (appCredentials["lang"] == "" || appCredentials["lang"] == "null" || appCredentials["lang"] == null) { + if (appCredentials["lang"] == "" || + appCredentials["lang"] == "null" || + appCredentials["lang"] == null) { _prepareConfigurationsErrorMap( - errorCode: ERROR_CODE_INVALID_SESSION_CONFIGURATION, errorMsg: 'Invalid language', errorDescription: 'Language can not empty or null'); + errorCode: ERROR_CODE_INVALID_SESSION_CONFIGURATION, + errorMsg: 'Invalid language', + errorDescription: 'Language can not empty or null'); return false; } return true; @@ -136,7 +154,9 @@ class GoSellSdkFlutter { static bool _validateSessionArge() { // validate trx mode - if (sessionParameters["trxMode"] == "" || sessionParameters["trxMode"] == "null" || sessionParameters["trxMode"] == null) { + if (sessionParameters["trxMode"] == "" || + sessionParameters["trxMode"] == "null" || + sessionParameters["trxMode"] == null) { _prepareConfigurationsErrorMap( errorCode: ERROR_CODE_INVALID_SESSION_CONFIGURATION, errorMsg: 'Invalid Transaction Mode', @@ -156,18 +176,24 @@ class GoSellSdkFlutter { } // validate customer - if (sessionParameters["customer"] == "null" || sessionParameters["customer"] == null) { + if (sessionParameters["customer"] == "null" || + sessionParameters["customer"] == null) { _prepareConfigurationsErrorMap( - errorCode: ERROR_CODE_INVALID_SESSION_CONFIGURATION, errorMsg: 'Invalid Customer', errorDescription: 'Customer can not be empty or null'); + errorCode: ERROR_CODE_INVALID_SESSION_CONFIGURATION, + errorMsg: 'Invalid Customer', + errorDescription: 'Customer can not be empty or null'); return false; } // validate amount - if (sessionParameters["amount"] == "null" || !Util.isNumeric(sessionParameters["amount"]) || sessionParameters["amount"] == "") { + if (sessionParameters["amount"] == "null" || + !Util.isNumeric(sessionParameters["amount"]) || + sessionParameters["amount"] == "") { _prepareConfigurationsErrorMap( errorCode: ERROR_CODE_INVALID_SESSION_CONFIGURATION, errorMsg: 'Invalid Amount', - errorDescription: 'Amount can not be empty or null or zero and must be numeric value'); + errorDescription: + 'Amount can not be empty or null or zero and must be numeric value'); return false; } @@ -182,12 +208,17 @@ class GoSellSdkFlutter { } static void _validateBooleanValues(String param) { - if (sessionParameters[param] == "null" || sessionParameters[param] == null || sessionParameters[param] == "") { + if (sessionParameters[param] == "null" || + sessionParameters[param] == null || + sessionParameters[param] == "") { sessionParameters[param] = false; } } - static void _prepareConfigurationsErrorMap({String errorCode, String errorMsg, String errorDescription}) { + static void _prepareConfigurationsErrorMap( + {required String errorCode, + required String errorMsg, + String? errorDescription}) { _tapSDKResult.putIfAbsent('sdk_result', () => 'SDK_ERROR'); _tapSDKResult.putIfAbsent('sdk_error_code', () => errorCode); _tapSDKResult.putIfAbsent('sdk_error_message', () => errorMsg); diff --git a/lib/model/models.dart b/lib/model/models.dart index 6b355ee..f5ec33b 100644 --- a/lib/model/models.dart +++ b/lib/model/models.dart @@ -1,11 +1,11 @@ class Reference { - String acquirer; - String gateway; - String payment; - String track; - String transaction; - String order; - String gosellID; + String? acquirer; + String? gateway; + String? payment; + String? track; + String? transaction; + String? order; + String? gosellID; Reference( {this.acquirer, @@ -32,7 +32,7 @@ class Reference { class Receipt { bool sms; bool email; - String id; + String? id; Receipt(this.sms, this.email, {this.id}); Map toJson() { @@ -45,21 +45,21 @@ class Receipt { } class Customer { - String firstName; - String middleName; - String lastName; - String email; + String? firstName; + String? middleName; + String? lastName; + String? email; // Phone phone; - String isdNumber; - String number; + String? isdNumber; + String? number; String customerId; - String metaData; + String? metaData; Customer( {this.isdNumber, this.number, - this.customerId, + required this.customerId, this.email, this.firstName, this.middleName, @@ -83,10 +83,10 @@ class Customer { } class Destinations { - double amount; - String currency; - int count; - List destinationlist; + double? amount; + String? currency; + int? count; + List? destinationlist; Destinations({this.amount, this.currency, this.count, this.destinationlist}); @@ -98,7 +98,7 @@ class Destinations { if (this.destinationlist != null) { data['destination'] = - this.destinationlist.map((v) => v.toJson()).toList(); + this.destinationlist!.map((v) => v.toJson()).toList(); } return data; @@ -106,11 +106,11 @@ class Destinations { } class Destination { - String id; - double amount; - String currency; - String description; - String reference; + String? id; + double? amount; + String? currency; + String? description; + String? reference; Destination( {this.id, this.amount, this.currency, this.description, this.reference}); @@ -129,15 +129,15 @@ class Destination { class PaymentItem { int amountPerUnit; String description; - Map discount; - String name; - Quantity quantity; - List taxes; - int totalAmount; + Map? discount; + String? name; + Quantity? quantity; + List? taxes; + int? totalAmount; PaymentItem( - {this.amountPerUnit, - this.description, + {this.amountPerUnit = 0, + this.description = '', this.discount, this.name, this.quantity, @@ -153,11 +153,11 @@ class PaymentItem { data['name'] = this.name; if (this.quantity != null) { - data['quantity'] = this.quantity.toJson(); + data['quantity'] = this.quantity!.toJson(); } if (this.taxes != null) { - data['taxes'] = this.taxes.map((v) => v.toJson()).toList(); + data['taxes'] = this.taxes!.map((v) => v.toJson()).toList(); } data['total_amount'] = this.totalAmount; @@ -167,11 +167,15 @@ class PaymentItem { } class Amount { - String type; - double value; - double maximumFee; - double minimumFee; - Amount({this.type, this.value, this.maximumFee, this.minimumFee}); + final String type; + final double value; + final double maximumFee; + final double minimumFee; + const Amount( + {this.type = '', + this.value = 0.0, + this.maximumFee = 0.0, + this.minimumFee = 0.0}); Map toJson() { final Map data = new Map(); @@ -186,7 +190,7 @@ class Amount { class Quantity { int value; - Quantity({this.value}); + Quantity({this.value = 0}); Map toJson() { final Map data = new Map(); @@ -200,7 +204,7 @@ class Tax { String description; Amount amount; - Tax({this.amount, this.name, this.description}); + Tax({this.amount = const Amount(), this.name = '', this.description = ''}); Map toJson() { final Map data = new Map(); @@ -218,7 +222,7 @@ class Shipping { String description; double amount; - Shipping({this.name, this.description, this.amount}); + Shipping({this.name = '', this.description = '', this.amount = 0.0}); Map toJson() { final Map data = new Map(); @@ -233,7 +237,7 @@ class AuthorizeAction { AuthorizeActionType type; int timeInHours; - AuthorizeAction({this.type, this.timeInHours}); + AuthorizeAction({required this.type, required this.timeInHours}); Map toJson() { final Map data = new Map(); diff --git a/lib/utils/util.dart b/lib/utils/util.dart index 682c4e9..6b30498 100644 --- a/lib/utils/util.dart +++ b/lib/utils/util.dart @@ -1,15 +1,13 @@ -mixin Util{ -static bool isNumeric(String s) { - +mixin Util { + static bool isNumeric(String? s) { if (s == null || s.contains('-')) { return false; } - String finalString = s.replaceAll('.','').replaceAll('0',''); - if(finalString.isEmpty){ + String finalString = s.replaceAll('.', '').replaceAll('0', ''); + if (finalString.isEmpty) { return false; } // return double.parse(s, (e) => null) != null; - return (double.tryParse(s) ?? null) !=null; + return (double.tryParse(s) ?? null) != null; } } - \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index 706519b..6dc48a2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,49 +7,49 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety.1" + version: "2.6.1" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.3" + version: "1.15.0" fake_async: dependency: transitive description: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -66,21 +66,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10-nullsafety.1" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.1" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -92,56 +92,56 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.2" + version: "1.8.1" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.1" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19-nullsafety.2" + version: "0.3.0" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" sdks: - dart: ">=2.10.0-110 <2.11.0" + dart: ">=2.12.0 <3.0.0" flutter: ">=1.10.0" diff --git a/pubspec.yaml b/pubspec.yaml index dfe9fd2..220f85c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ version: 2.0.7 homepage: https://github.com/Tap-Payments/gosellSDK-Flutter.git environment: - sdk: ">=2.1.0 <3.0.0" + sdk: ">=2.12.0 <3.0.0" flutter: ">=1.10.0" dependencies: