1010 *
1111 * @version 1.0.0
1212 */
13- if ( ! class_exists ( 'Paylike \\Adapter ' ) ) {
14- class Adapter {
13+ if (!class_exists ('Paylike \\Adapter ' )) {
14+ class Adapter
15+ {
1516
1617 public $ apiUrl = 'https://api.paylike.io ' ;
1718 private $ apiKey ;
@@ -21,11 +22,12 @@ class Adapter {
2122 *
2223 * @param $privateApiKey
2324 */
24- public function __construct ( $ privateApiKey ) {
25- if ( $ privateApiKey ) {
26- $ this ->setApiKey ( $ privateApiKey );
25+ public function __construct ($ privateApiKey )
26+ {
27+ if ($ privateApiKey ) {
28+ $ this ->setApiKey ($ privateApiKey );
2729 } else {
28- trigger_error ( 'Private Key is missing! ' , E_USER_ERROR );
30+ trigger_error ('Private Key is missing! ' , E_USER_ERROR );
2931
3032 return null ;
3133 }
@@ -35,7 +37,8 @@ public function __construct( $privateApiKey ) {
3537 * @param $key
3638 * set the api key.
3739 */
38- public function setApiKey ( $ key ) {
40+ public function setApiKey ($ key )
41+ {
3942 $ this ->apiKey = $ key ;
4043 }
4144
@@ -47,35 +50,37 @@ public function setApiKey( $key ) {
4750 *
4851 * @return bool|mixed
4952 */
50- public function request ( $ url , $ data = null , $ httpVerb = 'post ' ) {
53+ public function request ($ url , $ data = null , $ httpVerb = 'post ' )
54+ {
5155 $ url = $ this ->apiUrl . '/ ' . $ url ;
5256 $ ch = curl_init ();
53- curl_setopt ( $ ch , CURLOPT_URL , $ url );
54- curl_setopt ( $ ch , CURLOPT_HEADER , false );
55- curl_setopt ( $ ch , CURLOPT_HTTPHEADER , array (
57+ curl_setopt ($ ch , CURLOPT_URL , $ url );
58+ curl_setopt ($ ch , CURLOPT_HEADER , false );
59+ curl_setopt ($ ch , CURLOPT_HTTPHEADER , array (
5660 'Accept: application/json ' ,
57- 'Content-Type: application/json '
58- ) );
59- curl_setopt ( $ ch , CURLOPT_SSL_VERIFYPEER , false );
60- curl_setopt ( $ ch , CURLOPT_USERPWD , ": " . $ this ->apiKey );
61- curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true );
62- switch ( $ httpVerb ) {
61+ 'Content-Type: application/json ' ,
62+ 'X-Client: PHP ' . phpversion ()
63+ ));
64+ curl_setopt ($ ch , CURLOPT_SSL_VERIFYPEER , false );
65+ curl_setopt ($ ch , CURLOPT_USERPWD , ": " . $ this ->apiKey );
66+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
67+ switch ($ httpVerb ) {
6368 case 'post ' :
64- curl_setopt ( $ ch , CURLOPT_POST , true );
65- if ( $ data ) {
69+ curl_setopt ($ ch , CURLOPT_POST , true );
70+ if ($ data ) {
6671 $ encoded = json_encode ($ data );
67- curl_setopt ( $ ch , CURLOPT_POSTFIELDS , $ encoded );
72+ curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ encoded );
6873 }
6974 break ;
7075 case 'get ' :
7176 // can add args here for future use
7277 break ;
7378 }
74- $ result = curl_exec ( $ ch );
75- $ httpCode = curl_getinfo ( $ ch , CURLINFO_HTTP_CODE );
76- curl_close ( $ ch );
77- $ output = json_decode ( $ result , true );
78- if ( $ httpCode >= 200 || $ httpCode <= 299 ) {
79+ $ result = curl_exec ($ ch );
80+ $ httpCode = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
81+ curl_close ($ ch );
82+ $ output = json_decode ($ result , true );
83+ if ($ httpCode >= 200 && $ httpCode <= 299 ) {
7984 return $ output ;
8085 } else {
8186 return false ;
0 commit comments