1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
--
-- This file is part of TALER
-- Copyright (C) 2023 Taler Systems SA
--
-- TALER is free software; you can redistribute it and/or modify it under the
-- terms of the GNU General Public License as published by the Free Software
-- Foundation; either version 3, or (at your option) any later version.
--
-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along with
-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
--
-- Everything in one big transaction
BEGIN;
-- Check patch versioning is in place.
SELECT _v.register_patch('merchant-0002', NULL, NULL);
SET search_path TO merchant;
ALTER TABLE merchant_orders
ADD COLUMN fulfillment_url TEXT DEFAULT NULL
,ADD COLUMN session_id TEXT DEFAULT '' NOT NULL;
CREATE INDEX IF NOT EXISTS merchant_orders_by_merchant_and_session
ON merchant_orders
(merchant_serial,session_id);
CREATE INDEX IF NOT EXISTS merchant_orders_by_merchant_and_fullfilment_and_session
ON merchant_orders
(merchant_serial,fulfillment_url,session_id);
CREATE INDEX IF NOT EXISTS merchant_contract_terms_by_merchant_and_session
ON merchant_contract_terms
(merchant_serial,session_id);
-------------------------- Tokens -----------------------------
CREATE TABLE IF NOT EXISTS merchant_token_families
(token_family_serial BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY
,name TEXT NOT NULL UNIQUE
,description TEXT
,description_i18n BYTEA NOT NULL
,start_date INT8 NOT NULL
,expiration_date INT8 NOT NULL
,kind TEXT NOT NULL CHECK (kind IN ('subscription', 'discount'))
,pub BYTEA NOT NULL UNIQUE CHECK (LENGTH(pub)=32)
,h_pub BYTEA NOT NULL UNIQUE CHECK (LENGTH(h_pub)=64)
,priv BYTEA UNIQUE CHECK (LENGTH(priv)=32)
,cipher TEXT NOT NULL CHECK (cipher IN ('rsa', 'cs'))
,issued BIGINT DEFAULT 0
,redeemed BIGINT DEFAULT 0
);
COMMENT ON TABLE merchant_token_families
IS 'Token families configured by the merchant.';
COMMENT ON COLUMN merchant_token_families.name
IS 'Name of the token family.';
COMMENT ON COLUMN merchant_token_families.description
IS 'Human-readable description or details about the token family.';
COMMENT ON COLUMN merchant_token_families.description_i18n
IS 'JSON map from IETF BCP 47 language tags to localized descriptions';
COMMENT ON COLUMN merchant_token_families.start_date
IS 'Start date/time for the validity of the token family.';
COMMENT ON COLUMN merchant_token_families.expiration_date
IS 'Expiration date/time for the validity of the token family.';
COMMENT ON COLUMN merchant_token_families.kind
IS 'Kind of the token (e.g., subscription, discount).';
COMMENT ON COLUMN merchant_token_families.pub
IS 'Public key of the token family.';
COMMENT ON COLUMN merchant_token_families.h_pub
IS 'Hash of the public key for quick lookup.';
COMMENT ON COLUMN merchant_token_families.priv
IS 'Private key of the token family; can be NULL if no more tokens of this familiy should be issued.';
COMMENT ON COLUMN merchant_token_families.cipher
IS 'Cipher used (rsa or cs).';
COMMENT ON COLUMN merchant_token_families.issued
IS 'Counter for the number of tokens issued for this token family.';
COMMENT ON COLUMN merchant_token_families.redeemed
IS 'Counter for the number of tokens redeemed for this token family.';
CREATE TABLE IF NOT EXISTS merchant_spent_tokens
(spent_token_serial BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY
,order_serial BIGINT REFERENCES merchant_orders(order_serial) ON DELETE CASCADE
,token_family_serial BIGINT REFERENCES merchant_token_families(token_family_serial) ON DELETE CASCADE
,token_pub BYTEA NOT NULL UNIQUE CHECK (LENGTH(token_pub)=32)
,blind_sig BYTEA NOT NULL CHECK (LENGTH(blind_sig)=64)
);
COMMENT ON TABLE merchant_spent_tokens
IS 'Tokens that have been spent by customers.';
COMMENT ON COLUMN merchant_spent_tokens.order_id
IS 'Order the token was spent on.';
COMMENT ON COLUMN merchant_spent_tokens.token_family_id
IS 'Token family to which the spent token belongs.';
COMMENT ON COLUMN merchant_spent_tokens.token_pub
IS 'Public key of the spent token.';
COMMENT ON COLUMN merchant_spent_tokens.blind_sig
IS 'Blind signature for the spent token.';
-- Complete transaction
COMMIT;
|