Plugin Directory

Changeset 2891245


Ignore:
Timestamp:
03/31/2023 12:13:46 PM (3 years ago)
Author:
chaifinport
Message:

adding cart session management support

Location:
chaiport-payment/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • chaiport-payment/trunk/chaiportGateway.php

    r2888142 r2891245  
    44 * Plugin URI:        https://www.docs.portone.cloud/plugins_and_sdks/woocommerce-plugin.html
    55 * Description:       Single Payment
    6  * Version:           2.0.5
     6 * Version:           2.0.6
    77 * Requires at least: 5.6
    88 * Author:            PortOne
     
    5656 * This filter adds a custom bulk edit option to fetch order status
    5757 */
    58 add_filter('bulk_actions-edit-shop_order', 'chaiport_fetch_status_bulk_actions', 10, 1);
    59 function chaiport_fetch_status_bulk_actions($actions)
    60 {
    61     $actions['fetch_status'] = __('Fetch transaction status from PortOne', 'woocommerce');
    62     return $actions;
    63 }
     58//add_filter('bulk_actions-edit-shop_order', 'chaiport_fetch_status_bulk_actions', 10, 1);
     59//function chaiport_fetch_status_bulk_actions($actions)
     60//{
     61//  $actions['fetch_status'] = __('Fetch transaction status from PortOne', 'woocommerce');
     62//  return $actions;
     63//}
    6464
    6565
     
    691691
    692692            $merchantOrder = $publicKey . "-" . $order->get_id();
     693            $pl = $this->getPL($merchantOrder, $publicKey, $secretKey);
     694            if (strlen($pl) > 0) {
     695                $merchantOrder = $this->getRandomStringRandomInt( 4 ) . "_" . $merchantOrder;
     696            }
    693697
    694698            $order->add_order_note("PortOne OrderId: $merchantOrder");
     
    892896
    893897        /**
     898         * Fetch Payment Link Method
     899         */
     900        function getPL($order_id, $publicKey, $privateKey) {
     901            $apiUrl = "https://api.portone.cloud/api/paymentLink/" . $order_id . "/status";
     902            // Create token header as a JSON string
     903            $jwt_header = json_encode(['typ' => 'JWT', 'alg' => 'HS256']);
     904            $encodeData = array(
     905                "iss" => "CHAIPAY",
     906                "sub" => $publicKey,
     907                "iat" => time(),
     908                "exp" => time() + 500
     909            );
     910            $payload = json_encode($encodeData);
     911
     912            $base64UrlHeader = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($jwt_header));
     913            $base64UrlPayload = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($payload));
     914            $signature = hash_hmac('sha256', $base64UrlHeader . "." . $base64UrlPayload, $privateKey, true);
     915            $base64UrlSignature = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($signature));
     916            // Create JWT
     917            $token = $base64UrlHeader . "." . $base64UrlPayload . "." . $base64UrlSignature;
     918
     919            $header = array(
     920                'headers' => array(
     921                    'X-Chaipay-Client-Key' => $publicKey,
     922                    'Authorization' => "Bearer " . $token
     923                )
     924            );
     925
     926            $response = wp_remote_get($apiUrl, $header);
     927            $this->console_log("Existing PL: ", $response);
     928            if (wp_remote_retrieve_response_code($response) == 200) {
     929                $result = wp_remote_retrieve_body( $response );
     930                $data = json_decode($result, true);
     931                return $data['content']['link'];
     932            } else {
     933                return "";
     934            }
     935        }
     936
     937
     938        /**
    894939         * Custom Process Payment Method
    895940         * @param String $order_id WC Order Id
     
    901946            $order = wc_get_order($order_id);
    902947            $woocommerce->session->set(self::SESSION_KEY, get_bloginfo('name') . "-" . $order_id);
    903             $woocommerce->cart->empty_cart();
     948            //$woocommerce->cart->empty_cart();
    904949
    905950            $orderKey = $this->getOrderKey($order);
     
    10961141
    10971142        /*
    1098         * Method to print required data in console
     1143        * Method to print required data in console
    10991144         * PLEASE USE WHILE DEBUG ONLY OR IMPORTANT LOGGING
    1100         */
     1145        */
    11011146        public function console_log($message, $data)
    11021147        {
     
    11081153            echo '</script>';
    11091154        }
     1155
     1156
     1157        /**
     1158         * Uses random_int as core logic and generates a random string
     1159         * random_int is a pseudorandom number generator
     1160         *
     1161         * @param int $length
     1162         * @return string
     1163         */
     1164        function getRandomStringRandomInt($length = 16)
     1165        {
     1166            $stringSpace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
     1167            $pieces = [];
     1168            $max = mb_strlen($stringSpace, '8bit') - 1;
     1169            for ($i = 0; $i < $length; ++ $i) {
     1170                $pieces[] = $stringSpace[random_int(0, $max)];
     1171            }
     1172            return implode('', $pieces);
     1173        }
    11101174    }
    11111175}
  • chaiport-payment/trunk/readme.txt

    r2888142 r2891245  
    44Requires at least: 3.9.2
    55Tested up to: 6.1.1
    6 Stable tag: 2.0.5
     6Stable tag: 2.0.6
    77Requires PHP: 5.6
    88License: GPLv2 or later
Note: See TracChangeset for help on using the changeset viewer.