| @@ -29,9 +29,9 @@ | ||
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * Table creation schema |
| 33 | - * | |
| 33 | + * | |
| 34 | 34 | * @since 0.0.1 |
| 35 | 35 | */ |
| 36 | 36 | private function get_schema() { |
| 37 | 37 | global $wpdb; |
| @@ -46,15 +46,34 @@ | ||
| 46 | 46 | payment_date datetime DEFAULT NULL, |
| 47 | 47 | email varchar(50) NOT NULL DEFAULT '', |
| 48 | 48 | customer_info longtext, |
| 49 | 49 | form_fields_info longtext, |
| 50 | - currency varchar(11) NOT NULL DEFAULT '', | |
| 50 | + currency varchar(11) NOT NULL DEFAULT '', | |
| 51 | 51 | referer varchar(64) DEFAULT NULL, |
| 52 | 52 | obj_id text, |
| 53 | 53 | PRIMARY KEY (id), |
| 54 | 54 | KEY order_id (order_id), |
| 55 | - KEY status (status) | |
| 56 | - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 " | |
| 55 | + KEY status (status) | |
| 56 | + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ", | |
| 57 | + | |
| 58 | + // E-commerce subscription <-> order relation. The `source` column | |
| 59 | + // names the e-commerce integration that owns the row: woo, | |
| 60 | + // fluentcart, surecart, ... | |
| 61 | + // E-commerce data ONLY — Better Payment's own (Elementor/campaign) | |
| 62 | + // subscription payments never write here. All reads/writes go through | |
| 63 | + // Models\SubscriptionRelationModel. | |
| 64 | + "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}better_payment_subscription_order( | |
| 65 | + id bigint(20) unsigned NOT NULL AUTO_INCREMENT, | |
| 66 | + subscription_id bigint(20) unsigned NOT NULL, | |
| 67 | + order_id bigint(20) unsigned NOT NULL, | |
| 68 | + order_item_id bigint(20) unsigned NOT NULL DEFAULT 0, | |
| 69 | + type varchar(20) NOT NULL DEFAULT 'new', | |
| 70 | + source varchar(50) NOT NULL, | |
| 71 | + PRIMARY KEY (id), | |
| 72 | + KEY subscription_id (subscription_id), | |
| 73 | + KEY order_id (order_id), | |
| 74 | + KEY source (source) | |
| 75 | + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ", | |
| 57 | 76 | ]; |
| 58 | 77 | } |
| 59 | 78 | |
| 60 | 79 | /** |
| @@ -81,7 +100,49 @@ | ||
| 81 | 100 | public function enable_setup_wizard() |
| 82 | 101 | { |
| 83 | 102 | if ( !get_option( 'better_payment_setup_wizard' ) ) { |
| 84 | 103 | update_option( 'better_payment_setup_wizard', 'redirect' ); |
| 104 | + | |
| 105 | + /** | |
| 106 | + * A missing `better_payment_setup_wizard` option is this plugin's | |
| 107 | + * definition of a fresh install — it is what decides that the setup | |
| 108 | + * wizard is owed a redirect at all. The same test marks the install | |
| 109 | + * as eligible for the automatic usage-tracking opt-in, so the two can | |
| 110 | + * never disagree about what "new install" means. | |
| 111 | + * | |
| 112 | + * Deliberately scoped to fresh installs: an existing site that has | |
| 113 | + * already been through (or dismissed) the wizard keeps whatever | |
| 114 | + * tracking state it has. See | |
| 115 | + * Traits\Helper::maybe_auto_enable_usage_tracking(), which consumes | |
| 116 | + * this marker exactly once. | |
| 117 | + * | |
| 118 | + * @since 2.3.2 | |
| 119 | + */ | |
| 120 | + self::mark_tracking_auto_optin_pending(); | |
| 85 | 121 | } |
| 122 | + } | |
| 123 | + | |
| 124 | + /** | |
| 125 | + * Flag a fresh install for the automatic usage-tracking opt-in. | |
| 126 | + * | |
| 127 | + * Only ever sets the marker when the site has no tracking state at all. A | |
| 128 | + * site that reached consent before this option existed (an upgrade that | |
| 129 | + * re-runs activation, say) must not be handed a second, automatic opt-in. | |
| 130 | + * | |
| 131 | + * @return void | |
| 132 | + * @since 2.3.2 | |
| 133 | + */ | |
| 134 | + public function mark_tracking_auto_optin_pending() | |
| 135 | + { | |
| 136 | + if ( get_option( 'better_payment_tracking_auto_optin' ) ) { | |
| 137 | + return; | |
| 138 | + } | |
| 139 | + | |
| 140 | + $allow_tracking = get_option( 'wpins_allow_tracking' ); | |
| 141 | + | |
| 142 | + if ( is_array( $allow_tracking ) && isset( $allow_tracking[ basename( BETTER_PAYMENT_FILE, '.php' ) ] ) ) { | |
| 143 | + return; | |
| 144 | + } | |
| 145 | + | |
| 146 | + update_option( 'better_payment_tracking_auto_optin', 'pending' ); | |
| 86 | 147 | } |
| 87 | 148 | } |