CREATE TABLE IF NOT EXISTS `PREFIX_resursbank_order` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Prim Key',
  `order_id` int(10) unsigned NOT NULL COMMENT 'Order reference.',
  `test` tinyint(1) unsigned NOT NULL COMMENT 'Whether the purchase was conducted in test.',
  `ready_for_callback` tinyint(1) unsigned NOT NULL COMMENT 'Indicates whether order is ready to accept callbacks',
  `mapi_id` varchar(36) NULL DEFAULT NULL COMMENT 'MAPI payment UUID',
  PRIMARY KEY (`id`),
  CONSTRAINT `FK_RB_ORDER_ORDER` FOREIGN KEY (`order_id`) REFERENCES `PREFIX_orders` (`id_order`) ON DELETE CASCADE,
  UNIQUE (`order_id`)
  ) CHARSET=utf8 COMMENT='Resurs Bank Order Data Table';

CREATE TABLE IF NOT EXISTS `PREFIX_resursbank_payment_history` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Prim Key',
  `resursbank_order_id` int(10) unsigned NOT NULL COMMENT 'Order reference.',
  `event` varchar(255) NOT NULL COMMENT 'Event that was triggered.',
  `user` varchar(255) NOT NULL COMMENT 'User that triggered the event.',
  `extra` text NULL COMMENT 'Additional information about what happened.',
  `status_from` varchar(255) NULL COMMENT 'What status the payment went from.',
  `status_to` varchar(255) NULL COMMENT 'What status the payment went to.',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created At',
  `result` varchar(255) NULL COMMENT 'Event result, e.g. success, failure, info. Only used by Ecom widget.',
  `user_reference` varchar(255) NULL COMMENT 'Admin username or similar. Only used by Ecom widget.',
  PRIMARY KEY (`id`),
  CONSTRAINT `FK_RB_PH_RB_ORDER` FOREIGN KEY (`resursbank_order_id`) REFERENCES `PREFIX_resursbank_order` (`id`) ON DELETE CASCADE
  ) CHARSET=utf8 COMMENT='Resurs Bank Payment History';
