Changeset 2574473
- Timestamp:
- 07/29/2021 07:12:53 AM (5 years ago)
- Location:
- slimcd-payment-gateway
- Files:
-
- 19 added
- 4 edited
-
tags/1.0.1 (added)
-
tags/1.0.1/README.txt (added)
-
tags/1.0.1/assets (added)
-
tags/1.0.1/assets/images (added)
-
tags/1.0.1/assets/images/icon.png (added)
-
tags/1.0.1/assets/images/icon1.png (added)
-
tags/1.0.1/assets/images/icon2.png (added)
-
tags/1.0.1/assets/images/powered-by-SlimCd.png (added)
-
tags/1.0.1/assets/js (added)
-
tags/1.0.1/assets/js/slimcd_script.js (added)
-
tags/1.0.1/assets/styles (added)
-
tags/1.0.1/assets/styles/style.css (added)
-
tags/1.0.1/includes (added)
-
tags/1.0.1/includes/class-slimcd-payment-gateway.php (added)
-
tags/1.0.1/includes/convience-surcharge.php (added)
-
tags/1.0.1/includes/settings-slimcd-payment.php (added)
-
tags/1.0.1/includes/slimcd-checkout-description-fields.php (added)
-
tags/1.0.1/languages (added)
-
tags/1.0.1/slimcd-payment-for-woocommerce.php (added)
-
trunk/README.txt (modified) (1 diff)
-
trunk/assets/js/slimcd_script.js (modified) (3 diffs)
-
trunk/includes/class-slimcd-payment-gateway.php (modified) (5 diffs)
-
trunk/includes/slimcd-checkout-description-fields.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
slimcd-payment-gateway/trunk/README.txt
r2568688 r2574473 4 4 Requires at least: 4.9.0 5 5 Tested up to: 5.8 6 Stable tag: 1.0. 06 Stable tag: 1.0.1 7 7 Requires PHP: 7.0.0 8 8 License: GPLv2 or later -
slimcd-payment-gateway/trunk/assets/js/slimcd_script.js
r2557807 r2574473 1 1 jQuery(document).ready(function () { 2 2 jQuery(document).ajaxComplete(function () { 3 if ( 3 managePlaceOrderButton(); 4 jQuery("input[name='payment_method']:checked").val(); 5 if ( 4 6 jQuery("input[type=radio][name=payment_mode]:checked").val() == 5 7 "payment_mode_card" … … 15 17 } 16 18 17 if (jQuery("#slimcdDisclaimerError").length) {18 jQuery("#payment #place_order")19 .attr("disabled", "disabled")20 .attr("title", jQuery("#slimcdDisclaimerError p").text());21 }22 23 19 jQuery(document).on("change", "#payment", function () { 24 var payment_option = jQuery("input[name='payment_method']:checked").val(); 25 if (payment_option == "slimcd_payment") { 26 if (jQuery("#slimcdDisclaimerError").length) { 27 jQuery("#payment #place_order") 28 .attr("disabled", "disabled") 29 .attr("title", jQuery("#slimcdDisclaimerError p").text()); 30 } 31 } else { 32 jQuery("#payment #place_order") 33 .removeAttr("disabled") 34 .removeAttr("title"); 35 } 20 managePlaceOrderButton(); 36 21 }); 37 22 … … 57 42 } 58 43 } 44 45 function managePlaceOrderButton() { 46 var payment_option = jQuery("input[name='payment_method']:checked").val(); 47 if (payment_option == "slimcd_payment") { 48 if (jQuery("#slimcdDisclaimerError").length) { 49 jQuery("#payment #place_order") 50 .attr("disabled", "disabled") 51 .attr("title", jQuery("#slimcdDisclaimerError p").text()); 52 } 53 } else { 54 jQuery("#payment #place_order") 55 .removeAttr("disabled") 56 .removeAttr("title"); 57 } 58 } 59 59 }); 60 60 }); -
slimcd-payment-gateway/trunk/includes/class-slimcd-payment-gateway.php
r2569162 r2574473 26 26 add_action('woocommerce_thankyou_' . $this->id, array($this, 'slimcd_thankYouPage')); 27 27 add_action('wp_footer', array($this, 'slimcd_loadScript')); 28 add_action('wp_enqueue_scripts', array($this, 'slimcd_load_styles')); 29 add_filter('woocommerce_gateway_description', 'slimcd_description_fileds_options', 20, 2); 28 30 } 29 31 … … 119 121 "order_id" => $order->get_id(), 120 122 "receiptlabel" => $receiptlabel, 121 "company_name" => $order->get_billing_company() ?? null,123 "company_name" => $order->get_billing_company() ?? null, 122 124 "customer_note" => $order->get_customer_note() ?? null, 123 125 "email" => $order->get_billing_email() ?? null, … … 167 169 include __DIR__ . '/convience-surcharge.php'; 168 170 } 169 $this->slimcd_update_order_status($_POST['order_id']);171 $this->slimcd_update_order_status($_POST['order_id']); 170 172 echo "OK"; 171 173 } else { … … 179 181 die(); 180 182 } 181 182 183 public function slimcd_update_order_status($order_id) 183 184 public function slimcd_update_order_status($order_id) 184 185 { 185 186 $order = wc_get_order($order_id); … … 263 264 } 264 265 } 266 267 function slimcd_load_styles() 268 { 269 if (!is_admin()) { 270 wp_register_style('slimcd_checkout_description_filed_style', plugins_url('../assets/styles/style.css', __FILE__)); 271 wp_enqueue_style('slimcd_checkout_description_filed_style'); 272 } 273 } 274 265 275 /** 266 276 * Output for the order received page. -
slimcd-payment-gateway/trunk/includes/slimcd-checkout-description-fields.php
r2555533 r2574473 1 1 <?php 2 global $woocommerce; 3 $cartCurrency = get_woocommerce_currency(); 4 add_action('wp_enqueue_scripts', 'slimcd_load_styles'); 5 function slimcd_load_styles() 6 { 7 if (!is_admin()) { 8 wp_register_style('slimcd_checkout_description_filed_style', plugins_url('../assets/styles/style.css', __FILE__)); 9 wp_enqueue_style('slimcd_checkout_description_filed_style'); 10 } 11 } 12 if ($cartCurrency == "USD" || $cartCurrency == "CAD") { 13 14 $slimcd_settings = WC()->payment_gateways->payment_gateways()['slimcd_payment']; 15 if ((empty($slimcd_settings->settings['slimcd_formname_card']) && empty($slimcd_settings->settings['slimcd_formname_cheque'])) || empty($slimcd_settings->settings['slimcd_username'])) { 16 add_filter('woocommerce_gateway_description', 'slimcd_description_no_forms', 20, 2); 17 } else if (!empty($slimcd_settings->settings['slimcd_formname_card']) && !empty($slimcd_settings->settings['slimcd_formname_cheque'])) { 18 add_filter('woocommerce_gateway_description', 'slimcd_description_fileds', 20, 2); 19 } else if (!empty($slimcd_settings->settings['slimcd_formname_card']) && empty($slimcd_settings->settings['slimcd_formname_cheque'])) { 20 add_filter('woocommerce_gateway_description', 'slimcd_description_fileds_card', 20, 2); 21 } else if (empty($slimcd_settings->settings['slimcd_formname_card']) && !empty($slimcd_settings->settings['slimcd_formname_cheque'])) { 22 add_filter('woocommerce_gateway_description', 'slimcd_description_fileds_check', 20, 2); 23 } 24 25 26 function slimcd_description_no_forms($description, $payment_id) 27 { 28 if ('slimcd_payment' !== $payment_id) { 29 return $description; 30 } 31 ob_start(); 32 echo "<div id='slimcdDisclaimerError' class='text-danger'> 2 3 function slimcd_description_fileds_options($description, $payment_id) 4 { 5 if ('slimcd_payment' !== $payment_id) { 6 return $description; 7 } 8 $cartCurrency = get_woocommerce_currency(); 9 if ($cartCurrency == "USD" || $cartCurrency == "CAD") { 10 $slimcd_settings = WC()->payment_gateways->payment_gateways()['slimcd_payment']; 11 if ((empty($slimcd_settings->settings['slimcd_formname_card']) && empty($slimcd_settings->settings['slimcd_formname_cheque'])) || empty($slimcd_settings->settings['slimcd_username'])) { 12 $slimcdDescription = slimcd_description_no_forms($description); 13 } else if (!empty($slimcd_settings->settings['slimcd_formname_card']) && !empty($slimcd_settings->settings['slimcd_formname_cheque'])) { 14 $slimcdDescription = slimcd_description_fileds($slimcd_settings, $description); 15 } else if (!empty($slimcd_settings->settings['slimcd_formname_card']) && empty($slimcd_settings->settings['slimcd_formname_cheque'])) { 16 $slimcdDescription = slimcd_description_fileds_card($slimcd_settings, $description); 17 } else if (empty($slimcd_settings->settings['slimcd_formname_card']) && !empty($slimcd_settings->settings['slimcd_formname_cheque'])) { 18 $slimcdDescription = slimcd_description_fileds_check($slimcd_settings, $description); 19 } 20 } else { 21 $slimcdDescription = slimcd_description_not_supported_currency($description); 22 } 23 24 return $slimcdDescription; 25 } 26 27 /* Error message for un-supported currencies*/ 28 function slimcd_description_not_supported_currency($description) 29 { 30 ob_start(); 31 echo "<div id='slimcdDisclaimerError' class='text-danger'> 33 32 <p> 34 Error: API or form info is missing. Please contact site administrator33 Error: Payment currency must be USD or CAD 35 34 </p> 36 35 </div>"; 37 36 38 39 $description .= ob_get_clean(); 40 return $description; 41 } 42 function slimcd_description_fileds($description, $payment_id) 43 { 44 if ('slimcd_payment' !== $payment_id) { 45 return $description; 46 } 47 48 $slimcd_settings = WC()->payment_gateways->payment_gateways()['slimcd_payment']; 49 50 ob_start(); 51 52 woocommerce_form_field( 53 'payment_mode', 54 array( 55 'type' => 'radio', 56 'label' => __('Payment Method:', 'slimcd-payment-gateway'), 57 'class' => array('slimcd_payment_options'), 58 'required' => true, 59 'checked' => 'checked', 60 'default' => 'payment_mode_card', 61 'options' => array( 62 'payment_mode_card' => __('Credit Card', 'slimcd-payment-gateway'), 63 'payment_mode_cheque' => __('Checking Account', 'slimcd-payment-gateway'), 64 ), 65 ) 66 ); 67 68 $username = $slimcd_settings->settings['slimcd_username']; 69 $password = $slimcd_settings->settings['slimcd_password']; 70 $surcharge_convience = check_for_surcharge_convience($username, $password); 71 72 if ("Success" === $surcharge_convience['response']) { 73 74 $receiptlabel = null; 75 $disclaimerContentCreditCard = null; 76 $disclaimerContentCheck = null; 77 78 if ((int)$surcharge_convience['site']->surcharge_percentage > 0) { 79 $receiptlabel = "Surcharge"; 80 $disclaimerContentCreditCard = $slimcd_settings->settings['credit_card_surcharge_disclaimer']; 81 } else if ($surcharge_convience['site']->conveniencefee_enabled !== "False") { 82 $receiptlabel = $surcharge_convience['site']->conveniencefee_receiptlabel; 83 $disclaimerContentCreditCard = $slimcd_settings->settings['credit_card_convenience_fee_disclaimer']; 84 } 85 86 if ($surcharge_convience['site']->conveniencefee_enabled !== "False") { 87 $receiptlabel = $surcharge_convience['site']->conveniencefee_receiptlabel; 88 $disclaimerContentCheck = $slimcd_settings->settings['check_convenience_fee_disclaimer']; 89 } 90 91 92 93 echo "<div id='slimcdDisclaimer'> 37 $description .= ob_get_clean(); 38 return $description; 39 } 40 41 42 /** Error message when form is not are not available */ 43 44 function slimcd_description_no_forms($description) 45 { 46 ob_start(); 47 echo "<div id='slimcdDisclaimerError' class='text-danger'> 48 <p> 49 Error: API or form info is missing. Please contact site administrator 50 </p> 51 </div>"; 52 $description .= ob_get_clean(); 53 return $description; 54 } 55 56 /** Form for both card and check payment */ 57 function slimcd_description_fileds($slimcd_settings, $description) 58 { 59 ob_start(); 60 woocommerce_form_field( 61 'payment_mode', 62 array( 63 'type' => 'radio', 64 'label' => __('Payment Method:', 'slimcd-payment-gateway'), 65 'class' => array('slimcd_payment_options'), 66 'required' => true, 67 'checked' => 'checked', 68 'default' => 'payment_mode_card', 69 'options' => array( 70 'payment_mode_card' => __('Credit Card', 'slimcd-payment-gateway'), 71 'payment_mode_cheque' => __('Checking Account', 'slimcd-payment-gateway'), 72 ), 73 ) 74 ); 75 76 $username = $slimcd_settings->settings['slimcd_username']; 77 $password = $slimcd_settings->settings['slimcd_password']; 78 $surcharge_convience = check_for_surcharge_convience($username, $password); 79 80 if ("Success" === $surcharge_convience['response']) { 81 82 $receiptlabel = null; 83 $disclaimerContentCreditCard = null; 84 $disclaimerContentCheck = null; 85 86 if ((int)$surcharge_convience['site']->surcharge_percentage > 0) { 87 $receiptlabel = "Surcharge"; 88 $disclaimerContentCreditCard = $slimcd_settings->settings['credit_card_surcharge_disclaimer']; 89 } else if ($surcharge_convience['site']->conveniencefee_enabled !== "False") { 90 $receiptlabel = $surcharge_convience['site']->conveniencefee_receiptlabel; 91 $disclaimerContentCreditCard = $slimcd_settings->settings['credit_card_convenience_fee_disclaimer']; 92 } 93 94 if ($surcharge_convience['site']->conveniencefee_enabled !== "False") { 95 $receiptlabel = $surcharge_convience['site']->conveniencefee_receiptlabel; 96 $disclaimerContentCheck = $slimcd_settings->settings['check_convenience_fee_disclaimer']; 97 } 98 99 100 101 echo "<div id='slimcdDisclaimer'> 94 102 95 103 <div id='slimcdDisclaimerCreditCard' class='slimcdPaymentDisclaimer'><p> … … 103 111 </div>"; 104 112 105 woocommerce_form_field('receiptlabel', array(106 'type' => 'hidden',107 'required' => true,108 ), $receiptlabel);109 } else {110 echo "<div id='slimcdDisclaimerError' class='text-danger'>113 woocommerce_form_field('receiptlabel', array( 114 'type' => 'hidden', 115 'required' => true, 116 ), $receiptlabel); 117 } else { 118 echo "<div id='slimcdDisclaimerError' class='text-danger'> 111 119 <p> 112 120 Error : $surcharge_convience[description] 113 121 </p> 114 122 </div>"; 115 } 116 117 $description .= ob_get_clean(); 118 return $description; 119 } 120 121 function slimcd_description_fileds_card($description, $payment_id) 122 { 123 if ('slimcd_payment' !== $payment_id) { 124 return $description; 125 } 126 127 $slimcd_settings = WC()->payment_gateways->payment_gateways()['slimcd_payment']; 128 $username = $slimcd_settings->settings['slimcd_username']; 129 $password = $slimcd_settings->settings['slimcd_password']; 130 $surcharge_convience = check_for_surcharge_convience($username, $password); 131 ob_start(); 132 if ("Success" === $surcharge_convience['response']) { 133 $disclaimerContentCreditCard = null; 134 $receiptlabel = null; 135 if ((int)$surcharge_convience['site']->surcharge_percentage > 0) { 136 $receiptlabel = "Surcharge"; 137 $disclaimerContentCreditCard = $slimcd_settings->settings['credit_card_surcharge_disclaimer']; 138 } else if ($surcharge_convience['site']->conveniencefee_enabled !== "False") { 139 $receiptlabel = $surcharge_convience['site']->conveniencefee_receiptlabel; 140 $disclaimerContentCreditCard = $slimcd_settings->settings['credit_card_convenience_fee_disclaimer']; 141 } 142 echo "<div id='slimcdDisclaimer'> 123 } 124 125 $description .= ob_get_clean(); 126 return $description; 127 } 128 129 /** Description filed for card */ 130 function slimcd_description_fileds_card($slimcd_settings, $description) 131 { 132 133 $username = $slimcd_settings->settings['slimcd_username']; 134 $password = $slimcd_settings->settings['slimcd_password']; 135 $surcharge_convience = check_for_surcharge_convience($username, $password); 136 ob_start(); 137 if ("Success" === $surcharge_convience['response']) { 138 $disclaimerContentCreditCard = null; 139 $receiptlabel = null; 140 if ((int)$surcharge_convience['site']->surcharge_percentage > 0) { 141 $receiptlabel = "Surcharge"; 142 $disclaimerContentCreditCard = $slimcd_settings->settings['credit_card_surcharge_disclaimer']; 143 } else if ($surcharge_convience['site']->conveniencefee_enabled !== "False") { 144 $receiptlabel = $surcharge_convience['site']->conveniencefee_receiptlabel; 145 $disclaimerContentCreditCard = $slimcd_settings->settings['credit_card_convenience_fee_disclaimer']; 146 } 147 echo "<div id='slimcdDisclaimer'> 143 148 144 149 <div id='slimcdDisclaimerCreditCard' class='slimcdPaymentDisclaimer'><p> … … 147 152 </div>"; 148 153 149 woocommerce_form_field('receiptlabel', array(150 'type' => 'hidden',151 'required' => true,152 ), $receiptlabel);153 } else {154 echo "<div id='slimcdDisclaimerError' class='text-danger'>154 woocommerce_form_field('receiptlabel', array( 155 'type' => 'hidden', 156 'required' => true, 157 ), $receiptlabel); 158 } else { 159 echo "<div id='slimcdDisclaimerError' class='text-danger'> 155 160 <p> 156 161 Error : $surcharge_convience[description] 157 162 </p> 158 163 </div>"; 159 } 160 $description .= ob_get_clean(); 161 return $description; 162 } 163 164 function slimcd_description_fileds_check($description, $payment_id) 165 { 166 if ('slimcd_payment' !== $payment_id) { 167 return $description; 168 } 169 $disclaimerContentCheck = null; 170 $slimcd_settings = WC()->payment_gateways->payment_gateways()['slimcd_payment']; 171 $username = $slimcd_settings->settings['slimcd_username']; 172 $password = $slimcd_settings->settings['slimcd_password']; 173 $surcharge_convience = check_for_surcharge_convience($username, $password); 174 ob_start(); 175 if ("Success" === $surcharge_convience['response']) { 176 $receiptlabel = null; 177 if ($surcharge_convience['site']->conveniencefee_enabled !== "False") { 178 $receiptlabel = $surcharge_convience['site']->conveniencefee_receiptlabel; 179 $disclaimerContentCheck = $slimcd_settings->settings['check_convenience_fee_disclaimer']; 180 } 181 echo "<div id='slimcdDisclaimer'> 164 } 165 $description .= ob_get_clean(); 166 return $description; 167 } 168 169 /** Description filed for check */ 170 171 function slimcd_description_fileds_check($slimcd_settings, $description) 172 { 173 $disclaimerContentCheck = null; 174 $username = $slimcd_settings->settings['slimcd_username']; 175 $password = $slimcd_settings->settings['slimcd_password']; 176 $surcharge_convience = check_for_surcharge_convience($username, $password); 177 ob_start(); 178 if ("Success" === $surcharge_convience['response']) { 179 $receiptlabel = null; 180 if ($surcharge_convience['site']->conveniencefee_enabled !== "False") { 181 $receiptlabel = $surcharge_convience['site']->conveniencefee_receiptlabel; 182 $disclaimerContentCheck = $slimcd_settings->settings['check_convenience_fee_disclaimer']; 183 } 184 echo "<div id='slimcdDisclaimer'> 182 185 <div id='slimcdDisclaimerCreditCard' class='slimcdPaymentDisclaimer'><p> 183 186 $disclaimerContentCheck … … 185 188 </div>"; 186 189 187 woocommerce_form_field('receiptlabel', array(188 'type' => 'hidden',189 'required' => true,190 ), $receiptlabel);191 } else {192 echo "<div id='slimcdDisclaimerError' class='text-danger'>190 woocommerce_form_field('receiptlabel', array( 191 'type' => 'hidden', 192 'required' => true, 193 ), $receiptlabel); 194 } else { 195 echo "<div id='slimcdDisclaimerError' class='text-danger'> 193 196 <p> 194 197 Error : $surcharge_convience[description] 195 198 </p> 196 199 </div>"; 197 } 198 199 $description .= ob_get_clean(); 200 return $description; 201 } 202 203 204 205 function check_for_surcharge_convience($username, $password) 206 { 207 $data = array( 208 "username" => $username, 209 "clientid" => "0", 210 "siteid" => "0", 211 "password" => $password, 200 } 201 202 $description .= ob_get_clean(); 203 return $description; 204 } 205 206 /** Api Call for checking convinece and sur-charge */ 207 function check_for_surcharge_convience($username, $password) 208 { 209 $data = array( 210 "username" => $username, 211 "clientid" => "0", 212 "siteid" => "0", 213 "password" => $password, 214 ); 215 216 $response = wp_remote_post('https://stats.slimcd.com/soft/json/jsonscript.asp?service=GetUserClientSite3', array( 217 'headers' => array('Content-Type' => 'application/json; charset=utf-8'), 218 'body' => json_encode($data), 219 220 )); 221 if (is_wp_error($response)) { 222 return array( 223 "response" => "Error", 224 "description" => "Error while accessing API" 212 225 ); 213 214 $response = wp_remote_post('https://stats.slimcd.com/soft/json/jsonscript.asp?service=GetUserClientSite3', array( 215 'headers' => array('Content-Type' => 'application/json; charset=utf-8'), 216 'body' => json_encode($data), 217 218 )); 219 if (is_wp_error($response)) { 226 } else { 227 228 $result = json_decode(wp_remote_retrieve_body($response)); 229 230 if ($result->reply->response === "Success") { 220 231 return array( 221 "response" => "Error",222 " description" => "Error while accessing API"232 "response" => $result->reply->response, 233 "site" => $result->reply->datablock->SiteList->Site 223 234 ); 224 235 } else { 225 226 $result = json_decode(wp_remote_retrieve_body($response)); 227 228 if ($result->reply->response === "Success") { 229 return array( 230 "response" => $result->reply->response, 231 "site" => $result->reply->datablock->SiteList->Site 232 ); 233 } else { 234 return array( 235 "response" => $result->reply->response, 236 "description" => $result->reply->description 237 ); 238 } 239 } 240 } 241 } else { 242 add_filter('woocommerce_gateway_description', 'slimcd_description_no_usd', 20, 2); 243 function slimcd_description_no_usd($description, $payment_id) 244 { 245 if ('slimcd_payment' !== $payment_id) { 246 return $description; 247 } 248 ob_start(); 249 echo "<div id='slimcdDisclaimerError' class='text-danger'> 250 <p> 251 Error: Payment currency must be USD or CAD 252 </p> 253 </div>"; 254 255 $description .= ob_get_clean(); 256 return $description; 257 } 258 } 236 return array( 237 "response" => $result->reply->response, 238 "description" => $result->reply->description 239 ); 240 } 241 } 242 }
Note: See TracChangeset
for help on using the changeset viewer.