| 1 |
<?php |
| 2 |
/** |
| 3 |
* Cashfree Api |
| 4 |
*/ |
| 5 |
|
| 6 |
defined( 'ABSPATH' ) || exit; |
| 7 |
|
| 8 |
/** |
| 9 |
* Cashfree Api dispatcher class. |
| 10 |
*/ |
| 11 |
class WC_Cashfree_Api { |
| 12 |
|
| 13 |
/** |
| 14 |
* Constructor. |
| 15 |
* |
| 16 |
* @param string $id Api identifier. |
| 17 |
*/ |
| 18 |
private $id; |
| 19 |
|
| 20 |
public function __construct( $id ) { |
| 21 |
$this->id = $id; |
| 22 |
|
| 23 |
add_action( 'woocommerce_api_' . $this->id, array( $this, 'dispatch' ) ); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Dispatch request. |
| 28 |
*/ |
| 29 |
public function dispatch() { |
| 30 |
if ( ! empty( $_GET['action'] ) && ! empty( $_GET['order_key'] ) ) { |
| 31 |
$tag = 'api_' . $this->id . '_' . wc_clean( wp_unslash( $_GET['action'] ) ); |
| 32 |
if ( has_action( $tag ) ) { |
| 33 |
do_action( |
| 34 |
$tag, |
| 35 |
wc_clean( wp_unslash( $_REQUEST ) ), |
| 36 |
wc_clean( wp_unslash( $_GET['order_key'] ) ) |
| 37 |
); |
| 38 |
exit; |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
wp_die( esc_html__( 'Invalid URL.', 'cashfree' ) ); |
| 43 |
} |
| 44 |
} |
| 45 |
|