Files
carpseeds.pl/wp-content/plugins/przelewy24/includes/rest_api/class-p24-rest-common.php
2024-07-15 11:28:08 +02:00

81 lines
1.6 KiB
PHP

<?php
/**
* File that define P24_Rest_Common class.
*
* @package Przelewy24
*/
defined( 'ABSPATH' ) || exit;
/**
* Class that support card API.
*/
class P24_Rest_Common extends P24_Rest_Abstract {
/**
* Test access.
*
* @return array
*/
public function test_access() {
$path = '/testAccess';
$ret = $this->call( $path, null, 'GET' );
return $ret;
}
/**
* Test access bool.
*
* @return bool
*/
public function test_access_bool() {
$data = $this->test_access();
return isset( $data['error'] ) && empty( $data['error'] );
}
/**
* Get payment methods (internal).
*
* @param string $lang One of supported languages (only 'pl' and 'en' for now).
*
* @return array
*
* @throws LogicException When wrong language is provided.
*/
public function payment_methods( $lang ) {
$ret = $this->payment_methods_internal( $lang );
$new_data = array();
foreach ( $ret['data'] as $row ) {
if ( Przelewy24Generator::P24NOW !== $row['id'] ) {
$new_data[] = $row;
}
}
$ret['data'] = $new_data;
return $ret;
}
/**
* Get payment methods (internal).
*
* @param string $lang One of supported languages (only 'pl' and 'en' for now).
*
* @return array
*
* @throws LogicException When wrong language is provided.
*/
private function payment_methods_internal( $lang ) {
if ( ! in_array( $lang, array( 'pl', 'en' ), true ) ) {
$msg = 'The lang ' . $lang . ' is not supported.';
throw new LogicException( esc_html( $msg ) );
}
$path = '/payment/methods/' . $lang;
$ret = $this->call( $path, null, 'GET' );
return $ret;
}
}