Skip to content

Commit

Permalink
v1.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
dimosKougiou committed Jul 18, 2024
1 parent 26d7e84 commit aab4d0c
Show file tree
Hide file tree
Showing 13 changed files with 441 additions and 279 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
- Contributors: cardlink
- Tags: payments, payment-gateway
- Requires at least: 5.8.3
- Tested up to: 6.5.2
- Tested up to: 6.5.5
- Requires PHP: 7.x - 8.x
- License: GPLv2 or later
- License URI: http://www.gnu.org/licenses/gpl-2.0.html


## Changelog

- **1.0.7**
- Added support for block-based checkout.
- **1.0.6**
- Support Alpha bonus transactions.
- **1.0.5**
Expand Down
20 changes: 18 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Contributors: cardlink
Tags: payments, payment-gateway
Requires at least: 5.8.3
Tested up to: 6.5.2
Stable tag: 6.5.2
Tested up to: 6.5.5
Stable tag: 6.5.5
Requires PHP: 7.4
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -48,3 +48,19 @@ Here are the detailed instructions to manually install a WordPress plugin by tra

== Changelog ==

= 1.0.7 =
* Added support for block-based checkout.
= 1.0.6 =
* Support Alpha bonus transactions.
= 1.0.5 =
* Bugfix: Fix compatibility issues with Payment Plugins for Stripe WooCommerce and Payment Plugins for PayPal WooCommerce plugins
= 1.0.4 =
* Bugfix: Check if WooCommerce is installed and activated before initialize plugin functionality
= 1.0.3 =
* Styling updates on iframe popup window
= 1.0.2 =
* Bugfix: Installments total number
= 1.0.1 =
* Compatibility updates
= 1.0.0 =
* Initial release
32 changes: 28 additions & 4 deletions admin/class-cardlink-payment-gateway-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;

add_filter( 'admin_body_class', [ $this, 'admin_body_class'] );

}

/**
Expand Down Expand Up @@ -120,7 +122,7 @@ public function cardlink_message() {
} else {
$payment_method = $order->payment_method;
}
if ( is_order_received_page() && ( 'cardlink_payment_gateway_woocommerce' == $payment_method || 'cardlink_payment_gateway_woocommerce_iris' == $payment_method ) ) {
if ( is_order_received_page() && ( 'cardlink_payment_gateway_woocommerce' == $payment_method ) ) {
if ( method_exists( $order, 'get_meta' ) ) {
$cardlink_message = $order->get_meta( '_cardlink_message', true );
} else {
Expand All @@ -143,11 +145,33 @@ public function cardlink_message() {
public function woocommerce_add_cardlink_gateway( $methods ) {

$methods[] = 'Cardlink_Payment_Gateway_Woocommerce';
//$methods[] = 'Cardlink_Payment_Gateway_Woocommerce_Iris';

// $methods[] = 'WC_cardlink_Gateway_masterpass';

return $methods;
}

public static function woocommerce_gateway_block_support() {
if ( class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/blocks/class-wc-cardlink-payments-block.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_Cardlink_Blocks_Support() );
}
);

}
}

public function admin_body_class($classes) {

$payment_gateway_id = 'cardlink_payment_gateway_woocommerce';
$payment_gateways = WC_Payment_Gateways::instance();
$payment_gateway = $payment_gateways->payment_gateways()[$payment_gateway_id];
if ($payment_gateway->acquirer == '1') {
$classes .= ' acquirer-nexi-checkout';
}

return $classes;
}
}

2 changes: 1 addition & 1 deletion admin/css/cardlink-payment-gateway-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@

.installments_variation_row .button i {
vertical-align: middle;
}
}
12 changes: 12 additions & 0 deletions cardlink-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,15 @@ function run_cardlink_payment_gateway() {
if (in_array( $plugin_path, wp_get_active_and_valid_plugins() )) {
run_cardlink_payment_gateway();
}

function cardlink_payment_gateway_depedency_notice() {
if ( class_exists( 'WooCommerce' ) ) {
return;
}
?>
<div class="notice notice-error is-dismissible">
<p><?php _e( 'Cardlink Payment Gateway requires WooCommerce to be installed and active.', 'cardlink-payment-gateway' ); ?></p>
</div>
<?php
}
add_action( 'admin_notices', 'cardlink_payment_gateway_depedency_notice' );
90 changes: 90 additions & 0 deletions includes/blocks/class-wc-cardlink-payments-block.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

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

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

final class WC_Gateway_Cardlink_Blocks_Support extends AbstractPaymentMethodType {


protected $name = 'cardlink_payment_gateway_block';

public function initialize() {
$this->settings = get_option('woocommerce_cardlink_payment_gateway_woocommerce_settings', []);
add_action( 'woocommerce_rest_checkout_process_payment_with_context', [ $this, 'add_payment_request_order_meta' ], 8, 2 );
}

public function is_active() {
return filter_var( $this->get_setting( 'enabled', false ), FILTER_VALIDATE_BOOLEAN );
}

public function get_payment_method_script_handles() {
$plugin_path = plugin_dir_url( dirname( dirname( __FILE__ ) ) );
$script_asset_path = $plugin_path . '/public/js/cardlink-block.min.asset.php';
$script_asset = file_exists( $script_asset_path ) ? require( $script_asset_path ) : array(
'dependencies' => array(),
'version' => CARDLINK_PAYMENT_GATEWAY_VERSION
);
$script_url = $plugin_path . '/public/js/blocks/cardlink-block.min.js';

wp_register_script( 'wc-cardlink-payments-block', $script_url, $script_asset['dependencies'], $script_asset['version'], true );

if ( function_exists( 'wp_set_script_translations' ) ) {
wp_set_script_translations( 'wc-cardlink-payments-block', 'cardlink-payment-gateway', $plugin_path . '/languages/' );
}

return [ 'wc-cardlink-payments-block' ];
}

public function get_payment_method_data() {

$installments_variation_data = $this->get_setting( 'installments_variation' );
$installments_variation = null;
if ($installments_variation_data) {
$installments_split = explode( ',', $installments_variation_data );
foreach ( $installments_split as $key => $value ) {
$installment = explode( ':', $value );
if ( is_array( $installment ) && count( $installment ) != 2 ) {
// not valid rule for installments
continue;
}
$amount = (float) $installment[0];
$max_installments = (int) $installment[1];
$installments_variation[$amount] = $max_installments;
}
}

return [
'title' => $this->get_setting( 'title' ),
'description' => $this->get_setting( 'description' ),
'supports' => ['products'],
'tokenization' => $this->get_setting( 'tokenization' ) == 'yes',
'installments' => abs( $this->get_setting( 'installments' ) ),
'installment_variations' => $installments_variation,
];
}

public function add_payment_request_order_meta( PaymentContext $context, PaymentResult &$result ) {

$data = $context->payment_data;

if ( $context->payment_method == 'cardlink_payment_gateway_woocommerce' ) {
$payment_method = $context->payment_method;
$maybe_store_card = $context->payment_data['wc-' . $payment_method . '-new-payment-method'];
$data[$payment_method . '-card-store'] = $maybe_store_card;
$data[$payment_method . '-card-doseis'] = $context->payment_data['installmentsvalue'];
if (array_key_exists('token', $data)) {
$token_id = $data['token'];
$token_class = new WC_Payment_Token_Data_Store;
$token = $token_class->get_token_by_id( $token_id );
$data[$payment_method . '-card'] = $token->token;
}
$context->set_payment_data($data);
}

}
}
Loading

0 comments on commit aab4d0c

Please sign in to comment.