From 0195ffc9fab2565ce241d7e84bc52da56e808554 Mon Sep 17 00:00:00 2001 From: Zuhwa Date: Wed, 31 Dec 2025 16:09:22 +0800 Subject: [PATCH] Skip x402 payment for zero budget --- src/acpJob.ts | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/acpJob.ts b/src/acpJob.ts index 37858f7..e963001 100644 --- a/src/acpJob.ts +++ b/src/acpJob.ts @@ -160,7 +160,8 @@ class AcpJob { } const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare); - const isPercentagePricing: boolean = this.priceType === PriceType.PERCENTAGE; + const isPercentagePricing: boolean = + this.priceType === PriceType.PERCENTAGE; operations.push( this.acpContractClient.createPayableMemo( @@ -171,9 +172,7 @@ class AcpJob { isPercentagePricing ? BigInt(Math.round(this.priceValue * 10000)) // convert to basis points : feeAmount.amount, - isPercentagePricing - ? FeeType.PERCENTAGE_FEE - : FeeType.NO_FEE, + isPercentagePricing ? FeeType.PERCENTAGE_FEE : FeeType.NO_FEE, AcpJobPhases.TRANSACTION, type, expiredAt, @@ -241,11 +240,13 @@ class AcpJob { ) ); - const x402PaymentDetails = - await this.acpContractClient.getX402PaymentDetails(this.id); + if (this.price > 0) { + const x402PaymentDetails = + await this.acpContractClient.getX402PaymentDetails(this.id); - if (x402PaymentDetails.isX402) { - await this.performX402Payment(this.price); + if (x402PaymentDetails.isX402) { + await this.performX402Payment(this.price); + } } return await this.acpContractClient.handleOperation(operations); @@ -371,7 +372,8 @@ class AcpJob { ); const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare); - const isPercentagePricing: boolean = this.priceType === PriceType.PERCENTAGE && !skipFee; + const isPercentagePricing: boolean = + this.priceType === PriceType.PERCENTAGE && !skipFee; operations.push( this.acpContractClient.createPayableMemo( @@ -382,9 +384,7 @@ class AcpJob { isPercentagePricing ? BigInt(Math.round(this.priceValue * 10000)) // convert to basis points : feeAmount.amount, - isPercentagePricing - ? FeeType.PERCENTAGE_FEE - : FeeType.NO_FEE, + isPercentagePricing ? FeeType.PERCENTAGE_FEE : FeeType.NO_FEE, AcpJobPhases.COMPLETED, MemoType.PAYABLE_TRANSFER, expiredAt, @@ -437,7 +437,8 @@ class AcpJob { ); const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare); - const isPercentagePricing: boolean = this.priceType === PriceType.PERCENTAGE && !skipFee; + const isPercentagePricing: boolean = + this.priceType === PriceType.PERCENTAGE && !skipFee; operations.push( this.acpContractClient.createPayableMemo( @@ -448,9 +449,7 @@ class AcpJob { isPercentagePricing ? BigInt(Math.round(this.priceValue * 10000)) // convert to basis points : feeAmount.amount, - isPercentagePricing - ? FeeType.PERCENTAGE_FEE - : FeeType.NO_FEE, + isPercentagePricing ? FeeType.PERCENTAGE_FEE : FeeType.NO_FEE, AcpJobPhases.COMPLETED, MemoType.PAYABLE_NOTIFICATION, expiredAt,