Skip to content

Commit cefc080

Browse files
authored
Merge pull request #119 from AltaPay/support-surcharge
Support applying surcharge fee to order payments
2 parents 1452e2c + 8dbe3e9 commit cefc080

File tree

14 files changed

+221
-107
lines changed

14 files changed

+221
-107
lines changed

.github/workflows/deployment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ on:
1515
jobs:
1616
terraform:
1717
name: 'Terraform'
18-
runs-on: ubuntu-20.04
18+
runs-on: ubuntu-22.04
1919
outputs:
2020
ip: ${{ steps.expose_ip.outputs.ip}}
2121

.github/workflows/support-deployment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
jobs:
1111
terraform:
1212
name: 'Terraform'
13-
runs-on: ubuntu-20.04
13+
runs-on: ubuntu-22.04
1414

1515
steps:
1616

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [3.7.9]
5+
- Support applying surcharge fee to order payments.
6+
47
## [3.7.8]
58
- Fix: Remove restriction on order lines when placing an order.
69

altapay.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
* Author URI: https://altapay.com
88
* Text Domain: altapay
99
* Domain Path: /languages
10-
* Version: 3.7.8
10+
* Version: 3.7.9
1111
* Name: SDM_Altapay
1212
* WC requires at least: 3.9.0
13-
* WC tested up to: 9.7.1
13+
* WC tested up to: 9.8.1
1414
*
1515
* @package Altapay
1616
*/
@@ -41,7 +41,7 @@
4141
}
4242

4343
if ( ! defined( 'ALTAPAY_PLUGIN_VERSION' ) ) {
44-
define( 'ALTAPAY_PLUGIN_VERSION', '3.7.8' );
44+
define( 'ALTAPAY_PLUGIN_VERSION', '3.7.9' );
4545
}
4646

4747
// Include the autoloader, so we can dynamically include the rest of the classes.

helpers/traits/AltapayMaster.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use AltaPay\vendor\GuzzleHttp\Exception\ClientException;
2020
use Altapay\Api\Subscription\ChargeSubscription;
2121
use Altapay\Classes\Core;
22+
use Altapay\Api\Others\CalculateSurcharge;
2223

2324
trait AltapayMaster {
2425

@@ -70,6 +71,29 @@ public function scheduledSubscriptionsPayment( $amount, $renewal_order ) {
7071
return;
7172
}
7273

74+
$payment_method = wc_get_payment_gateway_by_order( $renewal_order );
75+
if ( $payment_method && isset( $payment_method->settings ) && is_array( $payment_method->settings ) ) {
76+
$settings = $payment_method->settings;
77+
$surcharge = $settings['surcharge'] ?? 'no';
78+
79+
if ( $surcharge === 'yes' ) {
80+
$api = new CalculateSurcharge( $this->getAuth() );
81+
$api->setPaymentId( $agreement_id );
82+
$api->setAmount( round( $amount, 2 ) );
83+
$surcharge = $api->call();
84+
if ( $surcharge->Result === 'Success' && $surcharge->SurchageAmount > 0 ) {
85+
$surchargeAmount = (float) $surcharge->SurchageAmount;
86+
$surcharge_fee = new \WC_Order_Item_Fee();
87+
$surcharge_fee->set_name( 'Surcharge' );
88+
$surcharge_fee->set_amount( $surchargeAmount );
89+
$surcharge_fee->set_total( $surchargeAmount );
90+
$surcharge_fee->set_tax_status( 'none' );
91+
$renewal_order->add_item( $surcharge_fee );
92+
$renewal_order->calculate_totals();
93+
}
94+
}
95+
}
96+
7397
// @phpstan-ignore-next-line
7498
if ( $this->payment_action === 'authorize_capture' ) {
7599
$reconciliationId = wp_generate_uuid4();

includes/AltapayFormFields.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@
9696
'default' => array( 'visa', 'masterCard', 'amex' ),
9797
'desc_tip' => true,
9898
),
99+
'surcharge' => array(
100+
'title' => __( 'Enable Surcharge?', 'altapay' ),
101+
'type' => 'checkbox',
102+
'label' => __( 'Check this option to enable surcharge for this payment method.', 'altapay' ),
103+
'default' => 'no',
104+
'desc_tip' => true,
105+
),
99106
);
100107

