CREATE TABLE IF NOT EXISTS paymenthub_configuration (
  customer text NOT NULL
    CONSTRAINT paymenthub_configuration_pk PRIMARY KEY,
  logfile text NOT NULL,
  available_provider text[] NOT NULL,
  css_file text,
  project_url text,
  impressum_url text,
  datenschutz_url text
);

ALTER TABLE paymenthub_configuration
  OWNER TO paymenthub;

CREATE TABLE IF NOT EXISTS wirecard_configuration (
  customer text NOT NULL
    CONSTRAINT wirecard_configuration_pkey PRIMARY KEY
    CONSTRAINT wirecard_configuration_paymenthub_configuration_customer_fk REFERENCES paymenthub_configuration ON UPDATE RESTRICT ON DELETE RESTRICT,
  logfile text NOT NULL,
  username text NOT NULL,
  password text NOT NULL,
  base_url text NOT NULL,
  base_url_endpoints json NOT NULL,
  backend_url text NOT NULL,
  backend_url_endpoints json NOT NULL
);

ALTER TABLE wirecard_configuration
  OWNER TO paymenthub;

CREATE TABLE IF NOT EXISTS wirecard_payment_method_configuration (
  customer text NOT NULL
    CONSTRAINT wirecard_payment_method_configuration_wirecard_configuration_cu REFERENCES wirecard_configuration ON UPDATE RESTRICT ON DELETE RESTRICT,
  payment_method text NOT NULL,
  maid text NOT NULL,
  secret text NOT NULL,
  transaction_type text NOT NULL,
  CONSTRAINT wirecard_payment_method_configuration_pk PRIMARY KEY (customer, payment_method)
);

ALTER TABLE wirecard_payment_method_configuration
  OWNER TO paymenthub;

CREATE TABLE IF NOT EXISTS wirecard_payment (
  id bigserial NOT NULL
    CONSTRAINT wirecard_pkey PRIMARY KEY,
  customer text NOT NULL
    CONSTRAINT wirecard_payment_wirecard_configuration_customer_fk REFERENCES wirecard_configuration ON UPDATE RESTRICT ON DELETE RESTRICT,
  initiator json NOT NULL,
  reference text NOT NULL,
  internal_reference text NOT NULL,
  redirect_urls json NOT NULL,
  check_payment boolean DEFAULT FALSE NOT NULL,
  paid boolean DEFAULT FALSE NOT NULL,
  failed boolean DEFAULT FALSE NOT NULL,
  cancelled boolean DEFAULT FALSE NOT NULL,
  transfer_data boolean DEFAULT FALSE NOT NULL,
  transferred boolean DEFAULT FALSE NOT NULL,
  register_request_timestamp timestamp,
  register_request json,
  register_response_timestamp timestamp,
  register_response json,
  payment_information_timestamp timestamp WITHOUT TIME ZONE[],
  payment_information jsonb
);

ALTER TABLE wirecard_payment
  OWNER TO paymenthub;

CREATE TABLE IF NOT EXISTS heidelpay_configuration (
  customer text NOT NULL
    CONSTRAINT heidelpay_configuration_pkey PRIMARY KEY
    CONSTRAINT heidelpay_configuration_paymenthub_configuration_customer_fk REFERENCES paymenthub_configuration ON UPDATE RESTRICT ON DELETE RESTRICT,
  logfile text NOT NULL,
  public_key text NOT NULL,
  private_key text NOT NULL,
  backend_url text NOT NULL,
  backend_url_endpoints json NOT NULL
);

ALTER TABLE heidelpay_configuration
  OWNER TO paymenthub;

CREATE TABLE IF NOT EXISTS heidelpay_payment (
  id bigserial NOT NULL
    CONSTRAINT heidelpay_payment_pkey PRIMARY KEY,
  customer text NOT NULL
    CONSTRAINT heidelpay_payment_heidelpay_configuration_customer_fk REFERENCES heidelpay_configuration ON UPDATE RESTRICT ON DELETE RESTRICT,
  initiator json NOT NULL,
  reference text NOT NULL,
  internal_reference text NOT NULL,
  amount integer NOT NULL,
  paid boolean DEFAULT FALSE NOT NULL,
  failed boolean DEFAULT FALSE NOT NULL,
  cancelled boolean DEFAULT FALSE NOT NULL,
  transfer_data boolean DEFAULT FALSE NOT NULL,
  transferred boolean DEFAULT FALSE NOT NULL,
  charge_timestamp timestamp WITHOUT TIME ZONE[],
  charge jsonb,
  create_timestamp timestamp DEFAULT (now())::timestamp WITHOUT TIME ZONE NOT NULL,
  pending boolean DEFAULT FALSE NOT NULL,
  payment_status_timestamp timestamp WITHOUT TIME ZONE[],
  payment_status jsonb
);

