
-- ---------------------------------------------------------------------------
-- pjStripe plugin - options migration (mirrors the pjPaypal update style)
-- ---------------------------------------------------------------------------

START TRANSACTION;

-- Idempotency: remove previous rows if the migration is re-run ---------------
DELETE FROM `options` WHERE `key` IN ('o_stripe_public_key', 'o_stripe_secret_key', 'o_stripe_cancel_url');
DELETE FROM `multi_lang` WHERE `model` = 'pjField' AND `field` = 'title' AND `foreign_id` IN (
	SELECT `id` FROM `fields` WHERE `key` IN (
		'opt_o_stripe_public_key', 'opt_o_stripe_secret_key', 'opt_o_stripe_cancel_url', 'plugin_stripe_payment_title', 'plugin_stripe_redirecting'
	)
);
DELETE FROM `fields` WHERE `key` IN (
	'opt_o_stripe_public_key', 'opt_o_stripe_secret_key', 'opt_o_stripe_cancel_url', 'plugin_stripe_payment_title', 'plugin_stripe_redirecting'
);

-- Options (Payments tab = 2) -------------------------------------------------
INSERT INTO `options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`) VALUES
(1, 'o_stripe_public_key', 2, '', NULL, 'string', 24, 1, NULL),
(1, 'o_stripe_secret_key', 2, '', NULL, 'string', 25, 1, NULL),
(1, 'o_stripe_cancel_url', 2, '', NULL, 'string', 26, 4, NULL);

-- Admin labels for those options ---------------------------------------------
INSERT INTO `fields` VALUES (NULL, 'opt_o_stripe_public_key', 'backend', 'Plugin / Stripe / Publishable key', 'plugin', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjField', '::LOCALE::', 'title', 'Stripe publishable key', 'plugin');

INSERT INTO `fields` VALUES (NULL, 'opt_o_stripe_secret_key', 'backend', 'Plugin / Stripe / Secret key', 'plugin', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjField', '::LOCALE::', 'title', 'Stripe secret key', 'plugin');

INSERT INTO `fields` VALUES (NULL, 'opt_o_stripe_cancel_url', 'backend', 'Plugin / Stripe / Cancel page', 'plugin', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjField', '::LOCALE::', 'title', 'Cancel page', 'plugin');

-- UI labels ------------------------------------------------------------------
INSERT INTO `fields` VALUES (NULL, 'plugin_stripe_payment_title', 'backend', 'Plugin / Stripe / Stripe payment', 'plugin', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjField', '::LOCALE::', 'title', 'Stripe payment', 'plugin');

INSERT INTO `fields` VALUES (NULL, 'plugin_stripe_redirecting', 'backend', 'Plugin / Stripe / Redirecting', 'plugin', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjField', '::LOCALE::', 'title', 'Redirecting to Stripe...', 'plugin');

COMMIT;
