Merge pull request #5373 from claudiosmweb/5237-feature-max-transaction-amount
Feature maximum transaction amount for payment gateways
This commit is contained in:
commit
630eeb4945
|
@ -49,6 +49,9 @@ abstract class WC_Payment_Gateway extends WC_Settings_API {
|
|||
/** @var array Array of supported features such as 'default_credit_card_form' */
|
||||
var $supports = array( 'products' );
|
||||
|
||||
/** @var int Maximum transaction amount, zero does not define a maximum */
|
||||
public $max_amount = 0;
|
||||
|
||||
/**
|
||||
* Get the return url (thank you page)
|
||||
*
|
||||
|
@ -70,6 +73,28 @@ abstract class WC_Payment_Gateway extends WC_Settings_API {
|
|||
return apply_filters( 'woocommerce_get_return_url', $return_url );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the order total in checkout and pay_for_order.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function get_order_total() {
|
||||
$total = 0;
|
||||
$order_id = absint( get_query_var( 'order-pay' ) );
|
||||
|
||||
// Gets order total from "pay for order" page.
|
||||
if ( 0 < $order_id ) {
|
||||
$order = new WC_Order( $order_id );
|
||||
$total = (float) $order->get_total();
|
||||
|
||||
// Gets order total from cart/checkout.
|
||||
} elseif ( 0 < WC()->cart->total ) {
|
||||
$total = (float) WC()->cart->total;
|
||||
}
|
||||
|
||||
return $total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check If The Gateway Is Available For Use
|
||||
*
|
||||
|
@ -77,7 +102,13 @@ abstract class WC_Payment_Gateway extends WC_Settings_API {
|
|||
* @return bool
|
||||
*/
|
||||
public function is_available() {
|
||||
return ( $this->enabled === "yes" );
|
||||
$is_available = ( 'yes' === $this->enabled ) ? true : false;
|
||||
|
||||
if ( 0 < $this->get_order_total() && $this->max_amount >= $this->get_order_total() ) {
|
||||
$is_available = false;
|
||||
}
|
||||
|
||||
return $is_available;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue