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 @@