Skip to content

Commit e779cff

Browse files
authored
Merge pull request #138 from Virtual-Protocol/fix/skip-x402-payment
Skip x402 payment for zero budget
2 parents 5a46534 + a234bf2 commit e779cff

3 files changed

Lines changed: 18 additions & 19 deletions

File tree

examples/acp_base/skip_evaluation/buyer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def on_new_task(job: ACPJob, memo_to_sign: Optional[ACPMemo] = None):
8787
"<your-schema-key-1>": "<your-schema-value-1>",
8888
"<your-schema-key-2>": "<your-schema-value-2>",
8989
},
90-
expired_at=datetime.now() + timedelta(minutes=3.1), # job expiry duration, minimum 3 minutes
90+
expired_at=datetime.now() + timedelta(minutes=5), # job expiry duration, minimum 3 minutes
9191
)
9292
logger.info(f"Job {job_id} initiated")
9393
logger.info("Listening for next steps...")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "virtuals-acp"
3-
version = "0.3.17"
3+
version = "0.3.18"
44
description = "Agent Commerce Protocol Python SDK by Virtuals"
55
authors = ["Steven Lee Soon Fatt <steven@virtuals.io>"]
66
readme = "README.md"

virtuals_acp/job.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,14 @@ def rejection_reason(self) -> Optional[str]:
154154
return None
155155

156156
request_memo = next(
157-
(
158-
m
159-
for m in self.memos
160-
if m.next_phase == ACPJobPhase.NEGOTIATION
161-
),
157+
(m for m in self.memos if m.next_phase == ACPJobPhase.NEGOTIATION),
162158
None,
163159
)
164160
if request_memo:
165161
return request_memo.signed_reason
166162

167163
fallback_memo = next(
168-
(m for m in self.memos if m.next_phase == ACPJobPhase.REJECTED),
169-
None
164+
(m for m in self.memos if m.next_phase == ACPJobPhase.REJECTED), None
170165
)
171166
return fallback_memo.content if fallback_memo else None
172167

@@ -293,9 +288,12 @@ def pay_and_accept_requirement(self, reason: Optional[str] = "") -> str | None:
293288
)
294289
)
295290

296-
x402PaymentDetails = self.acp_contract_client.get_x402_payment_details(self.id)
297-
if x402PaymentDetails.is_x402:
298-
self.perform_x402_payment(self.price)
291+
if self.price > 0:
292+
x402PaymentDetails = self.acp_contract_client.get_x402_payment_details(
293+
self.id
294+
)
295+
if x402PaymentDetails.is_x402:
296+
self.perform_x402_payment(self.price)
299297

300298
response = self.acp_contract_client.handle_operation(operations)
301299
return get_txn_hash_from_response(response)
@@ -325,7 +323,7 @@ def reject(self, reason: Optional[str] = None) -> str | None:
325323
content=memo_content,
326324
memo_type=MemoType.MESSAGE,
327325
is_secured=True,
328-
next_phase=ACPJobPhase.REJECTED
326+
next_phase=ACPJobPhase.REJECTED,
329327
)
330328
)
331329

@@ -347,8 +345,7 @@ def reject_payable(
347345

348346
operations.append(
349347
self.acp_contract_client.approve_allowance(
350-
amount.amount,
351-
amount.fare.contract_address
348+
amount.amount, amount.fare.contract_address
352349
)
353350
)
354351

@@ -520,8 +517,7 @@ def create_payable_notification(
520517

521518
operations.append(
522519
self.acp_contract_client.approve_allowance(
523-
amount.amount,
524-
amount.fare.contract_address
520+
amount.amount, amount.fare.contract_address
525521
)
526522
)
527523

@@ -543,7 +539,7 @@ def create_payable_notification(
543539
next_phase=ACPJobPhase.COMPLETED,
544540
memo_type=MemoType.PAYABLE_NOTIFICATION,
545541
expired_at=expired_at,
546-
token=amount.fare.contract_address
542+
token=amount.fare.contract_address,
547543
)
548544
)
549545

@@ -590,7 +586,10 @@ def perform_x402_payment(self, budget: float):
590586
self.acp_contract_client.update_job_x402_nonce(self.id, str(nonce))
591587

592588
x402_response = self.acp_contract_client.perform_x402_request(
593-
payment_url, self.acp_contract_client.get_acp_version(), str(budget), encoded_payment
589+
payment_url,
590+
self.acp_contract_client.get_acp_version(),
591+
str(budget),
592+
encoded_payment,
594593
)
595594
if x402_response.get("isPaymentRequired"):
596595
# If payment is required, submit transfer with authorization and handle the operation

0 commit comments

Comments
 (0)