moltspay 0.9.2 → 0.9.3

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/cli/index.js CHANGED
@@ -1316,7 +1316,66 @@ var MoltsPayServer = class {
1316
1316
  });
1317
1317
  }
1318
1318
  console.log(`[MoltsPay] /proxy: Verified by ${verifyResult.facilitator}`);
1319
- console.log(`[MoltsPay] /proxy: Settling payment...`);
1319
+ const { execute, service, params } = body;
1320
+ if (execute && service) {
1321
+ console.log(`[MoltsPay] /proxy: Executing skill first (pay on success): ${service}`);
1322
+ const skill = this.skills.get(service);
1323
+ if (!skill) {
1324
+ console.log(`[MoltsPay] /proxy: Service not found: ${service} - NOT settling`);
1325
+ return this.sendJson(res, 404, {
1326
+ success: false,
1327
+ paymentSettled: false,
1328
+ error: `Service not found: ${service}`
1329
+ });
1330
+ }
1331
+ let result;
1332
+ try {
1333
+ result = await skill.handler(params || {});
1334
+ console.log(`[MoltsPay] /proxy: Skill succeeded, now settling payment...`);
1335
+ } catch (err) {
1336
+ console.error(`[MoltsPay] /proxy: Skill failed: ${err.message} - NOT settling`);
1337
+ return this.sendJson(res, 500, {
1338
+ success: false,
1339
+ paymentSettled: false,
1340
+ error: `Service execution failed: ${err.message}`
1341
+ });
1342
+ }
1343
+ let settlement2 = null;
1344
+ try {
1345
+ settlement2 = await this.registry.settle(payment, requirements);
1346
+ console.log(`[MoltsPay] /proxy: Payment settled by ${settlement2.facilitator}: ${settlement2.transaction || "pending"}`);
1347
+ } catch (err) {
1348
+ console.error("[MoltsPay] /proxy: Settlement failed:", err.message);
1349
+ return this.sendJson(res, 200, {
1350
+ success: true,
1351
+ verified: true,
1352
+ settled: false,
1353
+ settlementError: err.message,
1354
+ from: payment.payload?.authorization?.from,
1355
+ // Buyer's wallet address
1356
+ paidTo: wallet,
1357
+ amount: amountNum,
1358
+ currency: currency || "USDC",
1359
+ memo,
1360
+ result
1361
+ });
1362
+ }
1363
+ return this.sendJson(res, 200, {
1364
+ success: true,
1365
+ verified: true,
1366
+ settled: settlement2?.success || false,
1367
+ txHash: settlement2?.transaction,
1368
+ from: payment.payload?.authorization?.from,
1369
+ // Buyer's wallet address
1370
+ paidTo: wallet,
1371
+ amount: amountNum,
1372
+ currency: currency || "USDC",
1373
+ facilitator: settlement2?.facilitator,
1374
+ memo,
1375
+ result
1376
+ });
1377
+ }
1378
+ console.log(`[MoltsPay] /proxy: Settling payment (no execution)...`);
1320
1379
  let settlement = null;
1321
1380
  try {
1322
1381
  settlement = await this.registry.settle(payment, requirements);
@@ -1333,6 +1392,8 @@ var MoltsPayServer = class {
1333
1392
  verified: true,
1334
1393
  settled: settlement?.success || false,
1335
1394
  txHash: settlement?.transaction,
1395
+ from: payment.payload?.authorization?.from,
1396
+ // Buyer's wallet address
1336
1397
  paidTo: wallet,
1337
1398
  amount: amountNum,
1338
1399
  currency: currency || "USDC",