ALTER TABLE heidelpay_payment
  OWNER TO paymenthub;

CREATE TABLE IF NOT EXISTS heidelpay_temporary_payment (
  id bigserial NOT NULL
    CONSTRAINT heidelpay_temporary_payment_pkey PRIMARY KEY,
  customer text NOT NULL
    CONSTRAINT heidelpay_temporary_payment_heidelpay_configuration_customer_fk REFERENCES heidelpay_configuration ON UPDATE RESTRICT ON DELETE RESTRICT,
  payment jsonb NOT NULL,
  redirect_urls jsonb NOT NULL,
  token text NOT NULL
);

ALTER TABLE heidelpay_temporary_payment
  OWNER TO paymenthub;

CREATE TABLE IF NOT EXISTS pmpayment_configuration (
  customer text NOT NULL
    CONSTRAINT pmpayment_configuration_pk PRIMARY KEY
    CONSTRAINT pmpayment_configuration_paymenthub_configuration_customer_fk REFERENCES paymenthub_configuration ON UPDATE RESTRICT ON DELETE RESTRICT,
  logfile text NOT NULL,
  ags text NOT NULL,
  procedure text NOT NULL,
  salt text NOT NULL,
  notify_url text NOT NULL,
  backend_url text NOT NULL,
  backend_url_endpoints json NOT NULL,
  auth_name text,
  auth_password text,
  auth_token text,
  expiration_date timestamp
);

ALTER TABLE pmpayment_configuration
  OWNER TO paymenthub;

CREATE TABLE IF NOT EXISTS pmpayment_payment (
  id bigserial NOT NULL
    CONSTRAINT pmpayment_payment_pkey PRIMARY KEY,
  customer text NOT NULL
    CONSTRAINT pmpayment_payment_pmpayment_configuration_customer_fk REFERENCES pmpayment_configuration ON UPDATE RESTRICT ON DELETE RESTRICT,
  initiator json NOT NULL,
  reference text NOT NULL,
  internal_reference text,
  redirect_url text NOT NULL,
  amount integer NOT NULL,
  init_data json NOT NULL,
  create_timestamp timestamp DEFAULT (now())::timestamp WITHOUT TIME ZONE NOT NULL,
  paid boolean DEFAULT FALSE NOT NULL,
  pending boolean DEFAULT FALSE NOT NULL,
  failed boolean DEFAULT FALSE NOT NULL,
  cancelled boolean DEFAULT FALSE NOT NULL,
  transfer_data boolean DEFAULT FALSE NOT NULL,
  transferred boolean DEFAULT FALSE NOT NULL,
  response_timestamp timestamp,
  txid text,
  response_redirect_url text,
  payment_status_timestamp timestamp WITHOUT TIME ZONE[],
  payment_status jsonb,
  transaction_details_timestamp timestamp WITHOUT TIME ZONE[],
  transaction_details jsonb,
  payment_method text
);

ALTER TABLE pmpayment_payment
  OWNER TO paymenthub;

CREATE TABLE IF NOT EXISTS payone_configuration (
  customer text NOT NULL
    CONSTRAINT payone_configuration_pk PRIMARY KEY
    CONSTRAINT payone_configuration_paymenthub_configuration_customer_fk REFERENCES paymenthub_configuration ON UPDATE RESTRICT ON DELETE RESTRICT,
  logfile text NOT NULL,
  mid numeric(6) NOT NULL,
  portalid text NOT NULL,
  api_version numeric(3, 1) NOT NULL,
  live boolean DEFAULT FALSE NOT NULL,
  secret_key text NOT NULL,
  api_urls json NOT NULL,
  sub_account_id numeric(6)
);

ALTER TABLE payone_configuration
  OWNER TO paymenthub;

