Skip to content

Commit

Permalink
Merge pull request #115 from AltaPay/fix-capture-issue
Browse files Browse the repository at this point in the history
Charge subscriptions using the renewal order total instead of the original reserved amount
  • Loading branch information
emicha authored Jan 7, 2025
2 parents 00e549f + a191c8f commit 29f59b8
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 65 deletions.
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.7.6]
- Fix: Charge subscriptions using the renewal order total instead of the original reserved amount.
- Support export reconciliation data with WooCommerce High-Performance Order Storage (HPOS).

## [3.7.5]
- Display agreement information in the "AltaPay Payment Actions" grid.
- Show the "pending payment" status if the subscription is awaiting a charge.
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.5
* Version: 3.7.6
* Name: SDM_Altapay
* WC requires at least: 3.9.0
* WC tested up to: 9.4.3
* WC tested up to: 9.5.1
*
* @package Altapay
*/
Expand Down Expand Up @@ -41,7 +41,7 @@
}

if ( ! defined( 'ALTAPAY_PLUGIN_VERSION' ) ) {
define( 'ALTAPAY_PLUGIN_VERSION', '3.7.5' );
define( 'ALTAPAY_PLUGIN_VERSION', '3.7.6' );
}

// Include the autoloader, so we can dynamically include the rest of the classes.
Expand Down
91 changes: 52 additions & 39 deletions classes/core/AltapayReconciliation.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class AltapayReconciliation {
*/
public function registerHooks() {
add_action( 'manage_posts_extra_tablenav', array( $this, 'addReconciliationExportButton' ), 20, 1 );
add_action( 'woocommerce_order_list_table_extra_tablenav', array( $this, 'addReconciliationExportButtonHpos' ), 10, 2 );
add_action( 'admin_init', array( $this, 'exportReconciliationCSV' ) );
}

Expand All @@ -32,17 +33,37 @@ public function addReconciliationExportButton( $which ) {
global $typenow;

if ( 'shop_order' === $typenow && 'top' === $which ) {
?>
<div class="alignleft actions altapay-export-reconciliation-data">
<button type="submit" name="export_reconciliation_data" class="button button-primary" value="1">
<?php echo __( 'Export Reconciliation Data', 'altapay' ); ?>
</button>
<input type="hidden" name="orders_pagenum" value="<?php echo isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0; ?>>">
</div>
<?php
$this->btnExportReconciliationData();
}
}

/**
* @param string $order_type The order type.
* @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
*
* @return void
*/
public function addReconciliationExportButtonHpos( $order_type, $which ) {

if ( 'shop_order' === $order_type && 'bottom' === $which ) {
$this->btnExportReconciliationData();
}
}

/**
* @return void
*/
public function btnExportReconciliationData() {
?>
<div class="alignleft actions altapay-export-reconciliation-data">
<button type="submit" name="export_reconciliation_data" class="button button-primary" value="1">
<?php echo __( 'Export Reconciliation Data', 'altapay' ); ?>
</button>
<input type="hidden" name="orders_pagenum" value="<?php echo isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; ?>>">
</div>
<?php
}

/**
* Save the reconciliation identifier details.
*
Expand Down Expand Up @@ -115,21 +136,15 @@ public function exportReconciliationCSV() {
$paged = isset( $_REQUEST['orders_pagenum'] ) ? absint( $_REQUEST['orders_pagenum'] ) : 1;

$args = array(
'posts_per_page' => $perPage,
'fields' => 'ids',
'post_type' => 'shop_order',
'post_status' => array_keys( wc_get_order_statuses() ),
'paged' => $paged,
'limit' => $perPage,
'return' => 'ids',
'type' => 'shop_order',
'paginate' => true,
'page' => $paged,
);

if ( ! empty( $_GET['_customer_user'] ) ) {
$args['meta_query'] = array(
array(
'key' => '_customer_user',
'value' => (int) sanitize_text_field( wp_unslash( $_GET['_customer_user'] ) ),
'compare' => '=',
),
);
$args['customer'] = (int) sanitize_text_field( wp_unslash( $_GET['_customer_user'] ) );
}

if ( ! empty( $_GET['post_status'] ) ) {
Expand All @@ -144,6 +159,10 @@ public function exportReconciliationCSV() {
$args['order'] = sanitize_text_field( wp_unslash( $_GET['order'] ) );
}

if ( ! empty( $_GET['status'] ) ) {
$args['status'] = sanitize_text_field( wp_unslash( $_GET['status'] ) );
}

if ( ! empty( $_GET['m'] ) ) {
$yearMonth = sanitize_text_field( wp_unslash( $_GET['m'] ) );

Expand All @@ -152,29 +171,23 @@ public function exportReconciliationCSV() {
$year = (int) substr( $yearMonth, 0, 4 );
$month = (int) substr( $yearMonth, 4, 2 );

$args['date_query'] = array(
array(
'year' => $year,
'month' => $month,
),
);
$last_day_of_month = date_create( "$year-$month" )->format( 'Y-m-t' );
$args['date_created'] = "$year-$month-01..." . $last_day_of_month;
}
}

$query = new \WP_Query( $args );

if ( $query->have_posts() ) {

$PostToSelect = substr( str_repeat( ',%d', count( $query->posts ) ), 1 );
$ordersData = wc_get_orders( $args );

$reconciliation_data =
$wpdb->get_results(
$wpdb->prepare(
"SELECT orderId, identifier, transactionType FROM {$wpdb->prefix}altapayReconciliationIdentifiers WHERE orderId IN ($PostToSelect) ",
$query->posts
),
ARRAY_A
);
if ( ! empty( $ordersData ) ) {
$orders = $ordersData->orders;
$orders_to_select = substr( str_repeat( ',%d', count( $orders ) ), 1 );
$reconciliation_data = $wpdb->get_results(
$wpdb->prepare(
"SELECT orderId, identifier, transactionType FROM {$wpdb->prefix}altapayReconciliationIdentifiers WHERE orderId IN ($orders_to_select) ",
$orders
),
ARRAY_A
);

$output = $output . 'Order ID,Date Created,Order Total,Currency,Transaction ID,Reconciliation Identifier,Type,Payment Method,Order Status';
$output .= "\n";
Expand Down
5 changes: 3 additions & 2 deletions classes/core/AltapaySettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ public function altapayOrderStatusCompleted( $orderID ) {

if ( $pay->CapturedAmount > 0 ) {
$this->saveCaptureWarning( 'Could not capture automatically. Manual capture is required for the order: ' . $orderID );
} else { // Order wasn't captured and must be captured now.
$amount = $pay->ReservedAmount; // Amount to capture.
} else {
// Order wasn't captured and must be captured now.
$amount = $order->get_total();

try {
if ( $subscription === true ) {
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.7.1
Stable tag: 3.7.5
Stable tag: 3.7.6
License: MIT
WC requires at least: 3.9.0
WC tested up to: 9.4.3
WC tested up to: 9.5.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,10 @@ AltaPay's Payment Gateway for WooCommerce provides merchants with access to a fu

== Changelog ==

= 3.7.6 =
* Fix: Charge subscriptions using the renewal order total instead of the original reserved amount.
* Support export reconciliation data with WooCommerce High-Performance Order Storage (HPOS).

= 3.7.5 =
* Display agreement information in the "AltaPay Payment Actions" grid.
* Show the "pending payment" status if the subscription is awaiting a charge.
Expand Down
32 changes: 15 additions & 17 deletions tests/integration-test/cypress/e2e/PageObjects/objects.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,17 @@ class Order {
cy.get("#toplevel_page_woocommerce > ul > li:nth-child(3) > a").click()
cy.get('tr').eq(1).click()
cy.get('#openCaptureModal').click().wait(2000)
cy.get('.lh-copy > :nth-child(1) > :nth-child(7) > .form-control').click().clear().type('0').click()
cy.get('#altapay_capture').click()
cy.get('.ap-order-capture-modify').first().click().clear().type('0')
cy.get('#altapay_capture').click().wait(3000)
cy.get('.payment-captured').then(($span) => {
const captured_amount = parseFloat($span.text().trim()); // Extract the value and convert to a number
expect(captured_amount).to.be.greaterThan(0); // Assert that the amount is greater than 0
});


}

refund() {


cy.get('#openRefundModal').click().wait(3000)
cy.get('#altapay_refund').click().wait(5000)
cy.get('body').then(($a) => {
Expand All @@ -151,19 +155,13 @@ class Order {
}

partial_refund() {

cy.get('#toplevel_page_woocommerce > .wp-has-submenu > .wp-menu-name').click({force:true}).wait(3000)
cy.get('body').then(($a) => {

if ($a.find('.components-modal__header > .components-button').length) {
cy.get('.components-modal__header > .components-button').click().wait(2000)
}
})
cy.get("#toplevel_page_woocommerce > ul > li:nth-child(3) > a").click()
cy.get('tr').eq(1).click()
cy.get('#openRefundModal').click().wait(3000)
cy.get('#TB_ajaxContent > [style="overflow-x:auto;"] > .responsive-table > .w-100 > :nth-child(3) > :nth-child(1) > :nth-child(7) > .form-control').click().clear().type('0').click()
cy.get('#altapay_refund').click().wait(2000)
cy.get('#openRefundModal').click().wait(2000)
cy.get('.ap-order-refund-modify').first().click().clear().type('0')
cy.get('#altapay_refund').click().wait(3000)
cy.get('.payment-refunded').then(($span) => {
const refunded_amount = parseFloat($span.text().trim()); // Extract the value and convert to a number
expect(refunded_amount).to.be.greaterThan(0); // Assert that the amount is greater than 0
});


}
Expand Down
4 changes: 2 additions & 2 deletions wiki.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,13 @@ In order to reconcile payments please follow the steps below:

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

The latest tested version is:
- WordPress 6.7.1, WooCommerce 9.4.3 and PHP 8.1
- WordPress 6.7.1, WooCommerce 9.5.1 and PHP 8.1


## Troubleshooting
Expand Down

0 comments on commit 29f59b8

Please sign in to comment.