xytara 3.1.16 → 3.2.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.
- package/README.md +120 -92
- package/RELEASE_NOTES.md +7 -3
- package/START_HERE.md +56 -224
- package/bin/xytara.js +21 -8
- package/client.js +79 -1
- package/lib/{delivery_receipt.js → delivery_receipt_verify.js} +14 -100
- package/package.json +25 -35
- package/scripts/verify_client.js +418 -0
- package/scripts/verify_release_candidate.js +146 -45
- package/.env.example +0 -173
- package/ADAPTER_START_HERE.md +0 -56
- package/BSV_TERANODE_PLATFORM_DISCONTINUITY_RUNBOOK.md +0 -126
- package/CARRIED_HANDOFF_DEMO.md +0 -60
- package/EXAMPLE_PATHS.md +0 -53
- package/FINAL_CONTRACT.md +0 -498
- package/PARTNER_READY_PATH.md +0 -71
- package/PUBLIC_DEMO_SCRIPT.md +0 -78
- package/REAL_PAYMENT_SETUP.md +0 -320
- package/SERVICE_CONTRACT.md +0 -419
- package/SUPABASE_RUNTIME_STATE_SETUP.md +0 -61
- package/TERMINOLOGY.md +0 -50
- package/WHY_XYTARA_XOONYA.md +0 -63
- package/XT1_EXECUTION_TRUTH_STANDARD.md +0 -78
- package/XYTARA_ADAPTER_PROTOCOL_TRUTH_MODEL.md +0 -75
- package/XYTARA_AUTONOMOUS_ENTRY_MODEL.md +0 -124
- package/XYTARA_DEFAULT_PATH_MODEL.md +0 -84
- package/XYTARA_EXECUTION_TRUTH_MODEL.md +0 -171
- package/XYTARA_PAYMENT_RAIL_TRUTH_MODEL.md +0 -68
- package/adapters/AUTHORING_GUIDE.md +0 -244
- package/adapters/ONBOARDING_POSTURE.md +0 -61
- package/adapters/THIRD_PARTY_SUBMISSION_PROCESS.md +0 -84
- package/adapters/adapter-manifest.schema.json +0 -283
- package/adapters/examples/example-execution-adapter.js +0 -61
- package/adapters/examples/example-execution-adapter.manifest.json +0 -81
- package/adapters/examples/example-settlement-adapter.js +0 -55
- package/adapters/examples/example-settlement-adapter.manifest.json +0 -78
- package/adapters/examples/example-third-party-acp-registration.submission-bundle.json +0 -124
- package/adapters/examples/example-third-party-erc8004-registration.submission-bundle.json +0 -121
- package/adapters/examples/example-third-party-identity-registration.certification-pack.json +0 -22
- package/adapters/examples/example-third-party-identity-registration.record.json +0 -26
- package/adapters/examples/example-third-party-identity-registration.submission-bundle.json +0 -126
- package/adapters/examples/example-third-party-langchain-registration.submission-bundle.json +0 -124
- package/adapters/examples/example-third-party-mpp-registration.submission-bundle.json +0 -120
- package/adapters/examples/example-third-party-registration.certification-pack.json +0 -22
- package/adapters/examples/example-third-party-registration.record.json +0 -28
- package/adapters/examples/example-third-party-registration.submission-bundle.json +0 -126
- package/adapters/examples/example-third-party-settlement-registration.certification-pack.json +0 -22
- package/adapters/examples/example-third-party-settlement-registration.record.json +0 -26
- package/adapters/examples/example-third-party-settlement-registration.submission-bundle.json +0 -127
- package/adapters/examples/langchain-reference-execution-adapter.js +0 -81
- package/adapters/examples/langchain-reference-execution-adapter.manifest.json +0 -79
- package/adapters/examples/langgraph-reference-execution-adapter.js +0 -81
- package/adapters/examples/langgraph-reference-execution-adapter.manifest.json +0 -79
- package/adapters/examples/minimal-third-party-execution-adapter.js +0 -61
- package/adapters/examples/minimal-third-party-execution-adapter.manifest.json +0 -79
- package/adapters/examples/minimal-third-party-execution-registration.record.json +0 -26
- package/adapters/examples/minimal-third-party-execution.certification-pack.json +0 -22
- package/adapters/examples/minimal-third-party-execution.submission-bundle.json +0 -126
- package/adapters/integration-certification-pack.schema.json +0 -82
- package/adapters/integration-registration-record.schema.json +0 -114
- package/adapters/integration-submission-bundle-set.schema.json +0 -39
- package/adapters/integration-submission-bundle.schema.json +0 -34
- package/adapters/interfaces.js +0 -56
- package/bin/xytara-release.js +0 -1429
- package/examples/_demo_env.js +0 -40
- package/examples/adapter_review_walkthrough.js +0 -54
- package/examples/export_carried_handoff.js +0 -81
- package/examples/funded_runtime_walkthrough.js +0 -71
- package/examples/partner_launch_walkthrough.js +0 -44
- package/examples/quickstart.js +0 -3256
- package/fixtures/catalog.js +0 -1156
- package/index.js +0 -395
- package/integrations/dispatch.js +0 -276
- package/integrations/registry-snapshot.schema.json +0 -36
- package/integrations/registry.js +0 -2261
- package/integrations/views.js +0 -28
- package/lib/a2a_lane_contract.js +0 -104
- package/lib/a2a_rpc.js +0 -287
- package/lib/a2c_lane_contract.js +0 -111
- package/lib/account_auth.js +0 -585
- package/lib/acp_lane_contract.js +0 -54
- package/lib/activity_audit_contract.js +0 -322
- package/lib/adapter_certification_contract.js +0 -130
- package/lib/adapter_depth_contract.js +0 -218
- package/lib/adapter_pack.js +0 -118
- package/lib/adapter_partner_pack.js +0 -89
- package/lib/adapter_promotion_pack.js +0 -89
- package/lib/adapter_protocol_truth_contract.js +0 -229
- package/lib/agent_identity.js +0 -162
- package/lib/announcement_pack.js +0 -61
- package/lib/artifact_distribution_lane_contract.js +0 -54
- package/lib/asyncapi_contract.js +0 -150
- package/lib/auth_interop_contract.js +0 -80
- package/lib/authority_binding_lifecycle_contract.js +0 -182
- package/lib/autonomous_entry_contract.js +0 -409
- package/lib/bolt_adapter.js +0 -187
- package/lib/bolt_lane_contract.js +0 -55
- package/lib/bolt_payment_front.js +0 -224
- package/lib/business_cockpit.js +0 -378
- package/lib/buyer_event_log.js +0 -230
- package/lib/buyer_safety_policy.js +0 -132
- package/lib/capability_execution_truth.js +0 -276
- package/lib/capability_registry.js +0 -633
- package/lib/catalog_contract.js +0 -966
- package/lib/catalog_family_model.js +0 -193
- package/lib/catalog_views.js +0 -55
- package/lib/cdp_jwt.js +0 -57
- package/lib/checkout_event_security.js +0 -142
- package/lib/checkout_processor_adapter.js +0 -217
- package/lib/cloudevents_contract.js +0 -80
- package/lib/command_flow.js +0 -911
- package/lib/commerce_artifacts.js +0 -591
- package/lib/commerce_authority.js +0 -449
- package/lib/commerce_bridge.js +0 -274
- package/lib/commerce_cases.js +0 -399
- package/lib/commerce_checkout.js +0 -509
- package/lib/commerce_coordination.js +0 -346
- package/lib/commerce_economics.js +0 -4017
- package/lib/commerce_identity.js +0 -578
- package/lib/commerce_quotes.js +0 -266
- package/lib/commerce_reports.js +0 -14461
- package/lib/commerce_runtime.js +0 -322
- package/lib/commerce_shell.js +0 -257
- package/lib/crypto_agility_matrix.js +0 -125
- package/lib/default_path_contract.js +0 -412
- package/lib/delivery_summary_contract.js +0 -95
- package/lib/ecosystem_entry.js +0 -64
- package/lib/erc8004_lane_contract.js +0 -65
- package/lib/event_system_lane_contract.js +0 -75
- package/lib/execution_dedupe.js +0 -86
- package/lib/execution_truth_contract.js +0 -234
- package/lib/external_credit_bridge.js +0 -142
- package/lib/external_execution_policy.js +0 -143
- package/lib/external_execution_runtime.js +0 -238
- package/lib/feature_control_lane_contract.js +0 -54
- package/lib/first_run_conversion_contract.js +0 -290
- package/lib/framework_lane_contract.js +0 -89
- package/lib/framework_provider_promotion.js +0 -235
- package/lib/full_catalog_contract.js +0 -525
- package/lib/go_live_operator_pack.js +0 -391
- package/lib/http_transport.js +0 -99
- package/lib/identity_auth.js +0 -175
- package/lib/identity_interop_contract.js +0 -82
- package/lib/integration_matrix_contract.js +0 -102
- package/lib/l402_adapter.js +0 -241
- package/lib/l402_lane_contract.js +0 -55
- package/lib/l402_payment_front.js +0 -265
- package/lib/launch_narrative.js +0 -53
- package/lib/lifecycle_continuity_contract.js +0 -115
- package/lib/machine_identity_registry_contract.js +0 -199
- package/lib/major_rails_lane_contract.js +0 -150
- package/lib/market_lane_contract.js +0 -467
- package/lib/market_lane_depth_contract.js +0 -182
- package/lib/market_lane_promotion_contract.js +0 -210
- package/lib/market_lane_trace_contract.js +0 -278
- package/lib/mcp_lane_contract.js +0 -137
- package/lib/mpp_adapter.js +0 -237
- package/lib/network_transport.js +0 -110
- package/lib/offline_verifiability_recovery_contract.js +0 -155
- package/lib/openapi_contract.js +0 -300
- package/lib/operational_receipt_contract.js +0 -165
- package/lib/operator_intelligence.js +0 -407
- package/lib/outreach_copy_pack.js +0 -51
- package/lib/outreach_message_pack.js +0 -71
- package/lib/outreach_proof.js +0 -71
- package/lib/outreach_target_pack.js +0 -60
- package/lib/partner_intelligence.js +0 -105
- package/lib/payment_config.js +0 -257
- package/lib/payment_front_registry.js +0 -53
- package/lib/payment_protocol_contract.js +0 -165
- package/lib/payment_rail_truth_contract.js +0 -324
- package/lib/payment_verification.js +0 -357
- package/lib/phase_10_closeout_pack.js +0 -45
- package/lib/phase_10_completion_pack.js +0 -76
- package/lib/phase_10_decision_record_pack.js +0 -54
- package/lib/phase_10_decision_resolution_pack.js +0 -53
- package/lib/phase_10_demand_signal_adapters_runtime_pack.js +0 -74
- package/lib/phase_10_ecosystem_backlog_triage_runtime_pack.js +0 -74
- package/lib/phase_10_freeze_baseline_pack.js +0 -67
- package/lib/phase_10_freeze_review_pack.js +0 -64
- package/lib/phase_10_gate_pack.js +0 -57
- package/lib/phase_10_long_tail_continuity_pack.js +0 -80
- package/lib/phase_10_long_tail_ecosystem_pack.js +0 -66
- package/lib/phase_10_niche_extension_registry_runtime_pack.js +0 -74
- package/lib/phase_1_claude_mcp_pack.js +0 -60
- package/lib/phase_1_claude_mcp_runtime_pack.js +0 -52
- package/lib/phase_1_ecosystem_pack.js +0 -67
- package/lib/phase_1_openai_codex_pack.js +0 -60
- package/lib/phase_1_openai_codex_runtime_pack.js +0 -52
- package/lib/phase_2_base_runtime_pack.js +0 -71
- package/lib/phase_2_base_usdc_runtime_pack.js +0 -72
- package/lib/phase_2_closeout_pack.js +0 -65
- package/lib/phase_2_completion_pack.js +0 -113
- package/lib/phase_2_decision_record_pack.js +0 -66
- package/lib/phase_2_decision_resolution_pack.js +0 -69
- package/lib/phase_2_eth_runtime_pack.js +0 -70
- package/lib/phase_2_evm_base_runtime_pack.js +0 -73
- package/lib/phase_2_evm_runtime_pack.js +0 -71
- package/lib/phase_2_flip_preview_pack.js +0 -60
- package/lib/phase_2_freeze_review_pack.js +0 -99
- package/lib/phase_2_gate_pack.js +0 -77
- package/lib/phase_2_payment_rails_pack.js +0 -71
- package/lib/phase_2_usdc_runtime_pack.js +0 -71
- package/lib/phase_3_brc_runtime_pack.js +0 -81
- package/lib/phase_3_bsv_teranode_runtime_pack.js +0 -83
- package/lib/phase_3_closeout_pack.js +0 -62
- package/lib/phase_3_completion_pack.js +0 -94
- package/lib/phase_3_decision_record_pack.js +0 -64
- package/lib/phase_3_decision_resolution_pack.js +0 -69
- package/lib/phase_3_freeze_baseline_pack.js +0 -67
- package/lib/phase_3_freeze_review_pack.js +0 -80
- package/lib/phase_3_gate_pack.js +0 -76
- package/lib/phase_3_metanet_runtime_pack.js +0 -81
- package/lib/phase_3_native_bsv_pack.js +0 -91
- package/lib/phase_3_native_continuity_pack.js +0 -82
- package/lib/phase_4_attestation_runtime_pack.js +0 -75
- package/lib/phase_4_closeout_pack.js +0 -45
- package/lib/phase_4_completion_pack.js +0 -94
- package/lib/phase_4_decision_record_pack.js +0 -54
- package/lib/phase_4_decision_resolution_pack.js +0 -45
- package/lib/phase_4_erc8004_runtime_pack.js +0 -76
- package/lib/phase_4_freeze_baseline_pack.js +0 -67
- package/lib/phase_4_freeze_review_pack.js +0 -68
- package/lib/phase_4_gate_pack.js +0 -58
- package/lib/phase_4_identity_registry_runtime_pack.js +0 -75
- package/lib/phase_4_identity_trust_pack.js +0 -73
- package/lib/phase_4_trust_continuity_pack.js +0 -86
- package/lib/phase_5_antelope_runtime_pack.js +0 -76
- package/lib/phase_5_closeout_pack.js +0 -44
- package/lib/phase_5_completion_pack.js +0 -82
- package/lib/phase_5_constellation_dag_runtime_pack.js +0 -76
- package/lib/phase_5_decision_record_pack.js +0 -54
- package/lib/phase_5_decision_resolution_pack.js +0 -45
- package/lib/phase_5_digibyte_dgb_runtime_pack.js +0 -76
- package/lib/phase_5_freeze_baseline_pack.js +0 -67
- package/lib/phase_5_freeze_review_pack.js +0 -68
- package/lib/phase_5_gate_pack.js +0 -58
- package/lib/phase_5_hedera_hbar_runtime_pack.js +0 -76
- package/lib/phase_5_kaspa_kas_runtime_pack.js +0 -76
- package/lib/phase_5_major_rails_continuity_pack.js +0 -86
- package/lib/phase_5_major_rails_pack.js +0 -110
- package/lib/phase_5_metal_runtime_pack.js +0 -76
- package/lib/phase_5_polkadot_dot_runtime_pack.js +0 -76
- package/lib/phase_5_proton_xpr_runtime_pack.js +0 -76
- package/lib/phase_5_solana_runtime_pack.js +0 -76
- package/lib/phase_6_autogen_runtime_pack.js +0 -72
- package/lib/phase_6_closeout_pack.js +0 -46
- package/lib/phase_6_completion_pack.js +0 -77
- package/lib/phase_6_decision_record_pack.js +0 -54
- package/lib/phase_6_decision_resolution_pack.js +0 -53
- package/lib/phase_6_framework_continuity_pack.js +0 -81
- package/lib/phase_6_framework_runtime_pack.js +0 -68
- package/lib/phase_6_freeze_baseline_pack.js +0 -68
- package/lib/phase_6_freeze_review_pack.js +0 -65
- package/lib/phase_6_gate_pack.js +0 -59
- package/lib/phase_6_langchain_runtime_pack.js +0 -72
- package/lib/phase_6_langgraph_runtime_pack.js +0 -72
- package/lib/phase_6_semantic_kernel_runtime_pack.js +0 -72
- package/lib/phase_7_closeout_pack.js +0 -45
- package/lib/phase_7_completion_pack.js +0 -85
- package/lib/phase_7_decision_record_pack.js +0 -53
- package/lib/phase_7_decision_resolution_pack.js +0 -53
- package/lib/phase_7_event_system_continuity_pack.js +0 -89
- package/lib/phase_7_event_system_pack.js +0 -76
- package/lib/phase_7_freeze_baseline_pack.js +0 -74
- package/lib/phase_7_freeze_review_pack.js +0 -65
- package/lib/phase_7_gate_pack.js +0 -58
- package/lib/phase_7_kafka_runtime_pack.js +0 -74
- package/lib/phase_7_mqtt_runtime_pack.js +0 -74
- package/lib/phase_7_nats_runtime_pack.js +0 -74
- package/lib/phase_7_webhook_event_bus_runtime_pack.js +0 -74
- package/lib/phase_8_closeout_pack.js +0 -46
- package/lib/phase_8_completion_pack.js +0 -82
- package/lib/phase_8_decision_record_pack.js +0 -54
- package/lib/phase_8_decision_resolution_pack.js +0 -53
- package/lib/phase_8_external_receipt_import_runtime_pack.js +0 -74
- package/lib/phase_8_external_result_import_runtime_pack.js +0 -74
- package/lib/phase_8_freeze_baseline_pack.js +0 -71
- package/lib/phase_8_freeze_review_pack.js +0 -64
- package/lib/phase_8_gate_pack.js +0 -58
- package/lib/phase_8_proof_bridge_continuity_pack.js +0 -86
- package/lib/phase_8_proof_bridges_pack.js +0 -72
- package/lib/phase_8_proof_bundle_normalization_runtime_pack.js +0 -74
- package/lib/phase_9_closeout_pack.js +0 -46
- package/lib/phase_9_completion_pack.js +0 -82
- package/lib/phase_9_custody_refs_runtime_pack.js +0 -74
- package/lib/phase_9_decision_record_pack.js +0 -54
- package/lib/phase_9_decision_resolution_pack.js +0 -53
- package/lib/phase_9_freeze_baseline_pack.js +0 -71
- package/lib/phase_9_freeze_review_pack.js +0 -64
- package/lib/phase_9_gate_pack.js +0 -58
- package/lib/phase_9_operator_accounting_bridges_runtime_pack.js +0 -74
- package/lib/phase_9_treasury_connectivity_pack.js +0 -72
- package/lib/phase_9_treasury_continuity_pack.js +0 -86
- package/lib/phase_9_treasury_destinations_runtime_pack.js +0 -74
- package/lib/phase_program_pack.js +0 -120
- package/lib/pricing_optimization_contract.js +0 -775
- package/lib/protocol_lane_contract.js +0 -117
- package/lib/provenance_lane_contract.js +0 -54
- package/lib/provider_lane_contract.js +0 -240
- package/lib/provider_network_contract.js +0 -149
- package/lib/provider_payout_execution.js +0 -155
- package/lib/provider_registry.js +0 -852
- package/lib/provider_runtime_journey_contract.js +0 -183
- package/lib/public_surface_policy_contract.js +0 -111
- package/lib/publish_plan.js +0 -51
- package/lib/rate_limiter.js +0 -81
- package/lib/record_queries.js +0 -48
- package/lib/release_candidate.js +0 -50
- package/lib/release_center.js +0 -1093
- package/lib/release_history.js +0 -205
- package/lib/release_manifest.js +0 -113
- package/lib/release_pack.js +0 -453
- package/lib/request_rate_limit.js +0 -144
- package/lib/resource_views.js +0 -31
- package/lib/revenue_launch_path_contract.js +0 -326
- package/lib/route_matchers.js +0 -34
- package/lib/route_params.js +0 -19
- package/lib/runtime_bridge.js +0 -124
- package/lib/runtime_operations_worker.js +0 -282
- package/lib/runtime_state_store.js +0 -495
- package/lib/settlement_bsv_live.js +0 -600
- package/lib/settlement_bsv_teranode.js +0 -117
- package/lib/settlement_lane_contract.js +0 -111
- package/lib/shared_signals_lane_contract.js +0 -54
- package/lib/signed_audit_provenance_contract.js +0 -83
- package/lib/soft_launch_pack.js +0 -78
- package/lib/stablecoin_lane_contract.js +0 -76
- package/lib/stripe_mpp_lane_contract.js +0 -96
- package/lib/stripe_mpp_payment_front.js +0 -258
- package/lib/telemetry_lane_contract.js +0 -54
- package/lib/treasury_destinations_contract.js +0 -764
- package/lib/treasury_egress_policy_contract.js +0 -91
- package/lib/treasury_lane_contract.js +0 -84
- package/lib/trust_portability_boundary_contract.js +0 -72
- package/lib/x402_facilitator.js +0 -198
- package/lib/x402_lane_contract.js +0 -136
- package/lib/x402_settlement_recovery.js +0 -175
- package/scripts/buyer_events_daily_report.js +0 -79
- package/scripts/registry_cli.js +0 -275
- package/scripts/state_backup_offsite.js +0 -196
- package/scripts/verify_a2a_rpc.js +0 -131
- package/scripts/verify_adapters.js +0 -554
- package/scripts/verify_agent_identity.js +0 -153
- package/scripts/verify_all.js +0 -4963
- package/scripts/verify_bolt_adapter.js +0 -128
- package/scripts/verify_buyer_event_log.js +0 -128
- package/scripts/verify_buyer_safety.js +0 -141
- package/scripts/verify_cdp_facilitator.js +0 -110
- package/scripts/verify_checkout_processor.js +0 -109
- package/scripts/verify_commerce_bridge.js +0 -177
- package/scripts/verify_control_plane_contracts.js +0 -34
- package/scripts/verify_control_plane_routes.js +0 -70
- package/scripts/verify_delivery_summary.js +0 -112
- package/scripts/verify_examples.js +0 -19
- package/scripts/verify_execution_dedupe.js +0 -189
- package/scripts/verify_execution_surfacing.js +0 -76
- package/scripts/verify_external_execution_retry.js +0 -140
- package/scripts/verify_final_activation.js +0 -191
- package/scripts/verify_first_run_conversions.js +0 -81
- package/scripts/verify_framework_provider_promotion.js +0 -152
- package/scripts/verify_full_catalog.js +0 -174
- package/scripts/verify_integrations.js +0 -620
- package/scripts/verify_l402_adapter.js +0 -86
- package/scripts/verify_lifecycle_continuity.js +0 -96
- package/scripts/verify_lifecycle_spend_binding.js +0 -88
- package/scripts/verify_market_lane_depth.js +0 -94
- package/scripts/verify_market_lane_promotion.js +0 -103
- package/scripts/verify_market_lane_traces.js +0 -98
- package/scripts/verify_market_lanes.js +0 -102
- package/scripts/verify_mpp_adapter.js +0 -128
- package/scripts/verify_operator_observability_boundary.js +0 -83
- package/scripts/verify_pricing_experiment_plan.js +0 -124
- package/scripts/verify_production_readiness.js +0 -268
- package/scripts/verify_provider_network.js +0 -819
- package/scripts/verify_provider_runtime_breadth.js +0 -109
- package/scripts/verify_provider_runtime_journeys.js +0 -111
- package/scripts/verify_rate_limiter.js +0 -52
- package/scripts/verify_refund_credit.js +0 -106
- package/scripts/verify_revenue_launch_paths.js +0 -105
- package/scripts/verify_runtime_durability.js +0 -52
- package/scripts/verify_runtime_state_guard.js +0 -117
- package/scripts/verify_service.js +0 -15421
- package/scripts/verify_settlement.js +0 -116
- package/scripts/verify_tooling.js +0 -1412
- package/scripts/verify_treasury_public_boundary.js +0 -97
- package/scripts/verify_verify_execute_settle.js +0 -209
- package/scripts/verify_x402_facilitator.js +0 -307
- package/scripts/verify_x402_settlement_recovery.js +0 -153
- package/server.js +0 -12245
package/lib/commerce_checkout.js
DELETED
|
@@ -1,509 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { createRefund, createRemediationTicket } = require("./commerce_cases");
|
|
4
|
-
const { applyRailCredits, buildCreditBalanceSummary, reverseRailCredits } = require("./commerce_economics");
|
|
5
|
-
const { dispatchRuntimeBridgeRequest } = require("./runtime_bridge");
|
|
6
|
-
|
|
7
|
-
function normalizeString(value, fallback) {
|
|
8
|
-
const trimmed = typeof value === "string" ? value.trim() : "";
|
|
9
|
-
return trimmed || fallback || null;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function buildDefaultHostedCheckoutState() {
|
|
13
|
-
return {
|
|
14
|
-
checkoutPurchaseIntents: new Map(),
|
|
15
|
-
checkoutSessions: new Map(),
|
|
16
|
-
checkoutEvents: new Map(),
|
|
17
|
-
runtimeBridgeDispatches: new Map(),
|
|
18
|
-
refunds: new Map()
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function normalizeHostedCheckoutState(state) {
|
|
23
|
-
const normalized = buildDefaultHostedCheckoutState();
|
|
24
|
-
if (!state || typeof state !== "object") {
|
|
25
|
-
return normalized;
|
|
26
|
-
}
|
|
27
|
-
for (const [key, value] of Object.entries(state)) {
|
|
28
|
-
if (typeof value !== "undefined") {
|
|
29
|
-
normalized[key] = value;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return normalized;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function ensureObject(value) {
|
|
36
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function nowIso() {
|
|
40
|
-
return new Date().toISOString();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function buildPrice(payload) {
|
|
44
|
-
const price = ensureObject(payload.price);
|
|
45
|
-
const amountMinor = Number.isFinite(Number(price.amount_minor))
|
|
46
|
-
? Number(price.amount_minor)
|
|
47
|
-
: Number.isFinite(Number(payload.amount_minor))
|
|
48
|
-
? Number(payload.amount_minor)
|
|
49
|
-
: 0;
|
|
50
|
-
return {
|
|
51
|
-
amount_minor: amountMinor,
|
|
52
|
-
currency: normalizeString(price.currency, normalizeString(payload.currency, "USD"))
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function buildCreditsUnits(payload, price) {
|
|
57
|
-
if (Number.isFinite(Number(payload.credits_units))) {
|
|
58
|
-
return Number(payload.credits_units);
|
|
59
|
-
}
|
|
60
|
-
if (Number.isFinite(Number(payload.quoted_units))) {
|
|
61
|
-
return Number(payload.quoted_units);
|
|
62
|
-
}
|
|
63
|
-
if (Number.isFinite(Number(payload.quantity))) {
|
|
64
|
-
return Number(payload.quantity);
|
|
65
|
-
}
|
|
66
|
-
return Math.max(1, Math.ceil((price.amount_minor || 0) / 100));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function listHostedCheckoutPurchaseIntents(state, accountId) {
|
|
70
|
-
const runtimeState = normalizeHostedCheckoutState(state);
|
|
71
|
-
const intents = Array.from(runtimeState.checkoutPurchaseIntents.values());
|
|
72
|
-
if (!accountId) return intents;
|
|
73
|
-
return intents.filter((intent) => intent.account_id === accountId);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function getHostedCheckoutPurchaseIntent(state, purchaseIntentId) {
|
|
77
|
-
const runtimeState = normalizeHostedCheckoutState(state);
|
|
78
|
-
return runtimeState.checkoutPurchaseIntents.get(purchaseIntentId) || null;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function createHostedCheckoutPurchaseIntent(state, body) {
|
|
82
|
-
const runtimeState = normalizeHostedCheckoutState(state);
|
|
83
|
-
const payload = ensureObject(body);
|
|
84
|
-
const createdAt = nowIso();
|
|
85
|
-
const price = buildPrice(payload);
|
|
86
|
-
const purchaseIntent = {
|
|
87
|
-
purchase_intent_id: normalizeString(payload.purchase_intent_id, `purchase_${runtimeState.checkoutPurchaseIntents.size + 1}`),
|
|
88
|
-
account_id: normalizeString(payload.account_id, "acct_demo"),
|
|
89
|
-
capability_id: normalizeString(payload.capability_id, null),
|
|
90
|
-
package_id: normalizeString(payload.package_id, null),
|
|
91
|
-
purchase_mode: normalizeString(payload.purchase_mode, "credits_topup"),
|
|
92
|
-
entitlement_mode: normalizeString(payload.entitlement_mode, "credits_issue"),
|
|
93
|
-
quantity: Number.isFinite(Number(payload.quantity)) ? Number(payload.quantity) : 1,
|
|
94
|
-
price,
|
|
95
|
-
quoted_units: Number.isFinite(Number(payload.quoted_units)) ? Number(payload.quoted_units) : null,
|
|
96
|
-
credits_units: buildCreditsUnits(payload, price),
|
|
97
|
-
task_input: payload.task_input && typeof payload.task_input === "object" && !Array.isArray(payload.task_input)
|
|
98
|
-
? payload.task_input
|
|
99
|
-
: null,
|
|
100
|
-
metadata: ensureObject(payload.metadata),
|
|
101
|
-
success_redirect_url: normalizeString(payload.success_redirect_url, null),
|
|
102
|
-
cancel_redirect_url: normalizeString(payload.cancel_redirect_url, null),
|
|
103
|
-
idempotency_key: normalizeString(payload.idempotency_key, `checkout_intent_${state.checkoutPurchaseIntents.size + 1}`),
|
|
104
|
-
checkout_status: "created",
|
|
105
|
-
customer_status: "created",
|
|
106
|
-
fulfillment: {
|
|
107
|
-
credits_issued: false,
|
|
108
|
-
execution_authorized: false,
|
|
109
|
-
package_access_granted: false
|
|
110
|
-
},
|
|
111
|
-
latest_checkout_session_id: null,
|
|
112
|
-
latest_checkout_reference: null,
|
|
113
|
-
latest_event_id: null,
|
|
114
|
-
created_at_iso: createdAt,
|
|
115
|
-
updated_at_iso: createdAt
|
|
116
|
-
};
|
|
117
|
-
runtimeState.checkoutPurchaseIntents.set(purchaseIntent.purchase_intent_id, purchaseIntent);
|
|
118
|
-
return purchaseIntent;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function createHostedCheckoutSession(state, purchaseIntentId, body) {
|
|
122
|
-
const runtimeState = normalizeHostedCheckoutState(state);
|
|
123
|
-
const payload = ensureObject(body);
|
|
124
|
-
const purchaseIntent = getHostedCheckoutPurchaseIntent(runtimeState, purchaseIntentId);
|
|
125
|
-
if (!purchaseIntent) return null;
|
|
126
|
-
|
|
127
|
-
const createdAt = nowIso();
|
|
128
|
-
const expiresAt = Number.isFinite(Number(payload.expires_in_seconds))
|
|
129
|
-
? new Date(Date.now() + Number(payload.expires_in_seconds) * 1000).toISOString()
|
|
130
|
-
: null;
|
|
131
|
-
const session = {
|
|
132
|
-
checkout_session_id: normalizeString(payload.checkout_session_id, `checkout_session_${runtimeState.checkoutSessions.size + 1}`),
|
|
133
|
-
purchase_intent_id: purchaseIntentId,
|
|
134
|
-
checkout_status: "checkout_pending",
|
|
135
|
-
checkout_provider: normalizeString(payload.checkout_provider, "hosted_checkout"),
|
|
136
|
-
checkout_reference: normalizeString(payload.checkout_reference, `checkout_ref_${runtimeState.checkoutSessions.size + 1}`),
|
|
137
|
-
amount_due_minor: purchaseIntent.price.amount_minor,
|
|
138
|
-
currency: purchaseIntent.price.currency,
|
|
139
|
-
expires_at_iso: expiresAt,
|
|
140
|
-
checkout_url: normalizeString(payload.checkout_url, null),
|
|
141
|
-
embedded_checkout_payload: ensureObject(payload.embedded_checkout_payload),
|
|
142
|
-
customer_reference: normalizeString(payload.customer_reference, purchaseIntent.account_id),
|
|
143
|
-
created_at_iso: createdAt,
|
|
144
|
-
updated_at_iso: createdAt
|
|
145
|
-
};
|
|
146
|
-
runtimeState.checkoutSessions.set(session.checkout_session_id, session);
|
|
147
|
-
runtimeState.checkoutPurchaseIntents.set(purchaseIntentId, {
|
|
148
|
-
...purchaseIntent,
|
|
149
|
-
checkout_status: "checkout_pending",
|
|
150
|
-
customer_status: "checkout_pending",
|
|
151
|
-
latest_checkout_session_id: session.checkout_session_id,
|
|
152
|
-
latest_checkout_reference: session.checkout_reference,
|
|
153
|
-
updated_at_iso: createdAt
|
|
154
|
-
});
|
|
155
|
-
return session;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function getHostedCheckoutSession(state, checkoutSessionId) {
|
|
159
|
-
const runtimeState = normalizeHostedCheckoutState(state);
|
|
160
|
-
return runtimeState.checkoutSessions.get(checkoutSessionId) || null;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function listHostedCheckoutSessions(state, purchaseIntentId) {
|
|
164
|
-
const runtimeState = normalizeHostedCheckoutState(state);
|
|
165
|
-
const sessions = Array.from(runtimeState.checkoutSessions.values());
|
|
166
|
-
if (!purchaseIntentId) return sessions;
|
|
167
|
-
return sessions.filter((session) => session.purchase_intent_id === purchaseIntentId);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function getHostedCheckoutEvent(state, eventId) {
|
|
171
|
-
const runtimeState = normalizeHostedCheckoutState(state);
|
|
172
|
-
return runtimeState.checkoutEvents.get(eventId) || null;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function getRuntimeBridgeDispatchByPurchaseIntent(state, purchaseIntentId) {
|
|
176
|
-
const runtimeState = normalizeHostedCheckoutState(state);
|
|
177
|
-
return Array.from(runtimeState.runtimeBridgeDispatches.values()).find((dispatch) =>
|
|
178
|
-
dispatch && dispatch.purchase_intent_id === purchaseIntentId
|
|
179
|
-
) || null;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function createHostedCheckoutRemediationTicket(state, purchaseIntent, event, refund, reasonCode, note) {
|
|
183
|
-
return createRemediationTicket(state, {
|
|
184
|
-
transaction_id: null,
|
|
185
|
-
receipt_id: null,
|
|
186
|
-
reason_code: reasonCode,
|
|
187
|
-
action_code: "compensate_or_review",
|
|
188
|
-
note,
|
|
189
|
-
actor: { type: "system", role: "hosted_checkout_compensator" },
|
|
190
|
-
context: {
|
|
191
|
-
purchase_intent_id: purchaseIntent.purchase_intent_id,
|
|
192
|
-
refund_id: refund ? refund.refund_id : null,
|
|
193
|
-
provider_reference: event.provider_reference || null,
|
|
194
|
-
payment_status: event.payment_status || null,
|
|
195
|
-
source: "hosted_checkout_compensation"
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function applyHostedCheckoutCompensation(state, purchaseIntent, event, refund) {
|
|
201
|
-
const balanceBefore = buildCreditBalanceSummary(state, purchaseIntent.account_id);
|
|
202
|
-
const currentAvailableUnits = Number(balanceBefore.available_units || 0);
|
|
203
|
-
const requiredUnits = Number(purchaseIntent.credits_units || 0);
|
|
204
|
-
const runtimeBridgeDispatch = getRuntimeBridgeDispatchByPurchaseIntent(state, purchaseIntent.purchase_intent_id);
|
|
205
|
-
const compensation = {
|
|
206
|
-
compensation_state: "review_required",
|
|
207
|
-
compensation_path: null,
|
|
208
|
-
reversal_credit_event_id: null,
|
|
209
|
-
remediation_ticket_id: null,
|
|
210
|
-
requires_manual_followup: true,
|
|
211
|
-
downstream_execution_detected: Boolean(runtimeBridgeDispatch),
|
|
212
|
-
insufficient_available_units: currentAvailableUnits < requiredUnits
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
if (purchaseIntent.fulfillment && purchaseIntent.fulfillment.credits_issued) {
|
|
216
|
-
const reversalResult = reverseRailCredits(state, {
|
|
217
|
-
account_id: purchaseIntent.account_id,
|
|
218
|
-
purchase_intent_id: purchaseIntent.purchase_intent_id,
|
|
219
|
-
provider_reference: event.provider_reference,
|
|
220
|
-
reason: event.payment_status === "chargeback"
|
|
221
|
-
? "hosted_checkout_chargeback_compensation"
|
|
222
|
-
: "hosted_checkout_refund_compensation"
|
|
223
|
-
});
|
|
224
|
-
if (reversalResult.ok) {
|
|
225
|
-
compensation.reversal_credit_event_id = reversalResult.reversal.credit_event_id;
|
|
226
|
-
compensation.compensation_path = "credit_reversal";
|
|
227
|
-
compensation.compensation_state = (currentAvailableUnits >= requiredUnits && !runtimeBridgeDispatch)
|
|
228
|
-
? "compensated"
|
|
229
|
-
: "remediation_required";
|
|
230
|
-
compensation.requires_manual_followup = compensation.compensation_state !== "compensated";
|
|
231
|
-
} else {
|
|
232
|
-
compensation.compensation_path = "credit_reversal_failed";
|
|
233
|
-
compensation.compensation_state = "compensation_failed";
|
|
234
|
-
}
|
|
235
|
-
} else if (purchaseIntent.fulfillment && purchaseIntent.fulfillment.execution_authorized) {
|
|
236
|
-
compensation.compensation_path = "execution_remediation";
|
|
237
|
-
compensation.compensation_state = "remediation_required";
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (compensation.compensation_state !== "compensated") {
|
|
241
|
-
const note = compensation.downstream_execution_detected
|
|
242
|
-
? "Hosted checkout reversal landed after execution dispatch and needs remediation review"
|
|
243
|
-
: compensation.insufficient_available_units
|
|
244
|
-
? "Hosted checkout reversal landed after funded capacity was partially or fully consumed"
|
|
245
|
-
: "Hosted checkout reversal requires explicit operator review";
|
|
246
|
-
const ticket = createHostedCheckoutRemediationTicket(
|
|
247
|
-
state,
|
|
248
|
-
purchaseIntent,
|
|
249
|
-
event,
|
|
250
|
-
refund,
|
|
251
|
-
event.payment_status === "chargeback" ? "chargeback_compensation_review_required" : "refund_compensation_review_required",
|
|
252
|
-
note
|
|
253
|
-
);
|
|
254
|
-
compensation.remediation_ticket_id = ticket.ticket_id;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
return compensation;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
function listHostedCheckoutRefunds(state, purchaseIntentId) {
|
|
261
|
-
const refunds = Array.from(state.refunds.values()).filter((refund) => refund && refund.purchase_intent_id);
|
|
262
|
-
if (!purchaseIntentId) return refunds;
|
|
263
|
-
return refunds.filter((refund) => refund.purchase_intent_id === purchaseIntentId);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
function buildHostedCheckoutOperatorSummary(state, accountId) {
|
|
267
|
-
const runtimeState = normalizeHostedCheckoutState(state);
|
|
268
|
-
const purchaseIntents = listHostedCheckoutPurchaseIntents(runtimeState, accountId);
|
|
269
|
-
const purchaseIntentIds = new Set(purchaseIntents.map((intent) => intent.purchase_intent_id));
|
|
270
|
-
const refunds = listHostedCheckoutRefunds(runtimeState).filter((refund) => purchaseIntentIds.has(refund.purchase_intent_id));
|
|
271
|
-
const bridgeDispatches = Array.from(runtimeState.runtimeBridgeDispatches.values()).filter((dispatch) => dispatch && dispatch.account_id === accountId);
|
|
272
|
-
return {
|
|
273
|
-
operator_summary_ref: `hosted_checkout.operator.${accountId}`,
|
|
274
|
-
account_id: accountId,
|
|
275
|
-
purchase_intent_count: purchaseIntents.length,
|
|
276
|
-
checkout_pending_count: purchaseIntents.filter((entry) => entry.checkout_status === "checkout_pending").length,
|
|
277
|
-
paid_intent_count: purchaseIntents.filter((entry) => entry.checkout_status === "paid").length,
|
|
278
|
-
credits_issued_count: purchaseIntents.filter((entry) => entry.fulfillment && entry.fulfillment.credits_issued).length,
|
|
279
|
-
execution_dispatched_count: bridgeDispatches.length,
|
|
280
|
-
refund_review_required_count: purchaseIntents.filter((entry) => entry.customer_status === "refund_review_required" || entry.customer_status === "refund_review_requested").length,
|
|
281
|
-
auto_compensated_count: purchaseIntents.filter((entry) => entry && entry.compensation && entry.compensation.compensation_state === "compensated").length,
|
|
282
|
-
compensation_review_required_count: purchaseIntents.filter((entry) => entry && entry.compensation && entry.compensation.compensation_state === "remediation_required").length,
|
|
283
|
-
compensation_failed_count: purchaseIntents.filter((entry) => entry && entry.compensation && entry.compensation.compensation_state === "compensation_failed").length,
|
|
284
|
-
refund_case_count: refunds.length,
|
|
285
|
-
refund_status_counts: refunds.reduce((acc, refund) => {
|
|
286
|
-
const key = refund && refund.status ? refund.status : "unknown";
|
|
287
|
-
acc[key] = (acc[key] || 0) + 1;
|
|
288
|
-
return acc;
|
|
289
|
-
}, {}),
|
|
290
|
-
linked_surfaces: {
|
|
291
|
-
purchase_intents: `/v1/checkout/purchase-intents?account_id=${encodeURIComponent(accountId)}`,
|
|
292
|
-
runtime_bridge_dispatches: `/v1/runtime-bridge/dispatches?account_id=${encodeURIComponent(accountId)}`
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
function requestHostedCheckoutRefund(state, purchaseIntentId, body) {
|
|
298
|
-
const purchaseIntent = getHostedCheckoutPurchaseIntent(state, purchaseIntentId);
|
|
299
|
-
if (!purchaseIntent) return null;
|
|
300
|
-
const payload = ensureObject(body);
|
|
301
|
-
const refund = createRefund(state, {
|
|
302
|
-
purchase_intent_id: purchaseIntentId,
|
|
303
|
-
transaction_id: normalizeString(payload.transaction_id, null),
|
|
304
|
-
receipt_id: normalizeString(payload.receipt_id, null),
|
|
305
|
-
reason_code: normalizeString(payload.reason_code, "refund_review_requested"),
|
|
306
|
-
note: normalizeString(payload.note, "Hosted checkout refund requested for operator review"),
|
|
307
|
-
requested_by: normalizeString(payload.requested_by, "checkout_requester"),
|
|
308
|
-
actor: payload.actor,
|
|
309
|
-
context: {
|
|
310
|
-
purchase_intent_id: purchaseIntentId,
|
|
311
|
-
source: "hosted_checkout",
|
|
312
|
-
...(ensureObject(payload.context))
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
state.checkoutPurchaseIntents.set(purchaseIntentId, {
|
|
316
|
-
...purchaseIntent,
|
|
317
|
-
customer_status: "refund_review_requested",
|
|
318
|
-
latest_refund_id: refund.refund_id,
|
|
319
|
-
updated_at_iso: nowIso()
|
|
320
|
-
});
|
|
321
|
-
return refund;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
async function normalizeHostedCheckoutEvent(state, body) {
|
|
325
|
-
const payload = ensureObject(body);
|
|
326
|
-
const eventId = normalizeString(payload.event_id, null);
|
|
327
|
-
if (eventId && state.checkoutEvents.has(eventId)) {
|
|
328
|
-
return state.checkoutEvents.get(eventId);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
const purchaseIntentId = normalizeString(payload.purchase_intent_id, null);
|
|
332
|
-
const purchaseIntent = getHostedCheckoutPurchaseIntent(state, purchaseIntentId);
|
|
333
|
-
if (!purchaseIntent) {
|
|
334
|
-
return null;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
const paymentStatus = normalizeString(payload.payment_status, "pending");
|
|
338
|
-
const timestamp = normalizeString(payload.timestamp, nowIso());
|
|
339
|
-
const event = {
|
|
340
|
-
event_id: eventId || `checkout_event_${state.checkoutEvents.size + 1}`,
|
|
341
|
-
purchase_intent_id: purchaseIntentId,
|
|
342
|
-
provider: normalizeString(payload.provider, "hosted_checkout"),
|
|
343
|
-
provider_event_type: normalizeString(payload.provider_event_type, "payment.status"),
|
|
344
|
-
provider_reference: normalizeString(payload.provider_reference, purchaseIntent.latest_checkout_reference || null),
|
|
345
|
-
payment_status: paymentStatus,
|
|
346
|
-
amount_received_minor: Number.isFinite(Number(payload.amount_received_minor))
|
|
347
|
-
? Number(payload.amount_received_minor)
|
|
348
|
-
: purchaseIntent.price.amount_minor,
|
|
349
|
-
currency: normalizeString(payload.currency, purchaseIntent.price.currency),
|
|
350
|
-
security_verification: ensureObject(payload.security_verification),
|
|
351
|
-
timestamp,
|
|
352
|
-
applied_status: "recorded",
|
|
353
|
-
credits_event_id: null,
|
|
354
|
-
created_at_iso: nowIso()
|
|
355
|
-
};
|
|
356
|
-
|
|
357
|
-
const nextIntent = {
|
|
358
|
-
...purchaseIntent,
|
|
359
|
-
latest_event_id: event.event_id,
|
|
360
|
-
updated_at_iso: event.created_at_iso
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
if (paymentStatus === "paid") {
|
|
364
|
-
nextIntent.checkout_status = "paid";
|
|
365
|
-
nextIntent.customer_status = "payment_received";
|
|
366
|
-
if (purchaseIntent.purchase_mode === "credits_topup" || purchaseIntent.entitlement_mode === "credits_issue") {
|
|
367
|
-
const creditEvent = applyRailCredits(state, {
|
|
368
|
-
account_id: purchaseIntent.account_id,
|
|
369
|
-
credit_event_id: `credit_${purchaseIntent.purchase_intent_id}`,
|
|
370
|
-
rail_kind: "hosted_checkout",
|
|
371
|
-
units: purchaseIntent.credits_units,
|
|
372
|
-
amount_minor: event.amount_received_minor,
|
|
373
|
-
currency: event.currency,
|
|
374
|
-
purchase_intent_id: purchaseIntent.purchase_intent_id,
|
|
375
|
-
provider_reference: event.provider_reference,
|
|
376
|
-
reason: "hosted_checkout_payment"
|
|
377
|
-
});
|
|
378
|
-
event.applied_status = "credits_issued";
|
|
379
|
-
event.credits_event_id = creditEvent.credit_event_id;
|
|
380
|
-
nextIntent.customer_status = "credits_issued";
|
|
381
|
-
nextIntent.fulfillment = {
|
|
382
|
-
...nextIntent.fulfillment,
|
|
383
|
-
credits_issued: true
|
|
384
|
-
};
|
|
385
|
-
} else if (purchaseIntent.purchase_mode === "single_task_execution" || purchaseIntent.entitlement_mode === "execution_authorization") {
|
|
386
|
-
const bridgeDispatch = await dispatchRuntimeBridgeRequest(state, {
|
|
387
|
-
request_id: `bridge_${purchaseIntent.purchase_intent_id}`,
|
|
388
|
-
account_id: purchaseIntent.account_id,
|
|
389
|
-
capability_id: purchaseIntent.capability_id,
|
|
390
|
-
execution_class: "single_task_execution",
|
|
391
|
-
input: ensureObject(purchaseIntent.task_input),
|
|
392
|
-
idempotency_key: purchaseIntent.idempotency_key,
|
|
393
|
-
callback_url: normalizeString(purchaseIntent.metadata.callback_url, null),
|
|
394
|
-
defer_completion: purchaseIntent.metadata.defer_completion === true,
|
|
395
|
-
settlement_mode: normalizeString(purchaseIntent.metadata.settlement_mode, "bsv_teranode"),
|
|
396
|
-
integration_id: normalizeString(purchaseIntent.metadata.integration_id, null),
|
|
397
|
-
integration_ids: Array.isArray(purchaseIntent.metadata.integration_ids) ? purchaseIntent.metadata.integration_ids : []
|
|
398
|
-
}, {
|
|
399
|
-
verification_mode: "hosted_checkout",
|
|
400
|
-
wallet_id: event.provider,
|
|
401
|
-
payment_payload: {
|
|
402
|
-
purchase_intent_id: purchaseIntent.purchase_intent_id,
|
|
403
|
-
provider_reference: event.provider_reference
|
|
404
|
-
},
|
|
405
|
-
purchase_intent_id: purchaseIntent.purchase_intent_id
|
|
406
|
-
});
|
|
407
|
-
event.applied_status = bridgeDispatch.status === 200 ? "execution_dispatched" : "dispatch_failed";
|
|
408
|
-
event.runtime_bridge_request_id = `bridge_${purchaseIntent.purchase_intent_id}`;
|
|
409
|
-
nextIntent.customer_status = bridgeDispatch.status === 200 ? "execution_dispatched" : "failed";
|
|
410
|
-
nextIntent.fulfillment = {
|
|
411
|
-
...nextIntent.fulfillment,
|
|
412
|
-
execution_authorized: bridgeDispatch.status === 200
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
} else if (paymentStatus === "failed") {
|
|
416
|
-
nextIntent.checkout_status = "failed";
|
|
417
|
-
nextIntent.customer_status = "failed";
|
|
418
|
-
} else if (paymentStatus === "refunded" || paymentStatus === "chargeback") {
|
|
419
|
-
nextIntent.checkout_status = paymentStatus;
|
|
420
|
-
nextIntent.customer_status = "refund_review_required";
|
|
421
|
-
event.applied_status = "refund_review_required";
|
|
422
|
-
const existingRefund = listHostedCheckoutRefunds(state, purchaseIntent.purchase_intent_id)[0] || null;
|
|
423
|
-
const refund = existingRefund || createRefund(state, {
|
|
424
|
-
purchase_intent_id: purchaseIntent.purchase_intent_id,
|
|
425
|
-
reason_code: paymentStatus === "chargeback" ? "chargeback_review_required" : "provider_refund_review_required",
|
|
426
|
-
note: paymentStatus === "chargeback"
|
|
427
|
-
? "Chargeback or reversal reported and queued for review"
|
|
428
|
-
: "Refund reported and queued for review",
|
|
429
|
-
requested_by: "provider_report",
|
|
430
|
-
context: {
|
|
431
|
-
purchase_intent_id: purchaseIntent.purchase_intent_id,
|
|
432
|
-
source: "hosted_checkout_event",
|
|
433
|
-
payment_status: paymentStatus,
|
|
434
|
-
provider_reference: event.provider_reference
|
|
435
|
-
}
|
|
436
|
-
});
|
|
437
|
-
nextIntent.latest_refund_id = refund.refund_id;
|
|
438
|
-
const compensation = applyHostedCheckoutCompensation(state, purchaseIntent, event, refund);
|
|
439
|
-
event.compensation = compensation;
|
|
440
|
-
nextIntent.compensation = compensation;
|
|
441
|
-
if (compensation.compensation_state === "compensated") {
|
|
442
|
-
refund.status = "completed";
|
|
443
|
-
refund.action_code = "auto_compensated";
|
|
444
|
-
refund.updated_at_iso = nowIso();
|
|
445
|
-
refund.history = [
|
|
446
|
-
...(Array.isArray(refund.history) ? refund.history : []),
|
|
447
|
-
{
|
|
448
|
-
at_iso: refund.updated_at_iso,
|
|
449
|
-
event: "auto_compensated",
|
|
450
|
-
note: paymentStatus === "chargeback"
|
|
451
|
-
? "Chargeback compensation applied automatically"
|
|
452
|
-
: "Refund compensation applied automatically",
|
|
453
|
-
reason_code: refund.reason_code,
|
|
454
|
-
action_code: "auto_compensated",
|
|
455
|
-
previous_status: "requested",
|
|
456
|
-
next_status: "completed",
|
|
457
|
-
actor: { type: "system", role: "hosted_checkout_compensator" },
|
|
458
|
-
context: {
|
|
459
|
-
purchase_intent_id: purchaseIntent.purchase_intent_id,
|
|
460
|
-
provider_reference: event.provider_reference,
|
|
461
|
-
reversal_credit_event_id: compensation.reversal_credit_event_id
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
].slice(-20);
|
|
465
|
-
state.refunds.set(refund.refund_id, refund);
|
|
466
|
-
nextIntent.customer_status = paymentStatus === "chargeback" ? "chargeback_compensated" : "refund_compensated";
|
|
467
|
-
event.applied_status = "auto_compensated";
|
|
468
|
-
if (nextIntent.fulfillment) {
|
|
469
|
-
nextIntent.fulfillment = {
|
|
470
|
-
...nextIntent.fulfillment,
|
|
471
|
-
credits_issued: false
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
|
-
} else {
|
|
475
|
-
nextIntent.customer_status = paymentStatus === "chargeback" ? "chargeback_review_required" : "refund_review_required";
|
|
476
|
-
event.applied_status = compensation.compensation_state === "compensation_failed"
|
|
477
|
-
? "compensation_failed"
|
|
478
|
-
: "refund_review_required";
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
state.checkoutPurchaseIntents.set(purchaseIntentId, nextIntent);
|
|
483
|
-
state.checkoutEvents.set(event.event_id, event);
|
|
484
|
-
|
|
485
|
-
if (purchaseIntent.latest_checkout_session_id && state.checkoutSessions.has(purchaseIntent.latest_checkout_session_id)) {
|
|
486
|
-
const session = state.checkoutSessions.get(purchaseIntent.latest_checkout_session_id);
|
|
487
|
-
state.checkoutSessions.set(purchaseIntent.latest_checkout_session_id, {
|
|
488
|
-
...session,
|
|
489
|
-
checkout_status: nextIntent.checkout_status,
|
|
490
|
-
updated_at_iso: nowIso()
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
return event;
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
module.exports = {
|
|
498
|
-
createHostedCheckoutPurchaseIntent,
|
|
499
|
-
createHostedCheckoutSession,
|
|
500
|
-
getHostedCheckoutEvent,
|
|
501
|
-
getHostedCheckoutPurchaseIntent,
|
|
502
|
-
getHostedCheckoutSession,
|
|
503
|
-
buildHostedCheckoutOperatorSummary,
|
|
504
|
-
listHostedCheckoutPurchaseIntents,
|
|
505
|
-
listHostedCheckoutRefunds,
|
|
506
|
-
listHostedCheckoutSessions,
|
|
507
|
-
normalizeHostedCheckoutEvent,
|
|
508
|
-
requestHostedCheckoutRefund
|
|
509
|
-
};
|