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