@labdigital/commercetools-mock 2.17.1 → 2.18.0
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/dist/index.cjs +4186 -3974
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +266 -413
- package/dist/index.d.ts +266 -413
- package/dist/index.js +4186 -3974
- package/dist/index.js.map +1 -1
- package/package.json +44 -46
- package/src/constants.ts +2 -2
- package/src/ctMock.test.ts +11 -11
- package/src/ctMock.ts +141 -127
- package/src/deprecation.ts +8 -0
- package/src/exceptions.ts +17 -15
- package/src/helpers.ts +32 -32
- package/src/index.test.ts +128 -128
- package/src/index.ts +3 -3
- package/src/lib/expandParser.ts +13 -13
- package/src/lib/haversine.test.ts +9 -9
- package/src/lib/haversine.ts +11 -11
- package/src/lib/masking.ts +11 -11
- package/src/lib/parser.ts +2 -2
- package/src/lib/password.ts +23 -3
- package/src/lib/predicateParser.test.ts +185 -183
- package/src/lib/predicateParser.ts +234 -234
- package/src/lib/projectionSearchFilter.test.ts +103 -101
- package/src/lib/projectionSearchFilter.ts +152 -150
- package/src/lib/proxy.ts +5 -5
- package/src/oauth/errors.ts +4 -4
- package/src/oauth/helpers.ts +6 -6
- package/src/oauth/server.test.ts +86 -86
- package/src/oauth/server.ts +158 -144
- package/src/oauth/store.ts +44 -43
- package/src/priceSelector.test.ts +35 -35
- package/src/priceSelector.ts +30 -30
- package/src/product-projection-search.ts +136 -134
- package/src/projectAPI.test.ts +7 -7
- package/src/projectAPI.ts +24 -22
- package/src/repositories/abstract.ts +168 -116
- package/src/repositories/associate-role.ts +90 -77
- package/src/repositories/attribute-group.ts +51 -40
- package/src/repositories/business-unit.ts +168 -148
- package/src/repositories/cart/actions.ts +489 -0
- package/src/repositories/cart/helpers.ts +30 -0
- package/src/repositories/cart/index.ts +180 -0
- package/src/repositories/cart-discount/actions.ts +148 -0
- package/src/repositories/cart-discount/index.ts +86 -0
- package/src/repositories/category/actions.ts +231 -0
- package/src/repositories/category/index.ts +52 -0
- package/src/repositories/channel.ts +88 -90
- package/src/repositories/custom-object.ts +46 -45
- package/src/repositories/customer/actions.ts +165 -0
- package/src/repositories/customer/index.ts +79 -0
- package/src/repositories/customer-group.ts +66 -55
- package/src/repositories/discount-code/actions.ts +149 -0
- package/src/repositories/discount-code/index.ts +50 -0
- package/src/repositories/errors.ts +10 -10
- package/src/repositories/extension.ts +64 -62
- package/src/repositories/helpers.ts +117 -118
- package/src/repositories/index.ts +80 -79
- package/src/repositories/inventory-entry/actions.ts +84 -0
- package/src/repositories/inventory-entry/index.ts +44 -0
- package/src/repositories/my-customer.ts +114 -0
- package/src/repositories/my-order.ts +8 -8
- package/src/repositories/order/actions.ts +281 -0
- package/src/repositories/{order.test.ts → order/index.test.ts} +77 -77
- package/src/repositories/order/index.ts +260 -0
- package/src/repositories/order-edit.ts +10 -23
- package/src/repositories/payment/actions.ts +305 -0
- package/src/repositories/payment/helpers.ts +17 -0
- package/src/repositories/payment/index.ts +56 -0
- package/src/repositories/product/actions.ts +943 -0
- package/src/repositories/product/helpers.ts +98 -0
- package/src/repositories/product/index.ts +130 -0
- package/src/repositories/product-discount.ts +127 -117
- package/src/repositories/product-projection.ts +56 -62
- package/src/repositories/product-selection.ts +31 -28
- package/src/repositories/product-type.ts +136 -134
- package/src/repositories/project.ts +133 -118
- package/src/repositories/quote-request.ts +7 -19
- package/src/repositories/quote.ts +7 -22
- package/src/repositories/review.ts +13 -26
- package/src/repositories/shipping-method/actions.ts +198 -0
- package/src/repositories/shipping-method/helpers.ts +10 -0
- package/src/repositories/shipping-method/index.ts +138 -0
- package/src/repositories/shopping-list/actions.ts +295 -0
- package/src/repositories/shopping-list/index.ts +122 -0
- package/src/repositories/staged-quote.ts +7 -20
- package/src/repositories/standalone-price.ts +57 -44
- package/src/repositories/state.ts +113 -68
- package/src/repositories/store.ts +106 -94
- package/src/repositories/subscription.ts +46 -22
- package/src/repositories/tax-category/actions.ts +94 -0
- package/src/repositories/tax-category/helpers.ts +8 -0
- package/src/repositories/tax-category/index.ts +25 -0
- package/src/repositories/type/actions.ts +162 -0
- package/src/repositories/type/index.ts +24 -0
- package/src/repositories/zone.ts +62 -58
- package/src/server.ts +9 -9
- package/src/services/abstract.ts +75 -72
- package/src/services/associate-roles.test.ts +27 -27
- package/src/services/associate-roles.ts +7 -7
- package/src/services/attribute-group.ts +7 -7
- package/src/services/business-units.test.ts +28 -28
- package/src/services/business-units.ts +7 -7
- package/src/services/cart-discount.test.ts +199 -199
- package/src/services/cart-discount.ts +7 -7
- package/src/services/cart.test.ts +261 -261
- package/src/services/cart.ts +22 -21
- package/src/services/category.test.ts +121 -121
- package/src/services/category.ts +7 -7
- package/src/services/channel.ts +7 -7
- package/src/services/custom-object.test.ts +130 -130
- package/src/services/custom-object.ts +34 -31
- package/src/services/customer-group.ts +7 -7
- package/src/services/customer.test.ts +205 -205
- package/src/services/customer.ts +23 -36
- package/src/services/discount-code.ts +7 -7
- package/src/services/extension.ts +7 -7
- package/src/services/index.ts +85 -81
- package/src/services/inventory-entry.test.ts +106 -106
- package/src/services/inventory-entry.ts +7 -7
- package/src/services/my-cart.test.ts +56 -56
- package/src/services/my-cart.ts +20 -20
- package/src/services/my-customer.test.ts +155 -104
- package/src/services/my-customer.ts +61 -75
- package/src/services/my-order.ts +16 -16
- package/src/services/my-payment.test.ts +40 -40
- package/src/services/my-payment.ts +7 -7
- package/src/services/my-shopping-list.ts +7 -7
- package/src/services/order.test.ts +243 -243
- package/src/services/order.ts +23 -18
- package/src/services/payment.test.ts +40 -40
- package/src/services/payment.ts +7 -7
- package/src/services/product-discount.ts +7 -7
- package/src/services/product-projection.test.ts +190 -190
- package/src/services/product-projection.ts +34 -32
- package/src/services/product-selection.test.ts +19 -19
- package/src/services/product-selection.ts +7 -7
- package/src/services/product-type.test.ts +38 -38
- package/src/services/product-type.ts +7 -7
- package/src/services/product.test.ts +658 -656
- package/src/services/product.ts +7 -7
- package/src/services/project.test.ts +24 -24
- package/src/services/project.ts +17 -17
- package/src/services/reviews.ts +7 -7
- package/src/services/shipping-method.test.ts +78 -78
- package/src/services/shipping-method.ts +16 -16
- package/src/services/shopping-list.test.ts +170 -170
- package/src/services/shopping-list.ts +7 -7
- package/src/services/standalone-price.test.ts +112 -112
- package/src/services/standalone-price.ts +7 -7
- package/src/services/state.test.ts +30 -30
- package/src/services/state.ts +7 -7
- package/src/services/store.test.ts +40 -40
- package/src/services/store.ts +7 -7
- package/src/services/subscription.ts +7 -7
- package/src/services/tax-category.test.ts +43 -43
- package/src/services/tax-category.ts +7 -7
- package/src/services/type.ts +7 -7
- package/src/services/zone.ts +7 -7
- package/src/shippingCalculator.test.ts +43 -43
- package/src/shippingCalculator.ts +23 -23
- package/src/storage/abstract.ts +36 -34
- package/src/storage/in-memory.ts +237 -233
- package/src/storage/index.ts +2 -2
- package/src/types.ts +91 -91
- package/src/repositories/cart-discount.ts +0 -219
- package/src/repositories/cart.ts +0 -659
- package/src/repositories/category.ts +0 -256
- package/src/repositories/customer.ts +0 -228
- package/src/repositories/discount-code.ts +0 -181
- package/src/repositories/inventory-entry.ts +0 -109
- package/src/repositories/order.ts +0 -514
- package/src/repositories/payment.ts +0 -342
- package/src/repositories/product.ts +0 -1106
- package/src/repositories/shipping-method.ts +0 -312
- package/src/repositories/shopping-list.ts +0 -392
- package/src/repositories/tax-category.ts +0 -111
- package/src/repositories/type.ts +0 -172
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CustomerReference,
|
|
3
|
+
Payment,
|
|
4
|
+
PaymentAddInterfaceInteractionAction,
|
|
5
|
+
PaymentAddTransactionAction,
|
|
6
|
+
PaymentChangeAmountPlannedAction,
|
|
7
|
+
PaymentChangeTransactionInteractionIdAction,
|
|
8
|
+
PaymentChangeTransactionStateAction,
|
|
9
|
+
PaymentChangeTransactionTimestampAction,
|
|
10
|
+
PaymentSetAnonymousIdAction,
|
|
11
|
+
PaymentSetCustomFieldAction,
|
|
12
|
+
PaymentSetCustomTypeAction,
|
|
13
|
+
PaymentSetCustomerAction,
|
|
14
|
+
PaymentSetInterfaceIdAction,
|
|
15
|
+
PaymentSetKeyAction,
|
|
16
|
+
PaymentSetMethodInfoInterfaceAction,
|
|
17
|
+
PaymentSetMethodInfoMethodAction,
|
|
18
|
+
PaymentSetMethodInfoNameAction,
|
|
19
|
+
PaymentSetStatusInterfaceCodeAction,
|
|
20
|
+
PaymentSetStatusInterfaceTextAction,
|
|
21
|
+
PaymentSetTransactionCustomFieldAction,
|
|
22
|
+
PaymentSetTransactionCustomTypeAction,
|
|
23
|
+
PaymentTransitionStateAction,
|
|
24
|
+
PaymentUpdateAction,
|
|
25
|
+
State,
|
|
26
|
+
Transaction,
|
|
27
|
+
} from "@commercetools/platform-sdk";
|
|
28
|
+
import type { Writable } from "~src/types";
|
|
29
|
+
import {
|
|
30
|
+
AbstractUpdateHandler,
|
|
31
|
+
RepositoryContext,
|
|
32
|
+
UpdateHandlerInterface,
|
|
33
|
+
} from "../abstract";
|
|
34
|
+
import {
|
|
35
|
+
createCentPrecisionMoney,
|
|
36
|
+
createCustomFields,
|
|
37
|
+
getReferenceFromResourceIdentifier,
|
|
38
|
+
} from "../helpers";
|
|
39
|
+
import { transactionFromTransactionDraft } from "./helpers";
|
|
40
|
+
|
|
41
|
+
export class PaymentUpdateHandler
|
|
42
|
+
extends AbstractUpdateHandler
|
|
43
|
+
implements UpdateHandlerInterface<Payment, PaymentUpdateAction>
|
|
44
|
+
{
|
|
45
|
+
addInterfaceInteraction(
|
|
46
|
+
context: RepositoryContext,
|
|
47
|
+
resource: Writable<Payment>,
|
|
48
|
+
{ type, fields }: PaymentAddInterfaceInteractionAction,
|
|
49
|
+
) {
|
|
50
|
+
resource.interfaceInteractions.push(
|
|
51
|
+
createCustomFields({ type, fields }, context.projectKey, this._storage)!,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
addTransaction(
|
|
56
|
+
context: RepositoryContext,
|
|
57
|
+
resource: Writable<Payment>,
|
|
58
|
+
{ transaction }: PaymentAddTransactionAction,
|
|
59
|
+
) {
|
|
60
|
+
resource.transactions = [
|
|
61
|
+
...resource.transactions,
|
|
62
|
+
transactionFromTransactionDraft(context, this._storage, transaction),
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
changeAmountPlanned(
|
|
67
|
+
_context: RepositoryContext,
|
|
68
|
+
resource: Writable<Payment>,
|
|
69
|
+
{ amount }: PaymentChangeAmountPlannedAction,
|
|
70
|
+
) {
|
|
71
|
+
resource.amountPlanned = createCentPrecisionMoney(amount);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
changeTransactionInteractionId(
|
|
75
|
+
_context: RepositoryContext,
|
|
76
|
+
resource: Writable<Payment>,
|
|
77
|
+
{
|
|
78
|
+
transactionId,
|
|
79
|
+
interactionId,
|
|
80
|
+
}: PaymentChangeTransactionInteractionIdAction,
|
|
81
|
+
) {
|
|
82
|
+
const transaction = resource.transactions.find(
|
|
83
|
+
(e: Transaction) => e.id === transactionId,
|
|
84
|
+
);
|
|
85
|
+
if (transaction) {
|
|
86
|
+
transaction.interactionId = interactionId;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
changeTransactionState(
|
|
91
|
+
_context: RepositoryContext,
|
|
92
|
+
resource: Writable<Payment>,
|
|
93
|
+
{ transactionId, state }: PaymentChangeTransactionStateAction,
|
|
94
|
+
) {
|
|
95
|
+
const index = resource.transactions.findIndex(
|
|
96
|
+
(e: Transaction) => e.id === transactionId,
|
|
97
|
+
);
|
|
98
|
+
const updatedTransaction: Transaction = {
|
|
99
|
+
...resource.transactions[index],
|
|
100
|
+
state,
|
|
101
|
+
};
|
|
102
|
+
resource.transactions[index] = updatedTransaction;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
changeTransactionTimestamp(
|
|
106
|
+
_context: RepositoryContext,
|
|
107
|
+
resource: Writable<Payment>,
|
|
108
|
+
{ transactionId, timestamp }: PaymentChangeTransactionTimestampAction,
|
|
109
|
+
) {
|
|
110
|
+
const transaction = resource.transactions.find(
|
|
111
|
+
(e: Transaction) => e.id === transactionId,
|
|
112
|
+
);
|
|
113
|
+
if (transaction) {
|
|
114
|
+
transaction.timestamp = timestamp;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
setAnonymousId(
|
|
119
|
+
_context: RepositoryContext,
|
|
120
|
+
resource: Writable<Payment>,
|
|
121
|
+
{ anonymousId }: PaymentSetAnonymousIdAction,
|
|
122
|
+
) {
|
|
123
|
+
resource.anonymousId = anonymousId;
|
|
124
|
+
resource.customer = undefined;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
setCustomer(
|
|
128
|
+
_context: RepositoryContext,
|
|
129
|
+
resource: Writable<Payment>,
|
|
130
|
+
{ customer }: PaymentSetCustomerAction,
|
|
131
|
+
) {
|
|
132
|
+
if (customer) {
|
|
133
|
+
const c = getReferenceFromResourceIdentifier<CustomerReference>(
|
|
134
|
+
customer,
|
|
135
|
+
_context.projectKey,
|
|
136
|
+
this._storage,
|
|
137
|
+
);
|
|
138
|
+
resource.customer = c;
|
|
139
|
+
resource.anonymousId = undefined;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
setCustomField(
|
|
144
|
+
context: RepositoryContext,
|
|
145
|
+
resource: Payment,
|
|
146
|
+
{ name, value }: PaymentSetCustomFieldAction,
|
|
147
|
+
) {
|
|
148
|
+
if (!resource.custom) {
|
|
149
|
+
throw new Error("Resource has no custom field");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
resource.custom.fields[name] = value;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
setCustomType(
|
|
156
|
+
context: RepositoryContext,
|
|
157
|
+
resource: Writable<Payment>,
|
|
158
|
+
{ type, fields }: PaymentSetCustomTypeAction,
|
|
159
|
+
) {
|
|
160
|
+
if (!type) {
|
|
161
|
+
resource.custom = undefined;
|
|
162
|
+
} else {
|
|
163
|
+
const resolvedType = this._storage.getByResourceIdentifier(
|
|
164
|
+
context.projectKey,
|
|
165
|
+
type,
|
|
166
|
+
);
|
|
167
|
+
if (!resolvedType) {
|
|
168
|
+
throw new Error(`Type ${type} not found`);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
resource.custom = {
|
|
172
|
+
type: {
|
|
173
|
+
typeId: "type",
|
|
174
|
+
id: resolvedType.id,
|
|
175
|
+
},
|
|
176
|
+
fields: fields ?? {},
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
setInterfaceId(
|
|
182
|
+
_context: RepositoryContext,
|
|
183
|
+
resource: Writable<Payment>,
|
|
184
|
+
{ interfaceId }: PaymentSetInterfaceIdAction,
|
|
185
|
+
) {
|
|
186
|
+
resource.interfaceId = interfaceId;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
setKey(
|
|
190
|
+
_context: RepositoryContext,
|
|
191
|
+
resource: Writable<Payment>,
|
|
192
|
+
{ key }: PaymentSetKeyAction,
|
|
193
|
+
) {
|
|
194
|
+
resource.key = key;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
setMethodInfoInterface(
|
|
198
|
+
_context: RepositoryContext,
|
|
199
|
+
resource: Writable<Payment>,
|
|
200
|
+
args: PaymentSetMethodInfoInterfaceAction,
|
|
201
|
+
) {
|
|
202
|
+
resource.paymentMethodInfo.paymentInterface = args.interface;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
setMethodInfoMethod(
|
|
206
|
+
_context: RepositoryContext,
|
|
207
|
+
resource: Writable<Payment>,
|
|
208
|
+
{ method }: PaymentSetMethodInfoMethodAction,
|
|
209
|
+
) {
|
|
210
|
+
resource.paymentMethodInfo.method = method;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
setMethodInfoName(
|
|
214
|
+
_context: RepositoryContext,
|
|
215
|
+
resource: Writable<Payment>,
|
|
216
|
+
{ name }: PaymentSetMethodInfoNameAction,
|
|
217
|
+
) {
|
|
218
|
+
resource.paymentMethodInfo.name = name;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
setStatusInterfaceCode(
|
|
222
|
+
_context: RepositoryContext,
|
|
223
|
+
resource: Writable<Payment>,
|
|
224
|
+
{ interfaceCode }: PaymentSetStatusInterfaceCodeAction,
|
|
225
|
+
) {
|
|
226
|
+
resource.paymentStatus.interfaceCode = interfaceCode;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
setStatusInterfaceText(
|
|
230
|
+
_context: RepositoryContext,
|
|
231
|
+
resource: Writable<Payment>,
|
|
232
|
+
{ interfaceText }: PaymentSetStatusInterfaceTextAction,
|
|
233
|
+
) {
|
|
234
|
+
resource.paymentStatus.interfaceText = interfaceText;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
setTransactionCustomField(
|
|
238
|
+
_context: RepositoryContext,
|
|
239
|
+
resource: Writable<Payment>,
|
|
240
|
+
{ transactionId, name, value }: PaymentSetTransactionCustomFieldAction,
|
|
241
|
+
) {
|
|
242
|
+
const transaction = resource.transactions.find(
|
|
243
|
+
(e: Transaction) => e.id === transactionId,
|
|
244
|
+
);
|
|
245
|
+
if (transaction) {
|
|
246
|
+
if (!transaction.custom) {
|
|
247
|
+
throw new Error("Transaction has no custom field");
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
transaction.custom.fields[name] = value;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
setTransactionCustomType(
|
|
255
|
+
context: RepositoryContext,
|
|
256
|
+
resource: Writable<Payment>,
|
|
257
|
+
{ transactionId, type, fields }: PaymentSetTransactionCustomTypeAction,
|
|
258
|
+
) {
|
|
259
|
+
const transaction = resource.transactions.find(
|
|
260
|
+
(e: Transaction) => e.id === transactionId,
|
|
261
|
+
);
|
|
262
|
+
if (transaction) {
|
|
263
|
+
if (!type) {
|
|
264
|
+
transaction.custom = undefined;
|
|
265
|
+
} else {
|
|
266
|
+
const resolvedType = this._storage.getByResourceIdentifier(
|
|
267
|
+
context.projectKey,
|
|
268
|
+
type,
|
|
269
|
+
);
|
|
270
|
+
if (!resolvedType) {
|
|
271
|
+
throw new Error(`Type ${type} not found`);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
transaction.custom = {
|
|
275
|
+
type: {
|
|
276
|
+
typeId: "type",
|
|
277
|
+
id: resolvedType.id,
|
|
278
|
+
},
|
|
279
|
+
fields: fields ?? {},
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
transitionState(
|
|
286
|
+
context: RepositoryContext,
|
|
287
|
+
resource: Writable<Payment>,
|
|
288
|
+
{ state }: PaymentTransitionStateAction,
|
|
289
|
+
) {
|
|
290
|
+
const stateObj = this._storage.getByResourceIdentifier(
|
|
291
|
+
context.projectKey,
|
|
292
|
+
state,
|
|
293
|
+
) as State | null;
|
|
294
|
+
|
|
295
|
+
if (!stateObj) {
|
|
296
|
+
throw new Error(`State ${state} not found`);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
resource.paymentStatus.state = {
|
|
300
|
+
typeId: "state",
|
|
301
|
+
id: stateObj.id,
|
|
302
|
+
obj: stateObj,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Transaction, TransactionDraft } from "@commercetools/platform-sdk";
|
|
2
|
+
import { v4 as uuidv4 } from "uuid";
|
|
3
|
+
import { AbstractStorage } from "~src/storage";
|
|
4
|
+
import { RepositoryContext } from "../abstract";
|
|
5
|
+
import { createCentPrecisionMoney, createCustomFields } from "../helpers";
|
|
6
|
+
|
|
7
|
+
export const transactionFromTransactionDraft = (
|
|
8
|
+
context: RepositoryContext,
|
|
9
|
+
storage: AbstractStorage,
|
|
10
|
+
draft: TransactionDraft,
|
|
11
|
+
): Transaction => ({
|
|
12
|
+
...draft,
|
|
13
|
+
id: uuidv4(),
|
|
14
|
+
amount: createCentPrecisionMoney(draft.amount),
|
|
15
|
+
custom: createCustomFields(draft.custom, context.projectKey, storage),
|
|
16
|
+
state: draft.state ?? "Initial", // Documented as default
|
|
17
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Payment,
|
|
3
|
+
PaymentDraft,
|
|
4
|
+
StateReference,
|
|
5
|
+
} from "@commercetools/platform-sdk";
|
|
6
|
+
import { getBaseResourceProperties } from "~src/helpers";
|
|
7
|
+
import { AbstractStorage } from "~src/storage/abstract";
|
|
8
|
+
import { AbstractResourceRepository, RepositoryContext } from "../abstract";
|
|
9
|
+
import {
|
|
10
|
+
createCentPrecisionMoney,
|
|
11
|
+
createCustomFields,
|
|
12
|
+
getReferenceFromResourceIdentifier,
|
|
13
|
+
} from "../helpers";
|
|
14
|
+
import { PaymentUpdateHandler } from "./actions";
|
|
15
|
+
import { transactionFromTransactionDraft } from "./helpers";
|
|
16
|
+
|
|
17
|
+
export class PaymentRepository extends AbstractResourceRepository<"payment"> {
|
|
18
|
+
constructor(storage: AbstractStorage) {
|
|
19
|
+
super("payment", storage);
|
|
20
|
+
this.actions = new PaymentUpdateHandler(this._storage);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
create(context: RepositoryContext, draft: PaymentDraft): Payment {
|
|
24
|
+
const resource: Payment = {
|
|
25
|
+
...getBaseResourceProperties(),
|
|
26
|
+
amountPlanned: createCentPrecisionMoney(draft.amountPlanned),
|
|
27
|
+
paymentMethodInfo: draft.paymentMethodInfo!,
|
|
28
|
+
paymentStatus: draft.paymentStatus
|
|
29
|
+
? {
|
|
30
|
+
...draft.paymentStatus,
|
|
31
|
+
state: draft.paymentStatus.state
|
|
32
|
+
? getReferenceFromResourceIdentifier<StateReference>(
|
|
33
|
+
draft.paymentStatus.state,
|
|
34
|
+
context.projectKey,
|
|
35
|
+
this._storage,
|
|
36
|
+
)
|
|
37
|
+
: undefined,
|
|
38
|
+
}
|
|
39
|
+
: {},
|
|
40
|
+
transactions: (draft.transactions || []).map((t) =>
|
|
41
|
+
transactionFromTransactionDraft(context, this._storage, t),
|
|
42
|
+
),
|
|
43
|
+
interfaceInteractions: (draft.interfaceInteractions || []).map(
|
|
44
|
+
(interaction) =>
|
|
45
|
+
createCustomFields(interaction, context.projectKey, this._storage)!,
|
|
46
|
+
),
|
|
47
|
+
custom: createCustomFields(
|
|
48
|
+
draft.custom,
|
|
49
|
+
context.projectKey,
|
|
50
|
+
this._storage,
|
|
51
|
+
),
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
return this.saveNew(context, resource);
|
|
55
|
+
}
|
|
56
|
+
}
|