PluginProbe
seQura / 3.0.0
seQura v3.0.0
4.3.4 4.3.3 4.3.2 4.3.1 trunk 2.0.0 2.0.10 2.0.11 2.0.12 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 3.0.0 3.0.2 3.0.5 3.0.6 3.0.7 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 4.0.0 All 30 releases
sequra / src / Controllers / Hooks / Payment / class-payment-controller.php

class-payment-controller.php in seQura 3.0.0, at src/Controllers/Hooks/Payment/class-payment-controller.php

92 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Payment Controller
4 *
5 * @package SeQura/WC
6 * @subpackage SeQura/WC/Controllers
7 */
8
9 namespace SeQura\WC\Controllers\Hooks\Payment;
10
11 use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
12 use SeQura\Core\Infrastructure\ServiceRegister;
13 use SeQura\WC\Controllers\Controller;
14 use SeQura\WC\Services\Interface_Logger_Service;
15 use SeQura\WC\Services\Order\Interface_Order_Service;
16 use SeQura\WC\Services\Payment\Sequra_Payment_Gateway;
17 use SeQura\WC\Services\Payment\Sequra_Payment_Gateway_Block_Support;
18 use WC_Order;
19
20 /**
21 * Respond to payment hooks
22 */
23 class Payment_Controller extends Controller implements Interface_Payment_Controller {
24
25 /**
26 * Order service
27 *
28 * @var Interface_Order_Service
29 */
30 private $order_service;
31
32 /**
33 * Constructor
34 */
35 public function __construct(
36 Interface_Logger_Service $logger,
37 string $templates_path,
38 Interface_Order_Service $order_service
39 ) {
40 parent::__construct( $logger, $templates_path );
41 $this->order_service = $order_service;
42 }
43
44 /**
45 * Register the gateway classes so that they can be used by WooCommerce
46 *
47 * @param string[] $gateways
48 * @return string[]
49 */
50 public function register_gateway_classes( $gateways ): array {
51 $this->logger->log_debug( 'Hook executed', __FUNCTION__, __CLASS__ );
52 if ( ! in_array( Sequra_Payment_Gateway::class, $gateways, true ) ) {
53 $gateways[] = Sequra_Payment_Gateway::class;
54 }
55 return $gateways;
56 }
57
58 /**
59 * Register the payment gateway block so that it can be used by Gutenberg
60 */
61 public function register_gateway_gutenberg_block(): void {
62 $this->logger->log_debug( 'Hook executed', __FUNCTION__, __CLASS__ );
63 add_action( 'woocommerce_blocks_payment_method_type_registration', array( $this, 'register_gateway_gutenberg_block_class' ) );
64 }
65
66 /**
67 * Register the payment gateway block class
68 */
69 public function register_gateway_gutenberg_block_class( PaymentMethodRegistry $payment_method_registry ): void {
70 $this->logger->log_debug( 'Hook executed', __FUNCTION__, __CLASS__ );
71 $payment_method_registry->register( ServiceRegister::getService( Sequra_Payment_Gateway_Block_Support::class ) );
72 }
73
74 /**
75 * Append text after the thank you message on the order received page
76 */
77 public function order_received_text( string $text, mixed $order ): string {
78 $this->logger->log_debug( 'Hook executed', __FUNCTION__, __CLASS__ );
79 $notices = wc_print_notices( true );
80 return $notices . $text;
81 }
82
83 /**
84 * Set the proper payment method description in the order
85 */
86 public function order_get_payment_method_title( string $value, mixed $order ): string {
87 $this->logger->log_debug( 'Hook executed', __FUNCTION__, __CLASS__ );
88 $sequra_payment_method = $order instanceof WC_Order ? $this->order_service->get_payment_method_title( $order ) : null;
89 return empty( $sequra_payment_method ) ? $value : $sequra_payment_method;
90 }
91 }
92