ap2_mandate_verifier 1.2.0 → 1.4.0
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.
- checksums.yaml +4 -4
- data/README.ja.md +19 -10
- data/README.md +19 -10
- data/docs/PAYMENT_POLICY.md +70 -0
- data/docs/PUBLIC_API.md +13 -3
- data/docs/RELEASE_120_CANDIDATE.md +2 -0
- data/docs/RELEASE_130_CANDIDATE.md +31 -0
- data/docs/RELEASE_140_CANDIDATE.md +17 -0
- data/docs/SELECTIVE_CHECKOUT.md +72 -0
- data/docs/SELECTIVE_PAYMENT.md +4 -4
- data/examples/payment_policy.rb +101 -0
- data/examples/selective_checkout.rb +97 -0
- data/examples/selective_checkout_payment.rb +72 -0
- data/lib/ap2_mandate_verifier/checkout_jwt.rb +1 -1
- data/lib/ap2_mandate_verifier/input_builder.rb +1 -1
- data/lib/ap2_mandate_verifier/payment.rb +111 -57
- data/lib/ap2_mandate_verifier/payment_policy.rb +115 -0
- data/lib/ap2_mandate_verifier/payment_receipt.rb +6 -5
- data/lib/ap2_mandate_verifier/root_disclosures.rb +8 -0
- data/lib/ap2_mandate_verifier/scoped_constraints.rb +1 -1
- data/lib/ap2_mandate_verifier/selective_checkout.rb +261 -0
- data/lib/ap2_mandate_verifier/selective_payment.rb +44 -33
- data/lib/ap2_mandate_verifier/trust_context.rb +6 -0
- data/lib/ap2_mandate_verifier.rb +2 -0
- metadata +15 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 412ad1e06628cf29cd6386aee72aa87e7f84b2abbcc5c117d56642312b138138
|
|
4
|
+
data.tar.gz: 6b8b9e3ab9f8501503185f34e4db692e5a55cda5413abeb791f23b21877dc702
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8b5f1a0f6b18626a856c2d059faed5f0b3fb043d41046113fe6e70c30758b9d994971257eeb9363cff38e71da89ecd6d25674dbaf87d461f262f25bc19cc0c9c
|
|
7
|
+
data.tar.gz: 48bad8d9969ab549f71d939819e3bef986b300951d7ea75b6b9f6fce3617337b20f0d1cf55f17ae2a0c8b8d219f1fbffee390640dfbfda809fa0e7e351449026
|
data/README.ja.md
CHANGED
|
@@ -1,22 +1,31 @@
|
|
|
1
|
-
# AP2 Mandate Verifier — Checkout
|
|
1
|
+
# AP2 Mandate Verifier — Checkout・PaymentのRuby SDK
|
|
2
2
|
|
|
3
|
-
###
|
|
3
|
+
### 1.4.0候補:PISPと支払い実行日時の条件
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
次期候補では、承認したPISPと実行可能期間を指定し、アプリが独立して確認した決済サービス・実行予定時刻と照合できます。日時は文字列比較せず解析し、旧1.xの既定動作を維持します。まだ公開していません。[仕様・API・公式との差](docs/PAYMENT_POLICY.md)、[3方式を実行するRuby例](examples/payment_policy.rb)、[公開前の確認](docs/RELEASE_140_CANDIDATE.md)。
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
### 公開済み1.
|
|
8
|
+
### 公開済み1.3.0:CheckoutとPaymentの選択的開示
|
|
9
|
+
|
|
10
|
+
承認済みの完全Openを安全に保持し、Checkoutの販売者・商品候補、Paymentの支払先・決済手段から必要な情報だけを提示できます。全必須条件と数量の検証を維持します。[仕様・API・Python差分](docs/SELECTIVE_CHECKOUT.md)、[Ruby単体の一連の例](examples/selective_checkout_payment.rb)、[公開照合記録](docs/POST_RELEASE_130.md)。
|
|
11
|
+
|
|
12
|
+
### 公開済み1.2.0:Payment候補の選択的開示
|
|
13
|
+
|
|
14
|
+
公開済み1.2.0の明示的な`SelectivePayment` profileで、支払先・決済手段の非選択候補を送らずに検証できます。必須条件・委任・原文参照は省略しません。[API・プライバシー・Python差分](docs/SELECTIVE_PAYMENT.md)、[保持/送信を比較するRuby単体例](examples/selective_payment.rb)、[公開照合記録](docs/POST_RELEASE_120.md)。既存`Payment`の既定profileは変更しません。
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Payment発行・検証(1.1.0から継続)
|
|
9
18
|
|
|
10
19
|
Direct/条件付きPayment Mandateと成功/エラーPayment Receiptを追加しました。[API・制約・信頼境界](docs/PAYMENT.md)、[Ruby単体サンプル](examples/payment.rb)、[公開照合記録](docs/POST_RELEASE_110.md)、[GitHub Release](https://github.com/cuichangquan/ap2-mandate-verifier/releases/tag/v1.1.0)。検証成功は実行許可ではなく、永続的・原子的な単発利用管理と実決済は利用アプリの責任です。
|
|
11
20
|
|
|
12
21
|
```sh
|
|
13
|
-
gem install ap2_mandate_verifier --version 1.
|
|
14
|
-
ruby "$(ruby -e 'puts Gem::Specification.find_by_name("ap2_mandate_verifier", "1.
|
|
22
|
+
gem install ap2_mandate_verifier --version 1.3.0
|
|
23
|
+
ruby "$(ruby -e 'puts Gem::Specification.find_by_name("ap2_mandate_verifier", "1.3.0").full_gem_path')/examples/payment.rb"
|
|
15
24
|
```
|
|
16
25
|
|
|
17
26
|
[English](README.md)
|
|
18
27
|
|
|
19
|
-
**公開済み安定版は1.
|
|
28
|
+
**公開済み安定版は1.3.0です。**
|
|
20
29
|
|
|
21
30
|
1.0.0では、既存のDirectと条件付きCheckoutの公開API・保守契約を確立しました。
|
|
22
31
|
0.8.0の引数・既定値・profile・結果の意味・保存形式と製品実装を維持します。
|
|
@@ -36,8 +45,8 @@ Agent処理へProvider秘密鍵を渡しません。[API・信頼境界](docs/CO
|
|
|
36
45
|
正式対応MRI 3.4.12/4.0.9で動くRuby単体の導入例です。source checkoutやRailsは不要です:
|
|
37
46
|
|
|
38
47
|
```sh
|
|
39
|
-
gem install ap2_mandate_verifier --version 1.
|
|
40
|
-
ruby "$(ruby -e 'puts Gem::Specification.find_by_name("ap2_mandate_verifier", "1.
|
|
48
|
+
gem install ap2_mandate_verifier --version 1.3.0
|
|
49
|
+
ruby "$(ruby -e 'puts Gem::Specification.find_by_name("ap2_mandate_verifier", "1.3.0").full_gem_path')/examples/conditional_checkout.rb"
|
|
41
50
|
```
|
|
42
51
|
|
|
43
52
|
[Ruby単体の実行例](examples/conditional_checkout.rb)はインストール済み公開APIだけを使い、
|
|
@@ -67,7 +76,7 @@ Rubyで購入委任データを検証する、AP2の固定profile向けGemです
|
|
|
67
76
|
正式対応は **MRI 3.4.12とMRI 4.0.9** です。利用者が選ぶGem環境で導入します。
|
|
68
77
|
|
|
69
78
|
```sh
|
|
70
|
-
gem install ap2_mandate_verifier --version 1.
|
|
79
|
+
gem install ap2_mandate_verifier --version 1.3.0
|
|
71
80
|
```
|
|
72
81
|
|
|
73
82
|
BundlerのGemfile:
|
data/README.md
CHANGED
|
@@ -1,22 +1,31 @@
|
|
|
1
|
-
# AP2 Mandate Verifier — Ruby SDK for Checkout
|
|
1
|
+
# AP2 Mandate Verifier — Ruby SDK for Checkout and Payment
|
|
2
2
|
|
|
3
|
-
###
|
|
3
|
+
### 1.4.0 candidate: PISP and execution-date conditions
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The next candidate adds explicit Payment profiles for approved PISPs and parsed inclusive execution windows, bound to independent application provider/time context. Existing1.x defaults remain unchanged. It is not published yet. [Contract/API/official differences](docs/PAYMENT_POLICY.md), [plain Ruby three-mode example](examples/payment_policy.rb), [release gates](docs/RELEASE_140_CANDIDATE.md).
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
### Published 1.
|
|
8
|
+
### Published 1.3.0: selective Checkout and Payment
|
|
9
|
+
|
|
10
|
+
Keep the complete approved Open confidential and disclose only the merchant/products needed for Checkout, then selected payee/instrument candidates for Payment. Every mandatory condition and quantity remains enforced. [Profile/API/privacy/Python limits](docs/SELECTIVE_CHECKOUT.md), [plain Ruby combined lifecycle](examples/selective_checkout_payment.rb), [verified publication](docs/POST_RELEASE_130.md).
|
|
11
|
+
|
|
12
|
+
### Published1.2.0: selective Payment
|
|
13
|
+
|
|
14
|
+
Published1.2.0 adds explicit `SelectivePayment` candidate-array disclosure: retain confidential full issuance, send selected payee/instrument disclosures only, and verify every mandatory condition and exact original-wire reference. [Profile/API/privacy/Python limits](docs/SELECTIVE_PAYMENT.md), [plain Ruby retained-vs-sent example](examples/selective_payment.rb), [verified publication](docs/POST_RELEASE_120.md). Existing `Payment` defaults remain unchanged.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Payment lifecycle (since1.1.0)
|
|
9
18
|
|
|
10
19
|
1.1.0 adds Direct and conditional Payment Mandates plus signed Success/Error Payment Receipts. [Payment APIs and constraints](docs/PAYMENT.md), [plain Ruby lifecycle sample](examples/payment.rb), [verified publication](docs/POST_RELEASE_110.md), [GitHub Release](https://github.com/cuichangquan/ap2-mandate-verifier/releases/tag/v1.1.0). Verification does not grant execution permission; durable atomic one-use state and actual payment remain application responsibilities.
|
|
11
20
|
|
|
12
21
|
```sh
|
|
13
|
-
gem install ap2_mandate_verifier --version 1.
|
|
14
|
-
ruby "$(ruby -e 'puts Gem::Specification.find_by_name("ap2_mandate_verifier", "1.
|
|
22
|
+
gem install ap2_mandate_verifier --version 1.3.0
|
|
23
|
+
ruby "$(ruby -e 'puts Gem::Specification.find_by_name("ap2_mandate_verifier", "1.3.0").full_gem_path')/examples/payment.rb"
|
|
15
24
|
```
|
|
16
25
|
|
|
17
26
|
[日本語](README.ja.md)
|
|
18
27
|
|
|
19
|
-
**Published stable: 1.
|
|
28
|
+
**Published stable: 1.3.0.**
|
|
20
29
|
|
|
21
30
|
1.0.0 establishes the stable public contract for the existing
|
|
22
31
|
Direct and conditional Checkout APIs. It preserves 0.8.0 signatures, defaults,
|
|
@@ -40,8 +49,8 @@ multi-item profile. Provider private keys never enter Agent operations.
|
|
|
40
49
|
Ruby-only Quick Start on MRI 3.4.12 or 4.0.9; no source checkout or Rails required:
|
|
41
50
|
|
|
42
51
|
```sh
|
|
43
|
-
gem install ap2_mandate_verifier --version 1.
|
|
44
|
-
ruby "$(ruby -e 'puts Gem::Specification.find_by_name("ap2_mandate_verifier", "1.
|
|
52
|
+
gem install ap2_mandate_verifier --version 1.3.0
|
|
53
|
+
ruby "$(ruby -e 'puts Gem::Specification.find_by_name("ap2_mandate_verifier", "1.3.0").full_gem_path')/examples/conditional_checkout.rb"
|
|
45
54
|
```
|
|
46
55
|
|
|
47
56
|
The [standalone Ruby example](examples/conditional_checkout.rb) uses only installed
|
|
@@ -75,7 +84,7 @@ The [Rails demo](https://github.com/cuichangquan/ap2-mandate-verifier-demo#readm
|
|
|
75
84
|
Formal support is **MRI 3.4.12 and MRI 4.0.9**. In your chosen Gem environment:
|
|
76
85
|
|
|
77
86
|
```sh
|
|
78
|
-
gem install ap2_mandate_verifier --version 1.
|
|
87
|
+
gem install ap2_mandate_verifier --version 1.3.0
|
|
79
88
|
```
|
|
80
89
|
|
|
81
90
|
Or add to your Gemfile:
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# PISP and execution-date Payment constraints (1.4.0 candidate)
|
|
2
|
+
|
|
3
|
+
New explicit complete/selective Payment profiles add `payment.allowed_pisps` and `payment.execution_date` without changing the existing1.x defaults. Direct and conditional issuance, presentation, strict verification, selective Checkout/Payment and Payment Receipt references share the existing cryptographic and Host verification paths. This SDK remains framework independent and performs no payment scheduling or execution.
|
|
4
|
+
|
|
5
|
+
## Ruby API
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
m = AP2MandateVerifier
|
|
9
|
+
profile = m::PaymentPolicy::PROFILE_REF
|
|
10
|
+
payment = m::Payment.details(**existing_checkout_details,
|
|
11
|
+
pisp: approved_pisp, execution_date: "2026-11-10T00:00:00Z",
|
|
12
|
+
profile_ref: profile)
|
|
13
|
+
constraints = existing_payment_constraints + [
|
|
14
|
+
{"type" => "payment.allowed_pisps", "allowed" => [approved_pisp]},
|
|
15
|
+
{"type" => "payment.execution_date",
|
|
16
|
+
"not_before" => "2026-11-10T00:00:00Z", "not_after" => "2026-11-30T23:59:59Z"}
|
|
17
|
+
]
|
|
18
|
+
open = m::Payment.issue_open(**existing_open_inputs,
|
|
19
|
+
constraints: constraints, candidate_policy: :independent, profile_ref: profile)
|
|
20
|
+
# Existing issue_closed/present flow, with profile_ref: profile on each call.
|
|
21
|
+
checked = m::Payment.verify(**existing_verification_inputs,
|
|
22
|
+
profile_ref: profile,
|
|
23
|
+
trusted_pisp: authenticated_registry.fetch("processor-A"),
|
|
24
|
+
execution_at: independent_application_execution_at)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Keep the application’s protected approval, authenticated registry and execution context distinct from received claims. Do not build the last two inputs by copying a received Payment. All existing parameters remain required; the snippets show only additions. The [complete installed Ruby example](../examples/payment_policy.rb) runs Direct, complete conditional and selective conditional Payment, rejects mismatched provider/time and an out-of-window date, then verifies both Receipt alternatives.
|
|
28
|
+
|
|
29
|
+
For `SelectivePayment`, use `PaymentPolicy::SELECTIVE_PROFILE_REF` on every lifecycle call (including `select`), retain its existing protected payee/instrument `approved_combinations` and `selective:` inputs, and add `candidate_policy: :independent` on issuance. `Payment.details` prepares the shared details using the new complete profile. Receipt `reference`, `sign` and `verify` take the corresponding explicit profile; final Closed bytes remain the reference source.
|
|
30
|
+
|
|
31
|
+
## Which conditions are checked, and when?
|
|
32
|
+
|
|
33
|
+
| Condition | Issuance/Agent preparation | Verification |
|
|
34
|
+
| --- | --- | --- |
|
|
35
|
+
| PISP identity | Validate exact legal/brand/domain fields and approved allowlist membership | Authenticate signed chain; compare Closed PISP to independent trusted application PISP and any allowed set |
|
|
36
|
+
| Execution instant | Parse explicit Closed/fixed date and every supplied bound; enforce inclusive window | Compare signed instant with independent application `execution_at`, then all window/fixed conditions |
|
|
37
|
+
| Existing amount/payee/instrument | Retain existing complete or selective constraints | Retain complete Checkout/Host/order/challenge/reference verification |
|
|
38
|
+
| Receipt | Sign a reference to exact final Closed bytes | Authenticate issuer, outcome/time and exact reference; no settlement inference |
|
|
39
|
+
|
|
40
|
+
The new profiles require both explicit `pisp` and `execution_date` in Closed and both `trusted_pisp` and `execution_at` during verification. New Open constraints can contain either new type or both, with at least one. This is a deliberately strict subset: it does not silently interpret an omitted date as immediate execution. The old profiles retain their existing contract.
|
|
41
|
+
|
|
42
|
+
## Independent trusted execution context
|
|
43
|
+
|
|
44
|
+
`trusted_pisp` must come from the application’s independently authenticated provider selection/registry/channel, not from a received token. Matching `expected_payment` alone is insufficient. Each PISP has exactly `legal_name`, `brand_name` and `domain_name`; all three compare exactly. Domain is canonical lowercase ASCII DNS in this supported profile (bounded valid labels; no URL, port, path, wildcard, trailing dot or unknown field). Names are bounded descriptive strings with no implicit Unicode or case normalization.
|
|
45
|
+
|
|
46
|
+
The official PISP Schema describes the domain as secured by an eIDAS QWAC certificate. This library does not fetch/validate QWACs, establish legal authorization or authenticate a network endpoint from text. Applications own certificate/channel validation, enrollment, revocation and the provenance/freshness of their trusted PISP input. A syntactically valid domain or valid Mandate signature does not establish those facts.
|
|
47
|
+
|
|
48
|
+
`execution_at` is an independently controlled application execution-plan/operational instant. It must represent the same instant as signed `execution_date`. It is distinct from `verified_at`, which checks signature/Mandate freshness. Future plan verification does not prove that execution occurred or will later occur under that context. At the actual execution gate, the application must recheck the actual provider/time/current approval and a valid Mandate, atomically consume one-use state and reconcile uncertain outcomes. The SDK does not schedule, call a PISP or settle a payment.
|
|
49
|
+
|
|
50
|
+
## Date semantics
|
|
51
|
+
|
|
52
|
+
The supported subset is an explicit RFC3339 timestamp: Gregorian year0001..9999, uppercase `T`/`Z`, valid calendar/time, optional1..9 fractional digits and an explicit `Z` or numeric offset. Offsets must be syntactically valid; `-00:00` (unknown offset), date-only/local timestamps, invalid dates, leap seconds and unsupported precision are rejected. Parsing produces an exact rational instant, without floating-point rounding or lexical comparison.
|
|
53
|
+
|
|
54
|
+
`not_before` and `not_after` are inclusive. At least one bound must be present; if both are present the lower instant cannot exceed the upper. Equivalent offsets denote the same instant for window/context comparisons. A bound ending at `23:59:59Z` denotes that exact instant; later fractions of that second are outside the window. Specify the intended fractional precision or next boundary explicitly. An Open fixed `execution_date` additionally binds its exact string through Agent delegation; a different representation cannot replace that fixed value even if it denotes the same instant.
|
|
55
|
+
|
|
56
|
+
## Profiles and compatibility
|
|
57
|
+
|
|
58
|
+
Use `PaymentPolicy::PROFILE_REF` (`ap2.payment.pisp_execution.complete.1`) with `Payment`, or `PaymentPolicy::SELECTIVE_PROFILE_REF` (`ap2.payment.pisp_execution.selective.1`) with `SelectivePayment`. Pass the corresponding explicit `profile_ref:` through issuance, selection/presentation, verification and Receipt APIs. New signed profile markers prevent silent cross-profile interpretation. Omitting the option preserves old defaults; old profiles reject the new fields/conditions/context.
|
|
59
|
+
|
|
60
|
+
For new Opens, `candidate_policy: :independent` explicitly means the protected consent approved independent PISP/payee/instrument sets. It is not proof of consent. Existing selective payee×instrument `approved_combinations` checks remain required. Correlated PISP/instrument/payee restrictions cannot be flattened into these sets; issue separate Opens for permitted combinations. Recurrence and cumulative budgets remain unsupported and fail closed.
|
|
61
|
+
|
|
62
|
+
PISP lists and execution conditions are mandatory visible content, including under `SelectivePayment`: the official Schema does not mark the PISP array as selectively disclosable. Only the existing payee/instrument candidate positions may be reduced. Keep complete issuance confidential; counts/order/issuer linkage and intentionally visible PISP conditions remain observable. Errors/diagnostics must not expose hidden candidate values or caller inputs.
|
|
63
|
+
|
|
64
|
+
Direct Payment uses exact protected `approved_payment`, including PISP and execution instant, rather than an Open constraint window. Conditional Payment adds Open constraints and keeps the exact reduced Checkout Open reference. `checkout_profile_ref:` still explicitly selects selective Checkout when used. Receipt authenticity remains a statement about signed reported outcome, not independent PISP/settlement confirmation.
|
|
65
|
+
|
|
66
|
+
## Official source and Python boundary
|
|
67
|
+
|
|
68
|
+
Adopted source remains AP2v0.2.0 `b4587ac1d055888a73b4b21750973cffba961793`: [Payment specification](https://github.com/google-agentic-commerce/AP2/blob/b4587ac1d055888a73b4b21750973cffba961793/docs/ap2/payment_mandate.md), [Open Schema](https://github.com/google-agentic-commerce/AP2/blob/b4587ac1d055888a73b4b21750973cffba961793/code/sdk/schemas/ap2/open_payment_mandate.json), [PISP Schema](https://github.com/google-agentic-commerce/AP2/blob/b4587ac1d055888a73b4b21750973cffba961793/code/sdk/schemas/ap2/types/pisp.json).
|
|
69
|
+
|
|
70
|
+
The normative text requires inclusive execution bounds. Schema permits weakly typed strings; it does not itself enforce this strict timestamp subset. The pinned Python evaluator compares date strings lexically and permits absent dates even with a date constraint. Its PISP evaluator does compare all three identity fields. Ruby’s parsed/context-bound behavior is an explicit safer supported subset, not an unqualified claim that all official high-level helpers behave identically. Source interoperability observed three lifecycle cases in each direction (Direct/complete conditional/selective conditional), twelve Receipt checks and62 negatives, plus six explicitly recorded upstream date-check disagreements. Separate positive variants cover PISP-only/date-only/one-sided constraints. Exact signed-wire hashes and actual runtime provenance are recorded with the candidate; supported claims do not extend to QWAC provenance, execution or generic AP2 conformance.
|
data/docs/PUBLIC_API.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Ruby SDK public API — 1.x
|
|
2
2
|
|
|
3
|
-
**Status: published 1.
|
|
3
|
+
**Status: published 1.3.0; the original 1.0.0 Checkout contract below is preserved.**
|
|
4
4
|
This document defines the 1.x contract for the existing Checkout APIs.
|
|
5
5
|
The 1.0.0 release preserves the 0.8.0 runtime behavior, API names and accepted
|
|
6
6
|
formats. Exact distribution identity and validation are in
|
|
@@ -202,6 +202,16 @@ observable error behavior, or the documented profile identities and bounds.
|
|
|
202
202
|
|
|
203
203
|
The preceding 1.0.0 Checkout contract remains unchanged. New `Payment` and `PaymentReceipt` APIs have a separate [Payment contract](PAYMENT.md); they are available in 1.1.0 and later, not in 1.0.0.
|
|
204
204
|
|
|
205
|
-
##
|
|
205
|
+
## Published1.2.0 selective Payment
|
|
206
206
|
|
|
207
|
-
New explicit `SelectivePayment` APIs are described in the [
|
|
207
|
+
New explicit `SelectivePayment` APIs are described in the [selective Payment contract](SELECTIVE_PAYMENT.md). They do not alter the published1.1.0 `Payment` default profile or Receipt reference format. They are available in1.2.0 and later, not in1.1.0.
|
|
208
|
+
|
|
209
|
+
## Published 1.3.0: selective Checkout
|
|
210
|
+
|
|
211
|
+
The additive `SelectiveCheckout` profile is available in published 1.3.0. See the [candidate contract](SELECTIVE_CHECKOUT.md) for mandatory disclosure, independent candidate semantics, original-wire references and application responsibilities. It is not available in the published 1.2.0 package. Existing complete profile defaults are preserved.
|
|
212
|
+
|
|
213
|
+
For the explicit selective Checkout profile, Evidence `original_root_graph_closure` records that every signed commitment and supplied disclosure was inspected and accounted for, allowing unresolved candidate leaves only at registered positions. It does not certify hidden preimages, their schema or uniqueness, or consent provenance. The checked scope covers the visible candidate subset and all mandatory conditions.
|
|
214
|
+
|
|
215
|
+
## 1.4.0 candidate: explicit Payment policy profiles
|
|
216
|
+
|
|
217
|
+
`PaymentPolicy::PROFILE_REF` and `SELECTIVE_PROFILE_REF` opt into PISP/execution constraints in existing `Payment`, `SelectivePayment` and `PaymentReceipt` APIs via `profile_ref:`. Verification additionally requires independently trusted `trusted_pisp:` and `execution_at:`; missing context is never filled from claims. New Open issuance requires `candidate_policy: :independent`. Both new fields are mandatory in Closed, even when only one new Open constraint is used. See [strict parsing, condition stages, API additions and official limitations](PAYMENT_POLICY.md). Old defaults, grammar and result meanings remain unchanged. No scheduler/payment execution is added.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> Historical preparation snapshot. The exact approved candidate is now published; see [publication evidence](POST_RELEASE_120.md). Earlier approval boundaries below describe that checkpoint.
|
|
2
|
+
|
|
1
3
|
# 1.2.0 candidate — unpublished, Owner decision required
|
|
2
4
|
|
|
3
5
|
Published1.1.0 remains the released SDK. This is preparation for an additive opt-in Payment candidate-disclosure profile. No RubyGems push/yank, formal tag, GitHub Release, announcement or deployment is authorized by this document. The Owner decides final version and publication after reviewing exact source/artifact/verification identity in Issue#238.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# 1.3.0 release candidate preparation
|
|
2
|
+
|
|
3
|
+
**Historical prepublication record. 1.3.0 is now published; see [verified publication](POST_RELEASE_130.md). Do not repeat its push or rebuild a substitute artifact.**
|
|
4
|
+
|
|
5
|
+
Status: release candidate prepared; final evidence and GO/HOLD judgment are tracked in [Issue #241](https://github.com/cuichangquan/ap2-mandate-verifier/issues/241). **Publication remains HOLD pending the Owner’s final decision.** RubyGems publication, formal v1.3.0 tag, GitHub Release and announcements require the Owner’s final approval. No production deployment or real payment is included.
|
|
6
|
+
|
|
7
|
+
## Proposed release notes
|
|
8
|
+
|
|
9
|
+
Ruby applications can retain the approved full Checkout Mandate while disclosing only the merchant and products needed for the purchase. Every required line group and quantity remains enforced, including overlapping product choices and multiple purchased lines. The same Ruby lifecycle can combine selective Checkout with selective Payment and authenticate their respective Receipts.
|
|
10
|
+
|
|
11
|
+
Existing complete Checkout and Payment profiles retain their APIs and defaults. The new Checkout profile requires explicit Host trust registration and explicit Payment issuance profile selection. It describes independent merchant/product candidate sets; correlated policies need separate Opens. Counts, ordering and issuer-JWT linkage remain visible. No general AP2 or official high-level Python facade conformance is claimed.
|
|
12
|
+
|
|
13
|
+
## Completion gates
|
|
14
|
+
|
|
15
|
+
- Exact source SHA and independent latest-HEAD review, with no unresolved substantive findings.
|
|
16
|
+
- Signed positive/negative/privacy/quantity coverage and all prior regressions on supported MRI versions.
|
|
17
|
+
- Official pinned Python low-level interoperability with independently checked expectations and explicit high-level limitations.
|
|
18
|
+
- CI on the reviewed HEAD; merged source tree equals reviewed tree.
|
|
19
|
+
- Build one candidate, inspect metadata/allowlist, install the same bytes offline under both supported MRI versions and compare every packaged file with source.
|
|
20
|
+
- Run standalone installed Checkout and combined Payment samples and optional demo.
|
|
21
|
+
- Record exact artifact size, SHA256, source and evidence before Owner GO/HOLD judgment.
|
|
22
|
+
|
|
23
|
+
## Observed local verification
|
|
24
|
+
|
|
25
|
+
The implementation has passed the full source regression suite under MRI 3.4.12 and 4.0.9, including 95 new selective Checkout assertions. An initial candidate passed ordinary offline installation on both versions with all 49 files matching source/archive/installed bytes, plus installed standalone and combined examples. Official pinned Python low-level interoperability passed two scenarios in each direction, eight Receipt checks and 28 negative controls, both from source and an ordinary installed Gem under Ruby 3.4.12 / Python 3.11.2.
|
|
26
|
+
|
|
27
|
+
The fixed candidate builder uses MRI 3.4.12, RubyGems 3.6.9 and `SOURCE_DATE_EPOCH=1793750400`. Two builds under that builder matched byte for byte. MRI 4.0.9’s RubyGems 4.0.20 changes the `rubygems_version` metadata; its payload was identical, but that independently built archive is not the approved candidate. Both supported MRIs must test the same fixed-builder archive. After any packaged source change, rebuild and repeat its package equality checks. Exact final artifact hash, merged source, latest review and CI links belong in the tracking issue/external manifest to avoid a self-referential package checksum.
|
|
28
|
+
|
|
29
|
+
## Publication procedure (not authorized yet)
|
|
30
|
+
|
|
31
|
+
After explicit approval of an exact candidate, recheck registry version absence and the approved artifact bytes/source/reviews/CI. The Owner can perform the single interactive RubyGems push using existing credentials and Docker. Never print credentials or retry an ambiguous push. Read registry metadata and download the published Gem, compare its complete bytes and payload to the approved candidate, then create the matching formal tag and GitHub Release only under the approved publication scope. Update published-state documentation after verification. Stop on any mismatch or uncertain mutation.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# 1.4.0 candidate preparation
|
|
2
|
+
|
|
3
|
+
Status: release candidate preparation. Final exact-source/package/CI evidence and GO/HOLD recommendation are recorded in the PR and external manifest after verification. RubyGems publication, formalv1.4.0 tag, GitHub Release, announcements, deployment and real payment remain HOLD for Owner decision.
|
|
4
|
+
|
|
5
|
+
## Proposed notes
|
|
6
|
+
|
|
7
|
+
Ruby applications can constrain a conditional Payment to approved PISPs and an inclusive execution window, bind its signed plan to independently trusted application provider/time context, and combine it with selective Checkout/Payment and Success/Error Receipts. Direct Payment binds exact approved PISP/date details. Existing1.x defaults remain unchanged.
|
|
8
|
+
|
|
9
|
+
This explicit profile supports strict parsed RFC3339 instants and exact PISP identity; it does not authenticate QWACs from strings, schedule payments, prove consent provenance or settlement. PISP/date conditions stay visible. Independent allowlists cannot express correlated provider/payment-method policies; separate Opens are required. Recurrence/budget remain unsupported.
|
|
10
|
+
|
|
11
|
+
## Final gates
|
|
12
|
+
|
|
13
|
+
Exact-source independent review with no unresolvedP1/P2; signed/context/date/crypto/SD/Receipt/privacy negatives; full regression and installed package verification under supportedMRI3.4.12/4.0.9; independent Python datetime oracle and pinned official SDK/Schema interoperability with discrepancies explicit; exactHEADCI; reproducible one-candidate archive and complete source/archive/installed file equality. Candidate source/size/hash, review/PR/CI links and GO/HOLD recommendation will be recorded externally to avoid self-referential checksums.
|
|
14
|
+
|
|
15
|
+
The fixed builder is existing MRI3.4.12/RubyGems3.6.9 with `SOURCE_DATE_EPOCH=1793750400`; build twice and compare complete archive bytes. Both supported MRI versions must install the same fixed-builder candidate. A different RubyGems builder may change metadata and must not be silently substituted. No checksum is embedded in its own package.
|
|
16
|
+
|
|
17
|
+
Only after Owner approves an exact candidate may publication begin. Recheck source/bytes/reviews/CI and registry absence immediately before a single owner-controlled interactive push. Never retry an ambiguous push; verify registry and downloaded bytes first. Formal tag/Release require matching published bytes and separately authorized release scope. No publish/deploy trigger may be introduced into CI.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Selective Checkout Mandates (published 1.3.0)
|
|
2
|
+
|
|
3
|
+
This explicit profile lets an application retain a confidential complete Open Checkout Mandate and send only the merchant and product candidates needed for a purchase. Every requirement and quantity remains visible and enforced. The existing complete Checkout profiles and their defaults remain available.
|
|
4
|
+
|
|
5
|
+
## Approval and disclosure boundary
|
|
6
|
+
|
|
7
|
+
The application authenticates the user, obtains informed approval and stores the complete issuance securely before selecting a presentation. Merchant and per-requirement product lists describe independent allowed sets. They cannot encode “merchant A only sells approved product X, merchant B only approved product Y”, or correlated choices between requirements. Issue separate Opens for correlated policies. Never expand a restricted approval into independent lists.
|
|
8
|
+
|
|
9
|
+
Only the elements of `checkout.allowed_merchants.allowed` and each `checkout.line_items.items[*].acceptable_items` may be omitted. The signed content disclosure, both constraints, every requirement ID and quantity, delegation key and validity interval are mandatory. At least one candidate per requirement must be disclosed. Unresolved commitments in any other location, unknown conditions and unsupported formats fail closed.
|
|
10
|
+
|
|
11
|
+
Keep the complete issuance and its unselected leaf disclosures out of network requests, logs, exception reporting and analytics. Selection is data minimization, not anonymity: the issuer JWT, candidate counts, ordering, mandatory requirements and resulting transaction remain observable. Presentations sharing an issuer JWT can be linked.
|
|
12
|
+
|
|
13
|
+
## Ruby API
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
m = AP2MandateVerifier
|
|
17
|
+
full = m::SelectiveCheckout.issue_open(
|
|
18
|
+
allowed_merchants: approved_merchants, requirements: approved_requirements,
|
|
19
|
+
candidate_policy: :independent,
|
|
20
|
+
agent_public_key_pem: agent_public_pem,
|
|
21
|
+
issued_at: now, expires_at: now + 600,
|
|
22
|
+
signer: provider_signer, public_key_pem: provider_public_pem)
|
|
23
|
+
|
|
24
|
+
# Keep full confidential; original candidate indices are zero based.
|
|
25
|
+
selected = m::SelectiveCheckout.select(
|
|
26
|
+
open_sd_jwt: full.root_presentation,
|
|
27
|
+
merchant_index: 0, item_indices: [[1], [0, 2]])
|
|
28
|
+
# Alternatively, select all approved candidates matching the actual cart IDs,
|
|
29
|
+
# and prove exact quantity coverage before returning the reduced Open:
|
|
30
|
+
selected = m::SelectiveCheckout.select_for_checkout(
|
|
31
|
+
open_sd_jwt: full.root_presentation, checkout: checkout_hash)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`candidate_policy: :independent` is an explicit contract, not proof of consent. Supply only independently approved candidate sets from protected application state. `item_indices` contains one nonempty index array for every requirement, in original requirement order. The selection API preserves original signed commitment slots. Its immutable `Open` exposes `root_presentation` and alias `open_sd_jwt`; selecting is structural preparation, not issuer authentication.
|
|
35
|
+
|
|
36
|
+
Use `SelectiveCheckout.issue_closed` with the reduced `root_presentation`, original Merchant `checkout_jwt`, independently selected issuer/Agent/Merchant public keys, expected Merchant ID, audience, nonce, time and Agent signer. Its immutable Closed exposes the existing `root_presentation`, `terminal_jws`, `checkout_jwt` and `closed_sd_jwt` fields. `present` restores those transport fields without claiming verification.
|
|
37
|
+
|
|
38
|
+
Configure `InputBuilder.trust(..., profile_ref: SelectiveCheckout::PROFILE_REF)` using the application’s authenticated registry, then use the existing `InputBuilder.prepare`, `restore`, `inputs` and `verify` lifecycle with the reduced Open. The new profile is `ap2.checkout.selective_candidates.1`; the presentation cannot select trusted policy for the Host. Checkout signing and Receipt APIs accept this explicit `profile_ref`.
|
|
39
|
+
|
|
40
|
+
For Payment, pass `checkout_profile_ref: SelectiveCheckout::PROFILE_REF` explicitly to `Payment.issue_open` or `SelectivePayment.issue_open`, and supply the reduced Checkout Open as `open_checkout_sd_jwt`. The default is unchanged. `SelectivePayment.verify` still takes the seven original Checkout verification inputs and rechecks the full Host-bound chain.
|
|
41
|
+
|
|
42
|
+
Run the installed Gem’s [standalone Checkout example](../examples/selective_checkout.rb) and [combined Checkout/Payment example](../examples/selective_checkout_payment.rb). They generate synthetic keys in memory, compare retained/sent disclosures and authenticate both Success/Error Receipt alternatives without executing a purchase.
|
|
43
|
+
|
|
44
|
+
## Verification and quantities
|
|
45
|
+
|
|
46
|
+
A new registered Host profile must be selected independently from the presentation. Verification follows the existing Host trust, issuer signature, complete commitment graph inspection, Agent key/signature/delegation, audience/nonce/time, Merchant signature and original Checkout binding, constraints and Host order/challenge verification path. A signature or a structurally restored presentation alone is insufficient.
|
|
47
|
+
|
|
48
|
+
For this profile, the existing Evidence field `original_root_graph_closure` means every signed commitment and every supplied disclosure was accounted for, with unresolved leaves allowed only at the registered candidate positions. It does not mean hidden candidate values were reconstructed or validated. A verifier cannot establish the schema, identity or uniqueness of an undisclosed preimage. The issuance API checks the complete approved candidate universe; presentation verification certifies the disclosed subset and every mandatory condition. These facts do not prove the application’s consent provenance.
|
|
49
|
+
|
|
50
|
+
All mandatory quantities participate in integer max-flow matching. Total required quantity must equal total purchased quantity and the maximum assignable flow. Matching uses product IDs; product titles are descriptive, as in the existing multi-item profile. Duplicate line IDs and requirement IDs are rejected. Multiple lines for the same product and overlapping candidate sets are supported. Hidden candidates do not add edges to the quantity graph.
|
|
51
|
+
|
|
52
|
+
The Agent signs the exact reduced Open bytes, including disclosure order and terminal `~`. The Host challenge and Payment reference must bind those same bytes. A confidential complete Open cannot be substituted after selection. Checkout Receipt references remain tied to the exact final Closed wire.
|
|
53
|
+
|
|
54
|
+
## Supported bounds
|
|
55
|
+
|
|
56
|
+
The explicit profile supports at most eight merchant candidates, eight mandatory requirements, eight product candidates per requirement and eight purchased lines. A reduced presentation contains exactly one merchant disclosure and a nonempty subset for every requirement. A complete issuance can contain up to 73 disclosures including its content disclosure. Each encoded disclosure is limited to 8,192 bytes, the compact issuer token to 16,384 bytes and the complete original Open wire to 131,072 bytes. JSON parsing retains the existing bounded depth policy. These are joint limits: long identifiers/values can exhaust a byte budget before a count limit is reached. Issuance checks the final representation before calling a signer.
|
|
57
|
+
|
|
58
|
+
## Compatibility and responsibility
|
|
59
|
+
|
|
60
|
+
Opt in explicitly when issuing a selective Checkout and configuring its Host trust profile. Existing complete profiles retain their missing-disclosure rejection. Existing saved records are not silently migrated. Payment issuance must explicitly identify the new Checkout profile when using its reduced Open; Payment verification still re-verifies the complete Checkout chain with independent Host inputs.
|
|
61
|
+
|
|
62
|
+
Verification establishes scoped checked facts; it does not authorize a purchase, execute payment or establish issuer provenance. The application owns consent, key enrollment/custody, revocation, current order state, atomic nonce consumption, replay prevention and uncertain outcome recovery. Receipt authenticity is distinct from independent settlement confirmation.
|
|
63
|
+
|
|
64
|
+
## Official source and interoperability
|
|
65
|
+
|
|
66
|
+
The adopted AP2 source remains pinned to `b4587ac1d055888a73b4b21750973cffba961793`. [Its Open Checkout Schema](https://github.com/google-agentic-commerce/AP2/blob/b4587ac1d055888a73b4b21750973cffba961793/code/sdk/schemas/ap2/open_checkout_mandate.json) marks merchant and acceptable-item array values as selectively disclosable while retaining mandatory line requirement structure. The explicit registered profile, strict limits and subset acceptance policy are this SDK’s supported contract, not a claim of general AP2 conformance.
|
|
67
|
+
|
|
68
|
+
The pinned Python SDK high-level presentation helper does not expose this candidate selection/profile flow. Interoperability must distinguish official low-level signatures/chain/typed Schema checks from the strict subset adapter. In particular, its max-flow helper may accept an empty candidate list as a wildcard or accept underfilled demand; this SDK requires nonempty disclosed candidates and exact quantity coverage. Official SDK acceptance alone is not a strict quantity oracle.
|
|
69
|
+
|
|
70
|
+
Source interoperability observed two Checkout scenarios in each direction, eight Success/Error Receipt checks and 28 negative controls under Ruby 3.4.12 / Python 3.11.2. The Python terminal adapter uses the official JWT primitive plus an exact reduced-wire `sd_hash`, because the SDK’s generic key-binding creator discloses its final payload while this supported Checkout grammar requires an inline final Closed payload. Source and installed-candidate evidence, final review and CI are recorded separately in the release preparation report; these limited synthetic observations do not establish production trust.
|
|
71
|
+
|
|
72
|
+
[Verified public artifact, tag and Release](POST_RELEASE_130.md). The original candidate preparation remains historical in [release preparation](RELEASE_130_CANDIDATE.md).
|
data/docs/SELECTIVE_PAYMENT.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# Payment candidate disclosure —
|
|
1
|
+
# Payment candidate disclosure — published1.2.0 profile
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[1.2.0 is published](POST_RELEASE_120.md). The1.1.0 complete-content Payment profile remains unchanged. New `AP2MandateVerifier::SelectivePayment` is an explicit opt-in conditional-only profile: `ap2.payment.selective_candidates.1`. Existing `Payment` remains strict and does not accept this new Open format. Existing Checkout/Payment/Receipt keyword/default/result/storage/reference contracts are unchanged. Payment verification/issuance additionally detaches mutable Agent-key inputs consistently and rechecks copied Checkout time; this tightens snapshot safety without changing supported formats or defaults. This is a framework-independent Ruby API; Rails is optional.
|
|
4
4
|
|
|
5
5
|
## Normative source and policy boundary
|
|
6
6
|
|
|
@@ -58,10 +58,10 @@ Official generic crypto verification and Schema validation are not this profile'
|
|
|
58
58
|
|
|
59
59
|
At most8payees/8instruments, one Agent hop, one immediate payment, supported1.1.0 integer minor units/currencies and600-second lifetime. Only known candidate-array disclosures are supported; no generic arbitrary SD or Checkout selective-disclosure extension. Open wire is limited to65,536bytes, root compactJWT to16,384bytes, each decoded disclosure to24,576bytes, and total disclosures to2–17. Each candidate array has1–8entries; selected presentation requires one revealed candidate per selective axis. Existing JSON depth24, finalClosed32,769-byte wire and per-field bounds are reused. All structural/signing bounds are checked before signer effects. Recurrence/budget/PISP/execution_date/risk_data, arbitrary delegation, unsupported algorithms and unknown constraints reject.
|
|
60
60
|
|
|
61
|
-
After installing
|
|
61
|
+
After installing published1.2.0 with its pinned dependencies:
|
|
62
62
|
|
|
63
63
|
```sh
|
|
64
64
|
ruby "$(ruby -e 'puts Gem::Specification.find_by_name("ap2_mandate_verifier", "1.2.0").full_gem_path')/examples/selective_payment.rb"
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
-
The runnable example prints retained/transmitted disclosure counts and byte counts, confirms unchanged issuer JWT and changed presentation bytes, verifies chosen Payment and both Receipt outcomes without printing unselected values/disclosures. Its approved matrix is explicitly synthetic; real code reads protected consent. The application owns user authentication/consent, key enrollment/custody/revocation, current order/trust, final authorization, payment, durable one-use identity and atomic state transitions. Missing/invalid Receipt or uncertain processing remains pending, never automatic retry permission.
|
|
67
|
+
The runnable example prints retained/transmitted disclosure counts and byte counts, confirms unchanged issuer JWT and changed presentation bytes, verifies chosen Payment and both Receipt outcomes without printing unselected values/disclosures. Its approved matrix is explicitly synthetic; real code reads protected consent. The application owns user authentication/consent, key enrollment/custody/revocation, current order/trust, final authorization, payment, durable one-use identity and atomic state transitions. Missing/invalid Receipt or uncertain processing remains pending, never automatic retry permission. Exact published artifact verification is in [publication evidence](POST_RELEASE_120.md); [release preparation](RELEASE_120_CANDIDATE.md) retains the historical candidate checkpoint.
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# Installed SDK only. Synthetic registry, approval and keys; no actual payment.
|
|
3
|
+
require "ap2_mandate_verifier"
|
|
4
|
+
require "time"
|
|
5
|
+
require_relative "selective_checkout"
|
|
6
|
+
module PaymentPolicyExample
|
|
7
|
+
M = AP2MandateVerifier
|
|
8
|
+
NOW = SelectiveCheckoutExample::NOW
|
|
9
|
+
def self.run
|
|
10
|
+
state = SelectiveCheckoutExample.run
|
|
11
|
+
provider, agent, merchant = state.fetch(:keys)
|
|
12
|
+
signer = ->(key) { M::CheckoutJWT.es256_signer(private_key: key) }
|
|
13
|
+
# These synthetic registry entries represent independently authenticated app
|
|
14
|
+
# state. Production code validates enrollment/channel/QWAC/revocation itself.
|
|
15
|
+
registry = {"processor-A" => {"legal_name" => "Example Payment Services Ltd.",
|
|
16
|
+
"brand_name" => "ExamplePay", "domain_name" => "pay.example"}}
|
|
17
|
+
trusted_pisp = registry.fetch("processor-A")
|
|
18
|
+
planned = Time.at(NOW + 3600).utc
|
|
19
|
+
date = planned.iso8601(3)
|
|
20
|
+
execution_at = planned.getlocal("+09:00").iso8601(3) # Same instant, different representation.
|
|
21
|
+
profile = M::PaymentPolicy::PROFILE_REF
|
|
22
|
+
selective_profile = M::PaymentPolicy::SELECTIVE_PROFILE_REF
|
|
23
|
+
checkout = state.fetch(:closed).checkout_jwt
|
|
24
|
+
details = M::Payment.details(checkout_jwt: checkout, trusted_merchant_public_key_pem: merchant.public_to_pem,
|
|
25
|
+
expected_merchant_id: "shop", payment_instrument: {"id" => "synthetic-card-A", "type" => "card"},
|
|
26
|
+
pisp: trusted_pisp, execution_date: date, profile_ref: profile)
|
|
27
|
+
direct_checkout = M::Buyer.issue_closed(checkout_jwt: checkout, approved_checkout_jwt: checkout,
|
|
28
|
+
trusted_merchant_public_key_pem: merchant.public_to_pem, expected_merchant_id: "shop", issued_at: NOW,
|
|
29
|
+
expires_at: NOW + 60, signer: signer.call(provider), public_key_pem: provider.public_to_pem)
|
|
30
|
+
direct_inputs = {closed_sd_jwt: direct_checkout.closed_sd_jwt, expected_checkout_jwt: checkout,
|
|
31
|
+
trusted_provider_public_key_pem: provider.public_to_pem, trusted_merchant_public_key_pem: merchant.public_to_pem,
|
|
32
|
+
expected_merchant_id: "shop", verified_at: NOW}
|
|
33
|
+
direct = M::Payment.issue_direct(payment: details, approved_payment: details, issued_at: NOW,
|
|
34
|
+
expires_at: NOW + 60, signer: signer.call(provider), public_key_pem: provider.public_to_pem, profile_ref: profile)
|
|
35
|
+
base = {expected_payment: details, trusted_provider_public_key_pem: provider.public_to_pem,
|
|
36
|
+
trusted_pisp: trusted_pisp, execution_at: execution_at, verified_at: NOW, profile_ref: profile}
|
|
37
|
+
direct_args = base.merge(closed_sd_jwt: direct.closed_sd_jwt, checkout_mode: :direct, checkout_inputs: direct_inputs)
|
|
38
|
+
raise "Direct policy verification failed" unless M::Payment.verify(**direct_args).verified?
|
|
39
|
+
wrong_pisp = trusted_pisp.merge("brand_name" => "Unapproved brand")
|
|
40
|
+
raise "PISP context mismatch accepted" if M::Payment.verify(**direct_args.merge(trusted_pisp: wrong_pisp)).verified?
|
|
41
|
+
raise "execution context mismatch accepted" if M::Payment.verify(**direct_args.merge(execution_at: (planned + 1).iso8601(3))).verified?
|
|
42
|
+
puts "Direct: approved PISP/date verified; wrong independent PISP/time rejected"
|
|
43
|
+
|
|
44
|
+
payees = [details.fetch("payee"), {"id" => "private-alternative", "name" => "Private alternative payee"}]
|
|
45
|
+
instruments = [details.fetch("payment_instrument"), {"id" => "private-card", "type" => "card"}]
|
|
46
|
+
conditions = [{"type" => "payment.amount_range", "currency" => "USD", "max" => 300},
|
|
47
|
+
{"type" => "payment.allowed_payees", "allowed" => payees},
|
|
48
|
+
{"type" => "payment.allowed_payment_instruments", "allowed" => instruments},
|
|
49
|
+
{"type" => "payment.allowed_pisps", "allowed" => [trusted_pisp]},
|
|
50
|
+
{"type" => "payment.execution_date", "not_before" => (planned - 1).iso8601(3), "not_after" => (planned + 1).iso8601(3)}]
|
|
51
|
+
open_args = {open_checkout_sd_jwt: state.fetch(:opening).root_presentation, constraints: conditions, fixed: {},
|
|
52
|
+
agent_public_key_pem: agent.public_to_pem, issued_at: NOW, expires_at: NOW + 60,
|
|
53
|
+
signer: signer.call(provider), public_key_pem: provider.public_to_pem,
|
|
54
|
+
checkout_profile_ref: M::SelectiveCheckout::PROFILE_REF, candidate_policy: :independent}
|
|
55
|
+
open = M::Payment.issue_open(**open_args, profile_ref: profile)
|
|
56
|
+
close_args = {payment: details, trusted_provider_public_key_pem: provider.public_to_pem,
|
|
57
|
+
agent_public_key_pem: agent.public_to_pem, audience: "credential-provider", nonce: "synthetic-policy-nonce",
|
|
58
|
+
verified_at: NOW, signer: signer.call(agent)}
|
|
59
|
+
closed = M::Payment.issue_closed(**close_args, open_sd_jwt: open, profile_ref: profile)
|
|
60
|
+
restored = M::Payment.present(open_sd_jwt: open, closed_sd_jwt: closed.closed_sd_jwt, profile_ref: profile)
|
|
61
|
+
raw = M::InputBuilder.inputs(**state.fetch(:host_inputs), saved_challenge: state.fetch(:saved),
|
|
62
|
+
terminal_jws: state.fetch(:closed).terminal_jws, expected_challenge_issuer_id: "host", clock_source_id: "synthetic-clock", verified_at: NOW)
|
|
63
|
+
expected_agent = {expected_agent_public_key_pem: agent.public_to_pem, expected_audience: "credential-provider", expected_nonce: "synthetic-policy-nonce"}
|
|
64
|
+
checked = M::Payment.verify(**base, **expected_agent, closed_sd_jwt: restored.closed_sd_jwt,
|
|
65
|
+
open_sd_jwt: restored.open_sd_jwt, checkout_mode: :conditional, checkout_inputs: raw)
|
|
66
|
+
raise "conditional policy verification failed" unless checked.verified?
|
|
67
|
+
begin
|
|
68
|
+
M::Payment.issue_closed(**close_args.merge(payment: details.merge("execution_date" => (planned + 2).iso8601(3))), open_sd_jwt: open, profile_ref: profile)
|
|
69
|
+
raise "outside execution window accepted"
|
|
70
|
+
rescue M::Payment::Invalid
|
|
71
|
+
puts "Conditional: allowed PISP/inclusive window verified; outside window rejected"
|
|
72
|
+
end
|
|
73
|
+
full = M::SelectivePayment.issue_open(**open_args, profile_ref: selective_profile,
|
|
74
|
+
approved_combinations: [[0,0],[0,1],[1,0],[1,1]], selective: :both)
|
|
75
|
+
reduced = M::SelectivePayment.select(open_sd_jwt: full, payee_index: 0, instrument_index: 0, profile_ref: selective_profile)
|
|
76
|
+
selective_closed = M::SelectivePayment.issue_closed(**close_args, open_presentation: reduced, profile_ref: selective_profile)
|
|
77
|
+
selective = M::SelectivePayment.present(open_presentation: reduced, closed_sd_jwt: selective_closed.closed_sd_jwt, profile_ref: selective_profile)
|
|
78
|
+
result = M::SelectivePayment.verify(**base.merge(profile_ref: selective_profile), **expected_agent,
|
|
79
|
+
open_presentation: reduced, closed_sd_jwt: selective.closed_sd_jwt, checkout_inputs: raw)
|
|
80
|
+
raise "selective policy verification failed" unless result.verified?
|
|
81
|
+
visible = reduced.split("~", -1)[1...-1].map { |s| JSON.parse(Base64.urlsafe_decode64(s)) }
|
|
82
|
+
raise "hidden candidate leaked" if JSON.generate(visible).include?("private-alternative") || JSON.generate(visible).include?("private-card")
|
|
83
|
+
puts "Selective: Checkout and Payment verified; unselected payee/instrument hidden; PISP/date conditions fully visible"
|
|
84
|
+
[[direct, profile], [restored, profile], [selective, selective_profile]].each do |payment, ref|
|
|
85
|
+
%w[Success Error].each do |outcome|
|
|
86
|
+
fields = outcome == "Success" ? {psp_confirmation_id: "synthetic-psp", network_confirmation_id: "synthetic-network"} :
|
|
87
|
+
{error: "declined", error_description: "Simulated refusal"}
|
|
88
|
+
receipt = M::PaymentReceipt.sign(closed_sd_jwt: payment.closed_sd_jwt, profile_ref: ref, issuer: "processor-A",
|
|
89
|
+
payment_id: "synthetic-policy-payment", outcome: outcome, issued_at: NOW, **fields,
|
|
90
|
+
signer: signer.call(merchant), public_key_pem: merchant.public_to_pem)
|
|
91
|
+
verified = M::PaymentReceipt.verify(jwt: receipt.jwt, closed_sd_jwt: payment.closed_sd_jwt, profile_ref: ref,
|
|
92
|
+
trusted_public_key_pem: merchant.public_to_pem, expected_issuer: "processor-A", expected_payment_id: "synthetic-policy-payment",
|
|
93
|
+
not_before: NOW, not_after: NOW + 60, verified_at: NOW)
|
|
94
|
+
raise "policy Receipt failed" unless verified.verified? && verified.outcome == outcome
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
puts "Success/Error Payment Receipts authenticated for all three modes"
|
|
98
|
+
puts "Synthetic plan only: no QWAC provenance, scheduling, execution permission or settlement is established."
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
PaymentPolicyExample.run if $PROGRAM_NAME == __FILE__
|