diff --git a/src/Gateways/AbstractGateway.php b/src/Gateways/AbstractGateway.php index 4586eae..7de426e 100644 --- a/src/Gateways/AbstractGateway.php +++ b/src/Gateways/AbstractGateway.php @@ -9,12 +9,11 @@ use GlobalPayments\Api\Entities\Exceptions\ApiException; use GlobalPayments\Api\Entities\Reporting\TransactionSummary; use GlobalPayments\WooCommercePaymentGatewayProvider\Gateways\Requests\RequestArg; +use GlobalPayments\WooCommercePaymentGatewayProvider\Plugin; use WC_Payment_Gateway_CC; use WC_Order; use GlobalPayments\Api\Entities\Transaction; -use GlobalPayments\WooCommercePaymentGatewayProvider\Plugin; - /** * Shared gateway method implementations */ @@ -140,8 +139,12 @@ abstract class AbstractGateway extends WC_Payment_Gateway_Cc { */ public $cvn_reject_conditions; - public function __construct() { + public function __construct( $is_provider = false ) { + if ( $is_provider ) { + return; + } $this->client = new Clients\SdkClient(); + $this->has_fields = true; $this->supports = array( 'products', @@ -165,8 +168,6 @@ public function __construct() { $this->init_settings(); $this->configure_merchant_settings(); $this->add_hooks(); - - } /** @@ -315,7 +316,7 @@ public function tokenization_script() { WC()->version, true ); - + wp_localize_script( 'globalpayments-helper', 'globalpayments_helper_params', @@ -745,6 +746,7 @@ protected function add_hooks() { 'admin_enforce_single_gateway' ) ); add_filter( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); + add_action( 'woocommerce_new_order', array( $this, 'admin_add_order_note_after_order_created' )); } if ( 'no' === $this->enabled ) { @@ -769,6 +771,33 @@ protected function add_hooks() { 'woocommerce_available_payment_gateways' ) ); } + + } + + /** + * Add order note when creating an order from admin with transaction ID + * + * @param int $order_id + * + * @return bool + */ + public function admin_add_order_note_after_order_created( $order_id ) { + if ( ! $order_id ) { + return; + } + + $order = wc_get_order( $order_id ); + if ( empty( $order) ) { + return; + } + if ( $this->id != $order->get_payment_method() ) { + return; + } + if ( empty( $order->get_transaction_id() )) { + return; + } + + $order->add_order_note( __( 'Order created with Transaction ID: ' ) . $order->get_transaction_id() ); } /** @@ -1222,7 +1251,5 @@ public function admin_enqueue_scripts( $hook_suffix ) { WC()->version ); } - } - } diff --git a/src/Gateways/ApplePayGateway.php b/src/Gateways/ApplePayGateway.php index bb3302c..b5a8bd3 100644 --- a/src/Gateways/ApplePayGateway.php +++ b/src/Gateways/ApplePayGateway.php @@ -88,7 +88,7 @@ class ApplePayGateway extends AbstractGateway { public function __construct() { parent::__construct(); - $this->gateway = new GpApiGateway(); + $this->gateway = new GpApiGateway( true ); } public function configure_method_settings() { diff --git a/src/Gateways/GooglePayGateway.php b/src/Gateways/GooglePayGateway.php index dbca869..42aff20 100644 --- a/src/Gateways/GooglePayGateway.php +++ b/src/Gateways/GooglePayGateway.php @@ -71,7 +71,7 @@ class GooglePayGateway extends AbstractGateway { public function __construct() { parent::__construct(); - $this->gateway = new GpApiGateway(); + $this->gateway = new GpApiGateway( true ); } public function get_first_line_support_email() {