PluginProbe
Booktics – Appointment Booking Calendar for Service Businesses / 1.0.28
Booktics – Appointment Booking Calendar for Service Businesses v1.0.28
1.0.29 1.0.28 1.0.27 1.0.26 1.0.25 1.0.24 1.0.23 1.0.22 1.0.21 1.0.20 1.0.19 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.2 1.0.3 All 31 releases
booktics / core / order / services / order-key.php

order-key.php in Booktics – Appointment Booking Calendar for Service Businesses 1.0.28, at core/order/services/order-key.php

48 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Booktics\Order\Services;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * Signed key that lets a guest open their own order without an account.
11 *
12 * Derived from the order id and number with a site salt, so it cannot be
13 * guessed from either value and needs nothing stored alongside the order.
14 *
15 * @package Booktics/Order
16 */
17 class Order_Key {
18
19 /**
20 * Build the view key for an order.
21 *
22 * @param int $order_id Order id.
23 * @param string $order_no Order number.
24 *
25 * @return string
26 */
27 public static function make( $order_id, $order_no ): string {
28 return hash_hmac( 'sha256', (string) $order_id . '|' . $order_no, wp_salt( 'booktics_order_view' ) );
29 }
30
31 /**
32 * Check a key against an order.
33 *
34 * @param int $order_id Order id.
35 * @param string $order_no Order number.
36 * @param string $provided_key Key supplied by the caller.
37 *
38 * @return bool
39 */
40 public static function verify( $order_id, $order_no, $provided_key ): bool {
41 if ( '' === $provided_key || strlen( $provided_key ) > 128 ) {
42 return false;
43 }
44
45 return hash_equals( self::make( $order_id, $order_no ), $provided_key );
46 }
47 }
48