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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

## [3.8.3]
- Fix: Unable to refund orders that contain deleted products.
- Avoid unnecessary extra API calls in the daily flow.

## [3.8.2]
- Load plugin CSS and JS only on the checkout page to improve performance.

Expand Down
33 changes: 3 additions & 30 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.8.2
* Version: 3.8.3
* Name: SDM_Altapay
* WC requires at least: 3.9.0
* WC tested up to: 10.0.2
* WC tested up to: 10.1.2
*
* @package Altapay
*/
Expand Down Expand Up @@ -41,7 +41,7 @@
}

if ( ! defined( 'ALTAPAY_PLUGIN_VERSION' ) ) {
define( 'ALTAPAY_PLUGIN_VERSION', '3.8.2' );
define( 'ALTAPAY_PLUGIN_VERSION', '3.8.3' );
}

// Include the autoloader, so we can dynamically include the rest of the classes.
Expand Down Expand Up @@ -301,12 +301,6 @@ function altapay_meta_box_side( $post_or_order_object ) {

if ( $txnID || $agreement_id ) {
$settings = new Core\AltapaySettings();
$login = $settings->altapayApiLogin();

if ( ! $login || is_wp_error( $login ) ) {
echo '<p><b>' . __( 'Could not connect to AltaPay!', 'altapay' ) . '</b></p>';
return;
}

if ( ! $txnID ) {
$txnID = $agreement_id;
Expand Down Expand Up @@ -557,14 +551,6 @@ function altapayCaptureCallback() {
}

if ( $txnID ) {

$login = $settings->altapayApiLogin();
if ( ! $login ) {
wp_send_json_error( array( 'error' => 'Could not login to the Merchant API:' ) );
} elseif ( is_wp_error( $login ) ) {
wp_send_json_error( array( 'error' => wp_kses_post( $login->get_error_message() ) ) );
}

$postOrderLines = isset( $_POST['orderLines'] ) ? wp_unslash( $_POST['orderLines'] ) : '';

$orderLines = array();
Expand Down Expand Up @@ -769,13 +755,6 @@ function altapayRefundPayment( $orderID, $amount, $reason, $isAjax ) {
return array( 'error' => 'Invalid order' );
}

$login = $settings->altapayApiLogin();
if ( ! $login ) {
return array( 'error' => 'Could not login to the Merchant API:' );
} elseif ( is_wp_error( $login ) ) {
return array( 'error' => wp_kses_post( $login->get_error_message() ) );
}

$postOrderLines = isset( $_POST['orderLines'] ) ? wp_unslash( $_POST['orderLines'] ) : '';
if ( $postOrderLines ) {
$selectedProducts = array(
Expand Down Expand Up @@ -939,12 +918,6 @@ function altapayReleasePayment() {
$reserved = 0;
$refunded = 0;

$login = $settings->altapayApiLogin();
if ( ! $login ) {
wp_send_json_error( array( 'error' => 'Could not login to the Merchant API:' ) );
} elseif ( is_wp_error( $login ) ) {
wp_send_json_error( array( 'error' => wp_kses_post( $login->get_error_message() ) ) );
}
try {
$auth = $settings->getAuth();
$api = new Payments( $auth );
Expand Down
16 changes: 6 additions & 10 deletions classes/core/AltapayOrderStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,26 @@ public function registerHooks() {
* @return void|WP_Error
*/
public function orderStatusChanged( $orderID, $previousStatus, $newStatus, $order ) {
if ( ! in_array( $newStatus, array( 'cancelled', 'completed' ), true ) ) {
return;
}

$txnID = $order->get_transaction_id();
$captured = 0;
$reserved = 0;
$refunded = 0;
$status = '';

$settings = new Core\AltapaySettings();
$login = $settings->altapayApiLogin();

if ( ! $login || is_wp_error( $login ) ) {
echo '<p><b>' . __( 'Could not connect to AltaPay!', 'altapay' ) . '</b></p>';
return;
}

$auth = $settings->getAuth();
$auth = $settings->getAuth();
try {
$api = new Payments( $auth );
$api->setTransaction( $txnID );
$payments = $api->call();
} catch ( Exception $e ) {
echo '<p><b>' . __( 'Could not fetch Payments from AltaPay!', 'altapay' ) . '</b></p>';
$order->add_order_note( $e->getMessage() );
return;
}

if ( $payments ) {
foreach ( $payments as $pay ) {
$reserved += $pay->ReservedAmount;
Expand Down
7 changes: 0 additions & 7 deletions classes/core/AltapaySettings.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,6 @@ public function altapayOrderStatusCompleted( $orderID ) {
return;
}

$login = $this->altapayApiLogin();
if ( ! $login || is_wp_error( $login ) ) {
error_log( 'Could not connect to AltaPay!' );

return;
}

try {
$auth = $this->getAuth();
$api = new Payments( $auth );
Expand Down
12 changes: 8 additions & 4 deletions classes/util/UtilMethods.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,19 @@ private function getOrderLine( $item, $isSubscription = false ) {
$quantity = $item->get_quantity();

// generate line date with all the calculated parameters
$orderLine = new OrderLine(
$orderLine = new OrderLine(
$item->get_name(),
$item->get_id(),
$quantity,
round( $item->get_subtotal() / $quantity, 2 )
);
$orderLine->productUrl = $product->get_permalink();
$orderLine->imageUrl = wp_get_attachment_url( $product->get_image_id() );
$orderLine->unitCode = $quantity > 1 ? 'units' : 'unit';

if ( $product ) {
$orderLine->productUrl = $product->get_permalink();
$orderLine->imageUrl = wp_get_attachment_url( $product->get_image_id() );
}

$orderLine->unitCode = $quantity > 1 ? 'units' : 'unit';

if ( ! $isSubscription ) {
$orderLine->taxAmount = round( $item->get_subtotal_tax(), 2 );
Expand Down
9 changes: 1 addition & 8 deletions helpers/traits/AltapayMaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ public function scheduledSubscriptionsPayment( $amount, $renewal_order ) {
return;
}

$login = $this->altapayApiLogin();
if ( ! $login || is_wp_error( $login ) ) {
echo '<p><b>' . __( 'Could not connect to AltaPay!', 'altapay' ) . '</b></p>';
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;
Expand Down Expand Up @@ -111,8 +105,7 @@ public function scheduledSubscriptionsPayment( $amount, $renewal_order ) {
$transaction = $jsonToArray[ $latest_transaction ];
$transaction_id = $transaction['TransactionId'];

$renewal_order->update_meta_data( '_transaction_id', $transaction_id );
$renewal_order->save();
$renewal_order->set_transaction_id( $transaction_id );

if ( $response->Result === 'Success' ) {
$reconciliation = new Core\AltapayReconciliation();
Expand Down
8 changes: 6 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Tags: AltaPay, Gateway, Payments, WooCommerce, Payment Card Industry
Requires PHP: 7.4
Requires at least: 5.0
Tested up to: 6.8.2
Stable tag: 3.8.2
Stable tag: 3.8.3
License: MIT
WC requires at least: 3.9.0
WC tested up to: 10.0.2
WC tested up to: 10.1.2
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,10 @@ AltaPay's Payment Gateway for WooCommerce provides merchants with access to a fu

== Changelog ==

= 3.8.3 =
* Fix: Unable to refund orders that contain deleted products.
* Avoid unnecessary extra API calls in the daily flow.

= 3.8.2 =
* Load plugin CSS and JS only on the checkout page to improve performance.

Expand Down
19 changes: 6 additions & 13 deletions views/paymentClass.tpl
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,6 @@ class WC_Gateway_{key} extends WC_Payment_Gateway {
global $wpdb;
$utilMethods = new Util\UtilMethods;
$altapayHelpers = new Helpers\AltapayHelpers;
// Create form request etc.
$login = $this->altapayApiLogin();
if ( ! $login || is_wp_error( $login ) ) {
throw new Exception( 'Could not connect to AltaPay!' );
}
// Create payment request
$order = new WC_Order( $order_id );

Expand All @@ -160,7 +155,7 @@ class WC_Gateway_{key} extends WC_Payment_Gateway {
$amount = $this->getOrderAmount( $order );
$currency = $order->get_currency();
$customerInfo = $this->setCustomer( $order );
$cookie = isset($_SERVER['HTTP_COOKIE']) ? $_SERVER['HTTP_COOKIE'] : '';
$cookie = $_SERVER['HTTP_COOKIE'] ?? '';
$language = 'en';
$languages = array(
'ca',
Expand Down Expand Up @@ -427,6 +422,7 @@ 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;
$capturedAmount = $transaction['CapturedAmount'] ?? 0;
$surchargeAmount = $transaction['SurchargeAmount'] ?? 0;

if ( $this->apply_surcharge === 'yes' && $surchargeAmount > 0 ) {
Expand Down Expand Up @@ -551,7 +547,6 @@ class WC_Gateway_{key} extends WC_Payment_Gateway {
if ( $transaction['AuthType'] === 'subscription_payment' and $transaction['TransactionStatus'] === 'pending' ) {
$order->update_status( 'on-hold', 'The payment is pending an update from the payment provider.' );
} else {
$order->add_order_note( __( 'Callback completed', 'altapay' ) );
$order->payment_complete();
}

Expand Down Expand Up @@ -607,12 +602,6 @@ class WC_Gateway_{key} extends WC_Payment_Gateway {

// Redirect to Order Confirmation Page
if ( $type === 'paymentAndCapture' && $requireCapture === 'true' && $callback_type == 'ok' ) {
$login = $this->altapayApiLogin();
if ( ! $login || is_wp_error( $login ) ) {
error_log( 'Could not connect to AltaPay!' );
return;
}

$api = new CaptureReservation( $this->getAuth() );
$api->setAmount( round( $amount, 2 ) );
$api->setTransaction( $txnId );
Expand All @@ -637,7 +626,11 @@ class WC_Gateway_{key} extends WC_Payment_Gateway {
} catch ( \Exception $e ) {
error_log( 'Exception ' . $e->getMessage() );
}
} elseif ( $type === 'paymentAndCapture' && $capturedAmount == $this->getOrderAmount( $order ) ) {
$order->update_meta_data( '_captured', true );
$order->save();
}

$redirect = $this->get_return_url( $order );
wp_redirect( $redirect );
exit;
Expand Down
4 changes: 2 additions & 2 deletions wiki.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,13 @@ The new credentials can now be used as the API Username and API Password in your

Minimum system requirements are:
- WordPress min. 5.0 – max. 6.8.2
- WooCommerce min. 3.9.0 – max. 10.0.2
- WooCommerce min. 3.9.0 – max. 10.1.2
- PHP 7.4 and above
- PHP-bcmath library installed.
- PHP-curl MUST be enabled.

The latest tested version is:
- WordPress 6.8.2, WooCommerce 10.0.2 and PHP 8.2
- WordPress 6.8.2, WooCommerce 10.1.2 and PHP 8.2


## Troubleshooting
Expand Down