;; lib/commerce/tests/payment.sx — provider-neutral payment-request envelope.
;; Uses (commerce-test name got expected) provided by conformance.sh.
;; Envelope construction is ledger-only (no flow env); pending-payments (which
;; needs the flow env) is exercised in the order suite.

(define q1 {:codes (list) :subtotal 1000 :discount 0 :total 1200 :tax 200})
(define q2 {:codes (list) :subtotal 5000 :discount 500 :total 4500 :tax 0})

(define b (persist/mem-backend))
(define _c1 (order-create b "P1" 1 q1))
(define _c2 (order-create b "P2" 1 q2))

(commerce-test
  "envelope"
  (payment-request b "P1" :GBP "https://shop/return")
  {:order "P1" :amount 1200 :return-url "https://shop/return" :currency :GBP})

(commerce-test
  "envelope-amount"
  (payment-request-amount (payment-request b "P1" :GBP "x"))
  1200)
(commerce-test
  "envelope-currency"
  (payment-request-currency (payment-request b "P1" :GBP "x"))
  :GBP)
(commerce-test
  "envelope-order"
  (payment-request-order (payment-request b "P1" :GBP "x"))
  "P1")
(commerce-test
  "envelope-return-url"
  (payment-request-return-url (payment-request b "P1" :GBP "https://r"))
  "https://r")

;; amount tracks the ledger total, currency is per-call (provider/instance config)
(commerce-test
  "envelope-amount-2"
  (payment-request-amount (payment-request b "P2" :EUR "x"))
  4500)
(commerce-test
  "envelope-currency-2"
  (payment-request-currency (payment-request b "P2" :EUR "x"))
  :EUR)
