@henrylabs-interview/payment-processor 0.2.13 → 0.2.15

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.
@@ -80,11 +80,11 @@ export class Checkout {
80
80
  status: 'failure',
81
81
  substatus: '501-not-supported',
82
82
  code: 501,
83
- message: 'This currency is currently not supported, please convert first.',
83
+ message: 'This currency is currently not supported, please convert to another supported currency first.',
84
84
  };
85
85
  }
86
- // Simulated random internal failure
87
- if (Math.random() > 0.85) {
86
+ // Simulated stupid internal failures
87
+ if ((params.customerId ?? '').length === crypto.randomUUID().length || (params.customerId ?? '').includes('-') || params.customerId === '') {
88
88
  return {
89
89
  _reqId: genReqId(),
90
90
  status: 'failure',
@@ -29,27 +29,12 @@ export async function readHistory() {
29
29
  export async function writeHistory(params) {
30
30
  const history = await readHistory();
31
31
  const now = Date.now();
32
- const existingIndex = history.findIndex((v) => v.id === params.id);
33
- let record;
34
- if (existingIndex !== -1) {
35
- // Replace existing record
36
- record = {
37
- ...history[existingIndex],
38
- ...params,
39
- createdAt: history[existingIndex]?.createdAt ?? now,
40
- updatedAt: now,
41
- };
42
- history[existingIndex] = record;
43
- }
44
- else {
45
- // Add new record
46
- record = {
47
- ...params,
48
- createdAt: now,
49
- updatedAt: now,
50
- };
51
- history.push(record);
52
- }
32
+ const record = {
33
+ ...params,
34
+ createdAt: now,
35
+ updatedAt: now,
36
+ };
37
+ history.push(record);
53
38
  await Bun.write(path, JSON.stringify(history, null, 2));
54
39
  return record;
55
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henrylabs-interview/payment-processor",
3
- "version": "0.2.13",
3
+ "version": "0.2.15",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",