diff --git a/binary-websocket-api b/binary-websocket-api index 4f8dc8e529..7bea0264ab 160000 --- a/binary-websocket-api +++ b/binary-websocket-api @@ -1 +1 @@ -Subproject commit 4f8dc8e529a455a3bb46ba980124fa354c4384f4 +Subproject commit 7bea0264ab42db03c455204e5675eff29251e6ff diff --git a/lib/api/response/p2p_country_list_response_result.dart b/lib/api/response/p2p_country_list_response_result.dart new file mode 100644 index 0000000000..3797582302 --- /dev/null +++ b/lib/api/response/p2p_country_list_response_result.dart @@ -0,0 +1,373 @@ +// ignore_for_file: prefer_single_quotes, unnecessary_import, unused_import + +import 'package:equatable/equatable.dart'; + +import 'package:flutter_deriv_api/helpers/helpers.dart'; + +/// P2p country list response model class. +abstract class P2pCountryListResponseModel { + /// Initializes P2p country list response model class . + const P2pCountryListResponseModel({ + this.p2pCountryList, + }); + + /// Country identified by country code + final Map? p2pCountryList; +} + +/// P2p country list response class. +class P2pCountryListResponse extends P2pCountryListResponseModel { + /// Initializes P2p country list response class. + const P2pCountryListResponse({ + super.p2pCountryList, + }); + + /// Creates an instance from JSON. + factory P2pCountryListResponse.fromJson( + dynamic p2pCountryListJson, + ) => + P2pCountryListResponse( + p2pCountryList: p2pCountryListJson == null + ? null + : Map.fromEntries(p2pCountryListJson + .entries + .map>( + (MapEntry entry) => + MapEntry(entry.key, + P2pCountryListProperty.fromJson(entry.value)))), + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + resultMap['p2p_country_list'] = p2pCountryList; + + return resultMap; + } + + /// Creates a copy of instance with given parameters. + P2pCountryListResponse copyWith({ + Map? p2pCountryList, + }) => + P2pCountryListResponse( + p2pCountryList: p2pCountryList ?? this.p2pCountryList, + ); +} + +/// FixedRateAdvertsEnum mapper. +final Map fixedRateAdvertsEnumMapper = + { + "disabled": FixedRateAdvertsEnum.disabled, + "enabled": FixedRateAdvertsEnum.enabled, + "list_only": FixedRateAdvertsEnum.listOnly, +}; + +/// FixedRateAdverts Enum. +enum FixedRateAdvertsEnum { + /// disabled. + disabled, + + /// enabled. + enabled, + + /// list_only. + listOnly, +} + +/// FloatRateAdvertsEnum mapper. +final Map floatRateAdvertsEnumMapper = + { + "disabled": FloatRateAdvertsEnum.disabled, + "enabled": FloatRateAdvertsEnum.enabled, + "list_only": FloatRateAdvertsEnum.listOnly, +}; + +/// FloatRateAdverts Enum. +enum FloatRateAdvertsEnum { + /// disabled. + disabled, + + /// enabled. + enabled, + + /// list_only. + listOnly, +} + +/// TypeEnum mapper. +final Map typeEnumMapper = { + "text": TypeEnum.text, + "memo": TypeEnum.memo, +}; + +/// Type Enum. +enum TypeEnum { + /// text. + text, + + /// memo. + memo, +} + +/// PaymentMethodsPropertyTypeEnum mapper. +final Map + paymentMethodsPropertyTypeEnumMapper = + { + "bank": PaymentMethodsPropertyTypeEnum.bank, + "ewallet": PaymentMethodsPropertyTypeEnum.ewallet, + "other": PaymentMethodsPropertyTypeEnum.other, +}; + +/// Type Enum. +enum PaymentMethodsPropertyTypeEnum { + /// bank. + bank, + + /// ewallet. + ewallet, + + /// other. + other, +} +/// P2p country list property model class. +abstract class P2pCountryListPropertyModel { + /// Initializes P2p country list property model class . + const P2pCountryListPropertyModel({ + required this.paymentMethods, + required this.localCurrency, + required this.floatRateOffsetLimit, + required this.floatRateAdverts, + required this.fixedRateAdverts, + required this.crossBorderAdsEnabled, + required this.countryName, + }); + + /// Payment method identifier. + final Map paymentMethods; + + /// Local currency of the country. + final String localCurrency; + + /// Maximum rate offset for floating rate adverts. + final double floatRateOffsetLimit; + + /// Availability of floating rate adverts. + final FloatRateAdvertsEnum floatRateAdverts; + + /// Availability of fixed rate adverts. + final FixedRateAdvertsEnum fixedRateAdverts; + + /// When `true`, users in this country may place orders on ads in other countries. + final bool crossBorderAdsEnabled; + + /// Display name of country. + final String countryName; +} + +/// P2p country list property class. +class P2pCountryListProperty extends P2pCountryListPropertyModel { + /// Initializes P2p country list property class. + const P2pCountryListProperty({ + required super.countryName, + required super.crossBorderAdsEnabled, + required super.fixedRateAdverts, + required super.floatRateAdverts, + required super.floatRateOffsetLimit, + required super.localCurrency, + required super.paymentMethods, + }); + + /// Creates an instance from JSON. + factory P2pCountryListProperty.fromJson(Map json) => + P2pCountryListProperty( + countryName: json['country_name'], + crossBorderAdsEnabled: getBool(json['cross_border_ads_enabled'])!, + fixedRateAdverts: + fixedRateAdvertsEnumMapper[json['fixed_rate_adverts']]!, + floatRateAdverts: + floatRateAdvertsEnumMapper[json['float_rate_adverts']]!, + floatRateOffsetLimit: getDouble(json['float_rate_offset_limit'])!, + localCurrency: json['local_currency'], + paymentMethods: Map.fromEntries( + json['payment_methods'] + .entries + .map>( + (MapEntry entry) => + MapEntry(entry.key, + PaymentMethodsProperty.fromJson(entry.value)))), + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + resultMap['country_name'] = countryName; + resultMap['cross_border_ads_enabled'] = crossBorderAdsEnabled; + resultMap['fixed_rate_adverts'] = fixedRateAdvertsEnumMapper.entries + .firstWhere((MapEntry entry) => + entry.value == fixedRateAdverts) + .key; + resultMap['float_rate_adverts'] = floatRateAdvertsEnumMapper.entries + .firstWhere((MapEntry entry) => + entry.value == floatRateAdverts) + .key; + resultMap['float_rate_offset_limit'] = floatRateOffsetLimit; + resultMap['local_currency'] = localCurrency; + resultMap['payment_methods'] = paymentMethods; + + return resultMap; + } + + /// Creates a copy of instance with given parameters. + P2pCountryListProperty copyWith({ + String? countryName, + bool? crossBorderAdsEnabled, + FixedRateAdvertsEnum? fixedRateAdverts, + FloatRateAdvertsEnum? floatRateAdverts, + double? floatRateOffsetLimit, + String? localCurrency, + Map? paymentMethods, + }) => + P2pCountryListProperty( + countryName: countryName ?? this.countryName, + crossBorderAdsEnabled: + crossBorderAdsEnabled ?? this.crossBorderAdsEnabled, + fixedRateAdverts: fixedRateAdverts ?? this.fixedRateAdverts, + floatRateAdverts: floatRateAdverts ?? this.floatRateAdverts, + floatRateOffsetLimit: floatRateOffsetLimit ?? this.floatRateOffsetLimit, + localCurrency: localCurrency ?? this.localCurrency, + paymentMethods: paymentMethods ?? this.paymentMethods, + ); +} +/// Payment methods property model class. +abstract class PaymentMethodsPropertyModel { + /// Initializes Payment methods property model class . + const PaymentMethodsPropertyModel({ + this.displayName, + this.fields, + this.type, + }); + + /// Display name of payment method. + final String? displayName; + + /// Payment method field definitions. + final Map? fields; + + /// Payment method type. + final PaymentMethodsPropertyTypeEnum? type; +} + +/// Payment methods property class. +class PaymentMethodsProperty extends PaymentMethodsPropertyModel { + /// Initializes Payment methods property class. + const PaymentMethodsProperty({ + super.displayName, + super.fields, + super.type, + }); + + /// Creates an instance from JSON. + factory PaymentMethodsProperty.fromJson(Map json) => + PaymentMethodsProperty( + displayName: json['display_name'], + fields: json['fields'] == null + ? null + : Map.fromEntries(json['fields'] + .entries + .map>( + (MapEntry entry) => + MapEntry( + entry.key, FieldsProperty.fromJson(entry.value)))), + type: json['type'] == null + ? null + : paymentMethodsPropertyTypeEnumMapper[json['type']], + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + resultMap['display_name'] = displayName; + resultMap['fields'] = fields; + resultMap['type'] = paymentMethodsPropertyTypeEnumMapper.entries + .firstWhere((MapEntry entry) => + entry.value == type) + .key; + + return resultMap; + } + + /// Creates a copy of instance with given parameters. + PaymentMethodsProperty copyWith({ + String? displayName, + Map? fields, + PaymentMethodsPropertyTypeEnum? type, + }) => + PaymentMethodsProperty( + displayName: displayName ?? this.displayName, + fields: fields ?? this.fields, + type: type ?? this.type, + ); +} +/// Fields property model class. +abstract class FieldsPropertyModel { + /// Initializes Fields property model class . + const FieldsPropertyModel({ + required this.type, + required this.required, + required this.displayName, + }); + + /// Field type. + final TypeEnum type; + + /// Is field required or optional. + final int required; + + /// Display name of payment method field. + final String displayName; +} + +/// Fields property class. +class FieldsProperty extends FieldsPropertyModel { + /// Initializes Fields property class. + const FieldsProperty({ + required super.displayName, + required super.required, + required super.type, + }); + + /// Creates an instance from JSON. + factory FieldsProperty.fromJson(Map json) => FieldsProperty( + displayName: json['display_name'], + required: json['required'], + type: typeEnumMapper[json['type']]!, + ); + + /// Converts an instance to JSON. + Map toJson() { + final Map resultMap = {}; + + resultMap['display_name'] = displayName; + resultMap['required'] = required; + resultMap['type'] = typeEnumMapper.entries + .firstWhere((MapEntry entry) => entry.value == type) + .key; + + return resultMap; + } + + /// Creates a copy of instance with given parameters. + FieldsProperty copyWith({ + String? displayName, + int? required, + TypeEnum? type, + }) => + FieldsProperty( + displayName: displayName ?? this.displayName, + required: required ?? this.required, + type: type ?? this.type, + ); +} diff --git a/lib/basic_api/generated/api.dart b/lib/basic_api/generated/api.dart index 04851a39cc..ce392527ba 100644 --- a/lib/basic_api/generated/api.dart +++ b/lib/basic_api/generated/api.dart @@ -166,6 +166,8 @@ export "p2p_advertiser_update_receive.dart"; export "p2p_advertiser_update_send.dart"; export "p2p_chat_create_receive.dart"; export "p2p_chat_create_send.dart"; +export "p2p_country_list_receive.dart"; +export "p2p_country_list_send.dart"; export "p2p_order_cancel_receive.dart"; export "p2p_order_cancel_send.dart"; export "p2p_order_confirm_receive.dart"; diff --git a/lib/basic_api/generated/methods/p2p_country_list_receive_methods.json b/lib/basic_api/generated/methods/p2p_country_list_receive_methods.json new file mode 100644 index 0000000000..76f788430c --- /dev/null +++ b/lib/basic_api/generated/methods/p2p_country_list_receive_methods.json @@ -0,0 +1,4 @@ +{ +"methods": "", +"imports": "import 'package:flutter_deriv_api/helpers/helpers.dart';\n" +} \ No newline at end of file diff --git a/lib/basic_api/generated/p2p_country_list_receive.dart b/lib/basic_api/generated/p2p_country_list_receive.dart new file mode 100644 index 0000000000..db050361e6 --- /dev/null +++ b/lib/basic_api/generated/p2p_country_list_receive.dart @@ -0,0 +1,61 @@ +/// Generated automatically from flutter_deriv_api|lib/basic_api/generated/p2p_country_list_receive.json. + +// ignore_for_file: always_put_required_named_parameters_first + +import '../response.dart'; + +/// P2p country list receive class. +class P2pCountryListReceive extends Response { + /// Initialize P2pCountryListReceive. + const P2pCountryListReceive({ + this.p2pCountryList, + super.echoReq, + super.error, + super.msgType, + super.reqId, + }); + + /// Creates an instance from JSON. + factory P2pCountryListReceive.fromJson(Map json) => + P2pCountryListReceive( + p2pCountryList: json['p2p_country_list'] as Map?, + echoReq: json['echo_req'] as Map?, + error: json['error'] as Map?, + msgType: json['msg_type'] as String?, + reqId: json['req_id'] as int?, + ); + + /// Country identified by country code + final Map? p2pCountryList; + + /// Converts this instance to JSON + @override + Map toJson() => { + 'p2p_country_list': p2pCountryList, + 'echo_req': echoReq, + 'error': error, + 'msg_type': msgType, + 'req_id': reqId, + }; + + /// Creates a copy of instance with given parameters + @override + P2pCountryListReceive copyWith({ + Map? p2pCountryList, + Map? echoReq, + Map? error, + String? msgType, + int? reqId, + }) => + P2pCountryListReceive( + p2pCountryList: p2pCountryList ?? this.p2pCountryList, + echoReq: echoReq ?? this.echoReq, + error: error ?? this.error, + msgType: msgType ?? this.msgType, + reqId: reqId ?? this.reqId, + ); + + /// Override equatable class. + @override + List get props => []; +} diff --git a/lib/basic_api/generated/p2p_country_list_send.dart b/lib/basic_api/generated/p2p_country_list_send.dart new file mode 100644 index 0000000000..09df110eb9 --- /dev/null +++ b/lib/basic_api/generated/p2p_country_list_send.dart @@ -0,0 +1,74 @@ +/// Generated automatically from flutter_deriv_api|lib/basic_api/generated/p2p_country_list_send.json. + +// ignore_for_file: always_put_required_named_parameters_first + +import '../request.dart'; + +/// P2p country list request class. +class P2pCountryListRequest extends Request { + /// Initialize P2pCountryListRequest. + const P2pCountryListRequest({ + this.country, + this.loginid, + this.p2pCountryList = true, + super.msgType = 'p2p_country_list', + super.passthrough, + super.reqId, + }); + + /// Creates an instance from JSON. + factory P2pCountryListRequest.fromJson(Map json) => + P2pCountryListRequest( + country: json['country'] as String?, + loginid: json['loginid'] as String?, + p2pCountryList: json['p2p_country_list'] == null + ? null + : json['p2p_country_list'] == 1, + passthrough: json['passthrough'] as Map?, + reqId: json['req_id'] as int?, + ); + + /// [Optional] 2-letter country code. If not provided all countries are returned. + final String? country; + + /// [Optional] The login id of the user. If left unspecified, it defaults to the initial authorized token's login id. + final String? loginid; + + /// Must be `true` + final bool? p2pCountryList; + + /// Converts this instance to JSON + @override + Map toJson() => { + 'country': country, + 'loginid': loginid, + 'p2p_country_list': p2pCountryList == null + ? null + : p2pCountryList! + ? 1 + : 0, + 'passthrough': passthrough, + 'req_id': reqId, + }; + + /// Creates a copy of instance with given parameters + @override + P2pCountryListRequest copyWith({ + String? country, + String? loginid, + bool? p2pCountryList, + Map? passthrough, + int? reqId, + }) => + P2pCountryListRequest( + country: country ?? this.country, + loginid: loginid ?? this.loginid, + p2pCountryList: p2pCountryList ?? this.p2pCountryList, + passthrough: passthrough ?? this.passthrough, + reqId: reqId ?? this.reqId, + ); + + /// Override equatable class. + @override + List get props => []; +} diff --git a/lib/basic_api/helper/response_mapper.helper.dart b/lib/basic_api/helper/response_mapper.helper.dart index 4eca3804e2..4fe1a41235 100644 --- a/lib/basic_api/helper/response_mapper.helper.dart +++ b/lib/basic_api/helper/response_mapper.helper.dart @@ -86,6 +86,7 @@ import '../generated/p2p_advertiser_payment_methods_receive.dart'; import '../generated/p2p_advertiser_relations_receive.dart'; import '../generated/p2p_advertiser_update_receive.dart'; import '../generated/p2p_chat_create_receive.dart'; +import '../generated/p2p_country_list_receive.dart'; import '../generated/p2p_order_cancel_receive.dart'; import '../generated/p2p_order_confirm_receive.dart'; import '../generated/p2p_order_create_receive.dart'; @@ -331,6 +332,8 @@ Response getGeneratedResponse(Map responseMap) { return P2pAdvertiserUpdateReceive.fromJson(responseMap); case 'p2p_chat_create': return P2pChatCreateReceive.fromJson(responseMap); + case 'p2p_country_list': + return P2pCountryListReceive.fromJson(responseMap); case 'p2p_order_cancel': return P2pOrderCancelReceive.fromJson(responseMap); case 'p2p_order_confirm':