101108
if ( $tokenStatus === 'CreditCard' ) {

readme.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ Contributors: altapay_integrations
33
Tags: AltaPay, Gateway, Payments, WooCommerce, Payment Card Industry
44
Requires PHP: 7.4
55
Requires at least: 5.0
6-
Tested up to: 6.7.2
7-
Stable tag: 3.7.8
6+
Tested up to: 6.8
7+
Stable tag: 3.7.9
88
License: MIT
99
WC requires at least: 3.9.0
10-
WC tested up to: 9.7.1
10+
WC tested up to: 9.8.1
1111
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1212

1313
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
3939

4040
== Changelog ==
4141

42+
= 3.7.9 =
43+
* Support applying surcharge fee to order payments.
44+
4245
= 3.7.8 =
4346
* Fix: Remove restriction on order lines when placing an order.
4447

views/altapay-payment-form.php

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
exit; // Exit if accessed directly
1717
}
1818

19-
$order_id = isset( $_POST['shop_orderid'] ) ? wp_unslash( $_POST['shop_orderid'] ) : 0;
20-
$order = wc_get_order( $order_id );
19+
$order_id = isset( $_POST['shop_orderid'] ) ? wp_unslash( $_POST['shop_orderid'] ) : 0;
20+
$order = wc_get_order( $order_id );
21+
$surcharge = 'no';
2122
if ( $order ) {
2223
$wpml_language = $order->get_meta( 'wpml_language' );
2324
if ( ! empty( $wpml_language ) ) {
@@ -28,6 +29,11 @@
2829
$sitepress->switch_lang( $wpml_language );
2930
}
3031
}
32+
$payment_method = wc_get_payment_gateway_by_order( $order );
33+
if ( $payment_method && isset( $payment_method->settings ) && is_array( $payment_method->settings ) ) {
34+
$settings = $payment_method->settings;
35+
$surcharge = $settings['surcharge'] ?? 'no';
36+
}
3137
}
3238
get_header();
3339
?>
@@ -542,6 +548,14 @@
542548
.woocommerce-page .col2-set .col-1, .woocommerce-column--shipping-address.col-2 {
543549
padding: 0;
544550
}
551+
.pensio_payment_form_submit_cell {
552+
display: flex;
553+
justify-content: space-between;
554+
align-items: center;
555+
}
556+
.pensio_payment_form_submit_cell span.secure-payments-text {
557+
margin-bottom: 10px;
558+
}
545559
@media screen and (min-width:769px){
546560
.altapay-page-wrapper {
547561
display: flex;
@@ -552,6 +566,17 @@
552566
}
553567
<?php } ?>
554568

569+
.altapay-surcharge {
570+
display: flex;
571+
justify-content: space-between;
572+
margin-bottom: 20px;
573+
}
574+
.surcharge-amount span.currency-symbol {
575+
display: none;
576+
}
577+
.Surcharged .surcharge-amount span.currency-symbol {
578+
display: inline-block;
579+
}
555580
/* Hide 'Show Klarna Page' button if hidden attribute exists */
556581
input#showKlarnaPage[hidden] {
557582
display: none;
@@ -562,6 +587,20 @@
562587
<div class="row">
563588
<div class="altapay-page-wrapper">
564589
<div class="altapay-payment-form-cnt <?php echo $container_class; ?>">
590+
<?php if ( $surcharge === 'yes' ) { ?>
591+
<div class="altapay-surcharge">
592+
<div class="surcharge-amount">
593+
<strong><?php echo __( 'Surcharge:', 'woocommerce' ); ?></strong>
594+
<span id="PensioSurcharge"></span>
595+
<span class="currency-symbol"><?php echo get_woocommerce_currency_symbol(); ?></span>
596+
</div>
597+
<div class="total-amount">
598+
<strong><?php echo __( 'Total:', 'woocommerce' ); ?></strong>
599+
<span id="PensioTotal"></span>
600+
<span class="currency-symbol"><?php echo get_woocommerce_currency_symbol(); ?></span>
601+
</div>
602+
</div>
603+
<?php } ?>
565604
<form id="PensioPaymentForm"></form>
566605
</div>
567606
<div class="altapay-order-details woocommerce">

