@riocrypto/common 1.0.79 → 1.0.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/clients/wyre-client.d.ts +30 -0
- package/build/clients/wyre-client.js +246 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Country } from "../types/country";
|
|
2
|
+
import { Fiat } from "../types/fiat";
|
|
3
|
+
import { PaymentMethod } from "../types/payment-method";
|
|
4
|
+
import { Quote } from "../types/quote";
|
|
5
|
+
import { Side } from "../types/side";
|
|
6
|
+
import { Crypto } from "../types/crypto";
|
|
7
|
+
import { WyreApiGetCardAuthorizationResponse } from "../types/wyre-api-get-card-authorization-response";
|
|
8
|
+
import { WyreApiCreateCardPaymentResponse } from "../types/wyre-api-create-card-payment-response";
|
|
9
|
+
declare class WyreClient {
|
|
10
|
+
private apiSecret;
|
|
11
|
+
private environment;
|
|
12
|
+
private wyreAccountId;
|
|
13
|
+
constructor(apiSecret: string, environment: "testwyre" | "sendwyre", wyreAccountId: string);
|
|
14
|
+
setOrderWebhook(accountId: string, webhookUrl: string): Promise<void>;
|
|
15
|
+
createWalletReservation(amount: string, currency: string, crypto: Crypto, address: string, firstName: string, lastName: string, phone: string, email: string, street1: string, city: string, country: string, postalCode: string, state: string): Promise<any>;
|
|
16
|
+
createWalletOrder(spreedlyToken: string, amount: string, currency: Fiat, crypto: Crypto, reservationId: string, cryptoAddress: string, firstName: string, lastName: string, email: string, phone: string, street1: string, city: string, state: string, country: string, postalCode: string): Promise<WyreApiCreateCardPaymentResponse>;
|
|
17
|
+
getAuthorizationCodesCard(wyreOrderId: string): Promise<WyreApiGetCardAuthorizationResponse>;
|
|
18
|
+
submitAuthorizationCodesCard(type: "SMS" | "CARD2FA" | "ALL", wyreOrderId: string, wyreOrderReservation: string, smsCode: string, card2faCode: string): Promise<{
|
|
19
|
+
walletOrderId: string;
|
|
20
|
+
success: boolean;
|
|
21
|
+
}>;
|
|
22
|
+
private getBlockchainNetwork;
|
|
23
|
+
getQuote(side: Side, crypto: Crypto, amount: number, fiat: Fiat, paymentMethod: PaymentMethod, country: Country): Promise<Quote>;
|
|
24
|
+
getProcessingFeeNumeric(subtotal: number, paymentMethod: PaymentMethod, unitedStates: boolean): number;
|
|
25
|
+
getTransferFeeNumberic(crypto: Crypto): number;
|
|
26
|
+
getPlatformFeeRate(): number;
|
|
27
|
+
getCurrencyConversion(amount: number, from: Fiat, to: Fiat): Promise<Number>;
|
|
28
|
+
}
|
|
29
|
+
export declare const wyreClient: WyreClient;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.wyreClient = void 0;
|
|
16
|
+
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
const country_1 = require("../types/country");
|
|
18
|
+
const fiat_1 = require("../types/fiat");
|
|
19
|
+
const liquidity_provider_1 = require("../types/liquidity-provider");
|
|
20
|
+
const payment_method_1 = require("../types/payment-method");
|
|
21
|
+
const processor_1 = require("../types/processor");
|
|
22
|
+
class WyreClient {
|
|
23
|
+
constructor(apiSecret, environment, wyreAccountId) {
|
|
24
|
+
this.apiSecret = apiSecret;
|
|
25
|
+
this.environment = environment;
|
|
26
|
+
this.wyreAccountId = wyreAccountId;
|
|
27
|
+
}
|
|
28
|
+
setOrderWebhook(accountId, webhookUrl) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
yield (0, axios_1.default)({
|
|
31
|
+
method: "post",
|
|
32
|
+
url: `https://api.${this.environment}.com/v2/digitalwallet/webhook`,
|
|
33
|
+
headers: {
|
|
34
|
+
Authorization: `Bearer ${this.apiSecret}`,
|
|
35
|
+
},
|
|
36
|
+
data: {
|
|
37
|
+
owner: `account:${accountId}`,
|
|
38
|
+
webhook: webhookUrl,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
createWalletReservation(amount, currency, crypto, address, firstName, lastName, phone, email, street1, city, country, postalCode, state) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const response = yield (0, axios_1.default)({
|
|
46
|
+
method: "post",
|
|
47
|
+
url: `https://api.${this.environment}.com/v3/orders/reserve`,
|
|
48
|
+
headers: {
|
|
49
|
+
Authorization: `Bearer ${this.apiSecret}`,
|
|
50
|
+
},
|
|
51
|
+
data: {
|
|
52
|
+
amount,
|
|
53
|
+
sourceCurrency: currency,
|
|
54
|
+
destCurrency: crypto,
|
|
55
|
+
dest: `${this.getBlockchainNetwork(crypto)}:${address}`,
|
|
56
|
+
firstName,
|
|
57
|
+
lastName,
|
|
58
|
+
phone,
|
|
59
|
+
email,
|
|
60
|
+
street1,
|
|
61
|
+
city,
|
|
62
|
+
state,
|
|
63
|
+
country,
|
|
64
|
+
postalCode,
|
|
65
|
+
referrerAccountId: this.wyreAccountId,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
return response.data;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
createWalletOrder(spreedlyToken, amount, currency, crypto, reservationId, cryptoAddress, firstName, lastName, email, phone, street1, city, state, country, postalCode) {
|
|
72
|
+
var _a, _b, _c;
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
try {
|
|
75
|
+
const basicAuth = "Basic " +
|
|
76
|
+
Buffer.from(process.env.SPREEDLY_ENV + ":" + process.env.SPREEDLY_SECRET).toString("base64");
|
|
77
|
+
const response = yield (0, axios_1.default)({
|
|
78
|
+
method: "post",
|
|
79
|
+
url: `https://core.spreedly.com/v1/receivers/${process.env.SPREEDLY_RECEIVER}/deliver.json`,
|
|
80
|
+
headers: {
|
|
81
|
+
Authorization: basicAuth,
|
|
82
|
+
},
|
|
83
|
+
data: {
|
|
84
|
+
delivery: {
|
|
85
|
+
payment_method_token: spreedlyToken,
|
|
86
|
+
url: `https://api.${process.env.WYRE_ENV}.com/v3/debitcard/process/partner`,
|
|
87
|
+
headers: `Content-Type: application/json\r\nAuthorization: Bearer ${process.env.WYRE_SECRET}`,
|
|
88
|
+
body: JSON.stringify({
|
|
89
|
+
amount,
|
|
90
|
+
sourceCurrency: currency,
|
|
91
|
+
destCurrency: crypto,
|
|
92
|
+
reservationId,
|
|
93
|
+
referrerAccountId: process.env.WYRE_ACCOUNT_ID,
|
|
94
|
+
referenceId: process.env.WYRE_ACCOUNT_ID,
|
|
95
|
+
dest: `${this.getBlockchainNetwork(crypto)}:${cryptoAddress}`,
|
|
96
|
+
email,
|
|
97
|
+
trigger3ds: true,
|
|
98
|
+
givenName: firstName,
|
|
99
|
+
familyName: lastName,
|
|
100
|
+
phone,
|
|
101
|
+
address: {
|
|
102
|
+
street1,
|
|
103
|
+
city,
|
|
104
|
+
state,
|
|
105
|
+
postalCode,
|
|
106
|
+
country,
|
|
107
|
+
},
|
|
108
|
+
debitCard: {
|
|
109
|
+
number: "{{credit_card_number}}",
|
|
110
|
+
year: "{{credit_card_year}}",
|
|
111
|
+
month: "{{credit_card_month}}",
|
|
112
|
+
cvv: "{{credit_card_verification_value}}",
|
|
113
|
+
},
|
|
114
|
+
}),
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
const data = JSON.parse((_c = (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.transaction) === null || _b === void 0 ? void 0 : _b.response) === null || _c === void 0 ? void 0 : _c.body);
|
|
119
|
+
return data;
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
console.log(error.response.data);
|
|
123
|
+
throw new Error("Something went wrong");
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
getAuthorizationCodesCard(wyreOrderId) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
const response = yield (0, axios_1.default)({
|
|
130
|
+
method: "get",
|
|
131
|
+
url: `https://api.${this.environment}.com/v3/debitcard/authorization/${wyreOrderId}`,
|
|
132
|
+
headers: {
|
|
133
|
+
Authorization: `Bearer ${this.apiSecret}`,
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
return response.data;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
submitAuthorizationCodesCard(type, wyreOrderId, wyreOrderReservation, smsCode, card2faCode) {
|
|
140
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
141
|
+
const response = yield (0, axios_1.default)({
|
|
142
|
+
method: "post",
|
|
143
|
+
url: `https://api.testwyre.com/v3/debitcard/authorize/partner`,
|
|
144
|
+
headers: {
|
|
145
|
+
Authorization: `Bearer ${this.apiSecret}`,
|
|
146
|
+
},
|
|
147
|
+
data: {
|
|
148
|
+
type,
|
|
149
|
+
walletOrderId: wyreOrderId,
|
|
150
|
+
reservation: wyreOrderReservation,
|
|
151
|
+
sms: smsCode,
|
|
152
|
+
card2fa: card2faCode,
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
return response.data;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
getBlockchainNetwork(crypto) {
|
|
159
|
+
if ([
|
|
160
|
+
"ETH",
|
|
161
|
+
"USDC",
|
|
162
|
+
"BAT",
|
|
163
|
+
"DAI",
|
|
164
|
+
"MKR",
|
|
165
|
+
"UNI",
|
|
166
|
+
"YFI",
|
|
167
|
+
"AAVE",
|
|
168
|
+
"COMP",
|
|
169
|
+
"LINK",
|
|
170
|
+
].includes(crypto)) {
|
|
171
|
+
return "ethereum";
|
|
172
|
+
}
|
|
173
|
+
else if (["BTC"].includes(crypto)) {
|
|
174
|
+
return "bitcoin";
|
|
175
|
+
}
|
|
176
|
+
else if (["AVAX"].includes(crypto)) {
|
|
177
|
+
return "avalanche";
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
return "ethereum";
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
getQuote(side, crypto, amount, fiat, paymentMethod, country) {
|
|
184
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
+
const response = yield (0, axios_1.default)({
|
|
186
|
+
method: "get",
|
|
187
|
+
url: `https://api.${this.environment}.com/v3/rates`,
|
|
188
|
+
});
|
|
189
|
+
const key = `${fiat}${crypto}`;
|
|
190
|
+
const price = response.data[key];
|
|
191
|
+
const platformRate = this.getPlatformFeeRate();
|
|
192
|
+
const processingFeeFiat = this.getProcessingFeeNumeric(amount, paymentMethod, country === country_1.Country.UnitedStates);
|
|
193
|
+
const platformFeeFiat = platformRate * amount;
|
|
194
|
+
const TransferFeeFiat = this.getTransferFeeNumberic(crypto);
|
|
195
|
+
return {
|
|
196
|
+
price,
|
|
197
|
+
fees: {
|
|
198
|
+
processingFeeFiat,
|
|
199
|
+
TransferFeeFiat,
|
|
200
|
+
platformFeeFiat,
|
|
201
|
+
},
|
|
202
|
+
liquidityProvider: liquidity_provider_1.LiquidityProvider.Wyre,
|
|
203
|
+
paymentProcessor: processor_1.Processor.Wyre,
|
|
204
|
+
amountCrypto: (amount - (processingFeeFiat + platformFeeFiat + TransferFeeFiat)) /
|
|
205
|
+
price,
|
|
206
|
+
amountFiat: amount,
|
|
207
|
+
paymentMethod,
|
|
208
|
+
crypto,
|
|
209
|
+
fiat,
|
|
210
|
+
side,
|
|
211
|
+
};
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
getProcessingFeeNumeric(subtotal, paymentMethod, unitedStates) {
|
|
215
|
+
switch (paymentMethod) {
|
|
216
|
+
case payment_method_1.PaymentMethod.Card:
|
|
217
|
+
if (unitedStates)
|
|
218
|
+
return subtotal * 0.029 + 0.3;
|
|
219
|
+
else
|
|
220
|
+
return subtotal * 0.039 + 0.3;
|
|
221
|
+
default:
|
|
222
|
+
return subtotal * 0.039 + 0.3;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
getTransferFeeNumberic(crypto) {
|
|
226
|
+
return 3;
|
|
227
|
+
}
|
|
228
|
+
getPlatformFeeRate() {
|
|
229
|
+
return 0.001;
|
|
230
|
+
}
|
|
231
|
+
getCurrencyConversion(amount, from, to) {
|
|
232
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
+
if (from === fiat_1.Fiat.USD) {
|
|
234
|
+
return amount;
|
|
235
|
+
}
|
|
236
|
+
const response = yield (0, axios_1.default)({
|
|
237
|
+
method: "get",
|
|
238
|
+
url: `https://api.${this.environment}.com/v3/rates`,
|
|
239
|
+
});
|
|
240
|
+
const key = `${from}${to}`;
|
|
241
|
+
const conversionRate = response.data[key];
|
|
242
|
+
return amount / conversionRate;
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
exports.wyreClient = new WyreClient(process.env.WYRE_SECRET, process.env.WYRE_ENV, process.env.WYRE_ACCOUNT_ID);
|
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -65,3 +65,4 @@ __exportStar(require("./types/user-update"), exports);
|
|
|
65
65
|
__exportStar(require("./types/wyre-api-create-card-payment-response"), exports);
|
|
66
66
|
__exportStar(require("./types/wyre-webhook-notification"), exports);
|
|
67
67
|
__exportStar(require("./types/wyre-api-get-card-authorization-response"), exports);
|
|
68
|
+
__exportStar(require("./clients/wyre-client"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.81",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@types/express": "^4.17.13",
|
|
24
|
+
"axios": "^0.27.2",
|
|
24
25
|
"express": "^4.18.1",
|
|
25
26
|
"express-validator": "^6.14.2",
|
|
26
27
|
"jsonwebtoken": "^8.5.1",
|