|
1
|
{ |
|
2
|
"nbformat": 4, |
|
3
|
"nbformat_minor": 5, |
|
4
|
"metadata": { |
|
5
|
"kernelspec": { |
|
6
|
"display_name": "Python 3", |
|
7
|
"language": "python", |
|
8
|
"name": "python3" |
|
9
|
}, |
|
10
|
"language_info": { |
|
11
|
"name": "python", |
|
12
|
"pygments_lexer": "ipython3" |
|
13
|
} |
|
14
|
}, |
|
15
|
"cells": [ |
|
16
|
{ |
|
17
|
"cell_type": "markdown", |
|
18
|
"metadata": {}, |
|
19
|
"source": [ |
|
20
|
"# Local x402 simulation (Omnipay)\n", |
|
21
|
"\n", |
|
22
|
"Local-only. No AWS, no live funds, no Bedrock. Synthetic proofs only.\n", |
|
23
|
"`value_transferred=false`." |
|
24
|
] |
|
25
|
}, |
|
26
|
{ |
|
27
|
"cell_type": "code", |
|
28
|
"execution_count": null, |
|
29
|
"metadata": {}, |
|
30
|
"outputs": [], |
|
31
|
"source": [ |
|
32
|
"from datetime import UTC, datetime, timedelta\n", |
|
33
|
"from decimal import Decimal\n", |
|
34
|
"\n", |
|
35
|
"from omnipay_x402 import VALUE_TRANSFERRED, live_agentcore_status\n", |
|
36
|
"from omnipay_x402.demo import build_demo\n", |
|
37
|
"from omnipay_x402.merchant import RESOURCE_URL\n", |
|
38
|
"from omnipay_x402.models import ApprovalGrant, PurchaseRequest\n", |
|
39
|
"\n", |
|
40
|
"assert VALUE_TRANSFERRED is False\n", |
|
41
|
"print(live_agentcore_status())\n", |
|
42
|
"\n", |
|
43
|
"now = datetime.now(UTC)\n", |
|
44
|
"app, merchant, payments = build_demo(now)\n", |
|
45
|
"purchase = PurchaseRequest(\n", |
|
46
|
" request_id=\"request-001\",\n", |
|
47
|
" resource_url=RESOURCE_URL,\n", |
|
48
|
" purpose=\"supplier_due_diligence\",\n", |
|
49
|
" idempotency_key=\"purchase-001\",\n", |
|
50
|
")\n", |
|
51
|
"grant = ApprovalGrant(\n", |
|
52
|
" approval_id=\"approval-001\",\n", |
|
53
|
" request_id=purchase.request_id,\n", |
|
54
|
" resource_url=purchase.resource_url,\n", |
|
55
|
" purpose=purchase.purpose,\n", |
|
56
|
" maximum_amount=Decimal(\"0.25\"),\n", |
|
57
|
" approved_by=\"synthetic-reviewer\",\n", |
|
58
|
" approved_at=now,\n", |
|
59
|
" expires_at=now + timedelta(minutes=10),\n", |
|
60
|
")\n", |
|
61
|
"result = app.purchase(purchase, approval=grant, now=now)\n", |
|
62
|
"print(result.status, result.receipt.receipt_id)\n", |
|
63
|
"print([e.event_type for e in result.audit_events])" |
|
64
|
] |
|
65
|
} |
|
66
|
] |
|
67
|
} |