Changeset 3003078
- Timestamp:
- 11/29/2023 06:54:54 AM (2 years ago)
- Location:
- bayarcash-wc
- Files:
-
- 42 added
- 20 edited
-
tags/3.0.0/bayarcash-wc.php (modified) (1 diff)
-
tags/3.0.0/includes/admin/bayarcash-wc-checkout.js (modified) (1 diff)
-
tags/3.0.0/includes/admin/bayarcash-wc-script.js (modified) (2 diffs)
-
tags/3.0.0/includes/helpers.php (modified) (10 diffs)
-
tags/3.0.0/includes/load.php (modified) (1 diff)
-
tags/3.0.0/includes/src/Bayarcash.php (modified) (6 diffs)
-
tags/3.0.0/includes/src/CronEvent.php (modified) (3 diffs)
-
tags/3.0.0/includes/src/DataRequest.php (modified) (3 diffs)
-
tags/3.0.0/includes/src/DataStore.php (modified) (3 diffs)
-
tags/3.0.0/includes/src/Gateway.php (added)
-
tags/3.0.0/includes/vendor (added)
-
tags/3.0.0/includes/vendor/autoload.php (added)
-
tags/3.0.0/includes/vendor/composer (added)
-
tags/3.0.0/includes/vendor/composer/ClassLoader.php (added)
-
tags/3.0.0/includes/vendor/composer/InstalledVersions.php (added)
-
tags/3.0.0/includes/vendor/composer/autoload_classmap.php (added)
-
tags/3.0.0/includes/vendor/composer/autoload_namespaces.php (added)
-
tags/3.0.0/includes/vendor/composer/autoload_psr4.php (added)
-
tags/3.0.0/includes/vendor/composer/autoload_real.php (added)
-
tags/3.0.0/includes/vendor/composer/autoload_static.php (added)
-
tags/3.0.0/includes/vendor/composer/index.html (added)
-
tags/3.0.0/includes/vendor/composer/installed.php (added)
-
tags/3.0.0/includes/vendor/index.html (added)
-
tags/3.0.0/includes/vendor/nawawi (added)
-
tags/3.0.0/includes/vendor/nawawi/base64-encryption (added)
-
tags/3.0.0/includes/vendor/nawawi/base64-encryption/index.html (added)
-
tags/3.0.0/includes/vendor/nawawi/base64-encryption/src (added)
-
tags/3.0.0/includes/vendor/nawawi/base64-encryption/src/Base64Encryption.php (added)
-
tags/3.0.0/includes/vendor/nawawi/base64-encryption/src/index.html (added)
-
tags/3.0.0/includes/vendor/nawawi/index.html (added)
-
tags/3.0.0/languages/bayarcash-wc.pot (modified) (2 diffs)
-
trunk/bayarcash-wc.php (modified) (1 diff)
-
trunk/includes/admin/bayarcash-wc-checkout.js (modified) (1 diff)
-
trunk/includes/admin/bayarcash-wc-script.js (modified) (2 diffs)
-
trunk/includes/helpers.php (modified) (10 diffs)
-
trunk/includes/load.php (modified) (1 diff)
-
trunk/includes/src/Bayarcash.php (modified) (6 diffs)
-
trunk/includes/src/CronEvent.php (modified) (3 diffs)
-
trunk/includes/src/DataRequest.php (modified) (3 diffs)
-
trunk/includes/src/DataStore.php (modified) (3 diffs)
-
trunk/includes/src/Gateway.php (added)
-
trunk/includes/vendor (added)
-
trunk/includes/vendor/autoload.php (added)
-
trunk/includes/vendor/composer (added)
-
trunk/includes/vendor/composer/ClassLoader.php (added)
-
trunk/includes/vendor/composer/InstalledVersions.php (added)
-
trunk/includes/vendor/composer/autoload_classmap.php (added)
-
trunk/includes/vendor/composer/autoload_namespaces.php (added)
-
trunk/includes/vendor/composer/autoload_psr4.php (added)
-
trunk/includes/vendor/composer/autoload_real.php (added)
-
trunk/includes/vendor/composer/autoload_static.php (added)
-
trunk/includes/vendor/composer/index.html (added)
-
trunk/includes/vendor/composer/installed.php (added)
-
trunk/includes/vendor/index.html (added)
-
trunk/includes/vendor/nawawi (added)
-
trunk/includes/vendor/nawawi/base64-encryption (added)
-
trunk/includes/vendor/nawawi/base64-encryption/index.html (added)
-
trunk/includes/vendor/nawawi/base64-encryption/src (added)
-
trunk/includes/vendor/nawawi/base64-encryption/src/Base64Encryption.php (added)
-
trunk/includes/vendor/nawawi/base64-encryption/src/index.html (added)
-
trunk/includes/vendor/nawawi/index.html (added)
-
trunk/languages/bayarcash-wc.pot (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
bayarcash-wc/tags/3.0.0/bayarcash-wc.php
r2988685 r3003078 29 29 \defined('ABSPATH') && !\defined('BAYARCASH_WC') || exit; 30 30 31 \define('BAYARCASH_WC', [ 32 'SLUG' => 'bayarcash-wc', 33 'FILE' => __FILE__, 34 'HOOK' => plugin_basename(__FILE__), 35 'PATH' => realpath(plugin_dir_path(__FILE__)), 36 'URL' => trailingslashit(plugin_dir_url(__FILE__)), 37 'ENDPOINT' => [ 38 'PUBLIC' => 'https://console.bayar.cash', 39 'PRIVATE' => 'https://console.bayarcash.dev', 40 ], 41 ]); 31 \define( 32 'BAYARCASH_WC', 33 [ 34 'SLUG' => 'bayarcash-wc', 35 'FILE' => __FILE__, 36 'HOOK' => plugin_basename(__FILE__), 37 'PATH' => realpath(plugin_dir_path(__FILE__)), 38 'URL' => trailingslashit(plugin_dir_url(__FILE__)), 39 'ENDPOINT' => [ 40 'PUBLIC' => 'https://console.bayar.cash', 41 'PRIVATE' => 'https://console.bayarcash.dev', 42 ], 43 ] 44 ); 42 45 43 46 require __DIR__.'/includes/load.php'; -
bayarcash-wc/tags/3.0.0/includes/admin/bayarcash-wc-checkout.js
r2988685 r3003078 1 1 ( function( $ ) { 2 2 /* custom_order_button_text */ 3 $( "form.checkout" ) 4 .on( 5 "change", 6 "input[name^=payment_method]", 7 function() { 8 $( document.body ).trigger( "update_checkout" ); 9 } 10 ); 3 $( 'form.checkout' ).on( 4 'change', 5 'input[name^=payment_method]', 6 function() { 7 $( document.body ).trigger( 'update_checkout' ); 8 } 9 ); 11 10 } )( jQuery ); -
bayarcash-wc/tags/3.0.0/includes/admin/bayarcash-wc-script.js
r2988685 r3003078 37 37 } 38 38 39 let is_sandbox_mode = $( 'input[type=checkbox]#woocommerce_bayarcash-wc_sandbox_mode' ).is( ':checked' ) ? 1 : 0; 40 39 41 $.ajax( { 40 42 url: config.ajaxurl, … … 47 49 "type": 'verify', 48 50 'bearer_token': token, 49 ' reset': is_reset,51 'sandbox_mode': is_sandbox_mode, 50 52 'nocache': ( new Date().getTime() ), 51 53 }, -
bayarcash-wc/tags/3.0.0/includes/helpers.php
r2988685 r3003078 13 13 \defined('ABSPATH') || exit; 14 14 15 function get_plugin_meta()15 function bayarcash_plugin_meta() 16 16 { 17 17 static $meta = null; … … 24 24 } 25 25 26 function get_version()27 { 28 return get_plugin_meta()['Version'];29 } 30 31 function data_request()26 function bayarcash_version() 27 { 28 return bayarcash_plugin_meta()['Version']; 29 } 30 31 function bayarcash_request_data() 32 32 { 33 33 static $inst = null; … … 39 39 } 40 40 41 function data_store()41 function bayarcash_data_store() 42 42 { 43 43 static $inst = null; … … 49 49 } 50 50 51 function is_fpx_transaction_status($status, $match) 51 function bayarcash_encryption() 52 { 53 static $inst = null; 54 if (null === $inst) { 55 $inst = new \BayarCash\WooCommerce\Nawawi\Utils\Base64Encryption(); 56 } 57 58 return $inst; 59 } 60 61 function bayarcash_return_token_set($data, $key, $type = 'fpx') 62 { 63 $str = $data.'|'.substr(md5($data), 0, 12).'|'.$type; 64 65 return bayarcash_encryption()->encrypt($str, $key); 66 } 67 68 function bayarcash_return_token_get($data, $key, $type) 69 { 70 $str = bayarcash_encryption()->decrypt($data, $key); 71 if ($str === $data || false === strpos($str, '|'.$type)) { 72 return false; 73 } 74 75 $str_a = explode('|', $str); 76 if ($str_a[2] !== $type) { 77 return false; 78 } 79 80 return (object) [ 81 'data' => $str_a[0], 82 'data_id' => $str_a[1], 83 'type' => $str_a[2], 84 ]; 85 } 86 87 function bayarcash_has_fpx_transaction_status($status, $match) 52 88 { 53 89 $lists = [ … … 68 104 } 69 105 70 function get_response_data($type = '')106 function bayarcash_populate_response_data($type = '') 71 107 { 72 108 if (empty($_POST)) { … … 193 229 } 194 230 195 function get_config() 231 function bayarcash_strip_whitespace($string) 232 { 233 return preg_replace('@[\s\n\r\t]+@s', '', $string); 234 } 235 236 function bayarcash_gateway_config() 196 237 { 197 238 if (!\function_exists('WC')) { … … 208 249 } 209 250 210 function get_endpoint()211 { 212 $config = get_config();251 function bayarcash_endpoint() 252 { 253 $config = bayarcash_gateway_config(); 213 254 214 255 if (!$config || empty($config->settings['sandbox_mode'])) { … … 219 260 } 220 261 221 function get_tokens()222 { 223 $config = get_config();262 function bayarcash_gateway_tokens() 263 { 264 $config = bayarcash_gateway_config(); 224 265 225 266 if (!$config || !isset($config->settings['portal_key']) || !isset($config->settings['bearer_token'])) { … … 230 271 } 231 272 232 $bearer_token = preg_replace('@[\s\n\r\t]+@s', '',$config->settings['portal_key']);233 $portal_key = preg_replace('@[\s\n\r\t]+@s', '',$config->settings['bearer_token']);273 $bearer_token = bayarcash_strip_whitespace($config->settings['portal_key']); 274 $portal_key = bayarcash_strip_whitespace($config->settings['bearer_token']); 234 275 235 276 return [ … … 239 280 } 240 281 241 function debug_log($text)282 function bayarcash_debug_log($text) 242 283 { 243 284 if (!\defined('BAYARCASH_GIVEWP_DEBUG') || true !== (bool) BAYARCASH_GIVEWP_DEBUG) { -
bayarcash-wc/tags/3.0.0/includes/load.php
r2988685 r3003078 9 9 */ 10 10 \defined('ABSPATH') || exit; 11 require_once __DIR__.'/src/CronEvent.php'; 12 require_once __DIR__.'/src/DataRequest.php'; 13 require_once __DIR__.'/src/DataStore.php'; 11 require_once __DIR__.'/vendor/autoload.php'; 14 12 require_once __DIR__.'/helpers.php'; 15 require_once __DIR__.'/src/Bayarcash.php'; -
bayarcash-wc/tags/3.0.0/includes/src/Bayarcash.php
r2988685 r3003078 64 64 'woocommerce_payment_gateways', 65 65 function ($gateways) { 66 $gateways[] = ' GatewayBayarcash';66 $gateways[] = '\\BayarCash\\WooCommerce\\Gateway'; 67 67 68 68 return $gateways; … … 74 74 function () { 75 75 if ($this->is_woocommerce_activated()) { 76 require_once __DIR__.'/Gateway Bayarcash.php';76 require_once __DIR__.'/Gateway.php'; 77 77 } 78 78 … … 90 90 } 91 91 92 $version = get_version().'c'.date('Ymdh');92 $version = bayarcash_version().'c'.date('Ymdh'); 93 93 wp_enqueue_script($this->slug.'-script', $this->url.'includes/admin/bayarcash-wc-script.js', ['jquery'], $version, false); 94 94 wp_localize_script( … … 127 127 function () { 128 128 if (!check_ajax_referer('bayarcash-wc-token-nonce', 'token', false) && !isset($_POST['type'])) { 129 delete_transient('bayarcash-wc-verfiy-token');130 129 wp_send_json_error('Invalid security token sent.'); 131 130 exit; 132 131 } 133 132 134 if (!empty($_POST['reset'])) {135 delete_transient('bayarcash-wc-verfiy-token');136 }137 138 133 $type = sanitize_text_field($_POST['type']); 139 134 140 135 if ('verify' === $type) { 141 if (get_transient('bayarcash-wc-verfiy-token')) {142 wp_send_json(['is_verified' => 1]);143 exit;144 }145 146 136 if (empty($_POST['bearer_token'])) { 147 137 wp_send_json_error($this->slug.':script: "'.$type.'" invalid request'); 148 138 } 149 139 150 $token = sanitize_text_field($_POST['bearer_token']); 151 $is_verified = data_request()->is_token_verified(['bearer_token' => $token]); 152 153 if ($is_verified) { 154 set_transient('bayarcash-wc-verfiy-token', 1, MINUTE_IN_SECONDS * 3); 155 } 140 $token = sanitize_text_field($_POST['bearer_token']); 141 $is_sandbox_mode = !empty($_POST['sandbox_mode']); 142 $is_verified = bayarcash_request_data()->is_token_verified(['bearer_token' => $token, 'local_sandbox_mode' => $is_sandbox_mode]); 156 143 157 144 wp_send_json(['is_verified' => $is_verified ? 1 : 0]); … … 159 146 } 160 147 161 delete_transient('bayarcash-wc-verfiy-token');162 148 wp_send_json_error($this->slug.':script: "'.$type.'" not available'); 163 149 exit; … … 168 154 public function is_woocommerce_activated() 169 155 { 170 return class_exists('WooCommerce' );156 return class_exists('WooCommerce', false) && class_exists('WC_Payment_Gateway', false); 171 157 } 172 158 -
bayarcash-wc/tags/3.0.0/includes/src/CronEvent.php
r2988685 r3003078 61 61 62 62 if (empty($orders_pending)) { 63 debug_log('No pending payment orders detected');63 bayarcash_debug_log('No pending payment orders detected'); 64 64 65 65 return; … … 79 79 80 80 if (empty($transaction_exchange_nos_cleaned)) { 81 debug_log('No pending payment orders detected');81 bayarcash_debug_log('No pending payment orders detected'); 82 82 83 83 return; … … 85 85 86 86 foreach ($transaction_exchange_nos_cleaned as $transaction_exchange_no) { 87 debug_log(sprintf('Transaction exchange to requery: ', $transaction_exchange_no));87 bayarcash_debug_log(sprintf('Transaction exchange to requery: ', $transaction_exchange_no)); 88 88 89 89 $data = [ 90 'bearer_token' => get_tokens()->bearer_token,90 'bearer_token' => bayarcash_gateway_tokens()->bearer_token, 91 91 'FPX_OrderRefNo' => $transaction_exchange_no, 92 92 ]; 93 93 94 $response_data = data_request()->check_payment_status($data);95 data_store()->update_payment_fpx($response_data);94 $response_data = bayarcash_request_data()->check_payment_status($data); 95 bayarcash_data_store()->update_payment_fpx($response_data); 96 96 } 97 97 } -
bayarcash-wc/tags/3.0.0/includes/src/DataRequest.php
r2988685 r3003078 30 30 private function send($param, $endpoint_url) 31 31 { 32 $meta = get_plugin_meta();32 $meta = bayarcash_plugin_meta(); 33 33 $ua_nam = strtolower(str_replace(' ', '-', $meta['Name'])); 34 34 $ua_ver = $meta['Version']; … … 67 67 } 68 68 69 public function check_payment_status(array $data, $ is_verify_only= false)69 public function check_payment_status(array $data, $local_endpoint = false) 70 70 { 71 $bearer_token = preg_replace('@[\s\n\r\t]+@s', '', $data['bearer_token']); 72 $endpoint = get_endpoint(); 71 $bearer_token = bayarcash_strip_whitespace($data['bearer_token']); 72 $endpoint = false === $local_endpoint ? bayarcash_endpoint() : $local_endpoint; 73 $endpoint_url = $endpoint.'/api/transactions/'; 73 74 74 75 if (!empty($data['FPX_OrderRefNo'])) { 75 76 $endpoint_url = $endpoint.'/api/transactions/?RefNo='.$data['FPX_OrderRefNo']; 76 }77 78 if ($is_verify_only) {79 $endpoint_url = $endpoint.'/api/transactions/';80 77 } 81 78 … … 102 99 public function is_token_verified(array $data) 103 100 { 104 $response = $this->check_payment_status($data, true); 101 if (!isset($data['bearer_token'], $data['local_sandbox_mode'])) { 102 return false; 103 } 104 105 $local_endpoint = false; 106 if (!empty($data['local_sandbox_mode'])) { 107 $local_endpoint = BAYARCASH_WC['ENDPOINT']['PRIVATE']; 108 } 109 110 $response = $this->check_payment_status($data, $local_endpoint); 105 111 if (!$response) { 112 return false; 113 } 114 115 $response_object = json_decode($response); 116 if (empty($response_object->output->transactionsList->recordsListData)) { 106 117 return false; 107 118 } -
bayarcash-wc/tags/3.0.0/includes/src/DataStore.php
r2988685 r3003078 28 28 $order_no = $order_details->get_id(); 29 29 30 if ( is_fpx_transaction_status($records->status, 'successful')) {30 if (bayarcash_has_fpx_transaction_status($records->status, 'successful')) { 31 31 delete_post_meta($order_no, 'bayarcash_wc_transaction_exchange_no'); 32 32 … … 44 44 } 45 45 46 if ( is_fpx_transaction_status($records->status, 'unsuccessful') || is_fpx_transaction_status($records->status, 'cancelled') && $order_details->needs_payment()) {46 if (bayarcash_has_fpx_transaction_status($records->status, 'unsuccessful') || bayarcash_has_fpx_transaction_status($records->status, 'cancelled') && $order_details->needs_payment()) { 47 47 delete_post_meta($order_no, 'bayarcash_wc_transaction_exchange_no'); 48 48 … … 62 62 private function get_order_note(string $message, $records): string 63 63 { 64 $transaction_url = get_endpoint().'/transactions?ref_no='.$records->exchange_order_no;64 $transaction_url = bayarcash_endpoint().'/transactions?ref_no='.$records->exchange_order_no; 65 65 $transaction_date = date('j F Y', strtotime($records->datetime)); 66 66 $transaction_time = date('h:i:s A', strtotime($records->datetime)); -
bayarcash-wc/tags/3.0.0/languages/bayarcash-wc.pot
r2988685 r3003078 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "Content-Transfer-Encoding: 8bit\n" 12 "POT-Creation-Date: 2023-11- 03T19:17:54+00:00\n"12 "POT-Creation-Date: 2023-11-27T20:06:22+00:00\n" 13 13 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 14 "X-Generator: WP-CLI 2.7.1\n" … … 43 43 msgstr "" 44 44 45 #: includes/src/Bayarcash.php:1 7745 #: includes/src/Bayarcash.php:163 46 46 msgid "Bayarcash require WooCommerce plugin. Please install and activate." 47 47 msgstr "" 48 48 49 #: includes/src/GatewayBayarcash.php:78 49 #: includes/src/Gateway.php:102 50 msgid "Please enter Portal key" 51 msgstr "" 52 53 #: includes/src/Gateway.php:105 54 msgid "Please enter Personal Access Token (PAT)" 55 msgstr "" 56 57 #: includes/src/Gateway.php:114 50 58 msgid "Return to payments" 51 59 msgstr "" 52 60 53 #: includes/src/Gateway Bayarcash.php:8161 #: includes/src/Gateway.php:117 54 62 msgid "Allow customers to pay with Bayarcash." 55 63 msgstr "" 56 64 57 #: includes/src/Gateway Bayarcash.php:9365 #: includes/src/Gateway.php:129 58 66 msgid "Enable/Disable" 59 67 msgstr "" 60 68 61 #: includes/src/Gateway Bayarcash.php:9562 #: includes/src/Gateway Bayarcash.php:9669 #: includes/src/Gateway.php:131 70 #: includes/src/Gateway.php:132 63 71 msgid "Enable Bayarcash payment platform" 64 72 msgstr "" 65 73 66 #: includes/src/Gateway Bayarcash.php:10174 #: includes/src/Gateway.php:137 67 75 msgid "Sandbox Mode" 68 76 msgstr "" 69 77 70 #: includes/src/Gateway Bayarcash.php:10371 #: includes/src/Gateway Bayarcash.php:10478 #: includes/src/Gateway.php:139 79 #: includes/src/Gateway.php:140 72 80 msgid "Enable Sandbox Mode" 73 81 msgstr "" 74 82 75 #: includes/src/Gateway Bayarcash.php:10983 #: includes/src/Gateway.php:145 76 84 msgid "Title" 77 85 msgstr "" 78 86 79 #: includes/src/Gateway Bayarcash.php:11187 #: includes/src/Gateway.php:147 80 88 msgid "This is the title the user sees during checkout." 81 89 msgstr "" 82 90 83 #: includes/src/Gateway Bayarcash.php:11791 #: includes/src/Gateway.php:153 84 92 msgid "Description" 85 93 msgstr "" 86 94 87 #: includes/src/Gateway Bayarcash.php:11995 #: includes/src/Gateway.php:155 88 96 msgid "This is the description the user sees during checkout." 89 97 msgstr "" 90 98 91 #: includes/src/Gateway Bayarcash.php:12199 #: includes/src/Gateway.php:157 92 100 msgid "Pay for your items securely with Bayarcash" 93 101 msgstr "" 94 102 95 #: includes/src/Gateway Bayarcash.php:124103 #: includes/src/Gateway.php:160 96 104 msgid "Personal Access Token (PAT)" 97 105 msgstr "" 98 106 99 #: includes/src/Gateway Bayarcash.php:126100 #: includes/src/Gateway Bayarcash.php:127107 #: includes/src/Gateway.php:162 108 #: includes/src/Gateway.php:163 101 109 msgid "Fill in your Bayarcash PAT here" 102 110 msgstr "" 103 111 104 #: includes/src/Gateway Bayarcash.php:132112 #: includes/src/Gateway.php:168 105 113 msgid "Portal Key" 106 114 msgstr "" 107 115 108 #: includes/src/Gateway Bayarcash.php:134109 #: includes/src/Gateway Bayarcash.php:135116 #: includes/src/Gateway.php:170 117 #: includes/src/Gateway.php:171 110 118 msgid "Fill in your Bayarcash portal key here" 111 119 msgstr "" 112 120 113 #: includes/src/Gateway Bayarcash.php:144121 #: includes/src/Gateway.php:180 114 122 msgid "Logs additional information. <br>Log file path: Your admin panel -> WooCommerce -> System Status -> Logs" 115 123 msgstr "" 116 124 117 #: includes/src/Gateway Bayarcash.php:147125 #: includes/src/Gateway.php:183 118 126 msgid "Place order text" 119 127 msgstr "" 120 128 121 #: includes/src/Gateway Bayarcash.php:149129 #: includes/src/Gateway.php:185 122 130 msgid "This is the text for Place Order button." 123 131 msgstr "" 124 132 125 #: includes/src/Gateway Bayarcash.php:151133 #: includes/src/Gateway.php:187 126 134 msgid "Pay with Bayarcash" 127 135 msgstr "" 128 136 129 #: includes/src/Gateway Bayarcash.php:152137 #: includes/src/Gateway.php:188 130 138 msgid "This is the text for Place Order button" 131 139 msgstr "" 132 140 133 #: includes/src/Gateway Bayarcash.php:189141 #: includes/src/Gateway.php:225 134 142 msgid "Personal Access Token (PAT) is empty" 135 143 msgstr "" 136 144 137 #: includes/src/Gateway Bayarcash.php:193145 #: includes/src/Gateway.php:229 138 146 msgid "Portal Key is empty" 139 147 msgstr "" 148 149 #: includes/src/Gateway.php:244 150 msgid "Subscription can't checkout with non subscription items" 151 msgstr "" 152 153 #: includes/src/Gateway.php:246 154 msgid "Subscription can't checkout with more than one subscriptions" 155 msgstr "" -
bayarcash-wc/trunk/bayarcash-wc.php
r2988685 r3003078 29 29 \defined('ABSPATH') && !\defined('BAYARCASH_WC') || exit; 30 30 31 \define('BAYARCASH_WC', [ 32 'SLUG' => 'bayarcash-wc', 33 'FILE' => __FILE__, 34 'HOOK' => plugin_basename(__FILE__), 35 'PATH' => realpath(plugin_dir_path(__FILE__)), 36 'URL' => trailingslashit(plugin_dir_url(__FILE__)), 37 'ENDPOINT' => [ 38 'PUBLIC' => 'https://console.bayar.cash', 39 'PRIVATE' => 'https://console.bayarcash.dev', 40 ], 41 ]); 31 \define( 32 'BAYARCASH_WC', 33 [ 34 'SLUG' => 'bayarcash-wc', 35 'FILE' => __FILE__, 36 'HOOK' => plugin_basename(__FILE__), 37 'PATH' => realpath(plugin_dir_path(__FILE__)), 38 'URL' => trailingslashit(plugin_dir_url(__FILE__)), 39 'ENDPOINT' => [ 40 'PUBLIC' => 'https://console.bayar.cash', 41 'PRIVATE' => 'https://console.bayarcash.dev', 42 ], 43 ] 44 ); 42 45 43 46 require __DIR__.'/includes/load.php'; -
bayarcash-wc/trunk/includes/admin/bayarcash-wc-checkout.js
r2988685 r3003078 1 1 ( function( $ ) { 2 2 /* custom_order_button_text */ 3 $( "form.checkout" ) 4 .on( 5 "change", 6 "input[name^=payment_method]", 7 function() { 8 $( document.body ).trigger( "update_checkout" ); 9 } 10 ); 3 $( 'form.checkout' ).on( 4 'change', 5 'input[name^=payment_method]', 6 function() { 7 $( document.body ).trigger( 'update_checkout' ); 8 } 9 ); 11 10 } )( jQuery ); -
bayarcash-wc/trunk/includes/admin/bayarcash-wc-script.js
r2988685 r3003078 37 37 } 38 38 39 let is_sandbox_mode = $( 'input[type=checkbox]#woocommerce_bayarcash-wc_sandbox_mode' ).is( ':checked' ) ? 1 : 0; 40 39 41 $.ajax( { 40 42 url: config.ajaxurl, … … 47 49 "type": 'verify', 48 50 'bearer_token': token, 49 ' reset': is_reset,51 'sandbox_mode': is_sandbox_mode, 50 52 'nocache': ( new Date().getTime() ), 51 53 }, -
bayarcash-wc/trunk/includes/helpers.php
r2988685 r3003078 13 13 \defined('ABSPATH') || exit; 14 14 15 function get_plugin_meta()15 function bayarcash_plugin_meta() 16 16 { 17 17 static $meta = null; … … 24 24 } 25 25 26 function get_version()27 { 28 return get_plugin_meta()['Version'];29 } 30 31 function data_request()26 function bayarcash_version() 27 { 28 return bayarcash_plugin_meta()['Version']; 29 } 30 31 function bayarcash_request_data() 32 32 { 33 33 static $inst = null; … … 39 39 } 40 40 41 function data_store()41 function bayarcash_data_store() 42 42 { 43 43 static $inst = null; … … 49 49 } 50 50 51 function is_fpx_transaction_status($status, $match) 51 function bayarcash_encryption() 52 { 53 static $inst = null; 54 if (null === $inst) { 55 $inst = new \BayarCash\WooCommerce\Nawawi\Utils\Base64Encryption(); 56 } 57 58 return $inst; 59 } 60 61 function bayarcash_return_token_set($data, $key, $type = 'fpx') 62 { 63 $str = $data.'|'.substr(md5($data), 0, 12).'|'.$type; 64 65 return bayarcash_encryption()->encrypt($str, $key); 66 } 67 68 function bayarcash_return_token_get($data, $key, $type) 69 { 70 $str = bayarcash_encryption()->decrypt($data, $key); 71 if ($str === $data || false === strpos($str, '|'.$type)) { 72 return false; 73 } 74 75 $str_a = explode('|', $str); 76 if ($str_a[2] !== $type) { 77 return false; 78 } 79 80 return (object) [ 81 'data' => $str_a[0], 82 'data_id' => $str_a[1], 83 'type' => $str_a[2], 84 ]; 85 } 86 87 function bayarcash_has_fpx_transaction_status($status, $match) 52 88 { 53 89 $lists = [ … … 68 104 } 69 105 70 function get_response_data($type = '')106 function bayarcash_populate_response_data($type = '') 71 107 { 72 108 if (empty($_POST)) { … … 193 229 } 194 230 195 function get_config() 231 function bayarcash_strip_whitespace($string) 232 { 233 return preg_replace('@[\s\n\r\t]+@s', '', $string); 234 } 235 236 function bayarcash_gateway_config() 196 237 { 197 238 if (!\function_exists('WC')) { … … 208 249 } 209 250 210 function get_endpoint()211 { 212 $config = get_config();251 function bayarcash_endpoint() 252 { 253 $config = bayarcash_gateway_config(); 213 254 214 255 if (!$config || empty($config->settings['sandbox_mode'])) { … … 219 260 } 220 261 221 function get_tokens()222 { 223 $config = get_config();262 function bayarcash_gateway_tokens() 263 { 264 $config = bayarcash_gateway_config(); 224 265 225 266 if (!$config || !isset($config->settings['portal_key']) || !isset($config->settings['bearer_token'])) { … … 230 271 } 231 272 232 $bearer_token = preg_replace('@[\s\n\r\t]+@s', '',$config->settings['portal_key']);233 $portal_key = preg_replace('@[\s\n\r\t]+@s', '',$config->settings['bearer_token']);273 $bearer_token = bayarcash_strip_whitespace($config->settings['portal_key']); 274 $portal_key = bayarcash_strip_whitespace($config->settings['bearer_token']); 234 275 235 276 return [ … … 239 280 } 240 281 241 function debug_log($text)282 function bayarcash_debug_log($text) 242 283 { 243 284 if (!\defined('BAYARCASH_GIVEWP_DEBUG') || true !== (bool) BAYARCASH_GIVEWP_DEBUG) { -
bayarcash-wc/trunk/includes/load.php
r2988685 r3003078 9 9 */ 10 10 \defined('ABSPATH') || exit; 11 require_once __DIR__.'/src/CronEvent.php'; 12 require_once __DIR__.'/src/DataRequest.php'; 13 require_once __DIR__.'/src/DataStore.php'; 11 require_once __DIR__.'/vendor/autoload.php'; 14 12 require_once __DIR__.'/helpers.php'; 15 require_once __DIR__.'/src/Bayarcash.php'; -
bayarcash-wc/trunk/includes/src/Bayarcash.php
r2988685 r3003078 64 64 'woocommerce_payment_gateways', 65 65 function ($gateways) { 66 $gateways[] = ' GatewayBayarcash';66 $gateways[] = '\\BayarCash\\WooCommerce\\Gateway'; 67 67 68 68 return $gateways; … … 74 74 function () { 75 75 if ($this->is_woocommerce_activated()) { 76 require_once __DIR__.'/Gateway Bayarcash.php';76 require_once __DIR__.'/Gateway.php'; 77 77 } 78 78 … … 90 90 } 91 91 92 $version = get_version().'c'.date('Ymdh');92 $version = bayarcash_version().'c'.date('Ymdh'); 93 93 wp_enqueue_script($this->slug.'-script', $this->url.'includes/admin/bayarcash-wc-script.js', ['jquery'], $version, false); 94 94 wp_localize_script( … … 127 127 function () { 128 128 if (!check_ajax_referer('bayarcash-wc-token-nonce', 'token', false) && !isset($_POST['type'])) { 129 delete_transient('bayarcash-wc-verfiy-token');130 129 wp_send_json_error('Invalid security token sent.'); 131 130 exit; 132 131 } 133 132 134 if (!empty($_POST['reset'])) {135 delete_transient('bayarcash-wc-verfiy-token');136 }137 138 133 $type = sanitize_text_field($_POST['type']); 139 134 140 135 if ('verify' === $type) { 141 if (get_transient('bayarcash-wc-verfiy-token')) {142 wp_send_json(['is_verified' => 1]);143 exit;144 }145 146 136 if (empty($_POST['bearer_token'])) { 147 137 wp_send_json_error($this->slug.':script: "'.$type.'" invalid request'); 148 138 } 149 139 150 $token = sanitize_text_field($_POST['bearer_token']); 151 $is_verified = data_request()->is_token_verified(['bearer_token' => $token]); 152 153 if ($is_verified) { 154 set_transient('bayarcash-wc-verfiy-token', 1, MINUTE_IN_SECONDS * 3); 155 } 140 $token = sanitize_text_field($_POST['bearer_token']); 141 $is_sandbox_mode = !empty($_POST['sandbox_mode']); 142 $is_verified = bayarcash_request_data()->is_token_verified(['bearer_token' => $token, 'local_sandbox_mode' => $is_sandbox_mode]); 156 143 157 144 wp_send_json(['is_verified' => $is_verified ? 1 : 0]); … … 159 146 } 160 147 161 delete_transient('bayarcash-wc-verfiy-token');162 148 wp_send_json_error($this->slug.':script: "'.$type.'" not available'); 163 149 exit; … … 168 154 public function is_woocommerce_activated() 169 155 { 170 return class_exists('WooCommerce' );156 return class_exists('WooCommerce', false) && class_exists('WC_Payment_Gateway', false); 171 157 } 172 158 -
bayarcash-wc/trunk/includes/src/CronEvent.php
r2988685 r3003078 61 61 62 62 if (empty($orders_pending)) { 63 debug_log('No pending payment orders detected');63 bayarcash_debug_log('No pending payment orders detected'); 64 64 65 65 return; … … 79 79 80 80 if (empty($transaction_exchange_nos_cleaned)) { 81 debug_log('No pending payment orders detected');81 bayarcash_debug_log('No pending payment orders detected'); 82 82 83 83 return; … … 85 85 86 86 foreach ($transaction_exchange_nos_cleaned as $transaction_exchange_no) { 87 debug_log(sprintf('Transaction exchange to requery: ', $transaction_exchange_no));87 bayarcash_debug_log(sprintf('Transaction exchange to requery: ', $transaction_exchange_no)); 88 88 89 89 $data = [ 90 'bearer_token' => get_tokens()->bearer_token,90 'bearer_token' => bayarcash_gateway_tokens()->bearer_token, 91 91 'FPX_OrderRefNo' => $transaction_exchange_no, 92 92 ]; 93 93 94 $response_data = data_request()->check_payment_status($data);95 data_store()->update_payment_fpx($response_data);94 $response_data = bayarcash_request_data()->check_payment_status($data); 95 bayarcash_data_store()->update_payment_fpx($response_data); 96 96 } 97 97 } -
bayarcash-wc/trunk/includes/src/DataRequest.php
r2988685 r3003078 30 30 private function send($param, $endpoint_url) 31 31 { 32 $meta = get_plugin_meta();32 $meta = bayarcash_plugin_meta(); 33 33 $ua_nam = strtolower(str_replace(' ', '-', $meta['Name'])); 34 34 $ua_ver = $meta['Version']; … … 67 67 } 68 68 69 public function check_payment_status(array $data, $ is_verify_only= false)69 public function check_payment_status(array $data, $local_endpoint = false) 70 70 { 71 $bearer_token = preg_replace('@[\s\n\r\t]+@s', '', $data['bearer_token']); 72 $endpoint = get_endpoint(); 71 $bearer_token = bayarcash_strip_whitespace($data['bearer_token']); 72 $endpoint = false === $local_endpoint ? bayarcash_endpoint() : $local_endpoint; 73 $endpoint_url = $endpoint.'/api/transactions/'; 73 74 74 75 if (!empty($data['FPX_OrderRefNo'])) { 75 76 $endpoint_url = $endpoint.'/api/transactions/?RefNo='.$data['FPX_OrderRefNo']; 76 }77 78 if ($is_verify_only) {79 $endpoint_url = $endpoint.'/api/transactions/';80 77 } 81 78 … … 102 99 public function is_token_verified(array $data) 103 100 { 104 $response = $this->check_payment_status($data, true); 101 if (!isset($data['bearer_token'], $data['local_sandbox_mode'])) { 102 return false; 103 } 104 105 $local_endpoint = false; 106 if (!empty($data['local_sandbox_mode'])) { 107 $local_endpoint = BAYARCASH_WC['ENDPOINT']['PRIVATE']; 108 } 109 110 $response = $this->check_payment_status($data, $local_endpoint); 105 111 if (!$response) { 112 return false; 113 } 114 115 $response_object = json_decode($response); 116 if (empty($response_object->output->transactionsList->recordsListData)) { 106 117 return false; 107 118 } -
bayarcash-wc/trunk/includes/src/DataStore.php
r2988685 r3003078 28 28 $order_no = $order_details->get_id(); 29 29 30 if ( is_fpx_transaction_status($records->status, 'successful')) {30 if (bayarcash_has_fpx_transaction_status($records->status, 'successful')) { 31 31 delete_post_meta($order_no, 'bayarcash_wc_transaction_exchange_no'); 32 32 … … 44 44 } 45 45 46 if ( is_fpx_transaction_status($records->status, 'unsuccessful') || is_fpx_transaction_status($records->status, 'cancelled') && $order_details->needs_payment()) {46 if (bayarcash_has_fpx_transaction_status($records->status, 'unsuccessful') || bayarcash_has_fpx_transaction_status($records->status, 'cancelled') && $order_details->needs_payment()) { 47 47 delete_post_meta($order_no, 'bayarcash_wc_transaction_exchange_no'); 48 48 … … 62 62 private function get_order_note(string $message, $records): string 63 63 { 64 $transaction_url = get_endpoint().'/transactions?ref_no='.$records->exchange_order_no;64 $transaction_url = bayarcash_endpoint().'/transactions?ref_no='.$records->exchange_order_no; 65 65 $transaction_date = date('j F Y', strtotime($records->datetime)); 66 66 $transaction_time = date('h:i:s A', strtotime($records->datetime)); -
bayarcash-wc/trunk/languages/bayarcash-wc.pot
r2988685 r3003078 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "Content-Transfer-Encoding: 8bit\n" 12 "POT-Creation-Date: 2023-11- 03T19:17:54+00:00\n"12 "POT-Creation-Date: 2023-11-27T20:06:22+00:00\n" 13 13 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 14 "X-Generator: WP-CLI 2.7.1\n" … … 43 43 msgstr "" 44 44 45 #: includes/src/Bayarcash.php:1 7745 #: includes/src/Bayarcash.php:163 46 46 msgid "Bayarcash require WooCommerce plugin. Please install and activate." 47 47 msgstr "" 48 48 49 #: includes/src/GatewayBayarcash.php:78 49 #: includes/src/Gateway.php:102 50 msgid "Please enter Portal key" 51 msgstr "" 52 53 #: includes/src/Gateway.php:105 54 msgid "Please enter Personal Access Token (PAT)" 55 msgstr "" 56 57 #: includes/src/Gateway.php:114 50 58 msgid "Return to payments" 51 59 msgstr "" 52 60 53 #: includes/src/Gateway Bayarcash.php:8161 #: includes/src/Gateway.php:117 54 62 msgid "Allow customers to pay with Bayarcash." 55 63 msgstr "" 56 64 57 #: includes/src/Gateway Bayarcash.php:9365 #: includes/src/Gateway.php:129 58 66 msgid "Enable/Disable" 59 67 msgstr "" 60 68 61 #: includes/src/Gateway Bayarcash.php:9562 #: includes/src/Gateway Bayarcash.php:9669 #: includes/src/Gateway.php:131 70 #: includes/src/Gateway.php:132 63 71 msgid "Enable Bayarcash payment platform" 64 72 msgstr "" 65 73 66 #: includes/src/Gateway Bayarcash.php:10174 #: includes/src/Gateway.php:137 67 75 msgid "Sandbox Mode" 68 76 msgstr "" 69 77 70 #: includes/src/Gateway Bayarcash.php:10371 #: includes/src/Gateway Bayarcash.php:10478 #: includes/src/Gateway.php:139 79 #: includes/src/Gateway.php:140 72 80 msgid "Enable Sandbox Mode" 73 81 msgstr "" 74 82 75 #: includes/src/Gateway Bayarcash.php:10983 #: includes/src/Gateway.php:145 76 84 msgid "Title" 77 85 msgstr "" 78 86 79 #: includes/src/Gateway Bayarcash.php:11187 #: includes/src/Gateway.php:147 80 88 msgid "This is the title the user sees during checkout." 81 89 msgstr "" 82 90 83 #: includes/src/Gateway Bayarcash.php:11791 #: includes/src/Gateway.php:153 84 92 msgid "Description" 85 93 msgstr "" 86 94 87 #: includes/src/Gateway Bayarcash.php:11995 #: includes/src/Gateway.php:155 88 96 msgid "This is the description the user sees during checkout." 89 97 msgstr "" 90 98 91 #: includes/src/Gateway Bayarcash.php:12199 #: includes/src/Gateway.php:157 92 100 msgid "Pay for your items securely with Bayarcash" 93 101 msgstr "" 94 102 95 #: includes/src/Gateway Bayarcash.php:124103 #: includes/src/Gateway.php:160 96 104 msgid "Personal Access Token (PAT)" 97 105 msgstr "" 98 106 99 #: includes/src/Gateway Bayarcash.php:126100 #: includes/src/Gateway Bayarcash.php:127107 #: includes/src/Gateway.php:162 108 #: includes/src/Gateway.php:163 101 109 msgid "Fill in your Bayarcash PAT here" 102 110 msgstr "" 103 111 104 #: includes/src/Gateway Bayarcash.php:132112 #: includes/src/Gateway.php:168 105 113 msgid "Portal Key" 106 114 msgstr "" 107 115 108 #: includes/src/Gateway Bayarcash.php:134109 #: includes/src/Gateway Bayarcash.php:135116 #: includes/src/Gateway.php:170 117 #: includes/src/Gateway.php:171 110 118 msgid "Fill in your Bayarcash portal key here" 111 119 msgstr "" 112 120 113 #: includes/src/Gateway Bayarcash.php:144121 #: includes/src/Gateway.php:180 114 122 msgid "Logs additional information. <br>Log file path: Your admin panel -> WooCommerce -> System Status -> Logs" 115 123 msgstr "" 116 124 117 #: includes/src/Gateway Bayarcash.php:147125 #: includes/src/Gateway.php:183 118 126 msgid "Place order text" 119 127 msgstr "" 120 128 121 #: includes/src/Gateway Bayarcash.php:149129 #: includes/src/Gateway.php:185 122 130 msgid "This is the text for Place Order button." 123 131 msgstr "" 124 132 125 #: includes/src/Gateway Bayarcash.php:151133 #: includes/src/Gateway.php:187 126 134 msgid "Pay with Bayarcash" 127 135 msgstr "" 128 136 129 #: includes/src/Gateway Bayarcash.php:152137 #: includes/src/Gateway.php:188 130 138 msgid "This is the text for Place Order button" 131 139 msgstr "" 132 140 133 #: includes/src/Gateway Bayarcash.php:189141 #: includes/src/Gateway.php:225 134 142 msgid "Personal Access Token (PAT) is empty" 135 143 msgstr "" 136 144 137 #: includes/src/Gateway Bayarcash.php:193145 #: includes/src/Gateway.php:229 138 146 msgid "Portal Key is empty" 139 147 msgstr "" 148 149 #: includes/src/Gateway.php:244 150 msgid "Subscription can't checkout with non subscription items" 151 msgstr "" 152 153 #: includes/src/Gateway.php:246 154 msgid "Subscription can't checkout with more than one subscriptions" 155 msgstr ""
Note: See TracChangeset
for help on using the changeset viewer.