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/index.js CHANGED
@@ -31274,7 +31274,66 @@ var MoltsPayServer = class {
31274
31274
  });
31275
31275
  }
31276
31276
  console.log(`[MoltsPay] /proxy: Verified by ${verifyResult.facilitator}`);
31277
- console.log(`[MoltsPay] /proxy: Settling payment...`);
31277
+ const { execute, service, params } = body;
31278
+ if (execute && service) {
31279
+ console.log(`[MoltsPay] /proxy: Executing skill first (pay on success): ${service}`);
31280
+ const skill = this.skills.get(service);
31281
+ if (!skill) {
31282
+ console.log(`[MoltsPay] /proxy: Service not found: ${service} - NOT settling`);
31283
+ return this.sendJson(res, 404, {
31284
+ success: false,
31285
+ paymentSettled: false,
31286
+ error: `Service not found: ${service}`
31287
+ });
31288
+ }
31289
+ let result;
31290
+ try {
31291
+ result = await skill.handler(params || {});
31292
+ console.log(`[MoltsPay] /proxy: Skill succeeded, now settling payment...`);
31293
+ } catch (err) {
31294
+ console.error(`[MoltsPay] /proxy: Skill failed: ${err.message} - NOT settling`);
31295
+ return this.sendJson(res, 500, {
31296
+ success: false,
31297
+ paymentSettled: false,
31298
+ error: `Service execution failed: ${err.message}`
31299
+ });
31300
+ }
31301
+ let settlement2 = null;
31302
+ try {
31303
+ settlement2 = await this.registry.settle(payment, requirements);
31304
+ console.log(`[MoltsPay] /proxy: Payment settled by ${settlement2.facilitator}: ${settlement2.transaction || "pending"}`);
31305
+ } catch (err) {
31306
+ console.error("[MoltsPay] /proxy: Settlement failed:", err.message);
31307
+ return this.sendJson(res, 200, {
31308
+ success: true,
31309
+ verified: true,
31310
+ settled: false,
31311
+ settlementError: err.message,
31312
+ from: payment.payload?.authorization?.from,
31313
+ // Buyer's wallet address
31314
+ paidTo: wallet,
31315
+ amount: amountNum,
31316
+ currency: currency || "USDC",
31317
+ memo,
31318
+ result
31319
+ });
31320
+ }
31321
+ return this.sendJson(res, 200, {
31322
+ success: true,
31323
+ verified: true,
31324
+ settled: settlement2?.success || false,
31325
+ txHash: settlement2?.transaction,
31326
+ from: payment.payload?.authorization?.from,
31327
+ // Buyer's wallet address
31328
+ paidTo: wallet,
31329
+ amount: amountNum,
31330
+ currency: currency || "USDC",
31331
+ facilitator: settlement2?.facilitator,
31332
+ memo,
31333
+ result
31334
+ });
31335
+ }
31336
+ console.log(`[MoltsPay] /proxy: Settling payment (no execution)...`);
31278
31337
  let settlement = null;
31279
31338
  try {
31280
31339
  settlement = await this.registry.settle(payment, requirements);
@@ -31291,6 +31350,8 @@ var MoltsPayServer = class {
31291
31350
  verified: true,
31292
31351
  settled: settlement?.success || false,
31293
31352
  txHash: settlement?.transaction,
31353
+ from: payment.payload?.authorization?.from,
31354
+ // Buyer's wallet address
31294
31355
  paidTo: wallet,
31295
31356
  amount: amountNum,
31296
31357
  currency: currency || "USDC",