PluginProbe
seQura / 3.0.5
seQura v3.0.5
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 / Services / Payment / class-payment-service.php

class-payment-service.php in seQura 3.0.5, at src/Services/Payment/class-payment-service.php

108 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Payment service interface
4 *
5 * @package SeQura/WC
6 * @subpackage SeQura/WC/Services
7 */
8
9 namespace SeQura\WC\Services\Payment;
10
11 use SeQura\Core\BusinessLogic\AdminAPI\AdminAPI;
12 use SeQura\WC\Core\Extension\Infrastructure\Configuration\Configuration;
13 use SeQura\WC\Services\I18n\Interface_I18n;
14 use Throwable;
15
16 /**
17 * Handle use cases related to payments
18 */
19 class Payment_Service implements Interface_Payment_Service {
20
21 /**
22 * Configuration
23 *
24 * @var Configuration
25 */
26 private $configuration;
27
28 /**
29 * I18n service
30 *
31 * @var Interface_I18n
32 */
33 private $i18n;
34
35 /**
36 * Constructor
37 */
38 public function __construct(
39 Configuration $configuration,
40 Interface_I18n $i18n
41 ) {
42 $this->configuration = $configuration;
43 $this->i18n = $i18n;
44 }
45
46 /**
47 * Get payment gateway ID
48 */
49 public function get_payment_gateway_id(): string {
50 return 'sequra';
51 }
52
53 /**
54 * Get payment gateway webhook identifier
55 */
56 public function get_event_webhook(): string {
57 return 'woocommerce_' . $this->get_payment_gateway_id();
58 }
59
60 /**
61 * Get IPN webhook identifier
62 */
63 public function get_ipn_webhook(): string {
64 return 'woocommerce_' . $this->get_payment_gateway_id() . '_ipn';
65 }
66
67 /**
68 * Get return URL webhook identifier
69 */
70 public function get_return_webhook(): string {
71 return 'woocommerce_' . $this->get_payment_gateway_id() . '_return';
72 }
73
74 /**
75 * Get current merchant ID
76 */
77 public function get_merchant_id(): ?string {
78 try {
79 $store_id = $this->configuration->get_store_id();
80
81 $countries = AdminAPI::get()
82 ->countryConfiguration( $store_id )
83 ->getCountryConfigurations()
84 ->toArray();
85
86 $merchant = null;
87 $current_country = $this->i18n->get_current_country();
88
89 foreach ( $countries as $country ) {
90 if ( $country['countryCode'] === $current_country ) {
91 $merchant = $country['merchantId'];
92 break;
93 }
94 }
95 return empty( $merchant ) ? null : $merchant;
96 } catch ( Throwable $e ) {
97 return null;
98 }
99 }
100
101 /**
102 * Sign the string using HASH_ALGO and merchant's password
103 */
104 public function sign( string $message ): string {
105 return hash_hmac( 'sha256', $message, $this->configuration->get_password() );
106 }
107 }
108