Changeset 2891245
- Timestamp:
- 03/31/2023 12:13:46 PM (3 years ago)
- Location:
- chaiport-payment/trunk
- Files:
-
- 2 edited
-
chaiportGateway.php (modified) (7 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
chaiport-payment/trunk/chaiportGateway.php
r2888142 r2891245 4 4 * Plugin URI: https://www.docs.portone.cloud/plugins_and_sdks/woocommerce-plugin.html 5 5 * Description: Single Payment 6 * Version: 2.0. 56 * Version: 2.0.6 7 7 * Requires at least: 5.6 8 8 * Author: PortOne … … 56 56 * This filter adds a custom bulk edit option to fetch order status 57 57 */ 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 //} 64 64 65 65 … … 691 691 692 692 $merchantOrder = $publicKey . "-" . $order->get_id(); 693 $pl = $this->getPL($merchantOrder, $publicKey, $secretKey); 694 if (strlen($pl) > 0) { 695 $merchantOrder = $this->getRandomStringRandomInt( 4 ) . "_" . $merchantOrder; 696 } 693 697 694 698 $order->add_order_note("PortOne OrderId: $merchantOrder"); … … 892 896 893 897 /** 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 /** 894 939 * Custom Process Payment Method 895 940 * @param String $order_id WC Order Id … … 901 946 $order = wc_get_order($order_id); 902 947 $woocommerce->session->set(self::SESSION_KEY, get_bloginfo('name') . "-" . $order_id); 903 $woocommerce->cart->empty_cart();948 //$woocommerce->cart->empty_cart(); 904 949 905 950 $orderKey = $this->getOrderKey($order); … … 1096 1141 1097 1142 /* 1098 * Method to print required data in console1143 * Method to print required data in console 1099 1144 * PLEASE USE WHILE DEBUG ONLY OR IMPORTANT LOGGING 1100 */1145 */ 1101 1146 public function console_log($message, $data) 1102 1147 { … … 1108 1153 echo '</script>'; 1109 1154 } 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 } 1110 1174 } 1111 1175 } -
chaiport-payment/trunk/readme.txt
r2888142 r2891245 4 4 Requires at least: 3.9.2 5 5 Tested up to: 6.1.1 6 Stable tag: 2.0. 56 Stable tag: 2.0.6 7 7 Requires PHP: 5.6 8 8 License: GPLv2 or later
Note: See TracChangeset
for help on using the changeset viewer.