@riocrypto/common 1.0.85 → 1.0.87
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/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -65,4 +65,3 @@ __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,31 +0,0 @@
|
|
|
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
|
-
getOrder(wyreOrderId: string): Promise<any>;
|
|
15
|
-
setOrderWebhook(accountId: string, webhookUrl: string): Promise<void>;
|
|
16
|
-
createWalletReservation(amount: string, currency: string, crypto: Crypto, address: string): Promise<any>;
|
|
17
|
-
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>;
|
|
18
|
-
getAuthorizationCodesCard(wyreOrderId: string): Promise<WyreApiGetCardAuthorizationResponse>;
|
|
19
|
-
submitAuthorizationCodesCard(type: "SMS" | "CARD2FA" | "ALL", wyreOrderId: string, wyreOrderReservation: string, smsCode: string, card2faCode: string): Promise<{
|
|
20
|
-
walletOrderId: string;
|
|
21
|
-
success: boolean;
|
|
22
|
-
}>;
|
|
23
|
-
private getBlockchainNetwork;
|
|
24
|
-
getQuote(side: Side, crypto: Crypto, amount: number, fiat: Fiat, paymentMethod: PaymentMethod, country: Country): Promise<Quote>;
|
|
25
|
-
getProcessingFeeNumeric(subtotal: number, paymentMethod: PaymentMethod, country: Country): number;
|
|
26
|
-
getTransferFeeNumberic(crypto: Crypto): number;
|
|
27
|
-
getPlatformFeeRate(): number;
|
|
28
|
-
getCurrencyConversion(amount: number, from: Fiat, to: Fiat): Promise<Number>;
|
|
29
|
-
}
|
|
30
|
-
export declare const wyreClient: WyreClient;
|
|
31
|
-
export {};
|
|
@@ -1,249 +0,0 @@
|
|
|
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
|
-
getOrder(wyreOrderId) {
|
|
29
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
const response = yield (0, axios_1.default)({
|
|
31
|
-
method: "get",
|
|
32
|
-
url: `https://api.${this.environment}.com/v3/orders/${wyreOrderId}/full`,
|
|
33
|
-
headers: {
|
|
34
|
-
Authorization: `Bearer ${this.apiSecret}`,
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
return response.data;
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
setOrderWebhook(accountId, webhookUrl) {
|
|
41
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
yield (0, axios_1.default)({
|
|
43
|
-
method: "post",
|
|
44
|
-
url: `https://api.${this.environment}.com/v2/digitalwallet/webhook`,
|
|
45
|
-
headers: {
|
|
46
|
-
Authorization: `Bearer ${this.apiSecret}`,
|
|
47
|
-
},
|
|
48
|
-
data: {
|
|
49
|
-
owner: `account:${accountId}`,
|
|
50
|
-
webhook: webhookUrl,
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
createWalletReservation(amount, currency, crypto, address) {
|
|
56
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
const response = yield (0, axios_1.default)({
|
|
58
|
-
method: "post",
|
|
59
|
-
url: `https://api.${this.environment}.com/v3/orders/reserve`,
|
|
60
|
-
headers: {
|
|
61
|
-
Authorization: `Bearer ${this.apiSecret}`,
|
|
62
|
-
},
|
|
63
|
-
data: {
|
|
64
|
-
amount,
|
|
65
|
-
sourceCurrency: currency,
|
|
66
|
-
destCurrency: crypto,
|
|
67
|
-
dest: `${this.getBlockchainNetwork(crypto)}:${address}`,
|
|
68
|
-
referrerAccountId: this.wyreAccountId,
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
return response.data;
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
createWalletOrder(spreedlyToken, amount, currency, crypto, reservationId, cryptoAddress, firstName, lastName, email, phone, street1, city, state, country, postalCode) {
|
|
75
|
-
var _a, _b, _c;
|
|
76
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
-
try {
|
|
78
|
-
const basicAuth = "Basic " +
|
|
79
|
-
Buffer.from(process.env.SPREEDLY_ENV + ":" + process.env.SPREEDLY_SECRET).toString("base64");
|
|
80
|
-
const response = yield (0, axios_1.default)({
|
|
81
|
-
method: "post",
|
|
82
|
-
url: `https://core.spreedly.com/v1/receivers/${process.env.SPREEDLY_RECEIVER}/deliver.json`,
|
|
83
|
-
headers: {
|
|
84
|
-
Authorization: basicAuth,
|
|
85
|
-
},
|
|
86
|
-
data: {
|
|
87
|
-
delivery: {
|
|
88
|
-
payment_method_token: spreedlyToken,
|
|
89
|
-
url: `https://api.${process.env.WYRE_ENV}.com/v3/debitcard/process/partner`,
|
|
90
|
-
headers: `Content-Type: application/json\r\nAuthorization: Bearer ${process.env.WYRE_SECRET}`,
|
|
91
|
-
body: JSON.stringify({
|
|
92
|
-
amount,
|
|
93
|
-
sourceCurrency: currency,
|
|
94
|
-
destCurrency: crypto,
|
|
95
|
-
reservationId,
|
|
96
|
-
referrerAccountId: process.env.WYRE_ACCOUNT_ID,
|
|
97
|
-
referenceId: process.env.WYRE_ACCOUNT_ID,
|
|
98
|
-
dest: `${this.getBlockchainNetwork(crypto)}:${cryptoAddress}`,
|
|
99
|
-
email,
|
|
100
|
-
trigger3ds: true,
|
|
101
|
-
givenName: firstName,
|
|
102
|
-
familyName: lastName,
|
|
103
|
-
phone,
|
|
104
|
-
address: {
|
|
105
|
-
street1,
|
|
106
|
-
city,
|
|
107
|
-
state,
|
|
108
|
-
postalCode,
|
|
109
|
-
country,
|
|
110
|
-
},
|
|
111
|
-
debitCard: {
|
|
112
|
-
number: "{{credit_card_number}}",
|
|
113
|
-
year: "{{credit_card_year}}",
|
|
114
|
-
month: "{{credit_card_month}}",
|
|
115
|
-
cvv: "{{credit_card_verification_value}}",
|
|
116
|
-
},
|
|
117
|
-
}),
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
});
|
|
121
|
-
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);
|
|
122
|
-
return data;
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
console.log(error.response.data);
|
|
126
|
-
throw new Error("Something went wrong");
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
getAuthorizationCodesCard(wyreOrderId) {
|
|
131
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
-
const response = yield (0, axios_1.default)({
|
|
133
|
-
method: "get",
|
|
134
|
-
url: `https://api.${this.environment}.com/v3/debitcard/authorization/${wyreOrderId}`,
|
|
135
|
-
headers: {
|
|
136
|
-
Authorization: `Bearer ${this.apiSecret}`,
|
|
137
|
-
},
|
|
138
|
-
});
|
|
139
|
-
return response.data;
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
submitAuthorizationCodesCard(type, wyreOrderId, wyreOrderReservation, smsCode, card2faCode) {
|
|
143
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
-
const response = yield (0, axios_1.default)({
|
|
145
|
-
method: "post",
|
|
146
|
-
url: `https://api.testwyre.com/v3/debitcard/authorize/partner`,
|
|
147
|
-
headers: {
|
|
148
|
-
Authorization: `Bearer ${this.apiSecret}`,
|
|
149
|
-
},
|
|
150
|
-
data: {
|
|
151
|
-
type,
|
|
152
|
-
walletOrderId: wyreOrderId,
|
|
153
|
-
reservation: wyreOrderReservation,
|
|
154
|
-
sms: smsCode,
|
|
155
|
-
card2fa: card2faCode,
|
|
156
|
-
},
|
|
157
|
-
});
|
|
158
|
-
return response.data;
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
getBlockchainNetwork(crypto) {
|
|
162
|
-
if ([
|
|
163
|
-
"ETH",
|
|
164
|
-
"USDC",
|
|
165
|
-
"BAT",
|
|
166
|
-
"DAI",
|
|
167
|
-
"MKR",
|
|
168
|
-
"UNI",
|
|
169
|
-
"YFI",
|
|
170
|
-
"AAVE",
|
|
171
|
-
"COMP",
|
|
172
|
-
"LINK",
|
|
173
|
-
].includes(crypto)) {
|
|
174
|
-
return "ethereum";
|
|
175
|
-
}
|
|
176
|
-
else if (["BTC"].includes(crypto)) {
|
|
177
|
-
return "bitcoin";
|
|
178
|
-
}
|
|
179
|
-
else if (["AVAX"].includes(crypto)) {
|
|
180
|
-
return "avalanche";
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
return "ethereum";
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
getQuote(side, crypto, amount, fiat, paymentMethod, country) {
|
|
187
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
-
const response = yield (0, axios_1.default)({
|
|
189
|
-
method: "get",
|
|
190
|
-
url: `https://api.${this.environment}.com/v3/rates`,
|
|
191
|
-
});
|
|
192
|
-
const key = `${fiat}${crypto}`;
|
|
193
|
-
const price = response.data[key];
|
|
194
|
-
const platformRate = this.getPlatformFeeRate();
|
|
195
|
-
const processingFeeFiat = this.getProcessingFeeNumeric(amount, paymentMethod, country);
|
|
196
|
-
const platformFeeFiat = platformRate * amount;
|
|
197
|
-
const TransferFeeFiat = this.getTransferFeeNumberic(crypto);
|
|
198
|
-
return {
|
|
199
|
-
price,
|
|
200
|
-
fees: {
|
|
201
|
-
processingFeeFiat,
|
|
202
|
-
TransferFeeFiat,
|
|
203
|
-
platformFeeFiat,
|
|
204
|
-
},
|
|
205
|
-
liquidityProvider: liquidity_provider_1.LiquidityProvider.Wyre,
|
|
206
|
-
paymentProcessor: processor_1.Processor.Wyre,
|
|
207
|
-
amountCrypto: (amount - (processingFeeFiat + platformFeeFiat + TransferFeeFiat)) /
|
|
208
|
-
price,
|
|
209
|
-
amountFiat: amount,
|
|
210
|
-
paymentMethod,
|
|
211
|
-
crypto,
|
|
212
|
-
fiat,
|
|
213
|
-
side,
|
|
214
|
-
};
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
getProcessingFeeNumeric(subtotal, paymentMethod, country) {
|
|
218
|
-
switch (paymentMethod) {
|
|
219
|
-
case payment_method_1.PaymentMethod.Card:
|
|
220
|
-
if (country === country_1.Country.UnitedStates)
|
|
221
|
-
return subtotal * 0.029 + 0.3;
|
|
222
|
-
else
|
|
223
|
-
return subtotal * 0.039 + 0.3;
|
|
224
|
-
default:
|
|
225
|
-
return subtotal * 0.039 + 0.3;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
getTransferFeeNumberic(crypto) {
|
|
229
|
-
return 3;
|
|
230
|
-
}
|
|
231
|
-
getPlatformFeeRate() {
|
|
232
|
-
return 0.001;
|
|
233
|
-
}
|
|
234
|
-
getCurrencyConversion(amount, from, to) {
|
|
235
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
236
|
-
if (from === fiat_1.Fiat.USD) {
|
|
237
|
-
return amount;
|
|
238
|
-
}
|
|
239
|
-
const response = yield (0, axios_1.default)({
|
|
240
|
-
method: "get",
|
|
241
|
-
url: `https://api.${this.environment}.com/v3/rates`,
|
|
242
|
-
});
|
|
243
|
-
const key = `${from}${to}`;
|
|
244
|
-
const conversionRate = response.data[key];
|
|
245
|
-
return amount / conversionRate;
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
exports.wyreClient = new WyreClient(process.env.WYRE_SECRET, process.env.WYRE_ENV, process.env.WYRE_ACCOUNT_ID);
|