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: 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/helpers/traits/AltapayMaster.php b/helpers/traits/AltapayMaster.php index 0cd10724..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 { @@ -70,6 +71,29 @@ 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'; + + 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(); + } + } + } + // @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..6f504b8f 100755 --- a/includes/AltapayFormFields.php +++ b/includes/AltapayFormFields.php @@ -96,6 +96,13 @@ '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, + ), ); if ( $tokenStatus === 'CreditCard' ) { 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/views/altapay-payment-form.php b/views/altapay-payment-form.php index e561ad15..abecacdf 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(); ?> @@ -542,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; @@ -552,6 +566,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 +587,20 @@
+ +
+
+ + + +
+
+ + + +
+
+
diff --git a/views/paymentClass.tpl b/views/paymentClass.tpl index 2d5c72f2..6365450a 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 === 'yes' && $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/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/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 ) 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 diff --git a/wiki.md b/wiki.md index c1370570..7302a13d 100644 --- a/wiki.md +++ b/wiki.md @@ -174,6 +174,7 @@ 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. | | Token Control | Enable Customer Token Control. | - Save the changes. @@ -297,14 +298,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