forked from Biscoint/exchanges-rfb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rfb_file.js
247 lines (193 loc) · 9.89 KB
/
rfb_file.js
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
function getIdentityRFB(identity_type){
return (identity_type === 'CPF') ? 1
: (identity_type === 'CNPJ') ? 2
: (identity_type === 'NIF_PF') ? 3
: (identity_type === 'NIF_PJ') ? 4
: (identity_type === 'PASSPORT') ? 5
: (identity_type === 'COUNTRY_NO_ID') ? 6
: (identity_type === 'USER_NO_ID') ? 7
: '';
}
export function createHeader(obj) {
const line_type = '0000';
const { exchange_name, exchange_cnpj, exchange_url } = obj;
const rfb_exchange_cnpj = exchange_cnpj.match(/\d+/g).join('');
return `${line_type}|${exchange_name}|${rfb_exchange_cnpj}|${exchange_url}\r\n`;
}
export function createFooter(obj) {
const line_type = '9999';
const { buySellQuantity, permutationQuantity, depositQuantity, withdrawQuantity, paymentQuantity, otherQuantity, buySellTotal } = obj;
const sellOnlyQuantity = 0;
const annualDeclarationQuantity = 0;
const rfb_buySellTotal = Number(buySellTotal).toFixed(2).replace(/\./g, ',');
return `${line_type}|${buySellQuantity}|${rfb_buySellTotal}|${sellOnlyQuantity}|${permutationQuantity}|${depositQuantity}|${withdrawQuantity}|${paymentQuantity}|${otherQuantity}|${annualDeclarationQuantity}\r\n`;
}
export function createBuySellOp(obj) {
const line_type = '0110';
const operation_code = 'I';
const {
date,
id,
brl_value,
brl_fees,
coin_symbol,
coin_quantity,
buyer_identity_type,
buyer_country,
buyer_document,
buyer_fullname,
buyer_address,
seller_identity_type,
seller_country,
seller_document,
seller_fullname,
seller_address,
} = obj;
const rfb_brl_value = brl_value.toFixed(2).replace(/\./g, ',');
const rfb_brl_fees = brl_fees.toFixed(2).replace(/\./g, ',');
const rfb_coin_quantity = coin_quantity.toFixed(10).replace(/\./g, ',');
const rfb_buyer_identity_type = getIdentityRFB(buyer_identity_type);
const rfb_buyer_cpf = (buyer_document && [1,2].indexOf(rfb_buyer_identity_type)) ? buyer_document.match(/\d+/g).join('') : '';
const rfb_buyer_nif = (buyer_document && [3,4,5].indexOf(rfb_buyer_identity_type)) ? buyer_document.match(/\d+/g).join('') : '';
const rfb_seller_identity_type = getIdentityRFB(seller_identity_type);
const rfb_seller_cpf = (seller_document && [1,2].indexOf(rfb_seller_identity_type)) ? seller_document.match(/\d+/g).join('') : '';
const rfb_seller_nif = (seller_document && [3,4,5].indexOf(rfb_seller_identity_type)) ? seller_document.match(/\d+/g).join('') : '';
return `${line_type}|${date}|${id}|${operation_code}|${rfb_brl_value}|${rfb_brl_fees}|${coin_symbol}|${rfb_coin_quantity}|${rfb_buyer_identity_type}|${buyer_country}|${rfb_buyer_cpf}|${rfb_buyer_nif}|${buyer_fullname}|${buyer_address}|${rfb_seller_identity_type}|${seller_country}|${rfb_seller_cpf}|${rfb_seller_nif}|${seller_fullname}|${seller_address}\r\n`;
}
export function createPermutationOp(obj) {
const line_type = '0210';
const operation_code = 'II';
const {
date,
id,
brl_fees,
user1_coin_symbol,
user1_coin_quantity,
user1_identity_type,
user1_country,
user1_document,
user1_fullname,
user1_address,
user2_coin_symbol,
user2_coin_quantity,
user2_identity_type,
user2_country,
user2_document,
user2_fullname,
user2_address,
} = obj;
const rfb_brl_fees = brl_fees.toFixed(2).replace(/\./g, ',');
const rfb_user1_coin_quantity = user1_coin_quantity.toFixed(10).replace(/\./g, ',');
const rfb_user2_coin_quantity = user2_coin_quantity.toFixed(10).replace(/\./g, ',');
const rfb_user1_identity_type = getIdentityRFB(user1_identity_type);
const rfb_user2_identity_type = getIdentityRFB(user2_identity_type);
const rfb_user1_cpf = (user1_document && [1,2].indexOf(rfb_user1_identity_type)) ? user1_document.match(/\d+/g).join('') : '';
const rfb_user1_nif = (user1_document &&[3,4,5].indexOf(rfb_user1_identity_type)) ? user1_document.match(/\d+/g).join('') : '';
const rfb_user2_cpf = (user2_document && [1,2].indexOf(rfb_user2_identity_type)) ? user2_document.match(/\d+/g).join('') : '';
const rfb_user2_nif = (user2_document && [3,4,5].indexOf(rfb_user2_identity_type)) ? user2_document.match(/\d+/g).join('') : '';
return `${line_type}|${date}|${id}|${operation_code}|${rfb_brl_fees}|${user1_coin_symbol}|${rfb_user1_coin_quantity}|${rfb_user1_identity_type}|${user1_country}|${rfb_user1_cpf}|${rfb_user1_nif}|${user1_fullname}|${user1_address}|${user2_coin_symbol}|${rfb_user2_coin_quantity}|${rfb_user2_identity_type}|${user2_country}|${rfb_user2_cpf}|${rfb_user2_nif}|${user2_fullname}|${user2_address}\r\n`;
}
export function createDepositOp(obj) {
const line_type = '0410';
const operation_code = 'IV';
const {
date,
id,
brl_fees,
coin_symbol,
coin_quantity,
identity_type,
country,
document,
fullname,
address,
} = obj;
const rfb_brl_fees = brl_fees.toFixed(2).replace(/\./g, ',');
const rfb_coin_quantity = coin_quantity.toFixed(10).replace(/\./g, ',');
const rfb_identity_type = getIdentityRFB(identity_type);
const rfb_cpf = (document && [1,2].indexOf(rfb_identity_type)) ? document.match(/\d+/g).join('') : '';
const rfb_nif = (document &&[3,4,5].indexOf(rfb_identity_type)) ? document.match(/\d+/g).join('') : '';
return `${line_type}|${date}|${id}|${operation_code}|${rfb_brl_fees}|${coin_symbol}|${rfb_coin_quantity}|${rfb_identity_type}|${country}|${rfb_cpf}|${rfb_nif}|${fullname}|${address}\r\n`;
}
export function createWithdrawOp(obj) {
const line_type = '0510';
const operation_code = 'V';
const {
date,
id,
brl_fees,
coin_symbol,
coin_quantity,
identity_type,
country,
document,
fullname,
address,
} = obj;
const rfb_brl_fees = brl_fees.toFixed(2).replace(/\./g, ',');
const rfb_coin_quantity = coin_quantity.toFixed(10).replace(/\./g, ',');
const rfb_identity_type = getIdentityRFB(identity_type);
const rfb_cpf = (document && [1,2].indexOf(rfb_identity_type)) ? document.match(/\d+/g).join('') : '';
const rfb_nif = (document && [3,4,5].indexOf(rfb_identity_type)) ? document.match(/\d+/g).join('') : '';
return `${line_type}|${date}|${id}|${operation_code}|${rfb_brl_fees}|${coin_symbol}|${rfb_coin_quantity}|${rfb_identity_type}|${country}|${rfb_cpf}|${rfb_nif}|${fullname}|${address}\r\n`;
}
export function createPaymentOp(obj) {
const line_type = '0710';
const operation_code = 'VII';
const {
date,
id,
brl_fees,
coin_symbol,
coin_quantity,
payer_identity_type,
payer_country,
payer_document,
payer_fullname,
payer_address,
receiver_identity_type,
receiver_country,
receiver_document,
receiver_fullname,
receiver_address,
} = obj;
const rfb_brl_fees = brl_fees.toFixed(2).replace(/\./g, ',');
const rfb_coin_quantity = coin_quantity.toFixed(10).replace(/\./g, ',');
const rfb_payer_identity_type = getIdentityRFB(payer_identity_type);
const rfb_receiver_identity_type = getIdentityRFB(receiver_identity_type);
const rfb_payer_cpf = (payer_document && [1,2].indexOf(rfb_payer_identity_type)) ? payer_document.match(/\d+/g).join('') : '';
const rfb_payer_nif = (payer_document &&[3,4,5].indexOf(rfb_payer_identity_type)) ? payer_document.match(/\d+/g).join('') : '';
const rfb_receiver_cpf = (receiver_document && [1,2].indexOf(rfb_receiver_identity_type)) ? receiver_document.match(/\d+/g).join('') : '';
const rfb_receiver_nif = (receiver_document && [3,4,5].indexOf(rfb_receiver_identity_type)) ? receiver_document.match(/\d+/g).join('') : '';
return `${line_type}|${date}|${id}|${operation_code}|${rfb_brl_fees}|${coin_symbol}|${rfb_coin_quantity}|${rfb_payer_identity_type}|${payer_country}|${rfb_payer_cpf}|${rfb_payer_nif}|${payer_fullname}|${payer_address}|${rfb_receiver_identity_type}|${receiver_country}|${rfb_receiver_cpf}|${rfb_receiver_nif}|${receiver_fullname}|${receiver_address}\r\n`;
}
export function createOtherOp(obj) {
const line_type = '0910';
const operation_code = 'IX';
const {
date,
id,
brl_fees,
coin_symbol,
coin_quantity,
origin_identity_type,
origin_country,
origin_document,
origin_fullname,
origin_address,
recipient_identity_type,
recipient_country,
recipient_document,
recipient_fullname,
recipient_address,
} = obj;
const rfb_brl_fees = brl_fees.toFixed(2).replace(/\./g, ',');
const rfb_coin_quantity = coin_quantity.toFixed(10).replace(/\./g, ',');
const rfb_origin_identity_type = getIdentityRFB(origin_identity_type);
const rfb_recipient_identity_type = getIdentityRFB(recipient_identity_type);
const rfb_origin_cpf = (origin_document && [1,2].indexOf(rfb_origin_identity_type)) ? origin_document.match(/\d+/g).join('') : '';
const rfb_origin_nif = (origin_document &&[3,4,5].indexOf(rfb_origin_identity_type)) ? origin_document.match(/\d+/g).join('') : '';
const rfb_recipient_cpf = (recipient_document && [1,2].indexOf(rfb_recipient_identity_type)) ? recipient_document.match(/\d+/g).join('') : '';
const rfb_recipient_nif = (recipient_document && [3,4,5].indexOf(rfb_recipient_identity_type)) ? recipient_document.match(/\d+/g).join('') : '';
return `${line_type}|${date}|${id}|${operation_code}|${rfb_brl_fees}|${coin_symbol}|${rfb_coin_quantity}|${rfb_origin_identity_type}|${origin_country}|${rfb_origin_cpf}|${rfb_origin_nif}|${origin_fullname}|${origin_address}|${rfb_recipient_identity_type}|${recipient_country}|${rfb_recipient_cpf}|${rfb_recipient_nif}|${recipient_fullname}|${recipient_address}\r\n`;
}