addie-js 0.0.6 → 0.0.8

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.
Files changed (2) hide show
  1. package/addie.js +217 -6
  2. package/package.json +2 -2
package/addie.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import sessionless from 'sessionless-node';
2
- import fetch from 'node-fetch';
3
2
 
4
3
  const get = async (url) => {
5
4
  return await fetch(url);
@@ -29,9 +28,34 @@ const _delete = async (url, payload) => {
29
28
  });
30
29
  };
31
30
 
31
+ const patch = async (url, payload) => {
32
+ return await fetch(url, {
33
+ method: 'patch',
34
+ body: JSON.stringify(payload),
35
+ headers: {'Content-Type': 'application/json'}
36
+ });
37
+ };
38
+
32
39
  const addie = {
33
40
  baseURL: 'https://dev.addie.allyabase.com/',
34
41
 
42
+ /**
43
+ * Configure the Addie client for different environments
44
+ * @param {Object} config - Configuration options
45
+ * @param {string} config.baseURL - Direct base URL (e.g., 'http://127.0.0.1:5116/')
46
+ * @param {string} config.wikiBaseURL - Wiki proxy base URL (e.g., 'http://127.0.0.1:5124')
47
+ * Will construct URL as: {wikiBaseURL}/plugin/allyabase/addie/
48
+ */
49
+ configure: (config) => {
50
+ if (config.wikiBaseURL) {
51
+ // Wiki proxy mode: route through wiki plugin
52
+ addie.baseURL = `${config.wikiBaseURL.replace(/\/$/, '')}/plugin/allyabase/addie/`;
53
+ } else if (config.baseURL) {
54
+ // Direct mode: use base URL as-is
55
+ addie.baseURL = config.baseURL.endsWith('/') ? config.baseURL : config.baseURL + '/';
56
+ }
57
+ },
58
+
35
59
  createUser: async (saveKeys, getKeys) => {
36
60
  const keys = (await getKeys()) || (await sessionless.generateKeys(saveKeys, getKeys))
37
61
  sessionless.getKeys = getKeys;
@@ -40,11 +64,13 @@ const addie = {
40
64
  timestamp: new Date().getTime() + '',
41
65
  pubKey: keys.pubKey
42
66
  };
67
+ console.log('signing', payload.timestamp + payload.pubKey);
43
68
 
44
69
  payload.signature = await sessionless.sign(payload.timestamp + payload.pubKey);
45
70
 
46
71
  const res = await put(`${addie.baseURL}user/create`, payload);
47
72
  const user = await res.json();
73
+ console.log('response from addie', user);
48
74
  const uuid = user.uuid;
49
75
 
50
76
  return uuid;
@@ -63,11 +89,33 @@ const addie = {
63
89
  return user;
64
90
  },
65
91
 
66
- addProcessorAccount: async (uuid, processorPayload) => {
67
- return 'unimplemented';
92
+ addProcessorAccount: async (uuid, processor, country, name, email) => {
93
+ const timestamp = new Date().getTime() + '';
94
+ const message = timestamp + uuid + name + email;
95
+ const signature = await sessionless.sign(message);
96
+
97
+ const payload = {
98
+ timestamp,
99
+ country,
100
+ name,
101
+ email,
102
+ signature
103
+ };
104
+
105
+ const url = `${addie.baseURL}user/${uuid}/processor/${processor}`;
106
+ const res = await put(url, payload);
107
+ const user = await res.json();
108
+
109
+ return user;
68
110
  },
69
111
 
70
- getPaymentIntent: async (uuid, processor, amount, currency, payees) => {
112
+ // `merchant` ({pubKey}) is the party who receives the bulk of the charge
113
+ // (91%) — an invoice's creator, say — as distinct from `payees`, the
114
+ // affiliate splits. It has to be forwarded: without it the server builds
115
+ // the intent with no merchant_pubkey in its metadata, and the later
116
+ // transfer step has no one to pay, so the charge succeeds and the money
117
+ // never leaves the platform account.
118
+ getPaymentIntent: async (uuid, processor, amount, currency, payees, merchant) => {
71
119
  const timestamp = new Date().getTime() + '';
72
120
  const message = timestamp + uuid + amount + currency;
73
121
  const signature = await sessionless.sign(message);
@@ -80,6 +128,10 @@ const addie = {
80
128
  "signature": signature
81
129
  };
82
130
 
131
+ if(merchant) {
132
+ payload.merchant = merchant;
133
+ }
134
+
83
135
  const url = `${addie.baseURL}user/${uuid}/processor/${processor}/intent`;
84
136
  const res = await post(url, payload); // Start here
85
137
  const intent = await res.json();
@@ -87,7 +139,7 @@ const addie = {
87
139
  return intent;
88
140
  },
89
141
 
90
- getPaymentIntentWithoutSplits: async (uuid, processor, amount, currency) => {
142
+ getPaymentIntentWithoutSplits: async (uuid, processor, amount, currency, savePaymentMethod = false) => {
91
143
  const timestamp = new Date().getTime() + '';
92
144
  const message = timestamp + uuid + amount + currency;
93
145
  const signature = await sessionless.sign(message);
@@ -96,16 +148,175 @@ const addie = {
96
148
  timestamp,
97
149
  amount,
98
150
  currency,
151
+ savePaymentMethod,
99
152
  "signature": signature
100
153
  };
101
154
 
102
155
  const url = `${addie.baseURL}user/${uuid}/processor/${processor}/intent-without-splits`;
103
- const res = await post(url, payload); // Start here
156
+ const res = await post(url, payload);
104
157
  const intent = await res.json();
105
158
 
106
159
  return intent;
107
160
  },
108
161
 
162
+ // Payment Method Management
163
+ createSetupIntent: async (processor = 'stripe') => {
164
+ const timestamp = new Date().getTime() + '';
165
+ const keys = await sessionless.getKeys();
166
+ const message = timestamp + (keys.pubKey || '');
167
+ const signature = await sessionless.sign(message);
168
+
169
+ const payload = {
170
+ timestamp,
171
+ pubKey: keys.pubKey,
172
+ signature
173
+ };
174
+
175
+ const url = `${addie.baseURL}processor/${processor}/setup-intent`;
176
+ const res = await post(url, payload);
177
+ const setupIntent = await res.json();
178
+
179
+ return setupIntent;
180
+ },
181
+
182
+ getSavedPaymentMethods: async (uuid, processor = 'stripe') => {
183
+ const timestamp = new Date().getTime() + '';
184
+ const message = timestamp + uuid;
185
+ const signature = await sessionless.sign(message);
186
+
187
+ const url = `${addie.baseURL}saved-payment-methods?uuid=${uuid}&timestamp=${timestamp}&processor=${processor}&signature=${signature}`;
188
+ const res = await get(url);
189
+ const result = await res.json();
190
+
191
+ return result;
192
+ },
193
+
194
+ deleteSavedPaymentMethod: async (uuid, paymentMethodId, processor = 'stripe') => {
195
+ const timestamp = new Date().getTime() + '';
196
+ const message = timestamp + uuid;
197
+ const signature = await sessionless.sign(message);
198
+
199
+ const payload = {
200
+ timestamp,
201
+ signature
202
+ };
203
+
204
+ const url = `${addie.baseURL}saved-payment-methods/${paymentMethodId}`;
205
+ const res = await _delete(url, payload);
206
+ const result = await res.json();
207
+
208
+ return result;
209
+ },
210
+
211
+ // Stripe Issuing (Virtual Cards)
212
+ createCardholder: async (individualInfo) => {
213
+ const timestamp = new Date().getTime() + '';
214
+ const keys = await sessionless.getKeys();
215
+ const message = timestamp + keys.pubKey;
216
+ const signature = await sessionless.sign(message);
217
+
218
+ const payload = {
219
+ timestamp,
220
+ pubKey: keys.pubKey,
221
+ signature,
222
+ individualInfo
223
+ };
224
+
225
+ const url = `${addie.baseURL}issuing/cardholder`;
226
+ const res = await post(url, payload);
227
+ const result = await res.json();
228
+
229
+ return result;
230
+ },
231
+
232
+ issueVirtualCard: async (currency = 'usd', spendingLimit) => {
233
+ const timestamp = new Date().getTime() + '';
234
+ const keys = await sessionless.getKeys();
235
+ const message = timestamp + keys.pubKey;
236
+ const signature = await sessionless.sign(message);
237
+
238
+ const payload = {
239
+ timestamp,
240
+ pubKey: keys.pubKey,
241
+ signature,
242
+ currency,
243
+ spendingLimit
244
+ };
245
+
246
+ const url = `${addie.baseURL}issuing/card/virtual`;
247
+ const res = await post(url, payload);
248
+ const result = await res.json();
249
+
250
+ return result;
251
+ },
252
+
253
+ getIssuedCards: async () => {
254
+ const timestamp = new Date().getTime() + '';
255
+ const keys = await sessionless.getKeys();
256
+ const message = timestamp + keys.pubKey;
257
+ const signature = await sessionless.sign(message);
258
+
259
+ const url = `${addie.baseURL}issuing/cards?timestamp=${timestamp}&pubKey=${keys.pubKey}&signature=${signature}`;
260
+ const res = await get(url);
261
+ const result = await res.json();
262
+
263
+ return result;
264
+ },
265
+
266
+ getCardTransactions: async (limit = 10) => {
267
+ const timestamp = new Date().getTime() + '';
268
+ const keys = await sessionless.getKeys();
269
+ const message = timestamp + keys.pubKey;
270
+ const signature = await sessionless.sign(message);
271
+
272
+ const url = `${addie.baseURL}issuing/transactions?timestamp=${timestamp}&pubKey=${keys.pubKey}&signature=${signature}&limit=${limit}`;
273
+ const res = await get(url);
274
+ const result = await res.json();
275
+
276
+ return result;
277
+ },
278
+
279
+ updateCardStatus: async (cardId, status) => {
280
+ const timestamp = new Date().getTime() + '';
281
+ const keys = await sessionless.getKeys();
282
+ const message = timestamp + keys.pubKey + cardId + status;
283
+ const signature = await sessionless.sign(message);
284
+
285
+ const payload = {
286
+ timestamp,
287
+ pubKey: keys.pubKey,
288
+ signature,
289
+ status
290
+ };
291
+
292
+ const url = `${addie.baseURL}issuing/card/${cardId}/status`;
293
+ const res = await patch(url, payload);
294
+ const result = await res.json();
295
+
296
+ return result;
297
+ },
298
+
299
+ // Transfer Processing
300
+ processPaymentTransfers: async (paymentIntentId) => {
301
+ const url = `${addie.baseURL}payment/${paymentIntentId}/process-transfers`;
302
+ const res = await post(url, {});
303
+ const result = await res.json();
304
+
305
+ return result;
306
+ },
307
+
308
+ // Distinct from processPaymentTransfers above: that one moves funds to
309
+ // payout *cards* (Stripe Issuing), this one settles splits to Stripe
310
+ // Connected Accounts. Two different server routes, two different
311
+ // processors on Addie's side — a Connect payout has to use this one.
312
+ processConnectedTransfers: async (paymentIntentId) => {
313
+ const url = `${addie.baseURL}payment/${paymentIntentId}/process-connected-transfers`;
314
+ const res = await post(url, {});
315
+ const result = await res.json();
316
+
317
+ return result;
318
+ },
319
+
109
320
  deleteUser: async (uuid) => {
110
321
  const timestamp = new Date().getTime() + '';
111
322
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "addie-js",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "Addie JavaScript client",
5
5
  "main": "addie.js",
6
6
  "scripts": {
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "git+https://github.com/planet-nine-app/addie.git"
11
+ "url": "git+https://github.com/freyja-love-and-magic/addie.git"
12
12
  },
13
13
  "type": "module",
14
14
  "author": "planetnineisaspaceship",