AdditionalOptions.class.php
2 months ago
CampaignInfo.class.php
2 months ago
Campaigns.class.php
2 months ago
ClickTracking.class.php
2 months ago
ContactForm7.class.php
2 months ago
Debugging.class.php
4 weeks ago
EDD.class.php
4 weeks ago
General.class.php
4 weeks ago
Integrations.class.php
2 months ago
LifterLMS.class.php
2 months ago
Marketpress.class.php
4 weeks ago
MemberPress.class.php
2 months ago
Membership2.class.php
2 months ago
PMPro.class.php
2 months ago
PPBuyNowButton.class.php
2 months ago
RestrictContentPro.class.php
2 months ago
S2Member.class.php
2 months ago
Signup.class.php
2 months ago
SimplePayPro.class.php
2 months ago
StripePayments.class.php
4 weeks ago
SureCart.class.php
2 months ago
WPEasyCart.class.php
2 months ago
WPPayForms.class.php
2 months ago
WishListMember.class.php
2 months ago
WooComm.class.php
4 weeks ago
SimplePayPro.class.php
196 lines
| 1 | <?php |
| 2 | if (!defined('ABSPATH')) exit; |
| 3 | |
| 4 | class postaffiliatepro_Form_Settings_SimplePayPro extends postaffiliatepro_Form_Base { |
| 5 | const SIMPLEPAYPRO_COMMISSION_ENABLED = 'simplepaypro-commission-enabled'; |
| 6 | const SIMPLEPAYPRO_CONFIG_PAGE = 'simplepaypro-config-page'; |
| 7 | const SIMPLEPAYPRO_CAMPAIGN = 'simplepaypro-campaign'; |
| 8 | const SIMPLEPAYPRO_TRACK_RECURRING = 'simplepaypro-track-recurring'; |
| 9 | const SIMPLEPAYPRO_DATA1 = 'simplepaypro-data1'; |
| 10 | const SIMPLEPAYPRO_DATA2 = 'simplepaypro-data2'; |
| 11 | const SIMPLEPAYPRO_DATA3 = 'simplepaypro-data3'; |
| 12 | const SIMPLEPAYPRO_DATA4 = 'simplepaypro-data4'; |
| 13 | const SIMPLEPAYPRO_DATA5 = 'simplepaypro-data5'; |
| 14 | |
| 15 | public function __construct() { |
| 16 | parent::__construct(self::SIMPLEPAYPRO_CONFIG_PAGE, 'options.php'); |
| 17 | } |
| 18 | |
| 19 | protected function getTemplateFile() { |
| 20 | return WP_PLUGIN_DIR . '/postaffiliatepro/Template/SimplePayProConfig.xtpl'; |
| 21 | } |
| 22 | |
| 23 | protected function initForm() { |
| 24 | $campaignHelper = new postaffiliatepro_Util_CampaignHelper(); |
| 25 | $campaignList = $campaignHelper->getCampaignsList(); |
| 26 | |
| 27 | $campaigns = array('0' => ' '); |
| 28 | foreach ($campaignList as $row) { |
| 29 | $campaigns[$row->get('campaignid')] = htmlspecialchars($row->get('name')); |
| 30 | } |
| 31 | $this->addSelect(self::SIMPLEPAYPRO_CAMPAIGN, $campaigns); |
| 32 | |
| 33 | $this->addCheckbox(self::SIMPLEPAYPRO_TRACK_RECURRING, null, 'onchange="hideConfigTable2()"'); |
| 34 | $productOptions = array( |
| 35 | '0' => ' ', |
| 36 | 'id' => __('customer ID','postaffiliatepro'), |
| 37 | 'email' => __('customer email','postaffiliatepro'), |
| 38 | 'name' => __('customer name','postaffiliatepro') |
| 39 | ); |
| 40 | $this->addSelect(self::SIMPLEPAYPRO_DATA1, $productOptions); |
| 41 | $this->addSelect(self::SIMPLEPAYPRO_DATA2, $productOptions); |
| 42 | $this->addSelect(self::SIMPLEPAYPRO_DATA3, $productOptions); |
| 43 | $this->addSelect(self::SIMPLEPAYPRO_DATA4, $productOptions); |
| 44 | $this->addSelect(self::SIMPLEPAYPRO_DATA5, $productOptions); |
| 45 | |
| 46 | $this->addSubmit(); |
| 47 | |
| 48 | $code = '<script type="text/javascript"> |
| 49 | const isRecurringEnabled = "' . get_option(self::SIMPLEPAYPRO_TRACK_RECURRING) . '"; |
| 50 | if (isRecurringEnabled === "true") { |
| 51 | document.getElementById(\'form-table2\').style.display = "none"; |
| 52 | } |
| 53 | |
| 54 | function hideConfigTable2() { |
| 55 | if (document.getElementById(\''.self::SIMPLEPAYPRO_TRACK_RECURRING.'_\').checked == false) { |
| 56 | document.getElementById(\'form-table2\').style.display = ""; |
| 57 | } else { |
| 58 | document.getElementById(\'form-table2\').style.display = "none"; |
| 59 | } |
| 60 | } |
| 61 | </script>'; |
| 62 | $this->addHtml('hider', $code); |
| 63 | $this->addHtml('papURL', get_option(postaffiliatepro::PAP_URL_SETTING_NAME).'plugins/Stripe/stripe.php'.((get_option(postaffiliatepro::CLICK_TRACKING_ACCOUNT_SETTING_NAME) != '')?'?AccountId='.get_option(postaffiliatepro::CLICK_TRACKING_ACCOUNT_SETTING_NAME):'')); |
| 64 | } |
| 65 | |
| 66 | public function initSettings() { |
| 67 | register_setting(postaffiliatepro::INTEGRATIONS_SETTINGS_PAGE_NAME, self::SIMPLEPAYPRO_COMMISSION_ENABLED); |
| 68 | register_setting(self::SIMPLEPAYPRO_CONFIG_PAGE, self::SIMPLEPAYPRO_CAMPAIGN); |
| 69 | register_setting(self::SIMPLEPAYPRO_CONFIG_PAGE, self::SIMPLEPAYPRO_DATA1); |
| 70 | register_setting(self::SIMPLEPAYPRO_CONFIG_PAGE, self::SIMPLEPAYPRO_DATA2); |
| 71 | register_setting(self::SIMPLEPAYPRO_CONFIG_PAGE, self::SIMPLEPAYPRO_DATA3); |
| 72 | register_setting(self::SIMPLEPAYPRO_CONFIG_PAGE, self::SIMPLEPAYPRO_DATA4); |
| 73 | register_setting(self::SIMPLEPAYPRO_CONFIG_PAGE, self::SIMPLEPAYPRO_DATA5); |
| 74 | register_setting(self::SIMPLEPAYPRO_CONFIG_PAGE, self::SIMPLEPAYPRO_TRACK_RECURRING); |
| 75 | } |
| 76 | |
| 77 | public function addPrimaryConfigMenu() { |
| 78 | if (get_option(self::SIMPLEPAYPRO_COMMISSION_ENABLED) === 'true') { |
| 79 | add_submenu_page( |
| 80 | 'integrations-config-page-handle', |
| 81 | 'Simple Pay Pro', |
| 82 | 'Simple Pay Pro', |
| 83 | 'manage_options', |
| 84 | 'simplepayprointegration-settings-page', |
| 85 | array($this, 'printConfigPage') |
| 86 | ); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | public function printConfigPage() { |
| 91 | $this->render(); |
| 92 | } |
| 93 | |
| 94 | public function addHiddenCodeToForm($formId, $form) { |
| 95 | // Adding hidden code to form so we could work with cookie in Stripe Customer object later |
| 96 | if (get_option(self::SIMPLEPAYPRO_TRACK_RECURRING) === 'true') { |
| 97 | postaffiliatepro::addHiddenFieldToPaymentForm(); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | public function modifyCustomerInfo($customer_args) { |
| 102 | if (get_option(self::SIMPLEPAYPRO_TRACK_RECURRING) == 'true' && !empty(sanitize_text_field(wp_unslash($_POST['form_values']['pap_custom'])))) { |
| 103 | $papCookie = sanitize_text_field(wp_unslash($_POST['form_values']['pap_custom'])); |
| 104 | if (isset($customer_args['description'])) { |
| 105 | $customer_args['description'] = $customer_args['description'] . '||' . $papCookie; |
| 106 | } else { |
| 107 | $customer_args['description'] = $papCookie; |
| 108 | } |
| 109 | } |
| 110 | return $customer_args; |
| 111 | } |
| 112 | |
| 113 | public function confirmationMessage($paymentData) { |
| 114 | if (get_option(self::SIMPLEPAYPRO_COMMISSION_ENABLED) !== 'true') { |
| 115 | echo "<!-- Post Affiliate Pro sale tracking error - tracking not enabled -->\n"; |
| 116 | return; |
| 117 | } |
| 118 | $HTMLcontent = ''; |
| 119 | if (get_option(self::SIMPLEPAYPRO_TRACK_RECURRING) !== 'true') { |
| 120 | $HTMLcontent .= "<!-- Post Affiliate Pro sale tracking -->\n"; |
| 121 | $contentToAsync = 'PostAffTracker.setAccountId(\'' . postaffiliatepro::getAccountName() . '\');'; |
| 122 | $contentToAsync .= "var sale = PostAffTracker.createSale();\n"; |
| 123 | $contentToAsync .= "sale.setTotalCost('" . ($paymentData['paymentintents'][0]->amount_received / 100) . "');\n"; |
| 124 | $contentToAsync .= "sale.setOrderID('". $paymentData['paymentintents'][0]->id ."');\n"; |
| 125 | $contentToAsync .= "sale.setProductID('". $paymentData['form']->id ."');\n"; |
| 126 | $contentToAsync .= "sale.setData1('". str_replace("'","\'",$this->getTrackingData($paymentData['customer'], 1))."');\n"; |
| 127 | $contentToAsync .= "sale.setData2('". str_replace("'","\'",$this->getTrackingData($paymentData['customer'], 2))."');\n"; |
| 128 | $contentToAsync .= "sale.setData3('". str_replace("'","\'",$this->getTrackingData($paymentData['customer'], 3))."');\n"; |
| 129 | $contentToAsync .= "sale.setData4('". str_replace("'","\'",$this->getTrackingData($paymentData['customer'], 4))."');\n"; |
| 130 | $contentToAsync .= "sale.setData5('". str_replace("'","\'",$this->getTrackingData($paymentData['customer'], 5))."');\n"; |
| 131 | |
| 132 | if (get_option(self::SIMPLEPAYPRO_CAMPAIGN) != '') { |
| 133 | $contentToAsync .= "sale.setCampaignID('".get_option(self::SIMPLEPAYPRO_CAMPAIGN)."');\n"; |
| 134 | } |
| 135 | |
| 136 | if (isset($paymentData['customer']->discount->coupon->id)) { |
| 137 | $contentToAsync .= "sale.setCoupon('". str_replace("'","\'",$paymentData['customer']->discount->coupon->id)."');\n"; |
| 138 | } |
| 139 | |
| 140 | $currency = $paymentData['form']->currency; |
| 141 | if (isset($paymentData['paymentintents'][0]->currency)) { |
| 142 | $currency = strtoupper($paymentData['paymentintents'][0]->currency); |
| 143 | } |
| 144 | $contentToAsync .= "sale.setCurrency('".$currency."');\n"; |
| 145 | |
| 146 | $contentToAsync .= 'PostAffTracker.register();'; |
| 147 | |
| 148 | if (get_option(postaffiliatepro::ASYNC_ENABLED) !== 'true') { |
| 149 | $HTMLcontent .= postaffiliatepro::getPAPTrackJSDynamicCode().'<script type="text/javascript">'; |
| 150 | $HTMLcontent .= $contentToAsync . "</script>\n"; |
| 151 | } else { |
| 152 | $HTMLcontent .= postaffiliatepro::getPAPTrackJSAsyncCode($contentToAsync); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | echo $HTMLcontent; |
| 157 | } |
| 158 | |
| 159 | private function getTrackingData($customer, $n) { |
| 160 | $data = get_option(constant('self::SIMPLEPAYPRO_DATA'.$n)); |
| 161 | switch ($data) { |
| 162 | case 'id': |
| 163 | if ($customer->id != '') { |
| 164 | return $customer->id; |
| 165 | } |
| 166 | return crc32($customer->email); |
| 167 | case 'email': |
| 168 | case 'name': |
| 169 | return $customer->{$data}; |
| 170 | default: return ''; |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | $papSubmenuPriority = 43; |
| 176 | $papIntegrationSimplePayPro = new postaffiliatepro_Form_Settings_SimplePayPro(); |
| 177 | add_action('admin_init', array( |
| 178 | $papIntegrationSimplePayPro, |
| 179 | 'initSettings' |
| 180 | ), 99); |
| 181 | add_action('admin_menu', array( |
| 182 | $papIntegrationSimplePayPro, |
| 183 | 'addPrimaryConfigMenu' |
| 184 | ), $papSubmenuPriority); |
| 185 | add_filter('simpay_payment_receipt_viewed', array( |
| 186 | $papIntegrationSimplePayPro, |
| 187 | 'confirmationMessage' |
| 188 | ), 99); |
| 189 | add_action('simpay_form_before_form_bottom', array( |
| 190 | $papIntegrationSimplePayPro, |
| 191 | 'addHiddenCodeToForm' |
| 192 | ), 99, 2); |
| 193 | add_filter('simpay_create_customer_args', array( |
| 194 | $papIntegrationSimplePayPro, |
| 195 | 'modifyCustomerInfo' |
| 196 | ), 99); |