spaps 0.3.6 → 0.3.7
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/package.json +1 -1
- package/src/local-server.js +40 -39
package/package.json
CHANGED
package/src/local-server.js
CHANGED
|
@@ -359,51 +359,52 @@ class LocalServer {
|
|
|
359
359
|
|
|
360
360
|
for (const product of localProducts) {
|
|
361
361
|
try {
|
|
362
|
-
// Check if product already exists in Stripe
|
|
362
|
+
// Check if product already exists in Stripe by searching metadata
|
|
363
363
|
let stripeProduct;
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
currency: product.currency,
|
|
385
|
-
metadata: {
|
|
386
|
-
spaps_managed: 'true'
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
syncResults.push({
|
|
391
|
-
id: product.id,
|
|
392
|
-
name: product.name,
|
|
393
|
-
action: 'created',
|
|
394
|
-
stripe_id: stripeProduct.id
|
|
395
|
-
});
|
|
396
|
-
} else {
|
|
397
|
-
throw error;
|
|
398
|
-
}
|
|
399
|
-
}
|
|
364
|
+
const existingProducts = await stripe.products.list({
|
|
365
|
+
limit: 100,
|
|
366
|
+
expand: ['data.default_price']
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
stripeProduct = existingProducts.data.find(p =>
|
|
370
|
+
p.metadata && p.metadata.spaps_id === product.id
|
|
371
|
+
);
|
|
372
|
+
|
|
373
|
+
if (!stripeProduct) {
|
|
374
|
+
// Create new product in Stripe
|
|
375
|
+
stripeProduct = await stripe.products.create({
|
|
376
|
+
name: product.name,
|
|
377
|
+
description: product.description,
|
|
378
|
+
metadata: {
|
|
379
|
+
spaps_managed: 'true',
|
|
380
|
+
created_by: 'spaps_admin',
|
|
381
|
+
spaps_id: product.id
|
|
382
|
+
}
|
|
383
|
+
});
|
|
400
384
|
|
|
401
|
-
|
|
385
|
+
// Create corresponding price
|
|
386
|
+
await stripe.prices.create({
|
|
387
|
+
product: stripeProduct.id,
|
|
388
|
+
unit_amount: product.price,
|
|
389
|
+
currency: product.currency,
|
|
390
|
+
metadata: {
|
|
391
|
+
spaps_managed: 'true',
|
|
392
|
+
spaps_price_id: product.price_id
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
syncResults.push({
|
|
397
|
+
id: product.id,
|
|
398
|
+
name: product.name,
|
|
399
|
+
action: 'created',
|
|
400
|
+
stripe_id: stripeProduct.id
|
|
401
|
+
});
|
|
402
|
+
} else {
|
|
402
403
|
// Update existing product
|
|
403
404
|
await stripe.products.update(stripeProduct.id, {
|
|
404
405
|
name: product.name,
|
|
405
406
|
description: product.description,
|
|
406
|
-
active: product.active
|
|
407
|
+
active: product.active !== false
|
|
407
408
|
});
|
|
408
409
|
|
|
409
410
|
syncResults.push({
|