Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/tutor-stripe/integration/StripeConfig.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 +
3 + namespace TutorStripe;
4 +
5 + use Tutor\Ecommerce\Settings;
6 + use Ollyo\PaymentHub\Core\Payment\BaseConfig;
7 + use TutorPro\Ecommerce\Config as EcommerceConfig;
8 + use Tutor\PaymentGateways\Configs\PaymentUrlsTrait;
9 + use Ollyo\PaymentHub\Contracts\Payment\ConfigContract;
10 +
11 + /**
12 + * StripeConfig class.
13 + *
14 + * This class handles the configuration for the Stripe payment gateway.
15 + * It extends the BaseConfig class and implements the ConfigContract interface.
16 + *
17 + * @since 1.0.0
18 + */
19 + class StripeConfig extends BaseConfig implements ConfigContract {
20 +
21 + use PaymentUrlsTrait;
22 +
23 + /**
24 + * Environment setting.
25 + *
26 + * @since 1.0.0
27 + *
28 + * @var string
29 + */
30 + private $environment;
31 +
32 + /**
33 + * Secret key.
34 + *
35 + * @since 1.0.0
36 + *
37 + * @var string
38 + */
39 + private $secret_key;
40 +
41 + /**
42 + * Public key.
43 + *
44 + * @since 1.0.0
45 + *
46 + * @var string
47 + */
48 + private $public_key;
49 +
50 + /**
51 + * Webhook signature key.
52 + *
53 + * @since 1.0.0
54 + *
55 + * @var string
56 + */
57 + private $webhook_signature_key;
58 +
59 + /**
60 + * The name of the payment gateway.
61 + *
62 + * @since 1.0.0
63 + *
64 + * @var string
65 + */
66 + protected $name = 'stripe';
67 +
68 + /**
69 + * Constructor.
70 + *
71 + * Initializes the StripeConfig object.
72 + *
73 + * @since 1.0.0
74 + */
75 + public function __construct() {
76 + parent::__construct();
77 + $settings = Settings::get_payment_gateway_settings( 'stripe' );
78 + $config_keys = array_keys( EcommerceConfig::get_stripe_config_keys() );
79 + foreach ( $config_keys as $key ) {
80 + if ( 'webhook_url' !== $key ) {
81 + $this->$key = $this->get_field_value( $settings, $key );
82 + }
83 + }
84 + }
85 +
86 + /**
87 + * Retrieves the mode of the Stripe payment gateway.
88 + *
89 + * @since 1.0.0
90 + *
91 + * @return string The mode of the payment gateway ('test' or 'live').
92 + */
93 + public function getMode(): string {
94 + return $this->environment;
95 + }
96 +
97 + /**
98 + * Retrieves the secret key for the Stripe payment gateway.
99 + *
100 + * @since 1.0.0
101 + *
102 + * @return string The secret key.
103 + */
104 + public function getSecretKey(): string {
105 + return $this->secret_key;
106 + }
107 +
108 + /**
109 + * Retrieves the public key for the Stripe payment gateway.
110 + *
111 + * @since 1.0.0
112 + *
113 + * @return string The public key.
114 + */
115 + public function getPublicKey(): string {
116 + return $this->public_key;
117 + }
118 +
119 + /**
120 + * Retrieves the webhook key for the Stripe payment gateway.
121 + *
122 + * @since 1.0.0
123 + *
124 + * @return string The public key.
125 + */
126 + public function getWebhookSecretKey(): string {
127 + return $this->webhook_signature_key;
128 + }
129 +
130 + /**
131 + * Determine whether payment gateway configured properly
132 + *
133 + * @since 1.0.0
134 + *
135 + * @return boolean
136 + */
137 + public function is_configured() {
138 + return $this->public_key && $this->secret_key && $this->webhook_signature_key;
139 + }
140 +
141 + /**
142 + * Determines whether the payment method should be saved for future use.
143 + *
144 + * @return bool returns true to indicate the payment method should be saved, false otherwise.
145 + * @since 1.0.0
146 + */
147 + private function savePaymentMethodForFutureUse(): bool {
148 + return true;
149 + }
150 +
151 + /**
152 + * Create the configuration for the Paddle payment gateway.
153 + *
154 + * @since 1.0.0
155 + */
156 + public function createConfig(): void {
157 + parent::createConfig();
158 +
159 + $this->updateConfig( 'save_payment_method', $this->savePaymentMethodForFutureUse() );
160 + }
161 + }
162 +