Skip to content

Commit ef73e71

Browse files
authored
Merge pull request #143 from Virtual-Protocol/fix/skip-x402-payment
Skip x402 payment for zero budget
2 parents 5b67963 + 22f56ba commit ef73e71

4 files changed

Lines changed: 19 additions & 20 deletions

File tree

examples/acp-base/skip-evaluation/buyer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async function buyer() {
7070
"<your-schema-key-2>": "<your-schema-value-2>",
7171
},
7272
undefined, // evaluator address, undefined fallback to empty address - skip-evaluation
73-
new Date(Date.now() + 1000 * 60 * 3.1) // job expiry duration, minimum 3 minutes
73+
new Date(Date.now() + 1000 * 60 * 5) // job expiry duration, minimum 5 minutes
7474
);
7575

7676
console.log(`Job ${jobId} initiated`);

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@virtuals-protocol/acp-node",
3-
"version": "0.3.0-beta.16",
3+
"version": "0.3.0-beta.17",
44
"main": "./dist/index.js",
55
"module": "./dist/index.mjs",
66
"types": "./dist/index.d.ts",

src/acpJob.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ class AcpJob {
160160
}
161161

162162
const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
163-
const isPercentagePricing: boolean = this.priceType === PriceType.PERCENTAGE;
163+
const isPercentagePricing: boolean =
164+
this.priceType === PriceType.PERCENTAGE;
164165

165166
operations.push(
166167
this.acpContractClient.createPayableMemo(
@@ -171,9 +172,7 @@ class AcpJob {
171172
isPercentagePricing
172173
? BigInt(Math.round(this.priceValue * 10000)) // convert to basis points
173174
: feeAmount.amount,
174-
isPercentagePricing
175-
? FeeType.PERCENTAGE_FEE
176-
: FeeType.NO_FEE,
175+
isPercentagePricing ? FeeType.PERCENTAGE_FEE : FeeType.NO_FEE,
177176
AcpJobPhases.TRANSACTION,
178177
type,
179178
expiredAt,
@@ -241,11 +240,13 @@ class AcpJob {
241240
)
242241
);
243242

244-
const x402PaymentDetails =
245-
await this.acpContractClient.getX402PaymentDetails(this.id);
243+
if (this.price > 0) {
244+
const x402PaymentDetails =
245+
await this.acpContractClient.getX402PaymentDetails(this.id);
246246

247-
if (x402PaymentDetails.isX402) {
248-
await this.performX402Payment(this.price);
247+
if (x402PaymentDetails.isX402) {
248+
await this.performX402Payment(this.price);
249+
}
249250
}
250251

251252
return await this.acpContractClient.handleOperation(operations);
@@ -371,7 +372,8 @@ class AcpJob {
371372
);
372373

373374
const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
374-
const isPercentagePricing: boolean = this.priceType === PriceType.PERCENTAGE && !skipFee;
375+
const isPercentagePricing: boolean =
376+
this.priceType === PriceType.PERCENTAGE && !skipFee;
375377

376378
operations.push(
377379
this.acpContractClient.createPayableMemo(
@@ -382,9 +384,7 @@ class AcpJob {
382384
isPercentagePricing
383385
? BigInt(Math.round(this.priceValue * 10000)) // convert to basis points
384386
: feeAmount.amount,
385-
isPercentagePricing
386-
? FeeType.PERCENTAGE_FEE
387-
: FeeType.NO_FEE,
387+
isPercentagePricing ? FeeType.PERCENTAGE_FEE : FeeType.NO_FEE,
388388
AcpJobPhases.COMPLETED,
389389
MemoType.PAYABLE_TRANSFER,
390390
expiredAt,
@@ -437,7 +437,8 @@ class AcpJob {
437437
);
438438

439439
const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
440-
const isPercentagePricing: boolean = this.priceType === PriceType.PERCENTAGE && !skipFee;
440+
const isPercentagePricing: boolean =
441+
this.priceType === PriceType.PERCENTAGE && !skipFee;
441442

442443
operations.push(
443444
this.acpContractClient.createPayableMemo(
@@ -448,9 +449,7 @@ class AcpJob {
448449
isPercentagePricing
449450
? BigInt(Math.round(this.priceValue * 10000)) // convert to basis points
450451
: feeAmount.amount,
451-
isPercentagePricing
452-
? FeeType.PERCENTAGE_FEE
453-
: FeeType.NO_FEE,
452+
isPercentagePricing ? FeeType.PERCENTAGE_FEE : FeeType.NO_FEE,
454453
AcpJobPhases.COMPLETED,
455454
MemoType.PAYABLE_NOTIFICATION,
456455
expiredAt,

0 commit comments

Comments
 (0)