Plugin Directory

Changeset 2707855


Ignore:
Timestamp:
04/11/2022 08:02:00 AM (4 years ago)
Author:
valuepaymy
Message:

Update plugin to 1.0.2

Location:
valuepay-for-woocommerce/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • valuepay-for-woocommerce/trunk/admin/settings.php

    r2701045 r2707855  
    3131            'title'       => __( 'API Credentials', 'valuepay-wc' ),
    3232            'type'        => 'title',
    33             'description' => __( 'API credentials can be obtained from ValuePay merchant dashboard under Business Profile page.', 'valuepay-wc' ),
     33            'description' => __( 'API credentials can be obtained from ValuePay merchant dashboard in Business Profile page.', 'valuepay-wc' ),
    3434        ),
    3535        'username' => array(
     
    5252            'title'       => __( 'Collection ID', 'valuepay-wc' ),
    5353            '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' ),
    5555        ),
    5656        'mandate_id' => array(
    5757            'title'       => __( 'Mandate ID', 'valuepay-wc' ),
    5858            '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' ),
    6060        ),
    6161        'frequency_type' => array(
  • valuepay-for-woocommerce/trunk/includes/abstracts/abstract-valuepay-wc-client.php

    r2701045 r2707855  
    88    public $app_key;
    99    public $app_secret;
    10     protected $debug = false;
     10
     11    protected $debug = true;
    1112
    1213    // HTTP request headers
     
    7879                );
    7980            } else {
    80                 throw new Exception( valuepay_wc_get_error_message( $response['wscode'] ) );
     81                throw new Exception( $this->get_formatted_error_message( $response['wscode'] ) );
    8182            }
    8283        }
     
    9495
    9596        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 );
    9899        } 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;
    113112
    114113    }
    115114
    116115    // 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 ) {
    118117
    119118        if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
     
    127126        foreach ( $params as $param ) {
    128127            // Return false if required parameters is not passed to the URL
    129             if ( !isset( $data[ $param ] ) ) {
     128            if ( !isset( $response[ $param ] ) ) {
    130129                return false;
    131130            }
    132131
    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 ] );
    135136            } else {
    136                 $allowed_params[ $param ] = trim( $data[ $param ] );
     137                $allowed_params[ $param ] = trim( sanitize_text_field( $response[ $param ] ) );
    137138            }
    138139        }
     
    179180    private function verify_hash( $response ) {
    180181
    181         if ( !( $this->app_secret ) ) {
     182        if ( !$this->app_secret ) {
    182183            throw new Exception( 'Missing application secret key.' );
    183184        }
     
    217218    }
    218219
     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
    219256    // Debug logging
    220257    private function log( $message ) {
  • valuepay-for-woocommerce/trunk/includes/class-valuepay-wc-gateway.php

    r2701045 r2707855  
    197197
    198198        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' );
    201201            }
    202202
    203             if ( !$identity_value ) {
    204                 wc_add_notice( __( 'Identity value field is required if payment type is recurring.', 'valuepay-wc' ), 'error' );
    205             }
    206 
    207203            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' );
    209205            }
    210206        }
     
    265261            }
    266262
     263            if ( !$payment_url ) {
     264                return;
     265            }
     266
    267267            valuepay_wc_logger( 'Payment created for order #' . $order_id );
    268268
     
    284284    private function get_enrolment_url( $order ) {
    285285
     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
    286313        $params = array(
    287314            '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,
    293320            'sub_mandate_id'  => $this->mandate_id,
    294             'sub_bank_id'     => $order->get_meta( '_valuepay_bank' ),
     321            'sub_bank_id'     => $bank,
    295322            'sub_amount'      => (float) $order->get_total(),
    296323        );
     
    332359    private function get_bill_url( $order ) {
    333360
     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
    334377        $params = array(
    335378            'username'          => $this->username,
     
    338381            'collection_id'     => $this->collection_id,
    339382            '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,
    343386            ),
    344387            'bill_frontend_url' => $this->get_return_url( $order ),
  • valuepay-for-woocommerce/trunk/includes/functions.php

    r2701045 r2707855  
    44// Get plugin setting by key
    55function valuepay_wc_get_setting( $key, $default = null ) {
     6
    67    $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
    815}
    916
     
    1118function valuepay_wc_notice( $message, $type = 'success' ) {
    1219
    13     $plugin = __( 'ValuePay for WooCommerce', 'valuepay-wc' );
     20    $plugin = esc_html__( 'ValuePay for WooCommerce', 'valuepay-wc' );
    1421
    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 );
    1623
    1724}
     
    4754}
    4855
    49 // Returns formatted error message by its code
    50 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 
    8456// Format telephone number
    8557function valuepay_wc_format_telephone( $telephone ) {
  • valuepay-for-woocommerce/trunk/readme.txt

    r2701045 r2707855  
    11=== ValuePay for WooCommerce ===
    2 Contributors: valuepay
     2Contributors: valuepaymy
    33Tags: valuepay, woocommerce, payment
    44Requires at least: 4.6
    5 Tested up to: 5.9
    6 Stable tag: 1.0.0
     5Tested up to: 5.9.2
     6Stable tag: 1.0.2
     7Requires PHP: 7.0
     8License: GPLv2 or later
     9License URI: https://www.gnu.org/licenses/gpl-2.0.html
    710
    811Accept payment on WooCommerce using ValuePay.
     
    1215Allows customer to made payment on WooCommerce using ValuePay.
    1316
    14 Notes:
     17= Notes: =
    1518- 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.
    1619- Recurring payment only creates one payment record in WooCommerce with "On Hold" status.
     
    2730== Changelog ==
    2831
     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
    2938= 1.0.0 - 2022-02-17 =
    3039- Initial release of the plugin
  • valuepay-for-woocommerce/trunk/valuepay-wc.php

    r2701045 r2707855  
    11<?php
    22/**
    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
    812 */
    913
    1014if ( !defined( 'ABSPATH' ) ) exit;
     15
     16if ( class_exists( 'Valuepay_WC' ) ) return;
    1117
    1218define( 'VALUEPAY_WC_FILE', __FILE__ );
     
    1420define( 'VALUEPAY_WC_PATH', plugin_dir_path( VALUEPAY_WC_FILE ) );
    1521define( 'VALUEPAY_WC_BASENAME', plugin_basename( VALUEPAY_WC_FILE ) );
    16 define( 'VALUEPAY_WC_VERSION', '1.0.0' );
     22define( 'VALUEPAY_WC_VERSION', '1.0.2' );
    1723
    1824// Plugin core class
Note: See TracChangeset for help on using the changeset viewer.