RouteSignature.php
50 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\PaymentGateways\Routes; |
| 4 | |
| 5 | /** |
| 6 | * Route signature for creating secure gateway route methods |
| 7 | * |
| 8 | * @since 2.19.0 |
| 9 | */ |
| 10 | class RouteSignature { |
| 11 | /** |
| 12 | * @var string |
| 13 | */ |
| 14 | private $signature; |
| 15 | |
| 16 | /** |
| 17 | * @since 2.19.0 |
| 18 | * |
| 19 | * @param int $gatewayId |
| 20 | * @param string $gatewayMethod |
| 21 | * @param string[] $args |
| 22 | */ |
| 23 | public function __construct($gatewayId, $gatewayMethod, $args) |
| 24 | { |
| 25 | $secureArgs = md5(implode('|', $args)); |
| 26 | |
| 27 | $this->signature = "$gatewayId@$gatewayMethod:$secureArgs"; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * @since 2.19.0 |
| 32 | * |
| 33 | * @return string |
| 34 | */ |
| 35 | public function toString() |
| 36 | { |
| 37 | return $this->signature; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * @since 2.19.0 |
| 42 | * |
| 43 | * @return false|string |
| 44 | */ |
| 45 | public function toNonce() |
| 46 | { |
| 47 | return wp_create_nonce($this->signature); |
| 48 | } |
| 49 | } |
| 50 |