diff --git a/.github/plugin-test.yml b/.github/workflows/plugin-test.yml similarity index 53% rename from .github/plugin-test.yml rename to .github/workflows/plugin-test.yml index fa52338..7f17277 100644 --- a/.github/plugin-test.yml +++ b/.github/workflows/plugin-test.yml @@ -9,13 +9,21 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 7.4 + tools: composer - name: Get Branch Name shell: bash run: echo "::set-output name=name::$(bash docker/branchname.sh)" id: branch - name: Start NGROK shell: bash - run: echo "::set-output name=host::$(timeout 1m bash docker/wordpress/ngrok.sh)" + run: | + NGROK_HOST=$(timeout 5m bash docker/wordpress/ngrok.sh) + echo "ngrok hostname: ${NGROK_HOST}" + echo "::set-output name=host::${NGROK_HOST}" id: ngrok env: NGROK_TOKEN: ${{ secrets.NGROK_TOKEN }} @@ -31,3 +39,14 @@ jobs: env: WP_URL: ${{ steps.ngrok.outputs.host }} run: curl https://${{ steps.ngrok.outputs.host }} + - name: Prepare Artifact + run: | + mkdir -p /tmp/artifact + cp -r woocommerce-qenta-checkout-page composer.* /tmp/artifact/ + cd /tmp/artifact && composer install && rm composer.* + - name: Upload Artifact + id: upload_artifact + uses: actions/upload-artifact@v2 + with: + name: woocommerce-qenta-checkout-page + path: /tmp/artifact diff --git a/docker/wordpress/ngrok.sh b/docker/wordpress/ngrok.sh index 01d24d4..0ab690f 100644 --- a/docker/wordpress/ngrok.sh +++ b/docker/wordpress/ngrok.sh @@ -1,15 +1,13 @@ #!/bin/bash -set -e - which ngrok >/dev/null if [[ $? == 0 ]]; then NGROK_BINARY="$(which ngrok)" else >&2 echo "Installing NGROK" cd ~/ - npm install ngrok - NGROK_BINARY="~/node_modules/ngrok/bin/ngrok" + npm install ngrok >&2 + NGROK_BINARY="./node_modules/ngrok/bin/ngrok" fi function get_ngrok_url() { diff --git a/scripts/wait-for-shop.sh b/scripts/wait-for-shop.sh new file mode 100644 index 0000000..e38f39e --- /dev/null +++ b/scripts/wait-for-shop.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# entrypoint of shop now puts 'ready' in a file after installation of +# wordpress, woocommerce and plugin +# docker exec woocommerce touch /tmp/shop.log +# docker exec woocommerce cat /tmp/shop.log +# docker exec woocommerce cat /tmp/debug.log +# timeout 15m docker exec woocommerce tail -f /tmp/shop.log | sed '/^ready/ q' + +function read_log() { + docker exec woocommerce cat /tmp/shop.log + #docker exec -it woocommerce "tail -f /path/to/file.log | sed '/^ready/ q'" +} + +LOG_CONTENT=$(read_log) +echo "Waiting for Shop Setup to finish" +while [[ -z $(read_log | grep ready) ]]; do + sleep 1; +done diff --git a/woocommerce-qenta-checkout-page/class-woocommerce-wcp-gateway.php b/woocommerce-qenta-checkout-page/class-woocommerce-wcp-gateway.php index 21979e1..fc2487e 100644 --- a/woocommerce-qenta-checkout-page/class-woocommerce-wcp-gateway.php +++ b/woocommerce-qenta-checkout-page/class-woocommerce-wcp-gateway.php @@ -7,13 +7,13 @@ * - Wrapped payment type in div * */ -require_once( WOOCOMMERCE_GATEWAY_WCP_BASEDIR . 'classes/class-woocommerce-wcp-config.php' ); -require_once( WOOCOMMERCE_GATEWAY_WCP_BASEDIR . 'classes/class-woocommerce-wcp-payments.php' ); +require_once( WOOCOMMERCE_GATEWAY_QPAY_BASEDIR . 'classes/class-woocommerce-wcp-config.php' ); +require_once( WOOCOMMERCE_GATEWAY_QPAY_BASEDIR . 'classes/class-woocommerce-wcp-payments.php' ); -define( 'WOOCOMMERCE_GATEWAY_WCP_NAME', 'Woocommerce2_QentaCheckoutPage' ); -define( 'WOOCOMMERCE_GATEWAY_WCP_VERSION', '2.0.3' ); -define( 'WOOCOMMERCE_GATEWAY_WCP_WINDOWNAME', 'QentaCheckoutPageFrame' ); -define( 'WOOCOMMERCE_GATEWAY_WCP_TABLE_NAME', 'woocommerce_wcp_transaction' ); +define( 'WOOCOMMERCE_GATEWAY_QPAY_NAME', 'Woocommerce2_QentaCheckoutPage' ); +define( 'WOOCOMMERCE_GATEWAY_QPAY_VERSION', '2.0.4' ); +define( 'WOOCOMMERCE_GATEWAY_QPAY_WINDOWNAME', 'QentaCheckoutPageFrame' ); +define( 'WOOCOMMERCE_GATEWAY_QPAY_TABLE_NAME', 'woocommerce_wcp_transaction' ); class WC_Gateway_WCP extends WC_Payment_Gateway { @@ -42,7 +42,7 @@ class WC_Gateway_WCP extends WC_Payment_Gateway { function __construct() { $this->id = 'qenta_checkout_page'; - $this->icon = WOOCOMMERCE_GATEWAY_WCP_URL . 'assets/images/qenta.png'; + $this->icon = WOOCOMMERCE_GATEWAY_QPAY_URL . 'assets/images/qenta.png'; $this->has_fields = true; $this->method_title = __( 'Qenta Checkout Page', 'woocommerce-wcp' ); $this->method_description = __( @@ -180,7 +180,7 @@ function process_payment( $order_id ) { $order = new WC_Order( $order_id ); - $paymenttype = $_POST['wcp_payment_method']; + $paymenttype = sanitize_text_field($_POST['wcp_payment_method']); if ( ! $this->is_paymenttype_enabled( $paymenttype ) ) { wc_add_notice( __( 'Payment type is not available, please select another payment type.', 'woocommerce-wcp' ), 'error' ); @@ -191,19 +191,19 @@ function process_payment( $order_id ) { $birthday = null; if ( isset( $_POST['wcp_birthday'] ) ) { - $birthday = $_POST['wcp_birthday']; + $birthday = sanitize_text_field($_POST['wcp_birthday']); } $financial_inst = null; if ( $paymenttype == 'eps' ) { - $financial_inst = $_POST['wcp_eps_financialInstitution']; + $financial_inst = sanitize_text_field($_POST['wcp_eps_financialInstitution']); } if ( $paymenttype == 'idl' ) { - $financial_inst = $_POST['wcp_idl_financialInstitution']; + $financial_inst = sanitize_text_field($_POST['wcp_idl_financialInstitution']); } if ( $this->use_iframe ) { - WC()->session->qenta_checkout_page_idl = isset( $_POST['wcp_idl_financialInstitution'] ) ? $_POST['wcp_idl_financialInstitution'] : ''; - WC()->session->qenta_checkout_page_eps = isset( $_POST['wcp_eps_financialInstitution'] ) ? $_POST['wcp_eps_financialInstitution'] : ''; + WC()->session->qenta_checkout_page_idl = isset( $_POST['wcp_idl_financialInstitution'] ) ? sanitize_text_field($_POST['wcp_idl_financialInstitution']) : ''; + WC()->session->qenta_checkout_page_eps = isset( $_POST['wcp_eps_financialInstitution'] ) ? sanitize_text_field($_POST['wcp_eps_financialInstitution']) : ''; WC()->session->qenta_checkout_page_type = $paymenttype; $page_url = version_compare( WC()->version, '2.1.0', '<' ) @@ -240,21 +240,21 @@ function payment_page( $order_id ) { $order = new WC_Order( $order_id ); $birthday = null; if ( isset( $_POST['wcp_birthday'] ) ) { - $birthday = $_POST['wcp_birthday']; + $birthday = sanitize_text_field($_POST['wcp_birthday']); } $financial_inst = null; if ( WC()->session->qenta_checkout_page_type == 'eps' && ( isset( $_POST['wcp_eps_financialInstitution'] ) || isset( WC()->session->qenta_checkout_page_eps ) ) ) { - $financial_inst = isset( $_POST['wcp_eps_financialInstitution'] ) ? $_POST['wcp_eps_financialInstitution'] : WC()->session->qenta_checkout_page_eps; + $financial_inst = isset( $_POST['wcp_eps_financialInstitution'] ) ? sanitize_text_field($_POST['wcp_eps_financialInstitution']) : WC()->session->qenta_checkout_page_eps; } if ( WC()->session->qenta_checkout_page_type == 'idl' && ( isset( $_POST['wcp_idl_financialInstitution'] ) || isset( WC()->session->qenta_checkout_page_idl ) ) ) { - $financial_inst = isset( $_POST['wcp_idl_financialInstitution'] ) ? $_POST['wcp_idl_financialInstitution'] : WC()->session->qenta_checkout_page_idl; + $financial_inst = isset( $_POST['wcp_idl_financialInstitution'] ) ? sanitize_text_field($_POST['wcp_idl_financialInstitution']) : WC()->session->qenta_checkout_page_idl; } $iframeUrl = $this->initiate_payment( $order, WC()->session->qenta_checkout_page_type, $birthday, $financial_inst ); ?> - @@ -284,8 +284,8 @@ function dispatch_callback() [ 'url' => $url, ], - WOOCOMMERCE_GATEWAY_WCP_BASEDIR, - WOOCOMMERCE_GATEWAY_WCP_BASEDIR + WOOCOMMERCE_GATEWAY_QPAY_BASEDIR, + WOOCOMMERCE_GATEWAY_QPAY_BASEDIR ); exit(); @@ -357,23 +357,25 @@ function return_request() { * @return string */ function confirm_request() { - foreach ( $_REQUEST as &$param ) { - $param = stripslashes( $param ); - } - foreach ( $_POST as &$param ) { - $param = stripslashes( $param ); - } + $params_request = array_map( 'sanitize_text_field', $_REQUEST ); + foreach ( $params_request as &$param ) { + $param = stripslashes( $param ); + } + $params_post = array_map( 'sanitize_text_field', $_POST ); + foreach ( $params_post as &$param ) { + $param = stripslashes( $param ); + } - $this->log( 'confirm_request:' . print_r( $_REQUEST, true ), 'info' ); + $this->log( 'confirm_request:' . print_r( $params_request, true ), 'info' ); $message = null; - if ( ! isset( $_REQUEST['wooOrderId'] ) || ! strlen( $_REQUEST['wooOrderId'] ) ) { + if ( ! isset( $params_request['wooOrderId'] ) || ! strlen( $params_request['wooOrderId'] ) ) { $message = 'order-id missing'; $this->log( $message, 'error' ); return QentaCEE\QPay\ReturnFactory::generateConfirmResponseString( $message ); } - $order_id = $_REQUEST['wooOrderId']; + $order_id = $params_request['wooOrderId']; $order = new WC_Order( $order_id ); if ( ! $order->get_id() ) { $message = "order with id `$order->get_id()` not found"; @@ -390,19 +392,19 @@ function confirm_request() { } $str = ''; - foreach ( $_POST as $k => $v ) { + foreach ( $params_post as $k => $v ) { $str .= "$k:$v\n"; } $str = trim( $str ); update_post_meta( $order->get_id(), 'wcp_data', $str ); if ( isset( $_REQUEST['paymentType'] ) ) { - update_post_meta($order->get_id(), '_payment_method', $_REQUEST['paymentType']); + update_post_meta($order->get_id(), '_payment_method', $params_request['paymentType']); } $message = null; try { - $return = QentaCEE\QPay\ReturnFactory::getInstance( $_POST, $this->_config->get_secret() ); + $return = QentaCEE\QPay\ReturnFactory::getInstance( $params_post, $this->_config->get_secret() ); if ( ! $return->validate() ) { $message = __( 'Validation error: invalid response', 'woocommerce-wcp' ); $order->update_status( 'failed', $message ); @@ -525,29 +527,31 @@ function changeWCPPayment(code) { changer.value = code; } - + get_enabled_paymenttypes() as $type ) { ?> -
  • +
  • -