Changeset 2707855
- Timestamp:
- 04/11/2022 08:02:00 AM (4 years ago)
- Location:
- valuepay-for-woocommerce/trunk
- Files:
-
- 6 edited
-
admin/settings.php (modified) (2 diffs)
-
includes/abstracts/abstract-valuepay-wc-client.php (modified) (6 diffs)
-
includes/class-valuepay-wc-gateway.php (modified) (5 diffs)
-
includes/functions.php (modified) (3 diffs)
-
readme.txt (modified) (3 diffs)
-
valuepay-wc.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
valuepay-for-woocommerce/trunk/admin/settings.php
r2701045 r2707855 31 31 'title' => __( 'API Credentials', 'valuepay-wc' ), 32 32 'type' => 'title', 33 'description' => __( 'API credentials can be obtained from ValuePay merchant dashboard underBusiness Profile page.', 'valuepay-wc' ),33 'description' => __( 'API credentials can be obtained from ValuePay merchant dashboard in Business Profile page.', 'valuepay-wc' ), 34 34 ), 35 35 'username' => array( … … 52 52 'title' => __( 'Collection ID', 'valuepay-wc' ), 53 53 'type' => 'text', 54 'description' => __( 'Collection information can be obtained from ValuePay merchant dashboard under FPX Payment menu, on My Collection List page. Leave blank to disable one time payment.', 'valuepay-wc' ),54 'description' => __( 'Collection ID can be obtained from ValuePay merchant dashboard under FPX Payment menu, in My Collection List page. Leave blank to disable one time payment.', 'valuepay-wc' ), 55 55 ), 56 56 'mandate_id' => array( 57 57 'title' => __( 'Mandate ID', 'valuepay-wc' ), 58 58 'type' => 'text', 59 'description' => __( 'Mandate ID can be obtained from ValuePay merchant dashboard under E-Mandate Collection menu, on My Mandate List page. Leave blank to disable recurring payment.', 'valuepay-wc' ),59 'description' => __( 'Mandate ID can be obtained from ValuePay merchant dashboard under E-Mandate Collection menu, in My Mandate List page. Leave blank to disable recurring payment.', 'valuepay-wc' ), 60 60 ), 61 61 'frequency_type' => array( -
valuepay-for-woocommerce/trunk/includes/abstracts/abstract-valuepay-wc-client.php
r2701045 r2707855 8 8 public $app_key; 9 9 public $app_secret; 10 protected $debug = false; 10 11 protected $debug = true; 11 12 12 13 // HTTP request headers … … 78 79 ); 79 80 } else { 80 throw new Exception( valuepay_wc_get_error_message( $response['wscode'] ) );81 throw new Exception( $this->get_formatted_error_message( $response['wscode'] ) ); 81 82 } 82 83 } … … 94 95 95 96 if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) { 96 $ data= file_get_contents( 'php://input' );97 $ data = json_decode( $data, true );97 $response = file_get_contents( 'php://input' ); 98 $response = json_decode( $response, true ); 98 99 } else { 99 $data = $_REQUEST; 100 } 101 102 $data = array_map( 'sanitize_text_field', $data ); 103 104 if ( empty( $data ) ) { 105 return false; 106 } 107 108 if ( !$formatted_data = $this->get_valid_ipn_response( $data ) ) { 109 return false; 110 } 111 112 return $formatted_data; 100 $response = $_REQUEST; 101 } 102 103 if ( !$response ) { 104 return false; 105 } 106 107 if ( !$formatted_response = $this->get_valid_ipn_response( $response ) ) { 108 return false; 109 } 110 111 return $formatted_response; 113 112 114 113 } 115 114 116 115 // Format IPN response data to only get accepted parameters 117 private function get_valid_ipn_response( array $ data) {116 private function get_valid_ipn_response( array $response ) { 118 117 119 118 if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) { … … 127 126 foreach ( $params as $param ) { 128 127 // Return false if required parameters is not passed to the URL 129 if ( !isset( $ data[ $param ] ) ) {128 if ( !isset( $response[ $param ] ) ) { 130 129 return false; 131 130 } 132 131 133 if ( is_array( $data[ $param ] ) ) { 134 $allowed_params[ $param ] = array_map( 'trim', $data[ $param ] ); 132 if ( is_array( $response[ $param ] ) ) { 133 $allowed_params[ $param ] = array_map( function( $value ) { 134 return trim( sanitize_text_field( $value ) ); 135 }, $response[ $param ] ); 135 136 } else { 136 $allowed_params[ $param ] = trim( $data[ $param ]);137 $allowed_params[ $param ] = trim( sanitize_text_field( $response[ $param ] ) ); 137 138 } 138 139 } … … 179 180 private function verify_hash( $response ) { 180 181 181 if ( ! ( $this->app_secret )) {182 if ( !$this->app_secret ) { 182 183 throw new Exception( 'Missing application secret key.' ); 183 184 } … … 217 218 } 218 219 220 221 // Returns formatted error message by its code 222 private function get_formatted_error_message( $error_code ) { 223 224 $errors = array( 225 'WS00' => __( 'Request executed successfully.', 'valuepay-wc' ), 226 'WS01' => __( 'Invalid endpoint', 'valuepay-wc' ), 227 'WS02' => __( 'No request body', 'valuepay-wc' ), 228 'WS03' => __( 'Data is not properly formatted', 'valuepay-wc' ), 229 'E01' => __( 'Missing mandatory field', 'valuepay-wc' ), 230 'E02' => __( 'Collection missing mandatory field for open bill amount', 'valuepay-wc' ), 231 'E03' => __( 'Collection missing mandatory field for fixed number amount', 'valuepay-wc' ), 232 'E04' => __( 'Collection value not valid amount', 'valuepay-wc' ), 233 'E05' => __( 'Collection alias is not available', 'valuepay-wc' ), 234 'E06' => __( 'Collection mandatory field indicator is not valid', 'valuepay-wc' ), 235 'E07' => __( 'Unable to cancel collection or bill', 'valuepay-wc' ), 236 'E08' => __( 'Unable to delete in-flight transaction. There is pending payment intent for this bill.', 'valuepay-wc' ), 237 'E09' => __( 'Invalid or inactive collection ID or mandate ID', 'valuepay-wc' ), 238 'E10' => __( 'Invalid bill ID', 'valuepay-wc' ), 239 'E11' => __( 'Invalid payment intent ID', 'valuepay-wc' ), 240 'E12' => __( 'Invalid merchant username or not active', 'valuepay-wc' ), 241 'E13' => __( 'Invalid reqhash calculation', 'valuepay-wc' ), 242 'E14' => __( 'Missing mandatory field for API', 'valuepay-wc' ), 243 'E15' => __( 'Billing amount is not valid', 'valuepay-wc' ), 244 'E16' => __( 'Billing buyer data field is not valid', 'valuepay-wc' ), 245 'E17' => __( 'Billing mobile number missing country code or invalid length', 'valuepay-wc' ), 246 'E18' => __( 'Billing e-mail address is invalid', 'valuepay-wc' ), 247 'E19' => __( 'Billing order number length exceed limit', 'valuepay-wc' ), 248 'E20' => __( 'Billing frontend or backend URL format is not valid or unsecured', 'valuepay-wc' ), 249 'E21' => __( 'Billing frontend or backend URL certificate cannot be verified with CA', 'valuepay-wc' ), 250 ); 251 252 return isset( $errors[ $error_code ] ) ? $errors[ $error_code ] : false; 253 254 } 255 219 256 // Debug logging 220 257 private function log( $message ) { -
valuepay-for-woocommerce/trunk/includes/class-valuepay-wc-gateway.php
r2701045 r2707855 197 197 198 198 if ( $payment_type === 'recurring' ) { 199 if ( !$identity_type ) {200 wc_add_notice( __( 'Identity type field is required if payment type is recurring.', 'valuepay-wc' ), 'error' );199 if ( !$identity_type || !$identity_value ) { 200 wc_add_notice( __( 'Identity information is required for recurring payment.', 'valuepay-wc' ), 'error' ); 201 201 } 202 202 203 if ( !$identity_value ) {204 wc_add_notice( __( 'Identity value field is required if payment type is recurring.', 'valuepay-wc' ), 'error' );205 }206 207 203 if ( !$bank ) { 208 wc_add_notice( __( 'Bank field is required if payment type is recurring.', 'valuepay-wc' ), 'error' );204 wc_add_notice( __( 'Bank is required for recurring payment.', 'valuepay-wc' ), 'error' ); 209 205 } 210 206 } … … 265 261 } 266 262 263 if ( !$payment_url ) { 264 return; 265 } 266 267 267 valuepay_wc_logger( 'Payment created for order #' . $order_id ); 268 268 … … 284 284 private function get_enrolment_url( $order ) { 285 285 286 $full_name = $order->get_formatted_billing_full_name() ?: $order->get_formatted_shipping_full_name(); 287 $email = $order->get_billing_email(); 288 $telephone = valuepay_wc_format_telephone( $order->get_billing_phone() ); 289 $identity_type = $order->get_meta( '_valuepay_identity_type' ); 290 $identity_value = $order->get_meta( '_valuepay_identity_value' ); 291 $bank = $order->get_meta( '_valuepay_bank' ); 292 293 if ( !$full_name ) { 294 throw new Exception( __( 'Name is required', 'valuepay-wc' ) ); 295 } 296 297 if ( !$email ) { 298 throw new Exception( __( 'Email is required', 'valuepay-wc' ) ); 299 } 300 301 if ( !$telephone ) { 302 throw new Exception( __( 'Telephone is required', 'valuepay-wc' ) ); 303 } 304 305 if ( !$identity_type || !$identity_value ) { 306 throw new Exception( __( 'Identity information is required for recurring payment', 'valuepay-wc' ) ); 307 } 308 309 if ( !$bank ) { 310 throw new Exception( __( 'Bank is required for recurring payment', 'valuepay-wc' ) ); 311 } 312 286 313 $params = array( 287 314 'username' => $this->username, 288 'sub_fullname' => $ order->get_formatted_billing_full_name() ?: $order->get_formatted_shipping_full_name(),289 'sub_ident_type' => $ order->get_meta( '_valuepay_identity_type' ),290 'sub_ident_value' => $ order->get_meta( '_valuepay_identity_value' ),291 'sub_telephone' => valuepay_wc_format_telephone( $order->get_billing_phone() ),292 'sub_email' => $ order->get_billing_email(),315 'sub_fullname' => $full_name, 316 'sub_ident_type' => $identity_type, 317 'sub_ident_value' => $identity_value, 318 'sub_telephone' => $telephone, 319 'sub_email' => $email, 293 320 'sub_mandate_id' => $this->mandate_id, 294 'sub_bank_id' => $ order->get_meta( '_valuepay_bank' ),321 'sub_bank_id' => $bank, 295 322 'sub_amount' => (float) $order->get_total(), 296 323 ); … … 332 359 private function get_bill_url( $order ) { 333 360 361 $full_name = $order->get_formatted_billing_full_name() ?: $order->get_formatted_shipping_full_name(); 362 $email = $order->get_billing_email(); 363 $telephone = valuepay_wc_format_telephone( $order->get_billing_phone() ); 364 365 if ( !$full_name ) { 366 throw new Exception( __( 'Name is required', 'valuepay-wc' ) ); 367 } 368 369 if ( !$email ) { 370 throw new Exception( __( 'Email is required', 'valuepay-wc' ) ); 371 } 372 373 if ( !$telephone ) { 374 throw new Exception( __( 'Telephone is required', 'valuepay-wc' ) ); 375 } 376 334 377 $params = array( 335 378 'username' => $this->username, … … 338 381 'collection_id' => $this->collection_id, 339 382 'buyer_data' => array( 340 'buyer_name' => $ order->get_formatted_billing_full_name() ?: $order->get_formatted_shipping_full_name(),341 'mobile_number' => valuepay_wc_format_telephone( $order->get_billing_phone() ),342 'email' => $ order->get_billing_email(),383 'buyer_name' => $full_name, 384 'mobile_number' => $telephone, 385 'email' => $email, 343 386 ), 344 387 'bill_frontend_url' => $this->get_return_url( $order ), -
valuepay-for-woocommerce/trunk/includes/functions.php
r2701045 r2707855 4 4 // Get plugin setting by key 5 5 function valuepay_wc_get_setting( $key, $default = null ) { 6 6 7 $settings = get_option( 'woocommerce_valuepay_settings' ); 7 return !empty( $settings[ $key ] ) ? $settings[ $key ] : $default; 8 9 if ( isset( $settings[ $key ] ) && !empty( $settings[ $key ] ) ) { 10 return $settings[ $key ]; 11 } 12 13 return $default; 14 8 15 } 9 16 … … 11 18 function valuepay_wc_notice( $message, $type = 'success' ) { 12 19 13 $plugin = __( 'ValuePay for WooCommerce', 'valuepay-wc' );20 $plugin = esc_html__( 'ValuePay for WooCommerce', 'valuepay-wc' ); 14 21 15 printf( '<div class="notice notice-%1$s"><p><strong>%2$s:</strong> %3$s</p></div>', esc_attr( $type ), esc_html( $plugin ), $message );22 printf( '<div class="notice notice-%1$s"><p><strong>%2$s:</strong> %3$s</p></div>', esc_attr( $type ), $plugin, $message ); 16 23 17 24 } … … 47 54 } 48 55 49 // Returns formatted error message by its code50 function valuepay_wc_get_error_message( $error_code ) {51 52 $errors = array(53 'WS00' => __( 'Request executed successfully.', 'valuepay-wc' ),54 'WS01' => __( 'Invalid endpoint', 'valuepay-wc' ),55 'WS02' => __( 'No request body', 'valuepay-wc' ),56 'WS03' => __( 'Data is not properly formatted', 'valuepay-wc' ),57 'E01' => __( 'Missing mandatory field', 'valuepay-wc' ),58 'E02' => __( 'Collection missing mandatory field for open bill amount', 'valuepay-wc' ),59 'E03' => __( 'Collection missing mandatory field for fixed number amount', 'valuepay-wc' ),60 'E04' => __( 'Collection value not valid amount', 'valuepay-wc' ),61 'E05' => __( 'Collection alias is not available', 'valuepay-wc' ),62 'E06' => __( 'Collection mandatory field indicator is not valid', 'valuepay-wc' ),63 'E07' => __( 'Unable to cancel collection or bill', 'valuepay-wc' ),64 'E08' => __( 'Unable to delete in-flight transaction. There is pending payment intent for this bill.', 'valuepay-wc' ),65 'E09' => __( 'Invalid or inactive collection ID or mandate ID', 'valuepay-wc' ),66 'E10' => __( 'Invalid bill ID', 'valuepay-wc' ),67 'E11' => __( 'Invalid payment intent ID', 'valuepay-wc' ),68 'E12' => __( 'Invalid merchant username or not active', 'valuepay-wc' ),69 'E13' => __( 'Invalid reqhash calculation', 'valuepay-wc' ),70 'E14' => __( 'Missing mandatory field for API', 'valuepay-wc' ),71 'E15' => __( 'Billing amount is not valid', 'valuepay-wc' ),72 'E16' => __( 'Billing buyer data field is not valid', 'valuepay-wc' ),73 'E17' => __( 'Billing mobile number missing country code or invalid length', 'valuepay-wc' ),74 'E18' => __( 'Billing e-mail address is invalid', 'valuepay-wc' ),75 'E19' => __( 'Billing order number length exceed limit', 'valuepay-wc' ),76 'E20' => __( 'Billing frontend or backend URL format is not valid or unsecured', 'valuepay-wc' ),77 'E21' => __( 'Billing frontend or backend URL certificate cannot be verified with CA', 'valuepay-wc' ),78 );79 80 return isset( $errors[ $error_code ] ) ? $errors[ $error_code ] : false;81 82 }83 84 56 // Format telephone number 85 57 function valuepay_wc_format_telephone( $telephone ) { -
valuepay-for-woocommerce/trunk/readme.txt
r2701045 r2707855 1 1 === ValuePay for WooCommerce === 2 Contributors: valuepay 2 Contributors: valuepaymy 3 3 Tags: valuepay, woocommerce, payment 4 4 Requires at least: 4.6 5 Tested up to: 5.9 6 Stable tag: 1.0.0 5 Tested up to: 5.9.2 6 Stable tag: 1.0.2 7 Requires PHP: 7.0 8 License: GPLv2 or later 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 7 10 8 11 Accept payment on WooCommerce using ValuePay. … … 12 15 Allows customer to made payment on WooCommerce using ValuePay. 13 16 14 Notes: 17 = Notes: = 15 18 - It is required to have name, email and phone number field on WooCommerce checkout page. So, if you are using any checkout simplify plugin, eg: Cartflows, please make sure that you display the required fields. 16 19 - Recurring payment only creates one payment record in WooCommerce with "On Hold" status. … … 27 30 == Changelog == 28 31 32 = 1.0.2 - 2022-04-10 = 33 - Modified: Improve instant payment notification response data sanitization 34 35 = 1.0.1 - 2022-03-09 = 36 - Modified: Minor improvements 37 29 38 = 1.0.0 - 2022-02-17 = 30 39 - Initial release of the plugin -
valuepay-for-woocommerce/trunk/valuepay-wc.php
r2701045 r2707855 1 1 <?php 2 2 /** 3 * Plugin Name: ValuePay for WooCommerce 4 * Description: Accept payment on WooCommerce using ValuePay. 5 * Version: 1.0.0 6 * Author: Valuefy Solutions Sdn Bhd 7 * Author URI: https://valuepay.my/ 3 * Plugin Name: ValuePay for WooCommerce 4 * Description: Accept payment on WooCommerce using ValuePay. 5 * Version: 1.0.2 6 * Requires at least: 4.6 7 * Requires PHP: 7.0 8 * Author: Valuefy Solutions Sdn Bhd 9 * Author URI: https://valuepay.my/ 10 * License: GPLv2 or later 11 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 8 12 */ 9 13 10 14 if ( !defined( 'ABSPATH' ) ) exit; 15 16 if ( class_exists( 'Valuepay_WC' ) ) return; 11 17 12 18 define( 'VALUEPAY_WC_FILE', __FILE__ ); … … 14 20 define( 'VALUEPAY_WC_PATH', plugin_dir_path( VALUEPAY_WC_FILE ) ); 15 21 define( 'VALUEPAY_WC_BASENAME', plugin_basename( VALUEPAY_WC_FILE ) ); 16 define( 'VALUEPAY_WC_VERSION', '1.0. 0' );22 define( 'VALUEPAY_WC_VERSION', '1.0.2' ); 17 23 18 24 // Plugin core class
Note: See TracChangeset
for help on using the changeset viewer.