| 1 |
<?php |
| 2 |
|
| 3 |
namespace Better_Payment\Lite\Blocks; |
| 4 |
|
| 5 |
use Better_Payment\Lite\Blocks\Settings as Settings; |
| 6 |
use Better_Payment\Lite\Traits\HasSingletone as HasSingletone; |
| 7 |
|
| 8 |
abstract class ThirdPartyIntegration { |
| 9 |
use HasSingletone; |
| 10 |
|
| 11 |
/** |
| 12 |
* Returns concat URL with the endpoint and version. |
| 13 |
* |
| 14 |
* @param string $endpoint |
| 15 |
* @param string $version |
| 16 |
* @return string |
| 17 |
*/ |
| 18 |
protected function url( $endpoint, $version = 'v1/' ) { |
| 19 |
return static::URL . $version . $endpoint; |
| 20 |
} |
| 21 |
|
| 22 |
public static function is_isset( $value, $default = '' ) { |
| 23 |
return isset( $_POST[ $value ] ) ? sanitize_text_field( $_POST[ $value ] ) : $default; |
| 24 |
} |
| 25 |
|
| 26 |
public function settings() { |
| 27 |
return Settings::get_instance(); |
| 28 |
} |
| 29 |
|
| 30 |
public function add_ajax( array $actions = array() ) { |
| 31 |
if ( ! empty( $actions ) ) { |
| 32 |
foreach ( $actions as $action => $method ) { |
| 33 |
if ( is_string( $method ) ) { |
| 34 |
add_action( "wp_ajax_$action", array( $this, $method ) ); |
| 35 |
add_action( "wp_ajax_nopriv_$action", array( $this, $method ) ); |
| 36 |
} else { |
| 37 |
add_action( "wp_ajax_$action", array( $this, $method['callback'] ) ); |
| 38 |
if ( isset( $method['public'] ) && $method['public'] == true ) { |
| 39 |
add_action( "wp_ajax_nopriv_$action", array( $this, $method['callback'] ) ); |
| 40 |
} |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
} |
| 46 |
|