AdditionalOptions.class.php
3 months ago
CampaignInfo.class.php
3 months ago
Campaigns.class.php
3 months ago
ClickTracking.class.php
3 months ago
ContactForm7.class.php
3 months ago
Debugging.class.php
2 months ago
EDD.class.php
2 months ago
General.class.php
2 months ago
Integrations.class.php
3 months ago
LifterLMS.class.php
3 months ago
Marketpress.class.php
2 months ago
MemberPress.class.php
3 months ago
Membership2.class.php
3 months ago
PMPro.class.php
3 months ago
PPBuyNowButton.class.php
3 months ago
RestrictContentPro.class.php
3 months ago
S2Member.class.php
3 months ago
Signup.class.php
3 months ago
SimplePayPro.class.php
3 months ago
StripePayments.class.php
2 months ago
SureCart.class.php
3 months ago
WPEasyCart.class.php
3 months ago
WPPayForms.class.php
3 months ago
WishListMember.class.php
3 months ago
WooComm.class.php
2 months ago
LifterLMS.class.php
192 lines
| 1 | <?php |
| 2 | if (!defined('ABSPATH')) exit; |
| 3 | |
| 4 | class postaffiliatepro_Form_Settings_LifterLMS extends postaffiliatepro_Form_Base { |
| 5 | const LIFTERLMS_COMMISSION_ENABLED = 'lifterlms-commission-enabled'; |
| 6 | const LIFTERLMS_CONFIG_PAGE = 'lifterlms-config-page'; |
| 7 | const LIFTERLMS_PRODUCT_ID = 'lifterlms-product-id'; |
| 8 | const LIFTERLMS_DATA1 = 'lifterlms-data1'; |
| 9 | const LIFTERLMS_DATA2 = 'lifterlms-data2'; |
| 10 | const LIFTERLMS_DATA3 = 'lifterlms-data3'; |
| 11 | const LIFTERLMS_DATA4 = 'lifterlms-data4'; |
| 12 | const LIFTERLMS_DATA5 = 'lifterlms-data5'; |
| 13 | const LIFTERLMS_CAMPAIGN = 'lifterlms-campaign'; |
| 14 | |
| 15 | public function __construct() { |
| 16 | parent::__construct(self::LIFTERLMS_CONFIG_PAGE, 'options.php'); |
| 17 | } |
| 18 | |
| 19 | protected function getTemplateFile() { |
| 20 | return WP_PLUGIN_DIR . '/postaffiliatepro/Template/LifterLMSConfig.xtpl'; |
| 21 | } |
| 22 | |
| 23 | protected function initForm() { |
| 24 | $this->addSelect(self::LIFTERLMS_PRODUCT_ID, array( |
| 25 | '0' => ' ', |
| 26 | 'product_id' => 'product ID', |
| 27 | 'product_title' => 'product title', |
| 28 | 'product_sku' => 'product SKU', |
| 29 | 'product_type' => 'product type', |
| 30 | 'plan_id' => 'plan ID', |
| 31 | 'plan_title' => 'plan title', |
| 32 | 'plan_sku' => 'plan SKU' |
| 33 | )); |
| 34 | |
| 35 | $dataOptions = array( |
| 36 | '0' => ' ', |
| 37 | 'user_id' => 'customer ID', |
| 38 | 'billing_email' => 'customer billing email', |
| 39 | 'billing_phone' => 'customer billing phone', |
| 40 | 'name' => 'customer billing name', // billing_first_name billing_last_name |
| 41 | 'address' => 'customer billing address', // billing_address_1 billing_address_2 billing_city billing_zip billing_state billing_country |
| 42 | 'coupon_code' => 'coupon code', |
| 43 | 'product_id' => 'product ID', |
| 44 | 'product_title' => 'product title', |
| 45 | 'product_sku' => 'product SKU', |
| 46 | 'product_type' => 'product type', |
| 47 | 'plan_id' => 'plan ID', |
| 48 | 'plan_title' => 'plan title', |
| 49 | 'plan_sku' => 'plan SKU' |
| 50 | ); |
| 51 | $this->addSelect(self::LIFTERLMS_DATA1, $dataOptions); |
| 52 | $this->addSelect(self::LIFTERLMS_DATA2, $dataOptions); |
| 53 | $this->addSelect(self::LIFTERLMS_DATA3, $dataOptions); |
| 54 | $this->addSelect(self::LIFTERLMS_DATA4, $dataOptions); |
| 55 | $this->addSelect(self::LIFTERLMS_DATA5, $dataOptions); |
| 56 | |
| 57 | $campaignHelper = new postaffiliatepro_Util_CampaignHelper(); |
| 58 | $campaignList = $campaignHelper->getCampaignsList(); |
| 59 | |
| 60 | $campaigns = array( |
| 61 | '0' => ' ' |
| 62 | ); |
| 63 | foreach ($campaignList as $row) { |
| 64 | $campaigns[$row->get('campaignid')] = htmlspecialchars($row->get('name')); |
| 65 | } |
| 66 | $this->addSelect(self::LIFTERLMS_CAMPAIGN, $campaigns); |
| 67 | |
| 68 | $this->addSubmit(); |
| 69 | } |
| 70 | |
| 71 | public function initSettings() { |
| 72 | register_setting(postaffiliatepro::INTEGRATIONS_SETTINGS_PAGE_NAME, self::LIFTERLMS_COMMISSION_ENABLED); |
| 73 | register_setting(self::LIFTERLMS_CONFIG_PAGE, self::LIFTERLMS_PRODUCT_ID); |
| 74 | register_setting(self::LIFTERLMS_CONFIG_PAGE, self::LIFTERLMS_DATA1); |
| 75 | register_setting(self::LIFTERLMS_CONFIG_PAGE, self::LIFTERLMS_DATA2); |
| 76 | register_setting(self::LIFTERLMS_CONFIG_PAGE, self::LIFTERLMS_DATA3); |
| 77 | register_setting(self::LIFTERLMS_CONFIG_PAGE, self::LIFTERLMS_DATA4); |
| 78 | register_setting(self::LIFTERLMS_CONFIG_PAGE, self::LIFTERLMS_DATA5); |
| 79 | register_setting(self::LIFTERLMS_CONFIG_PAGE, self::LIFTERLMS_CAMPAIGN); |
| 80 | } |
| 81 | |
| 82 | public function addPrimaryConfigMenu() { |
| 83 | if (get_option(self::LIFTERLMS_COMMISSION_ENABLED) === 'true') { |
| 84 | add_submenu_page('integrations-config-page-handle', 'LifterLMS', 'LifterLMS', 'manage_options', 'lifterlmsintegration-settings-page', array( |
| 85 | $this, |
| 86 | 'printConfigPage' |
| 87 | )); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | public function printConfigPage() { |
| 92 | $this->render(); |
| 93 | } |
| 94 | |
| 95 | public function addHiddenCodeToForm() { |
| 96 | if (get_option(self::LIFTERLMS_COMMISSION_ENABLED) === 'true') { |
| 97 | postaffiliatepro::addHiddenFieldToPaymentForm(); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | public function papLifterTrackSale($order) { |
| 102 | if (get_option(self::LIFTERLMS_COMMISSION_ENABLED) !== 'true') { |
| 103 | return; |
| 104 | } |
| 105 | if (!is_object($order)) { |
| 106 | $order = new LLMS_Order($order); |
| 107 | } |
| 108 | |
| 109 | $cookie = ''; |
| 110 | if (isset($_POST['pap_custom']) && !empty(wp_unslash($_POST['pap_custom']))) { |
| 111 | $cookie = sanitize_text_field(wp_unslash($_POST['pap_custom'])); |
| 112 | } |
| 113 | $query = 'AccountId=' . postaffiliatepro::getAccountName() . '&visitorId=' . substr($cookie, -32); |
| 114 | $campaignId = get_option(self::LIFTERLMS_CAMPAIGN); |
| 115 | if ($campaignId != '' && $campaignId !== '0') { |
| 116 | $query .= '&CampaignID=' . $campaignId; |
| 117 | } |
| 118 | $totalCost = ($order->get('trial_offer') === 'yes') ? $order->get('trial_total') : $order->get('total'); |
| 119 | $query .= "&TotalCost=$totalCost&OrderID={$order->get('id')}&ProductID={$order->get('product_id')}"; |
| 120 | $query .= "&Currency={$order->get('currency')}&ip={$order->get('user_ip_address')}&Coupon={$order->get('coupon_code')}"; |
| 121 | for ($d = 1; $d <=5; $d++) { |
| 122 | $query .= "&Data$d=" . urlencode($this->getTrackingData($order, $d)); |
| 123 | } |
| 124 | self::_log('Sending a tracking request with these details: ' . print_r($query, true)); |
| 125 | self::sendRequest(postaffiliatepro::parseSaleScriptPath(), $query); |
| 126 | } |
| 127 | |
| 128 | public function papLifterTrackRecurring($order) { |
| 129 | if (get_option(self::LIFTERLMS_COMMISSION_ENABLED) !== 'true') { |
| 130 | return; |
| 131 | } |
| 132 | if (!is_object($order)) { |
| 133 | $order = new LLMS_Order($order); |
| 134 | } |
| 135 | self::_log('Tracking of recurring order: ' . $order->get('id')); |
| 136 | |
| 137 | $session = $this->getApiSession(); |
| 138 | if ($session === null || $session === '0') { |
| 139 | self::_log('We have no session to PAP installation! Recurring commission failed. Try to create a regular commission.'); |
| 140 | $this->papLifterTrackSale($order); |
| 141 | return; |
| 142 | } |
| 143 | |
| 144 | if (!$this->fireRecurringCommissions($session, $order->get('id'), $order->get('total'))) { |
| 145 | self::_log('Recurring commission for order ID ' . $order->get('id') . ' failed, trying to create a regular commission.'); |
| 146 | $this->papLifterTrackSale($order); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | private function getTrackingData($order, $n) { |
| 151 | $data = get_option(constant('self::LIFTERLMS_DATA'.$n)); |
| 152 | switch ($data) { |
| 153 | case '0': |
| 154 | return ''; |
| 155 | case 'name': |
| 156 | return $order->get('billing_first_name') . ' ' . $order->get('billing_last_name'); |
| 157 | case 'address': |
| 158 | return $order->get('billing_address_1') . ' ' . $order->get('billing_address_2') . ' ' . $order->get('billing_city') . ' ' . $order->get('billing_zip') . ' ' . $order->get('billing_state') . ' ' . $order->get('billing_country'); |
| 159 | case 'user_id': |
| 160 | if ($order->get('user_id') != '') { |
| 161 | return $order->get('user_id'); |
| 162 | } |
| 163 | return crc32($order->get('billing_email')); |
| 164 | default: return $order->get($data); |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | $papSubmenuPriority = 20; |
| 170 | $papIntegrationLifterLMS = new postaffiliatepro_Form_Settings_LifterLMS(); |
| 171 | add_action('admin_init', array( |
| 172 | $papIntegrationLifterLMS, |
| 173 | 'initSettings' |
| 174 | ), 99); |
| 175 | add_action('admin_menu', array( |
| 176 | $papIntegrationLifterLMS, |
| 177 | 'addPrimaryConfigMenu' |
| 178 | ), $papSubmenuPriority); |
| 179 | |
| 180 | add_action('lifterlms_after_checkout_form', array( |
| 181 | $papIntegrationLifterLMS, |
| 182 | 'addHiddenCodeToForm' |
| 183 | )); |
| 184 | add_action('lifterlms_order_status_active', array( |
| 185 | $papIntegrationLifterLMS, |
| 186 | 'papLifterTrackSale' |
| 187 | )); |
| 188 | add_action('llms_charge_recurring_payment', array( |
| 189 | $papIntegrationLifterLMS, |
| 190 | 'papLifterTrackRecurring' |
| 191 | )); |
| 192 |