-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathtopup_virtual_response_result.dart
134 lines (111 loc) · 3.83 KB
/
topup_virtual_response_result.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// ignore_for_file: prefer_single_quotes, unnecessary_import, unused_import
import 'package:build/build.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter_deriv_api/api/exceptions/exceptions.dart';
import 'package:flutter_deriv_api/api/models/base_exception_model.dart';
import 'package:flutter_deriv_api/basic_api/generated/topup_virtual_receive.dart';
import 'package:flutter_deriv_api/basic_api/generated/topup_virtual_send.dart';
import 'package:flutter_deriv_api/helpers/helpers.dart';
import 'package:flutter_deriv_api/services/connection/api_manager/base_api.dart';
import 'package:deriv_dependency_injector/dependency_injector.dart';
/// Topup virtual response model class.
abstract class TopupVirtualResponseModel {
/// Initializes Topup virtual response model class .
const TopupVirtualResponseModel({
this.topupVirtual,
});
/// The information regarding a successful top up for a virtual money account
final TopupVirtual? topupVirtual;
}
/// Topup virtual response class.
class TopupVirtualResponse extends TopupVirtualResponseModel {
/// Initializes Topup virtual response class.
const TopupVirtualResponse({
super.topupVirtual,
});
/// Creates an instance from JSON.
factory TopupVirtualResponse.fromJson(
dynamic topupVirtualJson,
) =>
TopupVirtualResponse(
topupVirtual: topupVirtualJson == null
? null
: TopupVirtual.fromJson(topupVirtualJson),
);
/// Converts an instance to JSON.
Map<String, dynamic> toJson() {
final Map<String, dynamic> resultMap = <String, dynamic>{};
if (topupVirtual != null) {
resultMap['topup_virtual'] = topupVirtual!.toJson();
}
return resultMap;
}
static final BaseAPI _api = Injector()<BaseAPI>();
/// Topes up the virtual-money's account balance becomes when it becomes low.
///
/// For parameters information refer to [TopupVirtualRequest].
/// Throws a [BaseAPIException] if API response contains an error
static Future<TopupVirtualResponse> topUp({
TopupVirtualRequest? request,
String? loginId,
}) async {
final TopupVirtualReceive response = await _api.call(
request: request?.copyWith(loginid: loginId) ??
TopupVirtualRequest(loginid: loginId),
);
checkException(
response: response,
exceptionCreator: ({BaseExceptionModel? baseExceptionModel}) =>
BaseAPIException(baseExceptionModel: baseExceptionModel),
);
return TopupVirtualResponse.fromJson(response.topupVirtual);
}
/// Creates a copy of instance with given parameters.
TopupVirtualResponse copyWith({
TopupVirtual? topupVirtual,
}) =>
TopupVirtualResponse(
topupVirtual: topupVirtual ?? this.topupVirtual,
);
}
/// Topup virtual model class.
abstract class TopupVirtualModel {
/// Initializes Topup virtual model class .
const TopupVirtualModel({
this.amount,
this.currency,
});
/// Top up amount
final double? amount;
/// Top up currency string
final String? currency;
}
/// Topup virtual class.
class TopupVirtual extends TopupVirtualModel {
/// Initializes Topup virtual class.
const TopupVirtual({
super.amount,
super.currency,
});
/// Creates an instance from JSON.
factory TopupVirtual.fromJson(Map<String, dynamic> json) => TopupVirtual(
amount: getDouble(json['amount']),
currency: json['currency'],
);
/// Converts an instance to JSON.
Map<String, dynamic> toJson() {
final Map<String, dynamic> resultMap = <String, dynamic>{};
resultMap['amount'] = amount;
resultMap['currency'] = currency;
return resultMap;
}
/// Creates a copy of instance with given parameters.
TopupVirtual copyWith({
double? amount,
String? currency,
}) =>
TopupVirtual(
amount: amount ?? this.amount,
currency: currency ?? this.currency,
);
}