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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 8 months ago
PaypalConfig.php
167 lines
1 <?php
2
3 namespace Tutor\PaymentGateways\Configs;
4
5 use Tutor\Ecommerce\Settings;
6 use Ollyo\PaymentHub\Core\Payment\BaseConfig;
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 BaseConfig 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 getClientSecret(): string {
100 return $this->secret_id;
101 }
102
103 public function getName(): string {
104 return $this->name;
105 }
106
107 public function getClientID(): string {
108 return $this->client_id;
109 }
110
111 public function getMerchantEmail(): string {
112 return $this->merchant_email;
113 }
114
115 public function getApiURL() {
116 return 'test' === $this->environment ? static::API_URL_TEST : static::API_URL_LIVE;
117 }
118
119 /**
120 * Creates and updates configuration settings specific to the PayPal integration.
121 *
122 * Retrieves necessary configuration values using getter methods for webhook ID,
123 * client ID, merchant email, API URL, and client secret. Updates the configuration
124 * storage with these values to ensure they are available for subsequent operations
125 * such as API requests and webhook handling.
126 *
127 * @since 1.0.0
128 */
129 public function createConfig(): void {
130 parent::createConfig();
131
132 $config = array(
133 'client_id' => $this->getClientID(),
134 'merchant_email' => $this->getMerchantEmail(),
135 'api_url' => $this->getApiURL(),
136 'client_secret' => $this->getClientSecret(),
137 'save_payment_method' => true,
138 'webhook_id' => $this->webhook_id
139 );
140
141 $this->updateConfig( $config );
142 }
143
144 /**
145 * Determine whether payment gateway configured properly
146 *
147 * @since 3.0.0
148 *
149 * @return boolean
150 */
151 public function is_configured() {
152 // Return true if all the settings are filled.
153 return $this->merchant_email && $this->client_id && $this->secret_id;
154 }
155
156 /**
157 * Get config keys
158 *
159 * @since 3.0.0
160 *
161 * @return array
162 */
163 private function get_config_keys() {
164 return array_keys( Settings::get_paypal_config_keys() );
165 }
166 }
167