-- otp transactions
drop table otp_transactions cascade;
create table otp_transactions(
	otp_transaction_id serial,
	tranid varchar(16),
	ctstamp timestamp without time zone default now(),
	paid_tstamp timestamp without time zone,
	cancel_tstamp timestamp without time zone,
	refund_tstamp timestamp without time zone,
	amount double precision,
	currency varchar(3),
	informations text,
	comments text,
	constraint otp_transactions_otp_transaction_id_pkey primary key( otp_transaction_id )
);


comment on table otp_transactions is 'storage of otp transactions (bank specific)';
comment on column otp_transactions.otp_transaction_id is 'unique id of table';
comment on column otp_transactions.tranid is 'transaction (unique) id to OTP';
comment on column otp_transactions.ctstamp is 'creation timestamp of transaction';
comment on column otp_transactions.paid_tstamp is 'paid timestamp of transaction (if succeed)';
comment on column otp_transactions.cancel_tstamp is 'cancel timestamp of transaction (if cancelled)';
comment on column otp_transactions.refund_tstamp is 'refund timestamp of transaction (if refunded)';
comment on column otp_transactions.amount is 'amount of money to be transferred';
comment on column otp_transactions.currency is 'currency of money used in transaction';
comment on column otp_transactions.informations is 'informations (reserved)';
comment on column otp_transactions.comments is 'comments (reserved)';

-- global transactions
drop table cc_transactions;
create table cc_transactions(
	cc_transaction_id serial,
	ctstamp timestamp without time zone default now(),
	user_id integer not null references users( user_id ),
	paid_tstamp timestamp without time zone,
	cancel_tstamp timestamp without time zone,
	refund_tstamp timestamp without time zone,
	amount double precision,
	currency varchar(3),
	bankname varchar(16) default 'otp',
	bank_transaction_id integer,
	is_closed boolean default false,
	prolong_days integer,
	constraint cc_transactions_cc_transaction_id_pkey primary key( cc_transaction_id )
);

comment on table cc_transactions is 'storage of credit card transactions (global)';
comment on column cc_transactions.cc_transaction_id is 'unique id of creditcard transaction';
comment on column cc_transactions.ctstamp is 'creational timestamp of transaction';
comment on column cc_transactions.user_id is 'reference id to users table (not members, for future enhancements!)';
comment on column cc_transactions.paid_tstamp is 'paid timestamp of transaction (if succeed)';
comment on column cc_transactions.cancel_tstamp is 'cancel timestamp of transaction (if cancelled)';
comment on column cc_transactions.refund_tstamp is 'refund timestamp of transaction (if refunded)';
comment on column cc_transactions.amount is 'amount of money to be transferred';
comment on column cc_transactions.currency is 'currency of money used in transaction';
comment on column cc_transactions.bankname is 'name of the bank used to the transaction (otp)';
comment on column cc_transactions.bank_transaction_id is 'foreign id to specific table (otp_transactions)';
comment on column cc_transactions.is_closed is 'is closed flag of the transaction';
comment on column cc_transactions.prolong_days is 'prolonged days';


-- egyeb
select setval('otp_transactions_otp_transaction_id_seq',3000);
