Skip to content

Fix indentation #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
== Changelog ==

= 1.6.8 2025-03-20 =
= 1.6.9 2025-XX-XX =
* Changed - Indentation and documentation update

= 1.6.8 2025-04-11 =
* Added - Auto remove whitespace in brand id and secret key field on save
* Added - Site health check for CHIP's API connection
* Changed - Email fallback description and placeholder
Expand Down
20 changes: 10 additions & 10 deletions chip-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function add_gateways( $methods ) {
public function setting_link( $links ) {
$url_params = array(
'page' => 'wc-settings',
'tab' => 'checkout',
'tab' => 'checkout',
);

if ( defined( 'DISABLE_CLONE_WC_GATEWAY_CHIP' ) ) {
Expand All @@ -135,7 +135,7 @@ public function setting_link( $links ) {
$url = add_query_arg( $url_params, admin_url( 'admin.php' ) );

$new_links = array(
'settings' => sprintf( '<a href="%1$s">%2$s</a>', $url, esc_html__( 'Settings', 'chip-for-woocommerce' ) )
'settings' => sprintf( '<a href="%1$s">%2$s</a>', $url, esc_html__( 'Settings', 'chip-for-woocommerce' ) ),
);

return array_merge( $new_links, $links );
Expand All @@ -151,17 +151,17 @@ public static function load() {

public function block_support() {
if ( class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
include plugin_dir_path( WC_CHIP_FILE ) . 'includes/blocks/class-wc-gateway-chip-blocks.php';
include plugin_dir_path( WC_CHIP_FILE ) . 'includes/blocks/class-wc-gateway-chip-blocks-support.php';
include plugin_dir_path( WC_CHIP_FILE ) . 'includes/blocks/clone-wc-gateway-chip-blocks.php';
add_action(
'woocommerce_blocks_payment_method_type_registration',
function (Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry) {
$payment_method_registry->register( new WC_Gateway_Chip_Blocks_Support );
$payment_method_registry->register( new WC_Gateway_Chip_2_Blocks_Support );
$payment_method_registry->register( new WC_Gateway_Chip_3_Blocks_Support );
$payment_method_registry->register( new WC_Gateway_Chip_4_Blocks_Support );
$payment_method_registry->register( new WC_Gateway_Chip_5_Blocks_Support );
$payment_method_registry->register( new WC_Gateway_Chip_6_Blocks_Support );
function ( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
$payment_method_registry->register( new WC_Gateway_Chip_Blocks_Support() );
$payment_method_registry->register( new WC_Gateway_Chip_2_Blocks_Support() );
$payment_method_registry->register( new WC_Gateway_Chip_3_Blocks_Support() );
$payment_method_registry->register( new WC_Gateway_Chip_4_Blocks_Support() );
$payment_method_registry->register( new WC_Gateway_Chip_5_Blocks_Support() );
$payment_method_registry->register( new WC_Gateway_Chip_6_Blocks_Support() );
}
);
}
Expand Down
146 changes: 146 additions & 0 deletions includes/blocks/class-wc-gateway-chip-blocks-support.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?php
/**
* Add CHIP block checkout support
*
* @package CHIP for WooCommerce
*/

use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;

/**
* WC_Gateway_Chip_Blocks_Support
*/
class WC_Gateway_Chip_Blocks_Support extends AbstractPaymentMethodType {

/**
* Payment gateway object
*
* @var string
*/
protected $gateway;

/**
* Gateway id
*
* @var string
*/
protected $name = 'wc_gateway_chip';

/**
* Initialize the class
*
* Assign value to the gateway property
*
* @return void
*/
public function initialize() {
$this->gateway = Chip_Woocommerce::get_chip_gateway_class( $this->name );
$this->settings = $this->gateway->settings;
}

/**
* Get the payment method type
*
* @return bool
*/
public function is_active() {
return $this->gateway->is_available();
}

/**
* Get payment method script handles
*
* @return array
*/
public function get_payment_method_script_handles() {
$script_path = 'assets/js/frontend/blocks_' . $this->name . '.js';
$script_asset_path = plugin_dir_path( WC_CHIP_FILE ) . 'assets/js/frontend/blocks_' . $this->name . '.asset.php';
$script_asset = file_exists( $script_asset_path )
? require $script_asset_path
: array(
'dependencies' => array(),
'version' => WC_CHIP_MODULE_VERSION,
);
$script_url = WC_CHIP_URL . $script_path;

wp_register_script(
"wc-{$this->name}-blocks",
$script_url,
$script_asset['dependencies'],
$script_asset['version'],
true
);

$localize_variable = array(
'id' => $this->name,
'fpx_b2c' => array( 'empty' => 'bank' ),
'fpx_b2b1' => array( 'empty' => 'bank' ),
'razer' => array( 'empty' => 'ewallet' ),
);

$whitelisted_payment_method = $this->gateway->get_payment_method_whitelist();
$bypass_chip = $this->gateway->get_bypass_chip();

// Exclude razer_atome.
$razer_ewallet_list = array( 'razer_grabpay', 'razer_maybankqr', 'razer_shopeepay', 'razer_tng' );

if ( is_array( $whitelisted_payment_method ) && 'yes' === $bypass_chip ) {
if ( count( $whitelisted_payment_method ) == 1 ) {
if ( $whitelisted_payment_method[0] == 'fpx' ) {
$localize_variable['fpx_b2c'] = $this->gateway->list_fpx_banks();
unset( $localize_variable['fpx_b2c'][''] );
} elseif ( 'fpx_b2b1' === $whitelisted_payment_method[0] ) {
$localize_variable['fpx_b2b1'] = $this->gateway->list_fpx_b2b1_banks();
unset( $localize_variable['fpx_b2b1'][''] );
} else {
// Checker when whitelist one e-wallet only (razer).
if ( ( count( preg_grep( '/^razer_/', $whitelisted_payment_method ) ) > 0 ) ) {
$localize_variable['razer'] = $this->gateway->list_razer_ewallets();
unset( $localize_variable['razer'][''] );
}
}
} elseif ( count( array_diff( $whitelisted_payment_method, $razer_ewallet_list ) ) == 0 ) {
$localize_variable['razer'] = $this->gateway->list_razer_ewallets();
unset( $localize_variable['razer'][''] );
}
}

wp_localize_script( "wc-{$this->name}-blocks", 'gateway_' . $this->name, $localize_variable );

return array( "wc-{$this->name}-blocks" );
}

/**
* Get the payment method data.
* This method is used to get the payment method data for the block checkout.
*
* @return array
*/
public function get_payment_method_data() {
$pm_whitelist = $this->get_setting( 'payment_method_whitelist' );
$bypass_chip = $this->get_setting( 'bypass_chip' );
$js_display = '';

if ( is_array( $pm_whitelist ) && count( $pm_whitelist ) == 1 && $pm_whitelist[0] == 'fpx' && $bypass_chip == 'yes' ) {
$js_display = 'fpx';
} elseif ( is_array( $pm_whitelist ) && count( $pm_whitelist ) == 1 && $pm_whitelist[0] == 'fpx_b2b1' && $bypass_chip == 'yes' ) {
$js_display = 'fpx_b2b1';
} elseif ( is_array( $pm_whitelist ) && $bypass_chip == 'yes' ) {
$razer_ewallet_list = array( 'razer_grabpay', 'razer_maybankqr', 'razer_shopeepay', 'razer_tng' );
if ( count( array_diff( $pm_whitelist, $razer_ewallet_list ) ) == 0 ) {
$js_display = 'razer';
}
}

return array(
'title' => $this->get_setting( 'title' ),
'description' => $this->get_setting( 'description' ),
'supports' => array_filter( $this->gateway->supports, array( $this->gateway, 'supports' ) ),
'method_name' => $this->name,
'saved_option' => $this->gateway->supports( 'tokenization' ),
'save_option' => false,
'js_display' => $js_display,
'icon' => $this->gateway->icon,
);
}
}
103 changes: 0 additions & 103 deletions includes/blocks/class-wc-gateway-chip-blocks.php

This file was deleted.

2 changes: 1 addition & 1 deletion includes/blocks/clone-wc-gateway-chip-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ class WC_Gateway_Chip_5_Blocks_Support extends WC_Gateway_Chip_Blocks_Support {

class WC_Gateway_Chip_6_Blocks_Support extends WC_Gateway_Chip_Blocks_Support {
protected $name = 'wc_gateway_chip_6';
}
}
45 changes: 25 additions & 20 deletions includes/class-wc-api-fpx.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Chip_Woocommerce_API_FPX {

public function __construct( $logger, $debug ) {
$this->logger = $logger;
$this->debug = $debug;
$this->debug = $debug;
}

public function get_fpx() {
Expand All @@ -23,7 +23,7 @@ public function get_fpx_b2b1() {
return $this->call( 'GET', '/fpx_b2b1?time=' . time() );
}

private function call( $method, $route, $params = [] ) {
private function call( $method, $route, $params = array() ) {
if ( ! empty( $params ) ) {
$params = json_encode( $params );
}
Expand All @@ -32,9 +32,9 @@ private function call( $method, $route, $params = [] ) {
$method,
sprintf( '%s%s', WC_CHIP_FPX_ROOT_URL, $route ),
$params,
[
'Content-type' => 'application/json'
]
array(
'Content-type' => 'application/json',
)
);

$this->log_info( sprintf( 'received response: %s', $response ) );
Expand All @@ -54,22 +54,27 @@ private function call( $method, $route, $params = [] ) {
return $result;
}

private function request( $method, $url, $params = [], $headers = [] ) {
$this->log_info( sprintf(
'%s `%s`\n%s\n%s',
$method,
private function request( $method, $url, $params = array(), $headers = array() ) {
$this->log_info(
sprintf(
'%s `%s`\n%s\n%s',
$method,
$url,
var_export( $params, true ),
var_export( $headers, true )
)
);

$wp_request = wp_remote_request(
$url,
var_export( $params, true ),
var_export( $headers, true )
) );

$wp_request = wp_remote_request( $url, array(
'method' => $method,
'sslverify' => ! defined( 'WC_CHIP_SSLVERIFY_FALSE' ),
'headers' => $headers,
'body' => $params,
'timeout' => 3
) );
array(
'method' => $method,
'sslverify' => ! defined( 'WC_CHIP_SSLVERIFY_FALSE' ),
'headers' => $headers,
'body' => $params,
'timeout' => 3,
)
);

$response = wp_remote_retrieve_body( $wp_request );

Expand Down
Loading