From 067b1074be3424e029f771567abbb2ee3667e3a6 Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Wed, 16 Apr 2025 11:37:15 +0500 Subject: [PATCH 01/11] Support applying surcharge fee to order payments --- helpers/traits/AltapayMaster.php | 24 ++++++++++++++++++++++ includes/AltapayFormFields.php | 14 +++++++++++++ views/altapay-payment-form.php | 35 ++++++++++++++++++++++++++++++-- views/paymentClass.tpl | 13 ++++++++++++ views/tables/index.blade.php | 2 +- 5 files changed, 85 insertions(+), 3 deletions(-) diff --git a/helpers/traits/AltapayMaster.php b/helpers/traits/AltapayMaster.php index 0cd10724..0898c85b 100644 --- a/helpers/traits/AltapayMaster.php +++ b/helpers/traits/AltapayMaster.php @@ -70,6 +70,30 @@ public function scheduledSubscriptionsPayment( $amount, $renewal_order ) { return; } + $payment_method = wc_get_payment_gateway_by_order( $renewal_order ); + if ( $payment_method && isset( $payment_method->settings ) && is_array( $payment_method->settings ) ) { + $settings = $payment_method->settings; + $surcharge = $settings['surcharge'] ?? 'no'; + $surcharge_renewal_order = $settings['surcharge_renewal_order'] ?? 'no'; + + if ( $surcharge === 'yes' && $surcharge_renewal_order === 'yes' ) { + $fees = $parent_order->get_fees(); + foreach ( $fees as $fee ) { + $surchargeAmount = (float) $fee->get_total(); + if ( $fee->get_name() === 'Surcharge' ) { + $surcharge_fee = new \WC_Order_Item_Fee(); + $surcharge_fee->set_name( 'Surcharge' ); + $surcharge_fee->set_amount( $surchargeAmount ); + $surcharge_fee->set_total( $surchargeAmount ); + $surcharge_fee->set_tax_status( 'none' ); + $renewal_order->add_item( $surcharge_fee ); + } + } + + $renewal_order->calculate_totals(); + } + } + // @phpstan-ignore-next-line if ( $this->payment_action === 'authorize_capture' ) { $reconciliationId = wp_generate_uuid4(); diff --git a/includes/AltapayFormFields.php b/includes/AltapayFormFields.php index 9062c41c..28274e51 100755 --- a/includes/AltapayFormFields.php +++ b/includes/AltapayFormFields.php @@ -96,6 +96,20 @@ 'default' => array( 'visa', 'masterCard', 'amex' ), 'desc_tip' => true, ), + 'surcharge' => array( + 'title' => __( 'Enable Surcharge?', 'altapay' ), + 'type' => 'checkbox', + 'label' => __( 'Check this option to enable surcharge for this payment method.', 'altapay' ), + 'default' => 'no', + 'desc_tip' => true, + ), + 'surcharge_renewal_order' => array( + 'title' => __( 'Surcharge on renewal orders?', 'altapay' ), + 'type' => 'checkbox', + 'label' => __( 'Enable this option to apply surcharge to recurring orders.', 'altapay' ), + 'default' => 'no', + 'desc_tip' => true, + ), ); if ( $tokenStatus === 'CreditCard' ) { diff --git a/views/altapay-payment-form.php b/views/altapay-payment-form.php index e561ad15..c29041ad 100755 --- a/views/altapay-payment-form.php +++ b/views/altapay-payment-form.php @@ -16,8 +16,9 @@ exit; // Exit if accessed directly } -$order_id = isset( $_POST['shop_orderid'] ) ? wp_unslash( $_POST['shop_orderid'] ) : 0; -$order = wc_get_order( $order_id ); +$order_id = isset( $_POST['shop_orderid'] ) ? wp_unslash( $_POST['shop_orderid'] ) : 0; +$order = wc_get_order( $order_id ); +$surcharge = 'no'; if ( $order ) { $wpml_language = $order->get_meta( 'wpml_language' ); if ( ! empty( $wpml_language ) ) { @@ -28,6 +29,11 @@ $sitepress->switch_lang( $wpml_language ); } } + $payment_method = wc_get_payment_gateway_by_order( $order ); + if ( $payment_method && isset( $payment_method->settings ) && is_array( $payment_method->settings ) ) { + $settings = $payment_method->settings; + $surcharge = $settings['surcharge'] ?? 'no'; + } } get_header(); ?> @@ -552,6 +558,17 @@ } +.altapay-surcharge { + display: flex; + justify-content: space-between; + margin-bottom: 20px; +} +.surcharge-amount span.currency-symbol { + display: none; +} +.Surcharged .surcharge-amount span.currency-symbol { + display: inline-block; +} /* Hide 'Show Klarna Page' button if hidden attribute exists */ input#showKlarnaPage[hidden] { display: none; @@ -562,6 +579,20 @@
+ +
+
+ + + +
+
+ + + +
+
+
diff --git a/views/paymentClass.tpl b/views/paymentClass.tpl index 2d5c72f2..0ffa71d2 100755 --- a/views/paymentClass.tpl +++ b/views/paymentClass.tpl @@ -51,6 +51,7 @@ class WC_Gateway_{key} extends WC_Payment_Gateway { public $apple_pay_label; public $apple_pay_supported_networks; public $secret; + public $apply_surcharge; public function __construct() { // Set default gateway values @@ -69,6 +70,7 @@ class WC_Gateway_{key} extends WC_Payment_Gateway { $this->apple_pay_label = $this->get_option( 'apple_pay_label' ); $this->apple_pay_supported_networks = $this->get_option( 'apple_pay_supported_networks' ); $this->secret = $this->get_option( 'secret' ); + $this->apply_surcharge = $this->get_option( 'surcharge' ); // Load form fields @@ -425,6 +427,17 @@ class WC_Gateway_{key} extends WC_Payment_Gateway { $lastFourDigits = $transaction['CardInformation']['LastFourDigits'] ?? ''; $ccExpiryDate = isset( $transaction['CreditCardExpiry'] ) ? ( $transaction['CreditCardExpiry']['Month'] . '/' . $transaction['CreditCardExpiry']['Year'] ) : ''; $reservedAmount = $transaction['ReservedAmount'] ?? 0; + $surchargeAmount = $transaction['SurchargeAmount'] ?? 0; + + if ( $this->apply_surcharge && $surchargeAmount > 0 ) { + $surcharge_fee = new \WC_Order_Item_Fee(); + $surcharge_fee->set_name( 'Surcharge' ); + $surcharge_fee->set_amount( $surchargeAmount ); + $surcharge_fee->set_total( $surchargeAmount ); + $surcharge_fee->set_tax_status( 'none' ); + $order->add_item( $surcharge_fee ); + $order->calculate_totals(); + } /* Exit if payment already completed against the same order and diff --git a/views/tables/index.blade.php b/views/tables/index.blade.php index 2be9241b..120432b3 100755 --- a/views/tables/index.blade.php +++ b/views/tables/index.blade.php @@ -50,7 +50,7 @@ $toBeCaptured = round($reserved - $captured, 2); if( !empty($agreement_id) && $toBeCaptured == 0 ){ - $toBeCaptured = $total; + $toBeCaptured = round($total, 2); } @endphp @if ( $captured < $reserved || $reserved == 0 ) From 4beb928ff4022f23088f4a7e29bdb7689480a1ed Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Wed, 16 Apr 2025 11:37:41 +0500 Subject: [PATCH 02/11] Update version and release notes --- CHANGELOG.md | 3 +++ altapay.php | 6 +++--- readme.txt | 9 ++++++--- wiki.md | 6 +++--- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be5d40d4..e9732974 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog All notable changes to this project will be documented in this file. +## [3.7.9] +- Support applying surcharge fee to order payments. + ## [3.7.8] - Fix: Remove restriction on order lines when placing an order. diff --git a/altapay.php b/altapay.php index 5f10e94b..ec6eaa3f 100755 --- a/altapay.php +++ b/altapay.php @@ -7,10 +7,10 @@ * Author URI: https://altapay.com * Text Domain: altapay * Domain Path: /languages - * Version: 3.7.8 + * Version: 3.7.9 * Name: SDM_Altapay * WC requires at least: 3.9.0 - * WC tested up to: 9.7.1 + * WC tested up to: 9.8.1 * * @package Altapay */ @@ -41,7 +41,7 @@ } if ( ! defined( 'ALTAPAY_PLUGIN_VERSION' ) ) { - define( 'ALTAPAY_PLUGIN_VERSION', '3.7.8' ); + define( 'ALTAPAY_PLUGIN_VERSION', '3.7.9' ); } // Include the autoloader, so we can dynamically include the rest of the classes. diff --git a/readme.txt b/readme.txt index db46d28b..4ff6ef19 100644 --- a/readme.txt +++ b/readme.txt @@ -3,11 +3,11 @@ Contributors: altapay_integrations Tags: AltaPay, Gateway, Payments, WooCommerce, Payment Card Industry Requires PHP: 7.4 Requires at least: 5.0 -Tested up to: 6.7.2 -Stable tag: 3.7.8 +Tested up to: 6.8 +Stable tag: 3.7.9 License: MIT WC requires at least: 3.9.0 -WC tested up to: 9.7.1 +WC tested up to: 9.8.1 License URI: http://www.gnu.org/licenses/gpl-2.0.html A plugin that integrates your WooCommerce web shop to the AltaPay payments gateway. @@ -39,6 +39,9 @@ AltaPay's Payment Gateway for WooCommerce provides merchants with access to a fu == Changelog == += 3.7.9 = +* Support applying surcharge fee to order payments. + = 3.7.8 = * Fix: Remove restriction on order lines when placing an order. diff --git a/wiki.md b/wiki.md index c1370570..95756781 100644 --- a/wiki.md +++ b/wiki.md @@ -297,14 +297,14 @@ The new credentials can now be used as the API Username and API Password in your ## Supported versions Minimum system requirements are: -- WordPress min. 5.0 – max. 6.7.2 -- WooCommerce min. 3.9.0 – max. 9.7.1 +- WordPress min. 5.0 – max. 6.8 +- WooCommerce min. 3.9.0 – max. 9.8.1 - PHP 7.4 and above - PHP-bcmath library installed. - PHP-curl MUST be enabled. The latest tested version is: -- WordPress 6.7.2, WooCommerce 9.7.1 and PHP 8.2 +- WordPress 6.8, WooCommerce 9.8.1 and PHP 8.2 ## Troubleshooting From aba2d2932dc780c407454017ed4ef4c3564802fc Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Wed, 16 Apr 2025 11:40:23 +0500 Subject: [PATCH 03/11] Update formatting --- views/paymentClass.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/paymentClass.tpl b/views/paymentClass.tpl index 0ffa71d2..8dfde520 100755 --- a/views/paymentClass.tpl +++ b/views/paymentClass.tpl @@ -51,7 +51,7 @@ class WC_Gateway_{key} extends WC_Payment_Gateway { public $apple_pay_label; public $apple_pay_supported_networks; public $secret; - public $apply_surcharge; + public $apply_surcharge; public function __construct() { // Set default gateway values From 45004efd133ed30c8ccb435ed28222c408043ea0 Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Wed, 16 Apr 2025 11:50:50 +0500 Subject: [PATCH 04/11] Update ubuntu version --- .github/workflows/deployment.yml | 2 +- .github/workflows/support-deployment.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index 8254745e..80a3c2dd 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -15,7 +15,7 @@ on: jobs: terraform: name: 'Terraform' - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 outputs: ip: ${{ steps.expose_ip.outputs.ip}} diff --git a/.github/workflows/support-deployment.yml b/.github/workflows/support-deployment.yml index 8f1a594b..cb777b1c 100644 --- a/.github/workflows/support-deployment.yml +++ b/.github/workflows/support-deployment.yml @@ -10,7 +10,7 @@ on: jobs: terraform: name: 'Terraform' - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: From 8d82e1f491291cb2ebee0a09e01e36c0f0c36f26 Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Wed, 16 Apr 2025 12:11:28 +0500 Subject: [PATCH 05/11] Update branch to feature branch --- .github/workflows/deployment.yml | 2 +- .github/workflows/support-deployment.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index 80a3c2dd..4afde98f 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -35,7 +35,7 @@ jobs: with: repository: AltaPay/plugin-infrastructure token: ${{ secrets.ACCESS_TOKEN }} - ref: 'main' + ref: 'fix-deprecated-code' # Install version 1.0.8 of Terraform CLI - name: Setup Terraform diff --git a/.github/workflows/support-deployment.yml b/.github/workflows/support-deployment.yml index cb777b1c..d00f5bc9 100644 --- a/.github/workflows/support-deployment.yml +++ b/.github/workflows/support-deployment.yml @@ -28,7 +28,7 @@ jobs: with: repository: AltaPay/plugin-infrastructure token: ${{ secrets.ACCESS_TOKEN }} - ref: 'main' + ref: 'fix-deprecated-code' # Install version 1.0.8 of Terraform CLI - name: Setup Terraform From 1e4857b9791100ea975eaab74c6013e153a19b4b Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Wed, 16 Apr 2025 13:06:36 +0500 Subject: [PATCH 06/11] Update wiki --- wiki.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wiki.md b/wiki.md index 95756781..629d2e14 100644 --- a/wiki.md +++ b/wiki.md @@ -174,6 +174,8 @@ For the AltaPay payment method to appear in the checkout page: | Is Apple Pay? | Check if the terminal is for Apple Pay payments. | | Apple Pay form label | This controls the label shown on Apple Pay popup window. | | Apple Pay Supported Networks | The payment networks the merchant supports. | + | Enable Surcharge? | Check this option to enable surcharge for this payment method. | + | Surcharge on renewal orders? | Enable this option to apply surcharge to recurring orders as well. | | Token Control | Enable Customer Token Control. | - Save the changes. From 15ebe6dbbf0701a107304f054d944c2c108bd7d4 Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Wed, 16 Apr 2025 13:09:47 +0500 Subject: [PATCH 07/11] Change AltaPay/plugin-infrastructure branch name back to main --- .github/workflows/deployment.yml | 2 +- .github/workflows/support-deployment.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index 4afde98f..80a3c2dd 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -35,7 +35,7 @@ jobs: with: repository: AltaPay/plugin-infrastructure token: ${{ secrets.ACCESS_TOKEN }} - ref: 'fix-deprecated-code' + ref: 'main' # Install version 1.0.8 of Terraform CLI - name: Setup Terraform diff --git a/.github/workflows/support-deployment.yml b/.github/workflows/support-deployment.yml index d00f5bc9..cb777b1c 100644 --- a/.github/workflows/support-deployment.yml +++ b/.github/workflows/support-deployment.yml @@ -28,7 +28,7 @@ jobs: with: repository: AltaPay/plugin-infrastructure token: ${{ secrets.ACCESS_TOKEN }} - ref: 'fix-deprecated-code' + ref: 'main' # Install version 1.0.8 of Terraform CLI - name: Setup Terraform From cc8540c5445e943931907297a5b1c80ae9be369f Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Wed, 16 Apr 2025 14:09:55 +0500 Subject: [PATCH 08/11] Check if apply_surcharge is enabled --- views/paymentClass.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/paymentClass.tpl b/views/paymentClass.tpl index 8dfde520..6365450a 100755 --- a/views/paymentClass.tpl +++ b/views/paymentClass.tpl @@ -429,7 +429,7 @@ class WC_Gateway_{key} extends WC_Payment_Gateway { $reservedAmount = $transaction['ReservedAmount'] ?? 0; $surchargeAmount = $transaction['SurchargeAmount'] ?? 0; - if ( $this->apply_surcharge && $surchargeAmount > 0 ) { + if ( $this->apply_surcharge === 'yes' && $surchargeAmount > 0 ) { $surcharge_fee = new \WC_Order_Item_Fee(); $surcharge_fee->set_name( 'Surcharge' ); $surcharge_fee->set_amount( $surchargeAmount ); From a132556ccf67ae7f3653a85f65955169a08f65d4 Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Wed, 16 Apr 2025 14:28:06 +0500 Subject: [PATCH 09/11] Update styling for legacy form --- views/altapay-payment-form.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/views/altapay-payment-form.php b/views/altapay-payment-form.php index c29041ad..abecacdf 100755 --- a/views/altapay-payment-form.php +++ b/views/altapay-payment-form.php @@ -548,6 +548,14 @@ .woocommerce-page .col2-set .col-1, .woocommerce-column--shipping-address.col-2 { padding: 0; } + .pensio_payment_form_submit_cell { + display: flex; + justify-content: space-between; + align-items: center; + } + .pensio_payment_form_submit_cell span.secure-payments-text { + margin-bottom: 10px; + } @media screen and (min-width:769px){ .altapay-page-wrapper { display: flex; From da0895aeec53f52cc3840ff103a669a609bf9c69 Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Wed, 16 Apr 2025 17:55:09 +0500 Subject: [PATCH 10/11] Calculate surcharge for the renewal order --- helpers/traits/AltapayMaster.php | 36 ++++++++++++++++---------------- includes/AltapayFormFields.php | 7 ------- wiki.md | 1 - 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/helpers/traits/AltapayMaster.php b/helpers/traits/AltapayMaster.php index 0898c85b..2c0c0e13 100644 --- a/helpers/traits/AltapayMaster.php +++ b/helpers/traits/AltapayMaster.php @@ -19,6 +19,7 @@ use AltaPay\vendor\GuzzleHttp\Exception\ClientException; use Altapay\Api\Subscription\ChargeSubscription; use Altapay\Classes\Core; +use Altapay\Api\Others\CalculateSurcharge; trait AltapayMaster { @@ -72,25 +73,24 @@ public function scheduledSubscriptionsPayment( $amount, $renewal_order ) { $payment_method = wc_get_payment_gateway_by_order( $renewal_order ); if ( $payment_method && isset( $payment_method->settings ) && is_array( $payment_method->settings ) ) { - $settings = $payment_method->settings; - $surcharge = $settings['surcharge'] ?? 'no'; - $surcharge_renewal_order = $settings['surcharge_renewal_order'] ?? 'no'; - - if ( $surcharge === 'yes' && $surcharge_renewal_order === 'yes' ) { - $fees = $parent_order->get_fees(); - foreach ( $fees as $fee ) { - $surchargeAmount = (float) $fee->get_total(); - if ( $fee->get_name() === 'Surcharge' ) { - $surcharge_fee = new \WC_Order_Item_Fee(); - $surcharge_fee->set_name( 'Surcharge' ); - $surcharge_fee->set_amount( $surchargeAmount ); - $surcharge_fee->set_total( $surchargeAmount ); - $surcharge_fee->set_tax_status( 'none' ); - $renewal_order->add_item( $surcharge_fee ); - } + $settings = $payment_method->settings; + $surcharge = $settings['surcharge'] ?? 'no'; + + if ( $surcharge === 'yes' ) { + $api = new CalculateSurcharge( $this->getAuth() ); + $api->setPaymentId( $agreement_id ); + $api->setAmount( round( $amount, 2 ) ); + $surcharge = $api->call(); + if ( $surcharge->Result === 'Success' && $surcharge->SurchageAmount > 0 ) { + $surchargeAmount = (float) $surcharge->SurchageAmount; + $surcharge_fee = new \WC_Order_Item_Fee(); + $surcharge_fee->set_name( 'Surcharge' ); + $surcharge_fee->set_amount( $surchargeAmount ); + $surcharge_fee->set_total( $surchargeAmount ); + $surcharge_fee->set_tax_status( 'none' ); + $renewal_order->add_item( $surcharge_fee ); + $renewal_order->calculate_totals(); } - - $renewal_order->calculate_totals(); } } diff --git a/includes/AltapayFormFields.php b/includes/AltapayFormFields.php index 28274e51..6f504b8f 100755 --- a/includes/AltapayFormFields.php +++ b/includes/AltapayFormFields.php @@ -103,13 +103,6 @@ 'default' => 'no', 'desc_tip' => true, ), - 'surcharge_renewal_order' => array( - 'title' => __( 'Surcharge on renewal orders?', 'altapay' ), - 'type' => 'checkbox', - 'label' => __( 'Enable this option to apply surcharge to recurring orders.', 'altapay' ), - 'default' => 'no', - 'desc_tip' => true, - ), ); if ( $tokenStatus === 'CreditCard' ) { diff --git a/wiki.md b/wiki.md index 629d2e14..7302a13d 100644 --- a/wiki.md +++ b/wiki.md @@ -175,7 +175,6 @@ For the AltaPay payment method to appear in the checkout page: | Apple Pay form label | This controls the label shown on Apple Pay popup window. | | Apple Pay Supported Networks | The payment networks the merchant supports. | | Enable Surcharge? | Check this option to enable surcharge for this payment method. | - | Surcharge on renewal orders? | Enable this option to apply surcharge to recurring orders as well. | | Token Control | Enable Customer Token Control. | - Save the changes. From 8dbe3e9c57e6d13399746b7b36502cf566415585 Mon Sep 17 00:00:00 2001 From: Shahbaz Date: Thu, 17 Apr 2025 10:57:36 +0500 Subject: [PATCH 11/11] Include surcharge order line in payment actions grid --- views/tables/capture.blade.php | 98 ++++++++++++++++--------------- views/tables/order-line.blade.php | 17 ++++++ views/tables/refund.blade.php | 95 +++++++++++++++--------------- 3 files changed, 117 insertions(+), 93 deletions(-) create mode 100644 views/tables/order-line.blade.php diff --git a/views/tables/capture.blade.php b/views/tables/capture.blade.php index 19f1c61e..9fa037d2 100755 --- a/views/tables/capture.blade.php +++ b/views/tables/capture.blade.php @@ -20,11 +20,7 @@ - - - @php - $productsWithCoupon = array(); - @endphp + @foreach($order->get_items() as $item) @@ -45,26 +41,18 @@ $productUnitPriceWithTax = round(($total / $qty) + ($item->get_total_tax() / $qty), 2); $totalIncTax = round($total + $item->get_total_tax(), 2); @endphp - - - - - - {{$item->get_name()}} - {{$productUnitPriceWithTax}} - {{$productUnitPriceWithoutTax}} - {{ $qty }} - {{$discountPercent}} - - - - - {{$order->get_currency()}} {{$totalIncTax}} - - + @include('tables.order-line', [ + 'itemId' => $productID, + 'itemName' => $item->get_name(), + 'priceWithTax' => $productUnitPriceWithTax, + 'priceWithoutTax' => $productUnitPriceWithoutTax, + 'qty' => $qty, + 'discountPercent' => $discountPercent, + 'availableQty' => $capturableQty, + 'currency' => $order->get_currency(), + 'totalIncTax' => $totalIncTax, + 'type' => 'capture', + ]) @endforeach @if ($order->get_shipping_total() <> 0 || $order->get_shipping_tax() <> 0) @@ -78,28 +66,44 @@ @foreach ($order_shipping_methods as $ordershipping_key => $ordershippingmethods) @php($shipping_id = $ordershippingmethods['method_id']) @endforeach - - - @php - $capturableQty = ( isset( $items_captured[$shipping_id] ) && $items_captured[$shipping_id] == 1 ) ? 0 : 1; - @endphp - - - - {{$order->get_shipping_method()}} - {{$totalIncTax}} - {{$excTax}} - 1 - {{$discountPercentage}} - - - - - {{$order->get_currency()}} {{$totalIncTax}} - - + @php + $capturableQty = ( isset( $items_captured[$shipping_id] ) && $items_captured[$shipping_id] == 1 ) ? 0 : 1; + @endphp + @include('tables.order-line', [ + 'itemId' => $shipping_id, + 'itemName' => $order->get_shipping_method(), + 'priceWithTax' => $totalIncTax, + 'priceWithoutTax' => $excTax, + 'qty' => 1, + 'discountPercent' => $discountPercentage, + 'availableQty' => $capturableQty, + 'currency' => $order->get_currency(), + 'totalIncTax' => $totalIncTax, + 'type' => 'capture', + ]) @endif + + @php + $fees = $order->get_fees(); + @endphp + @foreach( $fees as $fee ) + @php + $surchargeAmount = (float) $fee->get_total(); + @endphp + @if( $fee->get_name() === 'Surcharge' ) + @include('tables.order-line', [ + 'itemId' => $fee->get_id(), + 'itemName' => $fee->get_name(), + 'priceWithTax' => $surchargeAmount, + 'priceWithoutTax' => $surchargeAmount, + 'qty' => 1, + 'discountPercent' => 0, + 'availableQty' => 1, + 'currency' => $order->get_currency(), + 'totalIncTax' => $surchargeAmount, + 'type' => 'capture' + ]) + @endif + @endforeach \ No newline at end of file diff --git a/views/tables/order-line.blade.php b/views/tables/order-line.blade.php new file mode 100644 index 00000000..d4f39c67 --- /dev/null +++ b/views/tables/order-line.blade.php @@ -0,0 +1,17 @@ + + + + + {{$itemName}} + {{$priceWithTax}} + {{$priceWithoutTax}} + {{ $qty }} + {{$discountPercent}} + + + + + {{$currency}} {{$totalIncTax}} + + \ No newline at end of file diff --git a/views/tables/refund.blade.php b/views/tables/refund.blade.php index a9282afa..1aca5735 100755 --- a/views/tables/refund.blade.php +++ b/views/tables/refund.blade.php @@ -22,9 +22,6 @@ - @php - $productsWithCoupon = array(); - @endphp @foreach($order->get_items() as $item) @if($item->get_total() == 0) @@ -44,27 +41,18 @@ $productUnitPriceWithTax = round(($total / $qty) + ($item->get_total_tax() / $qty), 2); $totalIncTax = round($total + $item->get_total_tax(), 2); @endphp - - - - - - {{$item->get_name()}} - {{$productUnitPriceWithTax}} - {{$productUnitPriceWithoutTax}} - {{$qty}} - {{$discountPercent}} - - - - - {{$order->get_currency()}} {{$totalIncTax}} - - + @include('tables.order-line', [ + 'itemId' => $productID, + 'itemName' => $item->get_name(), + 'priceWithTax' => $productUnitPriceWithTax, + 'priceWithoutTax' => $productUnitPriceWithoutTax, + 'qty' => $qty, + 'discountPercent' => $discountPercent, + 'availableQty' => $refundableQty, + 'currency' => $order->get_currency(), + 'totalIncTax' => $totalIncTax, + 'type' => 'refund', + ]) @endforeach @if ($order->get_shipping_total() <> 0 || $order->get_shipping_tax() <> 0) @@ -78,28 +66,43 @@ @foreach ($order_shipping_methods as $ordershipping_key => $ordershippingmethods) @php($shipping_id = $ordershippingmethods['method_id']) @endforeach - - - @php - $remaining_refund_amount = $order->get_remaining_refund_amount(); - @endphp - - - - {{$order->get_shipping_method()}} - {{$totalIncTax}} - {{$excTax}} - 1 - {{$discountPercentage}} - - - - - {{$order->get_currency()}} {{$totalIncTax}} - - + @php + $remaining_refund_amount = $order->get_remaining_refund_amount(); + @endphp + @include('tables.order-line', [ + 'itemId' => $shipping_id, + 'itemName' => $order->get_shipping_method(), + 'priceWithTax' => $totalIncTax, + 'priceWithoutTax' => $excTax, + 'qty' => 1, + 'discountPercent' => $discountPercentage, + 'availableQty' => $remaining_refund_amount == 0 ? 0 : 1, + 'currency' => $order->get_currency(), + 'totalIncTax' => $totalIncTax, + 'type' => 'refund', + ]) @endif + @php + $fees = $order->get_fees(); + @endphp + @foreach( $fees as $fee ) + @php + $surchargeAmount = (float) $fee->get_total(); + @endphp + @if( $fee->get_name() === 'Surcharge' ) + @include('tables.order-line', [ + 'itemId' => $fee->get_id(), + 'itemName' => $fee->get_name(), + 'priceWithTax' => $surchargeAmount, + 'priceWithoutTax' => $surchargeAmount, + 'qty' => 1, + 'discountPercent' => 0, + 'availableQty' => 1, + 'currency' => $order->get_currency(), + 'totalIncTax' => $surchargeAmount, + 'type' => 'refund', + ]) + @endif + @endforeach \ No newline at end of file