views/paymentClass.tpl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class WC_Gateway_{key} extends WC_Payment_Gateway {
5151
public $apple_pay_label;
5252
public $apple_pay_supported_networks;
5353
public $secret;
54+
public $apply_surcharge;
5455
5556
public function __construct() {
5657
// Set default gateway values
@@ -69,6 +70,7 @@ class WC_Gateway_{key} extends WC_Payment_Gateway {
6970
$this->apple_pay_label = $this->get_option( 'apple_pay_label' );
7071
$this->apple_pay_supported_networks = $this->get_option( 'apple_pay_supported_networks' );
7172
$this->secret = $this->get_option( 'secret' );
73+
$this->apply_surcharge = $this->get_option( 'surcharge' );
7274
7375
7476
// Load form fields
@@ -425,6 +427,17 @@ class WC_Gateway_{key} extends WC_Payment_Gateway {
425427
$lastFourDigits = $transaction['CardInformation']['LastFourDigits'] ?? '';
426428
$ccExpiryDate = isset( $transaction['CreditCardExpiry'] ) ? ( $transaction['CreditCardExpiry']['Month'] . '/' . $transaction['CreditCardExpiry']['Year'] ) : '';
427429
$reservedAmount = $transaction['ReservedAmount'] ?? 0;
430+
$surchargeAmount = $transaction['SurchargeAmount'] ?? 0;
431+
432+
if ( $this->apply_surcharge === 'yes' && $surchargeAmount > 0 ) {
433+
$surcharge_fee = new \WC_Order_Item_Fee();
434+
$surcharge_fee->set_name( 'Surcharge' );
435+
$surcharge_fee->set_amount( $surchargeAmount );
436+
$surcharge_fee->set_total( $surchargeAmount );
437+
$surcharge_fee->set_tax_status( 'none' );
438+
$order->add_item( $surcharge_fee );
439+
$order->calculate_totals();
440+
}
428441

429442
/*
430443
Exit if payment already completed against the same order and

views/tables/capture.blade.php

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@
2020
<th width="12%" class="fw6 bb b--black-20 tl pb3 pr3 bg-white"><?php esc_html_e( 'Total amount', 'altapay' ); ?></th>
2121
</tr>
2222
</thead>
23-
<tbody class="lh-copy">
24-
25-
@php
26-
$productsWithCoupon = array();
27-
@endphp
23+
<tbody>
2824

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

@@ -45,26 +41,18 @@
4541
$productUnitPriceWithTax = round(($total / $qty) + ($item->get_total_tax() / $qty), 2);
4642
$totalIncTax = round($total + $item->get_total_tax(), 2);
4743
@endphp
48-
49-
<tr class="ap-orderlines-capture">
50-
<td style="display:none">
51-
<input class="form-control ap-order-product-sku pv3 pr3 bb b--black-20" name="productID" type="text" value="{{$productID}}"/>
52-
</td>
53-
<td class="pv3 pr3 bb b--black-20"> {{$item->get_name()}} </td>
54-
<td class="ap-orderline-unit-price pv3 pr3 bb b--black-20">{{$productUnitPriceWithTax}}</td>
55-
<td class="pv3 pr3 bb b--black-20">{{$productUnitPriceWithoutTax}}</td>
56-
<td class="ap-orderline-capture-max-quantity pv3 pr3 bb b--black-20">{{ $qty }}</td>
57-
<td class="ap-orderline-discount-percent pv3 pr3 bb b--black-20">{{$discountPercent}}</td>
58-
<td class="pv3 pr3 bb b--black-20">
59-
<input style="width: 100px;" class="form-control ap-order-capture-modify"
60-
name="qty" value="{{$capturableQty}}"
61-
type="number"
62-
{{ !$capturableQty ? 'disabled' : '' }} />
63-
</td>
64-
<td class="ap-orderline-totalprice-capture pv3 pr3 bb b--black-20">
65-
<span class="totalprice-capture">{{$order->get_currency()}} {{$totalIncTax}}</span>
66-
</td>
67-
</tr>
44+
@include('tables.order-line', [
45+
'itemId' => $productID,
46+
'itemName' => $item->get_name(),
47+
'priceWithTax' => $productUnitPriceWithTax,
48+
'priceWithoutTax' => $productUnitPriceWithoutTax,
49+
'qty' => $qty,
50+
'discountPercent' => $discountPercent,
51+
'availableQty' => $capturableQty,
52+
'currency' => $order->get_currency(),
53+
'totalIncTax' => $totalIncTax,
54+
'type' => 'capture',
55+
])
6856
@endforeach
6957

7058
@if ($order->get_shipping_total() <> 0 || $order->get_shipping_tax() <> 0)
@@ -78,28 +66,44 @@
7866
@foreach ($order_shipping_methods as $ordershipping_key => $ordershippingmethods)
7967
@php($shipping_id = $ordershippingmethods['method_id'])
8068
@endforeach
81-
82-
<tr class="ap-orderlines-capture">
83-
@php
84-
$capturableQty = ( isset( $items_captured[$shipping_id] ) && $items_captured[$shipping_id] == 1 ) ? 0 : 1;
85-
@endphp
86-
<td style="display:none">
87-
<input class="form-control ap-order-product-sku pv3 pr3 bb b--black-20" name="productID"
88-
type="text" value="{{$shipping_id}}"/>
89-
</td>
90-
<td class="pv3 pr3 bb b--black-20">{{$order->get_shipping_method()}}</td>
91-
<td class="ap-orderline-unit-price pv3 pr3 bb b--black-20">{{$totalIncTax}}</td>
92-
<td class="pv3 pr3 bb b--black-20">{{$excTax}}</td>
93-
<td class="ap-orderline-capture-max-quantity pv3 pr3 bb b--black-20">1</td>
94-
<td class="ap-orderline-discount-percent pv3 pr3 bb b--black-20">{{$discountPercentage}}</td>
95-
<td class="pv3 pr3 bb b--black-20">
96-
<input class="form-control ap-order-capture-modify" name="qty"
97-
value="{{$capturableQty}}" type="number" style="width: 100px;" {{ $capturableQty === 0 ? 'disabled' : '' }} />
98-
</td>
99-
<td class="ap-orderline-totalprice-capture pv3 pr3 bb b--black-20">
100-
<span class="totalprice-capture">{{$order->get_currency()}} {{$totalIncTax}}</span>
101-
</td>
102-
</tr>
69+
@php
70+
$capturableQty = ( isset( $items_captured[$shipping_id] ) && $items_captured[$shipping_id] == 1 ) ? 0 : 1;
71+
@endphp
72+
@include('tables.order-line', [
73+
'itemId' => $shipping_id,
74+
'itemName' => $order->get_shipping_method(),
75+
'priceWithTax' => $totalIncTax,
76+
'priceWithoutTax' => $excTax,
77+
'qty' => 1,
78+
'discountPercent' => $discountPercentage,
79+
'availableQty' => $capturableQty,
80+
'currency' => $order->get_currency(),
81+
'totalIncTax' => $totalIncTax,
82+
'type' => 'capture',
83+
])
10384
@endif
85+
86+
@php
87+
$fees = $order->get_fees();
88+
@endphp
89+
@foreach( $fees as $fee )
90+
@php
91+
$surchargeAmount = (float) $fee->get_total();
92+
@endphp
93+
@if( $fee->get_name() === 'Surcharge' )
94+
@include('tables.order-line', [
95+
'itemId' => $fee->get_id(),
96+
'itemName' => $fee->get_name(),
97+
'priceWithTax' => $surchargeAmount,
98+
'priceWithoutTax' => $surchargeAmount,
99+
'qty' => 1,
100+
'discountPercent' => 0,
101+
'availableQty' => 1,
102+
'currency' => $order->get_currency(),
103+
'totalIncTax' => $surchargeAmount,
104+
'type' => 'capture'
105+
])
106+
@endif
107+
@endforeach
104108
</tbody>
105109
</table>

0 commit comments

Comments
 (0)