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.0 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / ecommerce / PaymentGateways / Configs / PaypalConfig.php
tutor / ecommerce / PaymentGateways / Configs Last commit date
PaymentUrlsTrait.php 1 year ago PaypalConfig.php 1 year ago
PaypalConfig.php
175 lines
1 <?php
2
3 namespace Tutor\PaymentGateways\Configs;
4
5 use Ollyo\PaymentHub\Contracts\Payment\ConfigContract;
6 use Ollyo\PaymentHub\Payments\Paypal\Config;
7 use phpDocumentor\Reflection\Types\Self_;
8 use Tutor\Ecommerce\Settings;
9
10 /**
11 * PaypalConfig class.
12 *
13 * This class handles the configuration for the Paypal payment gateway.
14 * It extends the BaseConfig class and implements the ConfigContract interface.
15 *
16 * @since 3.0.0
17 */
18 class PaypalConfig extends Config implements ConfigContract {
19
20 use PaymentUrlsTrait;
21
22 /**
23 * Constants for API URLs.
24 *
25 * @since 3.0.0
26 *
27 * @var string
28 */
29 const API_URL_TEST = 'https://api-m.sandbox.paypal.com';
30 const API_URL_LIVE = 'https://api-m.paypal.com';
31
32 /**
33 * PayPal environment key.
34 *
35 * @var string
36 * @since 3.0.0
37 */
38 private $environment;
39
40 /**
41 * PayPal merchant email key.
42 *
43 * @var string
44 * @since 3.0.0
45 */
46 private $merchant_email;
47
48 /**
49 * PayPal client ID key.
50 *
51 * @var string
52 * @since 3.0.0
53 */
54 private $client_id;
55
56 /**
57 * PayPal client secret id.
58 *
59 * @var string
60 * @since 3.0.0
61 */
62 private $secret_id;
63
64 /**
65 * PayPal webhook ID key.
66 *
67 * @var string
68 * @since 3.0.0
69 */
70 private $webhook_id;
71
72 /**
73 * The name of the payment gateway.
74 *
75 * @since 3.0.0
76 *
77 * @var string
78 */
79 protected $name = 'paypal';
80
81 public function __construct() {
82 parent::__construct();
83
84 $settings = Settings::get_payment_gateway_settings( $this->name );
85
86 $config_keys = $this->get_config_keys();
87 foreach ( $config_keys as $key ) {
88 $this->$key = $this->get_field_value( $settings, $key );
89 }
90 }
91
92 public function getMode(): string {
93 return 'test';
94 }
95
96 public function getClientSecret(): string {
97 return $this->secret_id;
98 }
99
100 public function getWebhookID(): string {
101 return $this->webhook_id;
102 }
103
104 public function getAdditionalInformation(): string {
105 return '';
106 }
107
108 public function getTitle(): string {
109 return '';
110 }
111
112 public function getName(): string {
113 return $this->name;
114 }
115
116 public function getClientID() : string {
117 return $this->client_id;
118 }
119
120 public function getMerchantEmail() : string {
121 return $this->merchant_email;
122 }
123
124 public function getApiURL() {
125 return $this->environment === 'test' ? static::API_URL_TEST : static::API_URL_LIVE;
126 }
127
128 /**
129 * Creates and updates configuration settings specific to the PayPal integration.
130 *
131 * Retrieves necessary configuration values using getter methods for webhook ID,
132 * client ID, merchant email, API URL, and client secret. Updates the configuration
133 * storage with these values to ensure they are available for subsequent operations
134 * such as API requests and webhook handling.
135 *
136 * @since 1.0.0
137 */
138 public function createConfig(): void {
139 parent::createConfig();
140
141 $config = array(
142 'webhook_id' => $this->getWebhookID(),
143 'client_id' => $this->getClientID(),
144 'merchant_email' => $this->getMerchantEmail(),
145 'api_url' => $this->getApiURL(),
146 'client_secret' => $this->getClientSecret(),
147 );
148
149 $this->updateConfig( $config );
150 }
151
152 /**
153 * Determine whether payment gateway configured properly
154 *
155 * @since 3.0.0
156 *
157 * @return boolean
158 */
159 public function is_configured() {
160 // Return true if all the settings are filled.
161 return $this->merchant_email && $this->client_id && $this->secret_id;
162 }
163
164 /**
165 * Get config keys
166 *
167 * @since 3.0.0
168 *
169 * @return array
170 */
171 private function get_config_keys() {
172 return array_keys( Settings::get_paypal_config_keys() );
173 }
174 }
175