Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/support-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
jobs:
terraform:
name: 'Terraform'
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

steps:

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
6 changes: 3 additions & 3 deletions altapay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.
Expand Down
24 changes: 24 additions & 0 deletions helpers/traits/AltapayMaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions includes/AltapayFormFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) {
Expand Down
9 changes: 6 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.

Expand Down
43 changes: 41 additions & 2 deletions views/altapay-payment-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) {
Expand All @@ -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();
?>
Expand Down Expand Up @@ -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;
Expand All @@ -552,6 +566,17 @@
}
<?php } ?>

.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;
Expand All @@ -562,6 +587,20 @@
<div class="row">
<div class="altapay-page-wrapper">
<div class="altapay-payment-form-cnt <?php echo $container_class; ?>">
<?php if ( $surcharge === 'yes' ) { ?>
<div class="altapay-surcharge">
<div class="surcharge-amount">
<strong><?php echo __( 'Surcharge:', 'woocommerce' ); ?></strong>
<span id="PensioSurcharge"></span>
<span class="currency-symbol"><?php echo get_woocommerce_currency_symbol(); ?></span>
</div>
<div class="total-amount">
<strong><?php echo __( 'Total:', 'woocommerce' ); ?></strong>
<span id="PensioTotal"></span>
<span class="currency-symbol"><?php echo get_woocommerce_currency_symbol(); ?></span>
</div>
</div>
<?php } ?>
<form id="PensioPaymentForm"></form>
</div>
<div class="altapay-order-details woocommerce">
Expand Down
13 changes: 13 additions & 0 deletions views/paymentClass.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
98 changes: 51 additions & 47 deletions views/tables/capture.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@
<th width="12%" class="fw6 bb b--black-20 tl pb3 pr3 bg-white"><?php esc_html_e( 'Total amount', 'altapay' ); ?></th>
</tr>
</thead>
<tbody class="lh-copy">

@php
$productsWithCoupon = array();
@endphp
<tbody>

@foreach($order->get_items() as $item)

Expand All @@ -45,26 +41,18 @@
$productUnitPriceWithTax = round(($total / $qty) + ($item->get_total_tax() / $qty), 2);
$totalIncTax = round($total + $item->get_total_tax(), 2);
@endphp

<tr class="ap-orderlines-capture">
<td style="display:none">
<input class="form-control ap-order-product-sku pv3 pr3 bb b--black-20" name="productID" type="text" value="{{$productID}}"/>
</td>
<td class="pv3 pr3 bb b--black-20"> {{$item->get_name()}} </td>
<td class="ap-orderline-unit-price pv3 pr3 bb b--black-20">{{$productUnitPriceWithTax}}</td>
<td class="pv3 pr3 bb b--black-20">{{$productUnitPriceWithoutTax}}</td>
<td class="ap-orderline-capture-max-quantity pv3 pr3 bb b--black-20">{{ $qty }}</td>
<td class="ap-orderline-discount-percent pv3 pr3 bb b--black-20">{{$discountPercent}}</td>
<td class="pv3 pr3 bb b--black-20">
<input style="width: 100px;" class="form-control ap-order-capture-modify"
name="qty" value="{{$capturableQty}}"
type="number"
{{ !$capturableQty ? 'disabled' : '' }} />
</td>
<td class="ap-orderline-totalprice-capture pv3 pr3 bb b--black-20">
<span class="totalprice-capture">{{$order->get_currency()}} {{$totalIncTax}}</span>
</td>
</tr>
@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)
Expand All @@ -78,28 +66,44 @@
@foreach ($order_shipping_methods as $ordershipping_key => $ordershippingmethods)
@php($shipping_id = $ordershippingmethods['method_id'])
@endforeach

<tr class="ap-orderlines-capture">
@php
$capturableQty = ( isset( $items_captured[$shipping_id] ) && $items_captured[$shipping_id] == 1 ) ? 0 : 1;
@endphp
<td style="display:none">
<input class="form-control ap-order-product-sku pv3 pr3 bb b--black-20" name="productID"
type="text" value="{{$shipping_id}}"/>
</td>
<td class="pv3 pr3 bb b--black-20">{{$order->get_shipping_method()}}</td>
<td class="ap-orderline-unit-price pv3 pr3 bb b--black-20">{{$totalIncTax}}</td>
<td class="pv3 pr3 bb b--black-20">{{$excTax}}</td>
<td class="ap-orderline-capture-max-quantity pv3 pr3 bb b--black-20">1</td>
<td class="ap-orderline-discount-percent pv3 pr3 bb b--black-20">{{$discountPercentage}}</td>
<td class="pv3 pr3 bb b--black-20">
<input class="form-control ap-order-capture-modify" name="qty"
value="{{$capturableQty}}" type="number" style="width: 100px;" {{ $capturableQty === 0 ? 'disabled' : '' }} />
</td>
<td class="ap-orderline-totalprice-capture pv3 pr3 bb b--black-20">
<span class="totalprice-capture">{{$order->get_currency()}} {{$totalIncTax}}</span>
</td>
</tr>
@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
</tbody>
</table>
2 changes: 1 addition & 1 deletion views/tables/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
17 changes: 17 additions & 0 deletions views/tables/order-line.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<tr class="ap-orderlines-{{$type}}">
<td style="display:none">
<input class="form-control pv3 pr3 bb b--black-20" name="productID" type="text" value="{{$itemId}}"/>
</td>
<td class="pv3 pr3 bb b--black-20">{{$itemName}}</td>
<td class="pv3 pr3 bb b--black-20">{{$priceWithTax}}</td>
<td class="pv3 pr3 bb b--black-20">{{$priceWithoutTax}}</td>
<td class="ap-orderline-{{$type}}-max-quantity pv3 pr3 bb b--black-20">{{ $qty }}</td>
<td class="pv3 pr3 bb b--black-20">{{$discountPercent}}</td>
<td class="pv3 pr3 bb b--black-20">
<input class="form-control ap-order-{{$type}}-modify" name="qty"
value="{{$availableQty}}" type="number" style="width: 100px;" {{ !$availableQty ? 'disabled' : '' }} />
</td>
<td class="pv3 pr3 bb b--black-20">
<span class="totalprice-{{$type}}">{{$currency}} {{$totalIncTax}}</span>
</td>
</tr>
Loading