diff --git a/README.md b/README.md
index 581b61a..8192940 100644
--- a/README.md
+++ b/README.md
@@ -62,10 +62,27 @@ define("CODECANYON_API_KEY", "UNr.....");
define("CODECANYON_SLUG_PLUGIN", "my-plugin");
```
+## Adding multiple products
+
+Add suffixes to the constants
+
+```
+define("FS__PLUGIN_ID_PRODUCT_1", "1234");
+define("FS__PLUGIN_PK_APIKEY_PRODUCT_1", "pk_abcde...");
+define("FS__PLUGIN_SK_APIKEY_PRODUCT_1", "sk_abcde...");
+define("FS__PLUGIN_PLAN_ID_PRODUCT_1", "5678");
+define("FS__PLUGIN_PRICING_ID_PRODUCT_1", "90123");
+define("CODECANYON_SLUG_PLUGIN_PRODUCT_1", "my-plugin");
+```
+
+Modify `get_constants_by_product` function with your product slugs and add more products if needed
+
+Edit the `render_shortcode` function with your product slugs and names
+
## Adding the license migration form
Create a new page with and with the following shortcode: `[ctf_form]`
## Contribution
-This plugin was originally contributed by the awesome team of [NextPress](https://nextpress.co) & [WP Ultimo](https://wpultimo.com/), Arindo Duque and Marcelo Assis, who've built it for migrating WP Ultimo from Gumroad to Freemius.
\ No newline at end of file
+This plugin was originally contributed by the awesome team of [NextPress](https://nextpress.co) & [WP Ultimo](https://wpultimo.com/), Arindo Duque and Marcelo Assis, who've built it for migrating WP Ultimo from Gumroad to Freemius.
diff --git a/ctf-init.php b/ctf-init.php
index c354d96..3bd9145 100755
--- a/ctf-init.php
+++ b/ctf-init.php
@@ -38,6 +38,8 @@ class Codecanyon_To_Freemius {
*/
public $version = '0.0.1';
+ public $debug = false;
+
/**
* WP_Error messages
*
@@ -205,6 +207,11 @@ public function render_shortcode($atts) {
'id' => '1',
'form_email_label' => __('Enter your email address', 'np-ctf'),
'form_license_label' => __('Enter your license key from CodeCanyon', 'np-ctf'),
+ 'form_product_label' => __('Select a product', 'np-ctf'),
+ 'form_products' => array(
+ 'dinery' => __('Dinery', 'np-ctf'),
+ 'margin' => __('Margin', 'np-ctf')
+ ),
'form_button_label' => __('Convert License', 'np-ctf'),
'form_success_message' => __('Confirmation email was successfully sent with your new access credentials and license key!', 'np-ctf'),
), $atts, 'ctf_form');
@@ -291,7 +298,7 @@ public function validation($data) {
*/
public function is_debug_mode() {
- return isset($_GET['debug']) && $_GET['debug'] === 'SECRET!!!!';
+ return $this->debug;
} // end is_debug_mode;
@@ -322,28 +329,45 @@ public function is_license_key_already_used($license_key) {
* Get ctf constants defined in wp-config.php
*
* @since 0.0.1
+ *
+ * @param string $product Product.
*
* @return array
*/
- public function get_constants_by_id() {
+ public function get_constants_by_product($product) {
- return array(
+ $defaults = array(
'freemius_dev_pk_apikey' => defined("FS__DEV_PK_APIKEY") ? constant("FS__DEV_PK_APIKEY") : '',
'freemius_dev_sk_apikey' => defined("FS__DEV_SK_APIKEY") ? constant("FS__DEV_SK_APIKEY") : '',
'freemius_dev_id' => defined("FS__DEV_ID") ? constant("FS__DEV_ID") : '',
-
- 'freemius_plugin_pk_apikey' => defined("FS__PLUGIN_PK_APIKEY") ? constant("FS__PLUGIN_PK_APIKEY") : '',
- 'freemius_plugin_sk_apikey' => defined("FS__PLUGIN_SK_APIKEY") ? constant("FS__PLUGIN_SK_APIKEY") : '',
- 'freemius_plugin_id' => defined("FS__PLUGIN_ID") ? constant("FS__PLUGIN_ID") : '',
- 'freemius_plugin_plan_id' => defined("FS__PLUGIN_PLAN_ID") ? constant("FS__PLUGIN_PLAN_ID") : '',
- 'freemius_plugin_pricing_id' => defined("FS__PLUGIN_PRICING_ID") ? constant("FS__PLUGIN_PRICING_ID") : '',
'freemius_plugin_expires_at' => defined("FS__PLUGIN_EXPIRES_AT") ? constant("FS__PLUGIN_EXPIRES_AT") : '',
-
'codecanyon_api_key' => defined("CODECANYON_API_KEY") ? constant("CODECANYON_API_KEY") : '',
- 'codecanyon_slug_plugin' => defined("CODECANYON_SLUG_PLUGIN") ? constant("CODECANYON_SLUG_PLUGIN") : '',
);
- } // end get_constants_by_id;
+ switch ($product) {
+ case 'dinery':
+ return array_merge( $defaults, array(
+ 'freemius_plugin_id' => defined("FS__PLUGIN_ID_PRODUCT_1") ? constant("FS__PLUGIN_ID_PRODUCT_1") : '',
+ 'freemius_plugin_pk_apikey' => defined("FS__PLUGIN_PK_APIKEY_PRODUCT_1") ? constant("FS__PLUGIN_PK_APIKEY_PRODUCT_1") : '',
+ 'freemius_plugin_sk_apikey' => defined("FS__PLUGIN_SK_APIKEY_PRODUCT_1") ? constant("FS__PLUGIN_SK_APIKEY_PRODUCT_1") : '',
+ 'freemius_plugin_plan_id' => defined("FS__PLUGIN_PLAN_ID_PRODUCT_1") ? constant("FS__PLUGIN_PLAN_ID_PRODUCT_1") : '',
+ 'freemius_plugin_pricing_id' => defined("FS__PLUGIN_PRICING_ID_PRODUCT_1") ? constant("FS__PLUGIN_PRICING_ID_PRODUCT_1") : '',
+ 'codecanyon_slug_plugin' => defined("CODECANYON_SLUG_PLUGIN_PRODUCT_1") ? constant("CODECANYON_SLUG_PLUGIN_PRODUCT_1") : '',
+ ) );
+ case 'margin':
+ return array_merge( $defaults, array(
+ 'freemius_plugin_id' => defined("FS__PLUGIN_ID_PRODUCT_2") ? constant("FS__PLUGIN_ID_PRODUCT_2") : '',
+ 'freemius_plugin_pk_apikey' => defined("FS__PLUGIN_PK_APIKEY_PRODUCT_2") ? constant("FS__PLUGIN_PK_APIKEY_PRODUCT_2") : '',
+ 'freemius_plugin_sk_apikey' => defined("FS__PLUGIN_SK_APIKEY_PRODUCT_2") ? constant("FS__PLUGIN_SK_APIKEY_PRODUCT_2") : '',
+ 'freemius_plugin_plan_id' => defined("FS__PLUGIN_PLAN_ID_PRODUCT_2") ? constant("FS__PLUGIN_PLAN_ID_PRODUCT_2") : '',
+ 'freemius_plugin_pricing_id' => defined("FS__PLUGIN_PRICING_ID_PRODUCT_2") ? constant("FS__PLUGIN_PRICING_ID_PRODUCT_2") : '',
+ 'codecanyon_slug_plugin' => defined("CODECANYON_SLUG_PLUGIN_PRODUCT_2") ? constant("CODECANYON_SLUG_PLUGIN_PRODUCT_2") : '',
+ ) );
+ default:
+ return $defaults; // or throw an error
+ }
+
+ } // end get_constants_by_product;
/**
* Handle of form submit
@@ -365,9 +389,10 @@ public function handle_form_submission() {
$data = array(
'license_key' => $_POST['license_key'],
'email' => $_POST['email'],
+ 'product' => $_POST['product'],
);
- $data = array_merge($data, $this->get_constants_by_id());
+ $data = array_merge($data, $this->get_constants_by_product($data['product']));
if (!$this->validation($data)) {
return;
@@ -379,7 +404,6 @@ public function handle_form_submission() {
if ($this->is_debug_mode()) {
-
} // end if;
if (!$license || $license->success == false) {
@@ -390,6 +414,14 @@ public function handle_form_submission() {
} // end if;
+
+ // Check if the purchase code matches the selected product
+ if ( strtolower($license->product) !== $data['product'] ) {
+ $this->messages->add('invalid-product', __('The product does not match your purchase code.', 'np-ctf'));
+ CTF_Logger::add('ctf_log_error', implode('
', $this->messages->get_error_messages()));
+ return;
+ }
+
$existing_user = $ctf_api->verify_freemius_exists_user($data['email']);
if (!$existing_user) {
diff --git a/inc/ctf-api.php b/inc/ctf-api.php
index f01319a..eb4f765 100755
--- a/inc/ctf-api.php
+++ b/inc/ctf-api.php
@@ -238,6 +238,7 @@ public function verify_envato_purchase_code($code) {
return (object) array(
'success' => isset($output->buyer),
'golden_ticket' => isset($output->buyer),
+ 'product' => isset($output->item->wordpress_theme_metadata->theme_name) ? $output->item->wordpress_theme_metadata->theme_name : '',
'purchase' => (object) array(
'refunded' => false,
)
diff --git a/views/main.php b/views/main.php
index a98e233..cda5f7d 100755
--- a/views/main.php
+++ b/views/main.php
@@ -25,6 +25,18 @@
+ +
+