PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.3.3
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.3.3
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / Models / WebhookRegistration.php
WebhookRegistration.php
71 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCart\Models;
4
5 use SureCart\Support\Encryption;
6
7 /**
8 * Webhook Model.
9 */
10 class WebhookRegistration {
11 /**
12 * Registered Webhook option name.
13 *
14 * @var string
15 */
16 public const REGISTERED_WEBHOOK_KEY = 'surecart_registered_webhook';
17
18 /**
19 * Deprecated Registered Webhook option name.
20 *
21 * @var string
22 */
23 public const DEPRECATED_WEBHOOK_KEY = 'ce_registered_webhook';
24
25 /**
26 * Save the registered webhook.
27 *
28 * @param array $webhook The webhook to save.
29 *
30 * @return bool
31 */
32 public function save( $webhook ): bool {
33 return update_option(
34 self::REGISTERED_WEBHOOK_KEY,
35 Encryption::encrypt(
36 json_encode(
37 [
38 'id' => $webhook['id'],
39 'url' => $webhook['url'],
40 'webhook_events' => $webhook['webhook_events'] ?? [],
41 'signing_secret' => $webhook['signing_secret'],
42 ]
43 )
44 )
45 );
46 }
47
48 /**
49 * Get registered webhook.
50 *
51 * @return array|null
52 */
53 public function get() {
54 $webhook = json_decode( Encryption::decrypt( (string) get_option( self::REGISTERED_WEBHOOK_KEY, '' ) ), true );
55 if ( empty( $webhook['signing_secret'] ) ) {
56 return null;
57 }
58 $webhook['signing_secret'] = $webhook['signing_secret'];
59 return new Webhook( $webhook );
60 }
61
62 /**
63 * Delete the registered webhook.
64 *
65 * @return boolean
66 */
67 public function delete(): bool {
68 return delete_option( self::REGISTERED_WEBHOOK_KEY );
69 }
70 }
71