CREATE TABLE IF NOT EXISTS payone_temporary_payment (
  id bigserial NOT NULL
    CONSTRAINT payone_temporary_payment_pkey PRIMARY KEY,
  customer text NOT NULL
    CONSTRAINT payone_temporary_payment_payone_configuration_customer_fk REFERENCES payone_configuration ON UPDATE RESTRICT ON DELETE RESTRICT,
  payment jsonb NOT NULL,
  redirect_urls jsonb NOT NULL,
  token text NOT NULL
);

ALTER TABLE payone_temporary_payment
  OWNER TO paymenthub;

CREATE TABLE IF NOT EXISTS payone_payment (
  id bigserial NOT NULL
    CONSTRAINT payone_payment_pkey PRIMARY KEY,
  customer text NOT NULL
    CONSTRAINT payone_payment_payone_configuration_customer_fk REFERENCES payone_configuration ON UPDATE RESTRICT ON DELETE RESTRICT,
  initiator json NOT NULL,
  reference text NOT NULL,
  amount integer NOT NULL,
  paid boolean DEFAULT FALSE NOT NULL,
  failed boolean DEFAULT FALSE NOT NULL,
  cancelled boolean DEFAULT FALSE NOT NULL,
  pending boolean DEFAULT FALSE NOT NULL,
  transfer_data boolean DEFAULT FALSE NOT NULL,
  transferred boolean DEFAULT FALSE NOT NULL,
  create_timestamp timestamp DEFAULT (now())::timestamp WITHOUT TIME ZONE NOT NULL,
  payment json,
  response_timestamp timestamp,
  response json,
  internal_reference text,
  authorize_response json,
  notify_timestamp timestamp WITHOUT TIME ZONE[],
  notification jsonb
);

ALTER TABLE payone_payment
  OWNER TO paymenthub;

CREATE TABLE IF NOT EXISTS saferpay_configuration (
  customer text NOT NULL
    CONSTRAINT saferpay_configuration_pkey PRIMARY KEY
    CONSTRAINT saferpay_configuration_paymenthub_configuration_customer_fk REFERENCES paymenthub_configuration ON UPDATE RESTRICT ON DELETE RESTRICT,
  logfile text NOT NULL,
  spec_version text NOT NULL,
  customer_id text NOT NULL,
  terminal_id text NOT NULL,
  api_url text NOT NULL,
  api_url_endpoints json NOT NULL,
  api_user text NOT NULL,
  api_password text NOT NULL,
  notify_url text
);

ALTER TABLE saferpay_configuration
  OWNER TO paymenthub;

CREATE TABLE IF NOT EXISTS saferpay_temporary_payment (
  id bigserial NOT NULL
    CONSTRAINT saferpay_temporary_payment_pkey PRIMARY KEY,
  customer text NOT NULL
    CONSTRAINT saferpay_temporary_payment_saferpay_configuration_customer_fk REFERENCES saferpay_configuration ON UPDATE RESTRICT ON DELETE RESTRICT,
  payment jsonb NOT NULL,
  redirect_urls jsonb NOT NULL,
  token text NOT NULL
);

ALTER TABLE saferpay_temporary_payment
  OWNER TO paymenthub;

CREATE TABLE IF NOT EXISTS saferpay_payment (
  id bigserial NOT NULL
    CONSTRAINT saferpay_payment_pkey PRIMARY KEY,
  customer text NOT NULL
    CONSTRAINT saferpay_payment_saferpay_configuration_customer_fk REFERENCES saferpay_configuration ON UPDATE RESTRICT ON DELETE RESTRICT,
  initiator json NOT NULL,
  reference text NOT NULL,
  internal_reference text,
  amount integer NOT NULL,
  paid boolean DEFAULT FALSE NOT NULL,
  failed boolean DEFAULT FALSE NOT NULL,
  cancelled boolean DEFAULT FALSE NOT NULL,
  pending boolean DEFAULT FALSE NOT NULL,
  transfer_data boolean DEFAULT FALSE NOT NULL,
  transferred boolean DEFAULT FALSE NOT NULL,
  type text NOT NULL,
  payment_method text,
  init_request_timestamp timestamp,
  init_request jsonb,
  init_response jsonb,
  transaction_id text,
  status_timestamp timestamp WITHOUT TIME ZONE[],
  status jsonb,
  capture_timestamp timestamp,
  capture jsonb,
  capture_id text,
  reference_count integer DEFAULT 0 NOT NULL
);

ALTER TABLE saferpay_payment
  OWNER TO paymenthub;

