Plugin Directory

Changeset 3003078


Ignore:
Timestamp:
11/29/2023 06:54:54 AM (2 years ago)
Author:
bayarcash
Message:

Update latest file changes

Location:
bayarcash-wc
Files:
42 added
20 edited

Legend:

Unmodified
Added
Removed
  • bayarcash-wc/tags/3.0.0/bayarcash-wc.php

    r2988685 r3003078  
    2929\defined('ABSPATH') && !\defined('BAYARCASH_WC') || exit;
    3030
    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);
    4245
    4346require __DIR__.'/includes/load.php';
  • bayarcash-wc/tags/3.0.0/includes/admin/bayarcash-wc-checkout.js

    r2988685 r3003078  
    11( function( $ ) {
    22    /* 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    );
    1110} )( jQuery );
  • bayarcash-wc/tags/3.0.0/includes/admin/bayarcash-wc-script.js

    r2988685 r3003078  
    3737                }
    3838
     39                let is_sandbox_mode = $( 'input[type=checkbox]#woocommerce_bayarcash-wc_sandbox_mode' ).is( ':checked' ) ? 1 : 0;
     40
    3941                $.ajax( {
    4042                    url: config.ajaxurl,
     
    4749                        "type": 'verify',
    4850                        'bearer_token': token,
    49                         'reset': is_reset,
     51                        'sandbox_mode': is_sandbox_mode,
    5052                        'nocache': ( new Date().getTime() ),
    5153                    },
  • bayarcash-wc/tags/3.0.0/includes/helpers.php

    r2988685 r3003078  
    1313\defined('ABSPATH') || exit;
    1414
    15 function get_plugin_meta()
     15function bayarcash_plugin_meta()
    1616{
    1717    static $meta = null;
     
    2424}
    2525
    26 function get_version()
    27 {
    28     return get_plugin_meta()['Version'];
    29 }
    30 
    31 function data_request()
     26function bayarcash_version()
     27{
     28    return bayarcash_plugin_meta()['Version'];
     29}
     30
     31function bayarcash_request_data()
    3232{
    3333    static $inst = null;
     
    3939}
    4040
    41 function data_store()
     41function bayarcash_data_store()
    4242{
    4343    static $inst = null;
     
    4949}
    5050
    51 function is_fpx_transaction_status($status, $match)
     51function 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
     61function 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
     68function 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
     87function bayarcash_has_fpx_transaction_status($status, $match)
    5288{
    5389    $lists = [
     
    68104}
    69105
    70 function get_response_data($type = '')
     106function bayarcash_populate_response_data($type = '')
    71107{
    72108    if (empty($_POST)) {
     
    193229}
    194230
    195 function get_config()
     231function bayarcash_strip_whitespace($string)
     232{
     233    return preg_replace('@[\s\n\r\t]+@s', '', $string);
     234}
     235
     236function bayarcash_gateway_config()
    196237{
    197238    if (!\function_exists('WC')) {
     
    208249}
    209250
    210 function get_endpoint()
    211 {
    212     $config = get_config();
     251function bayarcash_endpoint()
     252{
     253    $config = bayarcash_gateway_config();
    213254
    214255    if (!$config || empty($config->settings['sandbox_mode'])) {
     
    219260}
    220261
    221 function get_tokens()
    222 {
    223     $config = get_config();
     262function bayarcash_gateway_tokens()
     263{
     264    $config = bayarcash_gateway_config();
    224265
    225266    if (!$config || !isset($config->settings['portal_key']) || !isset($config->settings['bearer_token'])) {
     
    230271    }
    231272
    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']);
    234275
    235276    return [
     
    239280}
    240281
    241 function debug_log($text)
     282function bayarcash_debug_log($text)
    242283{
    243284    if (!\defined('BAYARCASH_GIVEWP_DEBUG') || true !== (bool) BAYARCASH_GIVEWP_DEBUG) {
  • bayarcash-wc/tags/3.0.0/includes/load.php

    r2988685 r3003078  
    99 */
    1010\defined('ABSPATH') || exit;
    11 require_once __DIR__.'/src/CronEvent.php';
    12 require_once __DIR__.'/src/DataRequest.php';
    13 require_once __DIR__.'/src/DataStore.php';
     11require_once __DIR__.'/vendor/autoload.php';
    1412require_once __DIR__.'/helpers.php';
    15 require_once __DIR__.'/src/Bayarcash.php';
  • bayarcash-wc/tags/3.0.0/includes/src/Bayarcash.php

    r2988685 r3003078  
    6464            'woocommerce_payment_gateways',
    6565            function ($gateways) {
    66                 $gateways[] = 'GatewayBayarcash';
     66                $gateways[] = '\\BayarCash\\WooCommerce\\Gateway';
    6767
    6868                return $gateways;
     
    7474            function () {
    7575                if ($this->is_woocommerce_activated()) {
    76                     require_once __DIR__.'/GatewayBayarcash.php';
     76                    require_once __DIR__.'/Gateway.php';
    7777                }
    7878
     
    9090                }
    9191
    92                 $version = get_version().'c'.date('Ymdh');
     92                $version = bayarcash_version().'c'.date('Ymdh');
    9393                wp_enqueue_script($this->slug.'-script', $this->url.'includes/admin/bayarcash-wc-script.js', ['jquery'], $version, false);
    9494                wp_localize_script(
     
    127127            function () {
    128128                if (!check_ajax_referer('bayarcash-wc-token-nonce', 'token', false) && !isset($_POST['type'])) {
    129                     delete_transient('bayarcash-wc-verfiy-token');
    130129                    wp_send_json_error('Invalid security token sent.');
    131130                    exit;
    132131                }
    133132
    134                 if (!empty($_POST['reset'])) {
    135                     delete_transient('bayarcash-wc-verfiy-token');
    136                 }
    137 
    138133                $type = sanitize_text_field($_POST['type']);
    139134
    140135                if ('verify' === $type) {
    141                     if (get_transient('bayarcash-wc-verfiy-token')) {
    142                         wp_send_json(['is_verified' => 1]);
    143                         exit;
    144                     }
    145 
    146136                    if (empty($_POST['bearer_token'])) {
    147137                        wp_send_json_error($this->slug.':script: "'.$type.'" invalid request');
    148138                    }
    149139
    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]);
    156143
    157144                    wp_send_json(['is_verified' => $is_verified ? 1 : 0]);
     
    159146                }
    160147
    161                 delete_transient('bayarcash-wc-verfiy-token');
    162148                wp_send_json_error($this->slug.':script: "'.$type.'" not available');
    163149                exit;
     
    168154    public function is_woocommerce_activated()
    169155    {
    170         return class_exists('WooCommerce');
     156        return class_exists('WooCommerce', false) && class_exists('WC_Payment_Gateway', false);
    171157    }
    172158
  • bayarcash-wc/tags/3.0.0/includes/src/CronEvent.php

    r2988685 r3003078  
    6161
    6262        if (empty($orders_pending)) {
    63             debug_log('No pending payment orders detected');
     63            bayarcash_debug_log('No pending payment orders detected');
    6464
    6565            return;
     
    7979
    8080        if (empty($transaction_exchange_nos_cleaned)) {
    81             debug_log('No pending payment orders detected');
     81            bayarcash_debug_log('No pending payment orders detected');
    8282
    8383            return;
     
    8585
    8686        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));
    8888
    8989            $data = [
    90                 'bearer_token'   => get_tokens()->bearer_token,
     90                'bearer_token'   => bayarcash_gateway_tokens()->bearer_token,
    9191                'FPX_OrderRefNo' => $transaction_exchange_no,
    9292            ];
    9393
    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);
    9696        }
    9797    }
  • bayarcash-wc/tags/3.0.0/includes/src/DataRequest.php

    r2988685 r3003078  
    3030    private function send($param, $endpoint_url)
    3131    {
    32         $meta   = get_plugin_meta();
     32        $meta   = bayarcash_plugin_meta();
    3333        $ua_nam = strtolower(str_replace(' ', '-', $meta['Name']));
    3434        $ua_ver = $meta['Version'];
     
    6767    }
    6868
    69     public function check_payment_status(array $data, $is_verify_only = false)
     69    public function check_payment_status(array $data, $local_endpoint = false)
    7070    {
    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/';
    7374
    7475        if (!empty($data['FPX_OrderRefNo'])) {
    7576            $endpoint_url = $endpoint.'/api/transactions/?RefNo='.$data['FPX_OrderRefNo'];
    76         }
    77 
    78         if ($is_verify_only) {
    79             $endpoint_url = $endpoint.'/api/transactions/';
    8077        }
    8178
     
    10299    public function is_token_verified(array $data)
    103100    {
    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);
    105111        if (!$response) {
     112            return false;
     113        }
     114
     115        $response_object = json_decode($response);
     116        if (empty($response_object->output->transactionsList->recordsListData)) {
    106117            return false;
    107118        }
  • bayarcash-wc/tags/3.0.0/includes/src/DataStore.php

    r2988685 r3003078  
    2828        $order_no      = $order_details->get_id();
    2929
    30         if (is_fpx_transaction_status($records->status, 'successful')) {
     30        if (bayarcash_has_fpx_transaction_status($records->status, 'successful')) {
    3131            delete_post_meta($order_no, 'bayarcash_wc_transaction_exchange_no');
    3232
     
    4444        }
    4545
    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()) {
    4747            delete_post_meta($order_no, 'bayarcash_wc_transaction_exchange_no');
    4848
     
    6262    private function get_order_note(string $message, $records): string
    6363    {
    64         $transaction_url  = get_endpoint().'/transactions?ref_no='.$records->exchange_order_no;
     64        $transaction_url  = bayarcash_endpoint().'/transactions?ref_no='.$records->exchange_order_no;
    6565        $transaction_date = date('j F Y', strtotime($records->datetime));
    6666        $transaction_time = date('h:i:s A', strtotime($records->datetime));
  • bayarcash-wc/tags/3.0.0/languages/bayarcash-wc.pot

    r2988685 r3003078  
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"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"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1414"X-Generator: WP-CLI 2.7.1\n"
     
    4343msgstr ""
    4444
    45 #: includes/src/Bayarcash.php:177
     45#: includes/src/Bayarcash.php:163
    4646msgid "Bayarcash require WooCommerce plugin. Please install and activate."
    4747msgstr ""
    4848
    49 #: includes/src/GatewayBayarcash.php:78
     49#: includes/src/Gateway.php:102
     50msgid "Please enter Portal key"
     51msgstr ""
     52
     53#: includes/src/Gateway.php:105
     54msgid "Please enter Personal Access Token (PAT)"
     55msgstr ""
     56
     57#: includes/src/Gateway.php:114
    5058msgid "Return to payments"
    5159msgstr ""
    5260
    53 #: includes/src/GatewayBayarcash.php:81
     61#: includes/src/Gateway.php:117
    5462msgid "Allow customers to pay with Bayarcash."
    5563msgstr ""
    5664
    57 #: includes/src/GatewayBayarcash.php:93
     65#: includes/src/Gateway.php:129
    5866msgid "Enable/Disable"
    5967msgstr ""
    6068
    61 #: includes/src/GatewayBayarcash.php:95
    62 #: includes/src/GatewayBayarcash.php:96
     69#: includes/src/Gateway.php:131
     70#: includes/src/Gateway.php:132
    6371msgid "Enable Bayarcash payment platform"
    6472msgstr ""
    6573
    66 #: includes/src/GatewayBayarcash.php:101
     74#: includes/src/Gateway.php:137
    6775msgid "Sandbox Mode"
    6876msgstr ""
    6977
    70 #: includes/src/GatewayBayarcash.php:103
    71 #: includes/src/GatewayBayarcash.php:104
     78#: includes/src/Gateway.php:139
     79#: includes/src/Gateway.php:140
    7280msgid "Enable Sandbox Mode"
    7381msgstr ""
    7482
    75 #: includes/src/GatewayBayarcash.php:109
     83#: includes/src/Gateway.php:145
    7684msgid "Title"
    7785msgstr ""
    7886
    79 #: includes/src/GatewayBayarcash.php:111
     87#: includes/src/Gateway.php:147
    8088msgid "This is the title the user sees during checkout."
    8189msgstr ""
    8290
    83 #: includes/src/GatewayBayarcash.php:117
     91#: includes/src/Gateway.php:153
    8492msgid "Description"
    8593msgstr ""
    8694
    87 #: includes/src/GatewayBayarcash.php:119
     95#: includes/src/Gateway.php:155
    8896msgid "This is the description the user sees during checkout."
    8997msgstr ""
    9098
    91 #: includes/src/GatewayBayarcash.php:121
     99#: includes/src/Gateway.php:157
    92100msgid "Pay for your items securely with Bayarcash"
    93101msgstr ""
    94102
    95 #: includes/src/GatewayBayarcash.php:124
     103#: includes/src/Gateway.php:160
    96104msgid "Personal Access Token (PAT)"
    97105msgstr ""
    98106
    99 #: includes/src/GatewayBayarcash.php:126
    100 #: includes/src/GatewayBayarcash.php:127
     107#: includes/src/Gateway.php:162
     108#: includes/src/Gateway.php:163
    101109msgid "Fill in your Bayarcash PAT here"
    102110msgstr ""
    103111
    104 #: includes/src/GatewayBayarcash.php:132
     112#: includes/src/Gateway.php:168
    105113msgid "Portal Key"
    106114msgstr ""
    107115
    108 #: includes/src/GatewayBayarcash.php:134
    109 #: includes/src/GatewayBayarcash.php:135
     116#: includes/src/Gateway.php:170
     117#: includes/src/Gateway.php:171
    110118msgid "Fill in your Bayarcash portal key here"
    111119msgstr ""
    112120
    113 #: includes/src/GatewayBayarcash.php:144
     121#: includes/src/Gateway.php:180
    114122msgid "Logs additional information. <br>Log file path: Your admin panel -> WooCommerce -> System Status -> Logs"
    115123msgstr ""
    116124
    117 #: includes/src/GatewayBayarcash.php:147
     125#: includes/src/Gateway.php:183
    118126msgid "Place order text"
    119127msgstr ""
    120128
    121 #: includes/src/GatewayBayarcash.php:149
     129#: includes/src/Gateway.php:185
    122130msgid "This is the text for Place Order button."
    123131msgstr ""
    124132
    125 #: includes/src/GatewayBayarcash.php:151
     133#: includes/src/Gateway.php:187
    126134msgid "Pay with Bayarcash"
    127135msgstr ""
    128136
    129 #: includes/src/GatewayBayarcash.php:152
     137#: includes/src/Gateway.php:188
    130138msgid "This is the text for Place Order button"
    131139msgstr ""
    132140
    133 #: includes/src/GatewayBayarcash.php:189
     141#: includes/src/Gateway.php:225
    134142msgid "Personal Access Token (PAT) is empty"
    135143msgstr ""
    136144
    137 #: includes/src/GatewayBayarcash.php:193
     145#: includes/src/Gateway.php:229
    138146msgid "Portal Key is empty"
    139147msgstr ""
     148
     149#: includes/src/Gateway.php:244
     150msgid "Subscription can't checkout with non subscription items"
     151msgstr ""
     152
     153#: includes/src/Gateway.php:246
     154msgid "Subscription can't checkout with more than one subscriptions"
     155msgstr ""
  • bayarcash-wc/trunk/bayarcash-wc.php

    r2988685 r3003078  
    2929\defined('ABSPATH') && !\defined('BAYARCASH_WC') || exit;
    3030
    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);
    4245
    4346require __DIR__.'/includes/load.php';
  • bayarcash-wc/trunk/includes/admin/bayarcash-wc-checkout.js

    r2988685 r3003078  
    11( function( $ ) {
    22    /* 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    );
    1110} )( jQuery );
  • bayarcash-wc/trunk/includes/admin/bayarcash-wc-script.js

    r2988685 r3003078  
    3737                }
    3838
     39                let is_sandbox_mode = $( 'input[type=checkbox]#woocommerce_bayarcash-wc_sandbox_mode' ).is( ':checked' ) ? 1 : 0;
     40
    3941                $.ajax( {
    4042                    url: config.ajaxurl,
     
    4749                        "type": 'verify',
    4850                        'bearer_token': token,
    49                         'reset': is_reset,
     51                        'sandbox_mode': is_sandbox_mode,
    5052                        'nocache': ( new Date().getTime() ),
    5153                    },
  • bayarcash-wc/trunk/includes/helpers.php

    r2988685 r3003078  
    1313\defined('ABSPATH') || exit;
    1414
    15 function get_plugin_meta()
     15function bayarcash_plugin_meta()
    1616{
    1717    static $meta = null;
     
    2424}
    2525
    26 function get_version()
    27 {
    28     return get_plugin_meta()['Version'];
    29 }
    30 
    31 function data_request()
     26function bayarcash_version()
     27{
     28    return bayarcash_plugin_meta()['Version'];
     29}
     30
     31function bayarcash_request_data()
    3232{
    3333    static $inst = null;
     
    3939}
    4040
    41 function data_store()
     41function bayarcash_data_store()
    4242{
    4343    static $inst = null;
     
    4949}
    5050
    51 function is_fpx_transaction_status($status, $match)
     51function 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
     61function 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
     68function 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
     87function bayarcash_has_fpx_transaction_status($status, $match)
    5288{
    5389    $lists = [
     
    68104}
    69105
    70 function get_response_data($type = '')
     106function bayarcash_populate_response_data($type = '')
    71107{
    72108    if (empty($_POST)) {
     
    193229}
    194230
    195 function get_config()
     231function bayarcash_strip_whitespace($string)
     232{
     233    return preg_replace('@[\s\n\r\t]+@s', '', $string);
     234}
     235
     236function bayarcash_gateway_config()
    196237{
    197238    if (!\function_exists('WC')) {
     
    208249}
    209250
    210 function get_endpoint()
    211 {
    212     $config = get_config();
     251function bayarcash_endpoint()
     252{
     253    $config = bayarcash_gateway_config();
    213254
    214255    if (!$config || empty($config->settings['sandbox_mode'])) {
     
    219260}
    220261
    221 function get_tokens()
    222 {
    223     $config = get_config();
     262function bayarcash_gateway_tokens()
     263{
     264    $config = bayarcash_gateway_config();
    224265
    225266    if (!$config || !isset($config->settings['portal_key']) || !isset($config->settings['bearer_token'])) {
     
    230271    }
    231272
    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']);
    234275
    235276    return [
     
    239280}
    240281
    241 function debug_log($text)
     282function bayarcash_debug_log($text)
    242283{
    243284    if (!\defined('BAYARCASH_GIVEWP_DEBUG') || true !== (bool) BAYARCASH_GIVEWP_DEBUG) {
  • bayarcash-wc/trunk/includes/load.php

    r2988685 r3003078  
    99 */
    1010\defined('ABSPATH') || exit;
    11 require_once __DIR__.'/src/CronEvent.php';
    12 require_once __DIR__.'/src/DataRequest.php';
    13 require_once __DIR__.'/src/DataStore.php';
     11require_once __DIR__.'/vendor/autoload.php';
    1412require_once __DIR__.'/helpers.php';
    15 require_once __DIR__.'/src/Bayarcash.php';
  • bayarcash-wc/trunk/includes/src/Bayarcash.php

    r2988685 r3003078  
    6464            'woocommerce_payment_gateways',
    6565            function ($gateways) {
    66                 $gateways[] = 'GatewayBayarcash';
     66                $gateways[] = '\\BayarCash\\WooCommerce\\Gateway';
    6767
    6868                return $gateways;
     
    7474            function () {
    7575                if ($this->is_woocommerce_activated()) {
    76                     require_once __DIR__.'/GatewayBayarcash.php';
     76                    require_once __DIR__.'/Gateway.php';
    7777                }
    7878
     
    9090                }
    9191
    92                 $version = get_version().'c'.date('Ymdh');
     92                $version = bayarcash_version().'c'.date('Ymdh');
    9393                wp_enqueue_script($this->slug.'-script', $this->url.'includes/admin/bayarcash-wc-script.js', ['jquery'], $version, false);
    9494                wp_localize_script(
     
    127127            function () {
    128128                if (!check_ajax_referer('bayarcash-wc-token-nonce', 'token', false) && !isset($_POST['type'])) {
    129                     delete_transient('bayarcash-wc-verfiy-token');
    130129                    wp_send_json_error('Invalid security token sent.');
    131130                    exit;
    132131                }
    133132
    134                 if (!empty($_POST['reset'])) {
    135                     delete_transient('bayarcash-wc-verfiy-token');
    136                 }
    137 
    138133                $type = sanitize_text_field($_POST['type']);
    139134
    140135                if ('verify' === $type) {
    141                     if (get_transient('bayarcash-wc-verfiy-token')) {
    142                         wp_send_json(['is_verified' => 1]);
    143                         exit;
    144                     }
    145 
    146136                    if (empty($_POST['bearer_token'])) {
    147137                        wp_send_json_error($this->slug.':script: "'.$type.'" invalid request');
    148138                    }
    149139
    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]);
    156143
    157144                    wp_send_json(['is_verified' => $is_verified ? 1 : 0]);
     
    159146                }
    160147
    161                 delete_transient('bayarcash-wc-verfiy-token');
    162148                wp_send_json_error($this->slug.':script: "'.$type.'" not available');
    163149                exit;
     
    168154    public function is_woocommerce_activated()
    169155    {
    170         return class_exists('WooCommerce');
     156        return class_exists('WooCommerce', false) && class_exists('WC_Payment_Gateway', false);
    171157    }
    172158
  • bayarcash-wc/trunk/includes/src/CronEvent.php

    r2988685 r3003078  
    6161
    6262        if (empty($orders_pending)) {
    63             debug_log('No pending payment orders detected');
     63            bayarcash_debug_log('No pending payment orders detected');
    6464
    6565            return;
     
    7979
    8080        if (empty($transaction_exchange_nos_cleaned)) {
    81             debug_log('No pending payment orders detected');
     81            bayarcash_debug_log('No pending payment orders detected');
    8282
    8383            return;
     
    8585
    8686        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));
    8888
    8989            $data = [
    90                 'bearer_token'   => get_tokens()->bearer_token,
     90                'bearer_token'   => bayarcash_gateway_tokens()->bearer_token,
    9191                'FPX_OrderRefNo' => $transaction_exchange_no,
    9292            ];
    9393
    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);
    9696        }
    9797    }
  • bayarcash-wc/trunk/includes/src/DataRequest.php

    r2988685 r3003078  
    3030    private function send($param, $endpoint_url)
    3131    {
    32         $meta   = get_plugin_meta();
     32        $meta   = bayarcash_plugin_meta();
    3333        $ua_nam = strtolower(str_replace(' ', '-', $meta['Name']));
    3434        $ua_ver = $meta['Version'];
     
    6767    }
    6868
    69     public function check_payment_status(array $data, $is_verify_only = false)
     69    public function check_payment_status(array $data, $local_endpoint = false)
    7070    {
    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/';
    7374
    7475        if (!empty($data['FPX_OrderRefNo'])) {
    7576            $endpoint_url = $endpoint.'/api/transactions/?RefNo='.$data['FPX_OrderRefNo'];
    76         }
    77 
    78         if ($is_verify_only) {
    79             $endpoint_url = $endpoint.'/api/transactions/';
    8077        }
    8178
     
    10299    public function is_token_verified(array $data)
    103100    {
    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);
    105111        if (!$response) {
     112            return false;
     113        }
     114
     115        $response_object = json_decode($response);
     116        if (empty($response_object->output->transactionsList->recordsListData)) {
    106117            return false;
    107118        }
  • bayarcash-wc/trunk/includes/src/DataStore.php

    r2988685 r3003078  
    2828        $order_no      = $order_details->get_id();
    2929
    30         if (is_fpx_transaction_status($records->status, 'successful')) {
     30        if (bayarcash_has_fpx_transaction_status($records->status, 'successful')) {
    3131            delete_post_meta($order_no, 'bayarcash_wc_transaction_exchange_no');
    3232
     
    4444        }
    4545
    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()) {
    4747            delete_post_meta($order_no, 'bayarcash_wc_transaction_exchange_no');
    4848
     
    6262    private function get_order_note(string $message, $records): string
    6363    {
    64         $transaction_url  = get_endpoint().'/transactions?ref_no='.$records->exchange_order_no;
     64        $transaction_url  = bayarcash_endpoint().'/transactions?ref_no='.$records->exchange_order_no;
    6565        $transaction_date = date('j F Y', strtotime($records->datetime));
    6666        $transaction_time = date('h:i:s A', strtotime($records->datetime));
  • bayarcash-wc/trunk/languages/bayarcash-wc.pot

    r2988685 r3003078  
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"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"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1414"X-Generator: WP-CLI 2.7.1\n"
     
    4343msgstr ""
    4444
    45 #: includes/src/Bayarcash.php:177
     45#: includes/src/Bayarcash.php:163
    4646msgid "Bayarcash require WooCommerce plugin. Please install and activate."
    4747msgstr ""
    4848
    49 #: includes/src/GatewayBayarcash.php:78
     49#: includes/src/Gateway.php:102
     50msgid "Please enter Portal key"
     51msgstr ""
     52
     53#: includes/src/Gateway.php:105
     54msgid "Please enter Personal Access Token (PAT)"
     55msgstr ""
     56
     57#: includes/src/Gateway.php:114
    5058msgid "Return to payments"
    5159msgstr ""
    5260
    53 #: includes/src/GatewayBayarcash.php:81
     61#: includes/src/Gateway.php:117
    5462msgid "Allow customers to pay with Bayarcash."
    5563msgstr ""
    5664
    57 #: includes/src/GatewayBayarcash.php:93
     65#: includes/src/Gateway.php:129
    5866msgid "Enable/Disable"
    5967msgstr ""
    6068
    61 #: includes/src/GatewayBayarcash.php:95
    62 #: includes/src/GatewayBayarcash.php:96
     69#: includes/src/Gateway.php:131
     70#: includes/src/Gateway.php:132
    6371msgid "Enable Bayarcash payment platform"
    6472msgstr ""
    6573
    66 #: includes/src/GatewayBayarcash.php:101
     74#: includes/src/Gateway.php:137
    6775msgid "Sandbox Mode"
    6876msgstr ""
    6977
    70 #: includes/src/GatewayBayarcash.php:103
    71 #: includes/src/GatewayBayarcash.php:104
     78#: includes/src/Gateway.php:139
     79#: includes/src/Gateway.php:140
    7280msgid "Enable Sandbox Mode"
    7381msgstr ""
    7482
    75 #: includes/src/GatewayBayarcash.php:109
     83#: includes/src/Gateway.php:145
    7684msgid "Title"
    7785msgstr ""
    7886
    79 #: includes/src/GatewayBayarcash.php:111
     87#: includes/src/Gateway.php:147
    8088msgid "This is the title the user sees during checkout."
    8189msgstr ""
    8290
    83 #: includes/src/GatewayBayarcash.php:117
     91#: includes/src/Gateway.php:153
    8492msgid "Description"
    8593msgstr ""
    8694
    87 #: includes/src/GatewayBayarcash.php:119
     95#: includes/src/Gateway.php:155
    8896msgid "This is the description the user sees during checkout."
    8997msgstr ""
    9098
    91 #: includes/src/GatewayBayarcash.php:121
     99#: includes/src/Gateway.php:157
    92100msgid "Pay for your items securely with Bayarcash"
    93101msgstr ""
    94102
    95 #: includes/src/GatewayBayarcash.php:124
     103#: includes/src/Gateway.php:160
    96104msgid "Personal Access Token (PAT)"
    97105msgstr ""
    98106
    99 #: includes/src/GatewayBayarcash.php:126
    100 #: includes/src/GatewayBayarcash.php:127
     107#: includes/src/Gateway.php:162
     108#: includes/src/Gateway.php:163
    101109msgid "Fill in your Bayarcash PAT here"
    102110msgstr ""
    103111
    104 #: includes/src/GatewayBayarcash.php:132
     112#: includes/src/Gateway.php:168
    105113msgid "Portal Key"
    106114msgstr ""
    107115
    108 #: includes/src/GatewayBayarcash.php:134
    109 #: includes/src/GatewayBayarcash.php:135
     116#: includes/src/Gateway.php:170
     117#: includes/src/Gateway.php:171
    110118msgid "Fill in your Bayarcash portal key here"
    111119msgstr ""
    112120
    113 #: includes/src/GatewayBayarcash.php:144
     121#: includes/src/Gateway.php:180
    114122msgid "Logs additional information. <br>Log file path: Your admin panel -> WooCommerce -> System Status -> Logs"
    115123msgstr ""
    116124
    117 #: includes/src/GatewayBayarcash.php:147
     125#: includes/src/Gateway.php:183
    118126msgid "Place order text"
    119127msgstr ""
    120128
    121 #: includes/src/GatewayBayarcash.php:149
     129#: includes/src/Gateway.php:185
    122130msgid "This is the text for Place Order button."
    123131msgstr ""
    124132
    125 #: includes/src/GatewayBayarcash.php:151
     133#: includes/src/Gateway.php:187
    126134msgid "Pay with Bayarcash"
    127135msgstr ""
    128136
    129 #: includes/src/GatewayBayarcash.php:152
     137#: includes/src/Gateway.php:188
    130138msgid "This is the text for Place Order button"
    131139msgstr ""
    132140
    133 #: includes/src/GatewayBayarcash.php:189
     141#: includes/src/Gateway.php:225
    134142msgid "Personal Access Token (PAT) is empty"
    135143msgstr ""
    136144
    137 #: includes/src/GatewayBayarcash.php:193
     145#: includes/src/Gateway.php:229
    138146msgid "Portal Key is empty"
    139147msgstr ""
     148
     149#: includes/src/Gateway.php:244
     150msgid "Subscription can't checkout with non subscription items"
     151msgstr ""
     152
     153#: includes/src/Gateway.php:246
     154msgid "Subscription can't checkout with more than one subscriptions"
     155msgstr ""
Note: See TracChangeset for help on using the changeset viewer.