Skip to content

Releases: kkiapay/wordpress-plugin

v2.4.6

20 Jun 16:00
Compare
Choose a tag to compare

What's Changed

Kkiapay logo changed

Before
kkiapay

After
kkiapay

v2.4.0

09 Mar 11:34
Compare
Choose a tag to compare

What's Changed

HPOS Support

HPOS stands for “High-Performance Order Storage”. This is a new feature introduced in WooCommerce 7.1 that aims to improve order management performance. We enable it into our plugin

if (class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class)) {
     \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true);
   }

Block Support

As Wordpress is oriented more towards the creation of blocks, we create a new class class WC_KKiapay_Gateway_Blocks_Support to handle enable block support in our plugin

Remove the php sdk

We remove all unnuncessary dependencies such as guzzle and use wordpress built-in functions. We removed the Guzzle library dependencies from the KkiaPay WooCommerce plugin. Guzzle is no longer needed to make HTTP requests because WordPress offers the built-in wp_remote_post function.
This contribute to reduces the total size of the plugin

Enhance the communication with Kkiapay

We change the kkiapay's stateData payload when the widget is open

$this->kkiapay_config['data'] = [
    "sdk" => "woocommerce",
    "woocommerce_version" => WOOCOMMERCE_VERSION,
    "order_id" => $order->get_id(),
    "orderer_name" => $order->get_formatted_billing_full_name(),
    "orderer_email" => $order->get_billing_email(),
    "orderer_phone" => $order->get_billing_phone(),
    "products" => $products
]

The variable $products is made like this:

$line_items = $order->get_items();

$products = '';

foreach ($line_items as $item_id => $item) {
    $id        = $item["product_id"];
    $name      = $item['name'];
    $quantity  = $item['qty'];
    $products .= $name . ' [product_id: ' . $id . '] ' . ' (Qty: ' . $quantity . ')';
    $products .= ' | ';
}

If you want to get all the products as array on your webhook you can do this with php

$products = "T-Shirt [product_id: 123] (Qty: 2) | Mug [product_id: 456] (Qty: 1)";

// Function to parse a product string
function parseProductString($productString) {
  $pattern = "/(.*) \[product_id: (\d+)\] \(Qty: (\d+)\)/";
  preg_match($pattern, $productString, $matches);
  if (empty($matches)) {
    return null; // Handle invalid product string
  }
  return [
    "name" => $matches[1],
    "product_id" => (int) $matches[2],
    "quantity" => (int) $matches[3],
  ];
}

// Initialize an empty array for products
$productList = [];

// Split the string by delimiter
$productStrings = explode(" | ", $products);

foreach ($productStrings as $productString) {
  // Parse each product string
  $product = parseProductString($productString);
  if ($product) {
    $productList[] = $product;
  }
}

// Print the resulting product array
print_r($productList);

Or this with js

const products = "T-Shirt [product_id: 123] (Qty: 2) | Mug [product_id: 456] (Qty: 1)";

// Function to parse a product string
function parseProductString(productString) {
  const pattern = /(.+) \[product_id: (\d+)\] \(Qty: (\d+)\)/;
  const match = productString.match(pattern);
  if (!match) {
    return null; // Handle invalid product string
  }
  return {
    name: match[1],
    productId: parseInt(match[2]), // Use parseInt for integer conversion
    quantity: parseInt(match[3]),
  };
}

// Initialize an empty array for products
const productList = [];

// Split the string by delimiter
const productStrings = products.split(" | ");

for (const productString of productStrings) {
  // Parse each product string
  const product = parseProductString(productString);
  if (product) {
    productList.push(product);
  }
}

// Print the resulting product array (use console.log for browser)
console.log(productList);

Change the CI

Add a script npm run zip to pack the plugin ready to deploy
The JavaScript script uses the zip-a-folder library to compress the plugin files into a single ZIP file. The ZIP file includes only the files needed to submit to the WordPress plugin, keeping the file size small and making the publishing process easier for developers.

New Contributors

Full Changelog: v1.0.7...v1.4.0