-- Register V5Pay as a Yumi web-payment factory.
-- Runtime credentials and URLs are intentionally not stored here; inject LIKEI_V5PAY_* variables
-- into rc-service-order. The application feature flag defaults to enabled and refuses calls until
-- merchantNo/appKey/secretKey/gateway/notify/return URLs are all present.

START TRANSACTION;

SET @factory_code := 'V5_PAY';
SET @factory_id := (
  SELECT `id`
  FROM `sys_pay_factory`
  WHERE `factory_code` = @factory_code
  LIMIT 1
);
SET @factory_id := IFNULL(@factory_id, 2048200000000000102);

INSERT INTO `sys_pay_factory`
  (`id`, `factory_code`, `factory_name`, `factory_icon`, `create_time`, `update_time`, `create_user`, `update_user`)
VALUES
  (@factory_id, @factory_code, 'V5Pay', '', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, NULL, NULL)
ON DUPLICATE KEY UPDATE
  `factory_name` = VALUES(`factory_name`),
  `factory_icon` = VALUES(`factory_icon`),
  `update_time` = CURRENT_TIMESTAMP;

COMMIT;

SELECT `id`, `factory_code`, `factory_name`
FROM `sys_pay_factory`
WHERE `factory_code` = @factory_code;
