-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1757030
commit ab1900e
Showing
8 changed files
with
1,052 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?php | ||
|
||
require_once(VIKSSLCOMMERZ_DIR."/lib/SslCommerzInterface.php"); | ||
|
||
abstract class AbstractSslCommerz implements SslCommerzInterface | ||
{ | ||
protected $apiUrl; | ||
protected $storeId; | ||
protected $storePassword; | ||
protected $apiDomain; | ||
|
||
protected function setStoreId($storeID) | ||
{ | ||
$this->storeId = $storeID; | ||
} | ||
|
||
protected function getStoreId() | ||
{ | ||
return $this->storeId; | ||
} | ||
|
||
protected function setStorePassword($storePassword) | ||
{ | ||
$this->storePassword = $storePassword; | ||
} | ||
|
||
protected function getStorePassword() | ||
{ | ||
return $this->storePassword; | ||
} | ||
|
||
protected function setApiUrl($url) | ||
{ | ||
$this->apiUrl = $url; | ||
} | ||
|
||
protected function getApiUrl() | ||
{ | ||
return $this->apiUrl; | ||
} | ||
|
||
|
||
protected function setApiDomain($url) | ||
{ | ||
$this->apiDomain = $url; | ||
} | ||
|
||
protected function getApiDomain() | ||
{ | ||
return $this->apiDomain; | ||
} | ||
|
||
/** | ||
* @param $data | ||
* @param array $header | ||
* @param bool $setLocalhost | ||
* @return bool|string | ||
*/ | ||
public function callToApi($data, $header = [], $setLocalhost = false) | ||
{ | ||
$curl = curl_init(); | ||
|
||
if (!$setLocalhost) { | ||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); | ||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); // The default value for this option is 2. It means, it has to have the same name in the certificate as is in the URL you operate against. | ||
} else { | ||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | ||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // When the verify value is 0, the connection succeeds regardless of the names in the certificate. | ||
} | ||
|
||
curl_setopt($curl, CURLOPT_URL, $this->getApiUrl()); | ||
curl_setopt($curl, CURLOPT_HEADER, 0); | ||
curl_setopt($curl, CURLOPT_HTTPHEADER, $header); | ||
curl_setopt($curl, CURLOPT_TIMEOUT, 60); | ||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | ||
|
||
curl_setopt($curl, CURLOPT_POST, 1); | ||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); | ||
|
||
$response = curl_exec($curl); | ||
$err = curl_error($curl); | ||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE); | ||
$curlErrorNo = curl_errno($curl); | ||
curl_close($curl); | ||
|
||
if ($code == 200 & !($curlErrorNo)) { | ||
return $response; | ||
} else { | ||
return "FAILED TO CONNECT WITH SSLCOMMERZ API"; | ||
//return "cURL Error #:" . $err; | ||
} | ||
} | ||
|
||
/** | ||
* @param $response | ||
* @param string $type | ||
* @param string $pattern | ||
* @return false|mixed|string | ||
*/ | ||
public function formatResponse($response, $type = 'checkout', $pattern = 'json') | ||
{ | ||
$sslcz = json_decode($response, true); | ||
|
||
if ($type != 'checkout') { | ||
return $sslcz; | ||
} else { | ||
if (isset($sslcz['GatewayPageURL']) && $sslcz['GatewayPageURL'] != "") { | ||
// this is important to show the popup, return or echo to send json response back | ||
$response = json_encode(['status' => 'success', 'data' => $sslcz['GatewayPageURL'], 'logo' => $sslcz['storeLogo']]); | ||
} else { | ||
$response = json_encode(['status' => 'fail', 'data' => null, 'message' => "JSON Data parsing error!"]); | ||
} | ||
|
||
if ($pattern == 'json') { | ||
return $response; | ||
} else { | ||
echo $response; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param $url | ||
* @param bool $permanent | ||
*/ | ||
public function redirect($url, $permanent = false) | ||
{ | ||
header('Location: ' . $url, true, $permanent ? 301 : 302); | ||
|
||
exit(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
|
||
interface SslCommerzInterface | ||
{ | ||
public function makePayment(array $data); | ||
|
||
public function orderValidate($trxID, $amount, $currency, $requestData); | ||
|
||
public function setParams($data); | ||
|
||
public function setRequiredInfo(array $data); | ||
|
||
public function setCustomerInfo(array $data); | ||
|
||
public function setShipmentInfo(array $data); | ||
|
||
public function setProductInfo(array $data); | ||
|
||
public function setAdditionalInfo(array $data); | ||
|
||
public function callToApi($data, $header = [], $setLocalhost = false); | ||
} |
Oops, something went wrong.