Skip to content
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

v 1.7.0 - Emoji in title clear, Payment method delete fixes, Fatal and warnings fixes #307

Merged
merged 15 commits into from
Feb 21, 2024
2 changes: 2 additions & 0 deletions Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ The Billwerk+ Payments plugin extends WooCommerce allowing you to take payments
See installation guide right here: https://docu.billwerk.plus/help/en/apps/woocommerce/setup-woocommerce-plugin.html

== Changelog ==
v 1.7.0 - Emoji in title clear, Payment method delete fixes, Fatal and warnings fixes
v 1.6.4 - Fix settle string fatal error
v 1.6.3 - Woocommerce zero payment fixes
v 1.6.2 - Fix user handle generate
v 1.6.1 - Card saving fixes, user creation fixes
Expand Down
3 changes: 1 addition & 2 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,13 @@ jQuery(document).ready(function ($) {
});

$(document).on('click', '#woocommerce-order-actions .button', function (e) {
e.preventDefault();

var order_id = $("#reepay_order_id").data('order-id');
var amount = $('#reepay_order_total').data('order-total');
var authorized = $('#reepay_order_total_authorized').val();
var settled = $('#reepay_order_total_settled').val();
var formatted_amount = $("#reepay_order_total").val();
if (amount > 0 && settled < authorized && $("#order_status option:selected").val() == 'wc-completed') {
e.preventDefault();
const settle = window.confirm('You are about to change the order status. Do you want to capture the remaining amount of ' + formatted_amount + ' at the same time? Click OK to continue with settle. Click Cancel to continue without settle.');

$.ajax({
Expand Down
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

107 changes: 57 additions & 50 deletions includes/Admin/MetaBoxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,63 +44,40 @@ public function add_meta_boxes() {
? wc_get_page_screen_id( 'shop-order' )
: 'shop_order';

$order_id = ! empty( $_REQUEST['id'] ) ? $_REQUEST['id'] : 0;
$order = wc_get_order( $order_id );
if ( $order ) {
$order_data = $order->get_data();
if ( ! empty( $_REQUEST['id'] ) ) {
$order_id = $_REQUEST['id'];
} elseif ( ! empty( $_GET['post'] ) ) {
$order_id = $_GET['post'];
}

if ( empty( $order ) || ! rp_is_order_paid_via_reepay( $order ) ) {
return;
}
if ( ! empty( $order_id ) ) {
$order = wc_get_order( $order_id );
if ( $order ) {
$order_data = $order->get_data();

$gateway = rp_get_payment_method( $order );
if ( empty( $order ) || ! rp_is_order_paid_via_reepay( $order ) ) {
return;
}

if ( empty( $gateway ) ) {
return;
}
$gateway = rp_get_payment_method( $order );

if ( ! empty( $order->get_meta( '_reepay_order' ) ) && 0 !== $order_data['parent_id'] ) {
$parent_order = wc_get_order( $order_data['parent_id'] );
$subscription = $parent_order->get_meta( '_reepay_subscription_handle' );
} elseif ( ! empty( $order->get_meta( '_reepay_subscription_handle_parent' ) ) ) {
$subscription = $order->get_meta( '_reepay_subscription_handle_parent' );
} else {
$subscription = $order->get_meta( '_reepay_subscription_handle' );
}
if ( empty( $gateway ) ) {
return;
}

add_meta_box(
'reepay_checkout_customer',
__( 'Customer', 'reepay-checkout-gateway' ),
array( $this, 'generate_meta_box_content_customer' ),
$screen,
'side',
'high',
array(
'order' => $order,
'gateway' => $gateway,
)
);

if ( ! empty( $order->get_transaction_id() ) ) {
add_meta_box(
'reepay_checkout_invoice',
__( 'Invoice', 'reepay-checkout-gateway' ),
array( $this, 'generate_meta_box_content_invoice' ),
$screen,
'side',
'high',
array(
'order' => $order,
'gateway' => $gateway,
)
);
}
if ( ! empty( $order->get_meta( '_reepay_order' ) ) && 0 !== $order_data['parent_id'] ) {
$parent_order = wc_get_order( $order_data['parent_id'] );
$subscription = $parent_order->get_meta( '_reepay_subscription_handle' );
} elseif ( ! empty( $order->get_meta( '_reepay_subscription_handle_parent' ) ) ) {
$subscription = $order->get_meta( '_reepay_subscription_handle_parent' );
} else {
$subscription = $order->get_meta( '_reepay_subscription_handle' );
}

if ( ! empty( $subscription ) ) {
add_meta_box(
'reepay_checkout_subscription',
__( 'Subscription', 'reepay-checkout-gateway' ),
array( $this, 'generate_meta_box_content_subscription' ),
'reepay_checkout_customer',
__( 'Customer', 'reepay-checkout-gateway' ),
array( $this, 'generate_meta_box_content_customer' ),
$screen,
'side',
'high',
Expand All @@ -109,6 +86,36 @@ public function add_meta_boxes() {
'gateway' => $gateway,
)
);

if ( ! empty( $order->get_transaction_id() ) ) {
add_meta_box(
'reepay_checkout_invoice',
__( 'Invoice', 'reepay-checkout-gateway' ),
array( $this, 'generate_meta_box_content_invoice' ),
$screen,
'side',
'high',
array(
'order' => $order,
'gateway' => $gateway,
)
);
}

if ( ! empty( $subscription ) ) {
add_meta_box(
'reepay_checkout_subscription',
__( 'Subscription', 'reepay-checkout-gateway' ),
array( $this, 'generate_meta_box_content_subscription' ),
$screen,
'side',
'high',
array(
'order' => $order,
'gateway' => $gateway,
)
);
}
}
}
}
Expand Down
39 changes: 39 additions & 0 deletions includes/Functions/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,43 @@ function rp_format_credit_card( string $cc ) {

return $new_cc;
}

/**
* Clear product titles emoji
*
* @param string $title Product title.
*
* @return string the nicely formatted value
*/
function rp_clear_ordertext( string $title ): string {
// Match Enclosed Alphanumeric Supplement.
$regex_alphanumeric = '/[\x{1F100}-\x{1F1FF}]/u';
$clear_string = preg_replace( $regex_alphanumeric, '', $title );

// Match Miscellaneous Symbols and Pictographs.
$regex_symbols = '/[\x{1F300}-\x{1F5FF}]/u';
$clear_string = preg_replace( $regex_symbols, '', $clear_string );

// Match Emoticons.
$regex_emoticons = '/[\x{1F600}-\x{1F64F}]/u';
$clear_string = preg_replace( $regex_emoticons, '', $clear_string );

// Match Transport And Map Symbols.
$regex_transport = '/[\x{1F680}-\x{1F6FF}]/u';
$clear_string = preg_replace( $regex_transport, '', $clear_string );

// Match Supplemental Symbols and Pictographs.
$regex_supplemental = '/[\x{1F900}-\x{1F9FF}]/u';
$clear_string = preg_replace( $regex_supplemental, '', $clear_string );

// Match Miscellaneous Symbols.
$regex_misc = '/[\x{2600}-\x{26FF}]/u';
$clear_string = preg_replace( $regex_misc, '', $clear_string );

// Match Dingbats.
$regex_dingbats = '/[\x{2700}-\x{27BF}]/u';
$clear_string = preg_replace( $regex_dingbats, '', $clear_string );

return $clear_string;
}
}
5 changes: 4 additions & 1 deletion includes/Gateways/ReepayCheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public function __construct() {
$this->private_key = apply_filters( 'woocommerce_reepay_private_key', $this->settings['private_key'] ?: $this->private_key );
$this->private_key_test = apply_filters( 'woocommerce_reepay_private_key_test', $this->settings['private_key_test'] ?: $this->private_key_test );
$this->test_mode = $this->settings['test_mode'] ?: $this->test_mode;
$this->settle = $this->settings['settle'] ?: $this->settle;
$this->language = $this->settings['language'] ?: $this->language;
$this->save_cc = $this->settings['save_cc'] ?: $this->save_cc;
$this->debug = $this->settings['debug'] ?: $this->debug;
Expand All @@ -84,6 +83,10 @@ public function __construct() {
$this->failed_webhooks_email = $this->settings['failed_webhooks_email'] ?: $this->failed_webhooks_email;
$this->handle_failover = ! empty( $this->settings['handle_failover'] ) ?: $this->handle_failover;

if ( ! empty( $this->settings['settle'] ) && is_array( $this->settings['settle'] ) ) {
$this->settle = $this->settings['settle'];
}

if ( 'yes' === $this->save_cc ) {
$this->supports[] = 'add_payment_method';
}
Expand Down
45 changes: 39 additions & 6 deletions includes/Gateways/ReepayGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -1389,24 +1389,57 @@ public function get_order_items( WC_Order $order, $only_not_settled = false ): a
if ( $order_item->get_product() && wcr_is_subscription_product( $order_item->get_product() ) ) {
$fee = $order_item->get_product()->get_meta( '_reepay_subscription_fee' );
if ( ! empty( $fee ) && ! empty( $fee['enabled'] ) && 'yes' === $fee['enabled'] ) {
$setup_fees[] = $order_item->get_product()->get_name() . ' - ' . $fee['text'];
$setup_fees[] = rp_clear_ordertext( $order_item->get_product()->get_name() ) . ' - ' . $fee['text'];
}
$sub_amount_discount += floatval( $order_item->get_meta( '_line_discount' ) );
continue;
}

$price = $order->get_line_subtotal( $order_item, false, false );
$price = $order->get_line_subtotal( $order_item, false, false );
$this->log(
array(
'source' => 'Price',
'result' => $price,
)
);

$price_with_tax = $order->get_line_subtotal( $order_item, true, false );
$tax = $price_with_tax - $price;
$tax_percent = ( $tax > 0 && $price > 0 ) ? round( 100 / ( $price / $tax ) ) : 0;
$unit_price = round( ( $prices_incl_tax ? $price_with_tax : $price ) / $order_item->get_quantity(), 2 );
$this->log(
array(
'source' => 'Price with tax',
'result' => $price_with_tax,
)
);

$tax = $price_with_tax - $price;
$this->log(
array(
'source' => 'Tax amount',
'result' => $tax,
)
);

$tax_percent = ( $tax > 0 && $price > 0 ) ? round( 100 / ( $price / $tax ) ) : 0;
$this->log(
array(
'source' => 'Tax percent',
'result' => $tax_percent,
)
);
$unit_price = round( ( $prices_incl_tax ? $price_with_tax : $price ) / $order_item->get_quantity(), 2 );
$this->log(
array(
'source' => 'Unit price',
'result' => $unit_price,
)
);

if ( $only_not_settled && ! empty( $order_item->get_meta( 'settled' ) ) ) {
continue;
}

$items[] = array(
'ordertext' => $order_item->get_name(),
'ordertext' => rp_clear_ordertext( $order_item->get_name() ),
'quantity' => $order_item->get_quantity(),
'amount' => rp_prepare_amount( $unit_price, $order->get_currency() ),
'vat' => round( $tax_percent / 100, 2 ),
Expand Down
2 changes: 1 addition & 1 deletion includes/OrderFlow/OrderCapture.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ public function get_item_data( WC_Order_Item $order_item, WC_Order $order ): arr
$unit_price = round( ( $prices_incl_tax ? $price['with_tax'] : $price['original'] ) / $order_item->get_quantity(), 2 );

return array(
'ordertext' => $order_item->get_name(),
'ordertext' => rp_clear_ordertext( $order_item->get_name() ),
'quantity' => $order_item->get_quantity(),
'amount' => rp_prepare_amount( $unit_price, $order->get_currency() ),
'vat' => round( $tax_percent / 100, 2 ),
Expand Down
8 changes: 4 additions & 4 deletions includes/Tokens/ReepayTokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ public static function get_payment_token_by_order( WC_Order $order ) {
public static function get_payment_token_subscription( WC_Subscription $subscription ) {
$token = $subscription->get_meta( '_reepay_token' );
// If token wasn't stored in Subscription.
if ( empty( $token ) ) {
if ( ! is_wp_error( $token ) && empty( $token ) ) {
$order = $subscription->get_parent();
if ( $order ) {
if ( ! is_wp_error( $order ) && $order ) {
$token = $order->get_meta( '_reepay_token' );
if ( empty( $token ) ) {
if ( ! is_wp_error( $order ) && empty( $token ) ) {
$invoice_data = reepay()->api( $order )->get_invoice_data( $order );
if ( ! empty( $invoice_data ) && ! is_wp_error( $invoice_data ) ) {
if ( ! empty( $invoice_data['recurring_payment_method'] ) ) {
Expand Down Expand Up @@ -285,7 +285,7 @@ public static function get_payment_token( string $token ) {
*
* @return bool
*/
public static function delete_card( WC_Payment_Token $token ): bool {
public static function delete_card( WC_Payment_Token $token ) {
$result = reepay()->api( 'api-delete-card' )->delete_payment_method( $token->get_token() );

if ( is_wp_error( $result ) ) {
Expand Down
22 changes: 21 additions & 1 deletion includes/Tokens/TokenReepay.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
namespace Reepay\Checkout\Tokens;

use Exception;
use Reepay\Checkout\Tokens\ReepayTokens;
use WC_HTTPS;
use WC_Payment_Gateway;
use WC_Payment_Token;
use WC_Payment_Tokens;
use WC_Payment_Token_CC;
use Reepay\Checkout\Tokens\ReepayTokens;

defined( 'ABSPATH' ) || exit();

Expand Down Expand Up @@ -79,6 +80,25 @@ public function get_display_name( $deprecated = '' ): string {
return $display;
}

/**
* Delete payment method in reepay side.
*
* @param bool $force_delete From parent.
*
* @return bool
*/
public function delete( $force_delete = false ) {
global $wp;

if ( isset( $wp->query_vars['delete-payment-method'] ) ) {
$token_id = absint( $wp->query_vars['delete-payment-method'] );
$token = WC_Payment_Tokens::get( $token_id );
ReepayTokens::delete_card( $token );
}

return parent::delete();
}

/**
* Get card image url
*
Expand Down
2 changes: 1 addition & 1 deletion reepay-woocommerce-payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Description: Get a plug-n-play payment solution for WooCommerce, that is easy to use, highly secure and is built to maximize the potential of your e-commerce.
* Author: Billwerk+
* Author URI: http://billwerk.plus
* Version: 1.6.3
* Version: 1.7.0
* Text Domain: reepay-checkout-gateway
* Domain Path: /languages
* WC requires at least: 3.0.0
Expand Down
2 changes: 1 addition & 1 deletion templates/meta-boxes/invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ class="reepay-admin-card-logo"/>
<?php _e( 'See invoice', 'reepay-subscriptions-for-woocommerce' ); ?>
</a>
</li>
</ul>
</ul>
Loading