Skip to content

Commit

Permalink
QDEVFE-201 (#82)
Browse files Browse the repository at this point in the history
Refactor plugin for Wordpress store submission
Update CI, demo store
  • Loading branch information
HMKnapp authored Nov 3, 2021
1 parent 0f51f7b commit e8eb6fd
Show file tree
Hide file tree
Showing 41 changed files with 510 additions and 515 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
WORDPRESS_HOST=
NGROK_TOKEN=
PLUGIN_URL=https://github.com/qenta-cee/woocommerce-qcs.git
PLUGIN_URL=
PLUGIN_VERSION=
WORDPRESS_ADMIN_USER=
WORDPRESS_ADMIN_PASS=
Expand Down
21 changes: 20 additions & 1 deletion .github/workflows/plugin-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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-seamless 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-seamless
path: /tmp/artifact
5 changes: 5 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
tools: composer
- name: Install Dependencies
run: composer install
- name: Pack Release zip
Expand Down
15 changes: 11 additions & 4 deletions docker/wordpress/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -e

touch /tmp/shop.log

# If we are in Github plugin repo CI environment
CI_REPO_URL=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}
if [[ ${CI_REPO_URL} == ${PLUGIN_URL//.git/} ]]; then
Expand Down Expand Up @@ -80,16 +82,21 @@ function setup_store() {
wp option set woocommerce_default_country "AT"
wp_set_array woocommerce_onboarding_profile skipped 1
wp wc --user=admin tool run install_pages
wp option update page_on_front 5
wp option update show_on_front page
wp option update blogdescription "QENTA Plugin DEMO"
wp theme install twentytwenty --activate
wp post delete 2 --force
wp post delete 1 --force
}

function print_info() {
echo
echo '####################################'
echo
echo "URL: https://${WORDPRESS_URL}"
echo "Shop: https://${WORDPRESS_URL}/?post_type=product"
echo "Panel: https://${WORDPRESS_URL}/wp-admin/"
echo "Plugin Config: https://${WORDPRESS_URL}/wp-admin/admin.php?page=wc-settings&tab=checkout"
echo "Shop: https://${WORDPRESS_URL}"
echo "Admin Panel: https://${WORDPRESS_URL}/wp-admin/"
echo "Plugin Config: https://${WORDPRESS_URL}/wp-admin/admin.php?page=wc-settings&tab=checkout&section=woocommerce_wcs"
echo "User: ${WORDPRESS_ADMIN_USER}"
echo "Password: ${WORDPRESS_ADMIN_PASS}"
echo
Expand Down
6 changes: 2 additions & 4 deletions docker/wordpress/ngrok.sh
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
7 changes: 6 additions & 1 deletion woocommerce-qenta-checkout-seamless/assets/scripts/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ wpOnload = function () {
tabPane.className = tabPane.className + ' active';
});
}
}
}

function goToWctPage(page) {
start = "?page=qenta_transactions_page&transaction_start=" + page;
window.location.href = start;
}
278 changes: 131 additions & 147 deletions woocommerce-qenta-checkout-seamless/classes/class-qenta-admin.php

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,17 @@ public function __construct( $settings ) {
public function refund( $order_id = 0, $amount = 0, $reason = '' ) {
global $wpdb;

$order_id = $_POST['order_id'];
$refund_amount = $_POST['refund_amount'];
$params_post = array_map( 'sanitize_text_field', $_POST );
$order_id = $params_post['order_id'];
$refund_amount = $params_post['refund_amount'];
if ( $refund_amount <= 0 ) {
$this->_logger->error( __( 'Refund amount must be greater than zero.', 'woocommerce-qenta-checkout-seamless' ) );
$this->_logger->error( esc_html( __( 'Refund amount must be greater than zero.', 'woocommerce-qenta-checkout-seamless' ) ) );

return false;
}

$line_item_qtys = json_decode( str_replace( '\\', "", $_POST['line_item_qtys'] ) );
$line_item_totals = (array) json_decode( str_replace( '\\', "", $_POST['line_item_totals'] ) );
$line_item_qtys = json_decode( str_replace( '\\', "", $params_post['line_item_qtys'] ) );
$line_item_totals = (array) json_decode( str_replace( '\\', "", $params_post['line_item_totals'] ) );
$refund_items = array();
$total_items = 0;

Expand Down Expand Up @@ -331,7 +332,7 @@ private function logResponseErrors( $method, $errors ) {
foreach ( $errors as $error ) {
$_errors[] = $error->getConsumerMessage();
}
$this->_logger->error( "$method : processing refund failed with error(s): " . join( '|', $_errors ) );
$this->_logger->error( esc_html( "$method : processing refund failed with error(s): " . join( '|', $_errors ) ) );
}

/**
Expand All @@ -358,7 +359,7 @@ public function transfer_fund_refund( $amount, $currency, $order_number, $woocom
$refundable_sum = $wpdb->get_row( $refundable_sum );

if ( $refundable_sum !== null && $amount > $refundable_sum->sum ) {
$this->_logger->error( __METHOD__ . ":" . __( 'The refunded amount must be less than deposited amount.', 'woocommerce-qenta-checkout-seamless' ) );
$this->_logger->error( __METHOD__ . ":" . esc_html( __( 'The refunded amount must be less than deposited amount.', 'woocommerce-qenta-checkout-seamless' ) ) );

return false;
}
Expand Down Expand Up @@ -506,6 +507,7 @@ public function depositreversal( $orderNumber, $paymentNumber ) {
* @return array
*/
public function approvereversal( $orderNumber ) {
$params_post = array_map( 'sanitize_text_field', $_POST );
$response = $this->get_client()->approveReversal( $orderNumber );
$transaction = new WC_Gateway_Qenta_Checkout_Seamless_Transaction( $this->_settings );

Expand All @@ -518,8 +520,8 @@ public function approvereversal( $orderNumber ) {

return array( 'type' => 'error', 'message' => join( "<br>", $errors ) );
} else {
if( isset($_POST['id_tx'])){
$transaction->update( array( 'payment_state' => 'CANCELED BY ADMIN' ), array( 'id_tx' => $_POST['id_tx'] ) );
if( isset($params_post['id_tx'])){
$transaction->update( array( 'payment_state' => 'CANCELED BY ADMIN' ), array( 'id_tx' => $params_post['id_tx'] ) );
}
return array( 'type' => 'updated', 'message' => __( 'APPROVEREVERSAL', 'woocommerce-qenta-checkout-seamless' ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
* Please do not use the plugin if you do not agree to these terms of use!
*/

define( 'WOOCOMMERCE_GATEWAY_WCS_NAME', 'QentaCheckoutSeamless' );
define( 'WOOCOMMERCE_GATEWAY_WCS_VERSION', '2.0.2' );
define( 'WOOCOMMERCE_GATEWAY_QMORE_NAME', 'QentaCheckoutSeamless' );
define( 'WOOCOMMERCE_GATEWAY_QMORE_VERSION', '2.0.3' );

/**
* Config class
Expand Down Expand Up @@ -205,8 +205,8 @@ public function get_plugin_version() {
return QentaCEE\QMore\FrontendClient::generatePluginVersion(
'woocommerce',
WC()->version,
WOOCOMMERCE_GATEWAY_WCS_NAME,
WOOCOMMERCE_GATEWAY_WCS_VERSION
WOOCOMMERCE_GATEWAY_QMORE_NAME,
WOOCOMMERCE_GATEWAY_QMORE_VERSION
);
}

Expand Down
Loading

0 comments on commit e8eb6fd

Please sign in to comment.