Skip to content

Commit

Permalink
Remove deprecated code (maxSeq) and improve some comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
ulrikmoe committed Dec 3, 2018
1 parent 95fd0b9 commit 7662674
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions lib/Scanpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,32 @@ class Scanpay {

public function __construct($apikey = '') {
// Check if libcurl is enabled
if (!function_exists('curl_init')) { die("ERROR: Please enable php-curl\n"); }
if (!function_exists('curl_init')) {
die("ERROR: Please enable php-curl\n");
}

// Public cURL handle (we want to reuse connections)
// Public cURL handle (reuse handle)
$this->ch = curl_init();
$this->headers = [
'authorization' => 'Authorization: Basic ' . base64_encode($apikey),
'x-sdk' => 'X-SDK: PHP-1.3.1/'. PHP_VERSION,
'x-sdk' => 'X-SDK: PHP-1.3.2/'. PHP_VERSION,
'content-type' => 'Content-Type: application/json',
'expect' => 'Expect: ', // Prevent 'Expect: 100-continue' on POSTs >1024b.
'expect' => 'Expect: ',
];
/* The 'Expect' header will disable libcurl's expect-logic,
which will save us a HTTP roundtrip on POSTs >1024b. */
$this->apikey = $apikey;
}

/* Let merchant override headers and convert to regular array (cURL req.) */
/* Create indexed array from associative array ($this->headers).
Let the merchant overwrite the headers. */
protected function httpHeaders($o=[]) {
$ret = $this->headers;
if (isset($o['headers'])) {
foreach($o['headers'] as $key => &$val) {
$ret[strtolower($key)] = $key . ': ' . $val;
}
}
// Redefine API Key (DEPRECATED!!!)
if (isset($o['auth'])) {
$ret['authorization'] = 'Authorization: Basic ' . base64_encode($o['auth']);
}
return array_values($ret);
}

Expand All @@ -48,11 +49,14 @@ protected function request($path, $opts=[], $data=null) {
CURLOPT_CONNECTTIMEOUT => 20,
CURLOPT_TIMEOUT => 20,
CURLOPT_USE_SSL => CURLUSESSL_ALL,
CURLOPT_SSLVERSION => 6, // TLSv1.2
CURLOPT_SSLVERSION => 6,
];
// Let the merchant override $curlopts.

// Let the merchant overwrite $curlopts.
if (isset($opts['curl'])) {
foreach($opts['curl'] as $key => &$val) { $curlopts[$key] = $val; }
foreach($opts['curl'] as $key => &$val) {
$curlopts[$key] = $val;
}
}
curl_setopt_array($this->ch, $curlopts);

Expand Down Expand Up @@ -95,15 +99,6 @@ public function seq($seqnum, $opts=[]) {
throw new \Exception('Invalid response from server');
}

// maxSeq. (DEPRECATED!!!)
public function maxSeq($opts=[]) {
$o = $this->request('/v1/seq', $opts);
if (isset($o['seq']) && is_int($o['seq'])) {
return $o['seq'];
}
throw new \Exception('Invalid response from server');
}

// handlePing: Convert data to JSON and validate integrity
public function handlePing($opts=[]) {
ignore_user_abort(true);
Expand Down

0 comments on commit 7662674

Please sign in to comment.