Viewing file: Paylith.php (2.04 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php defined('BASEPATH') or exit('No direct script access allowed');
class Paylith {
private $apiKey, $apiSecret;
public function __construct($parameters) { $this->apiKey = $parameters["api_key"]; $this->apiSecret = $parameters["api_secret"]; }
private function generateToken($conversationId, $userId, $userEmail, $userIpAddress, $userPhone) { $hashStr = [ 'apiKey' => $this->apiKey, 'conversationId' => $conversationId, 'userId' => $userId, 'userEmail' => $userEmail, 'userIpAddress' => $userIpAddress, 'userPhone' => $userPhone ];
ksort($hashStr);
$hash = hash_hmac('sha256', implode('|', $hashStr) . $this->apiSecret, $this->apiKey); return hash_hmac('md5', $hash, $this->apiKey); }
public function createProductLink($conversationId, $userId, $userEmail, $userIpAddress, $productName, $productAmount, $userPhone) { return $this->request( 'token', [ 'token' => $this->generateToken($conversationId, $userId, $userEmail, $userIpAddress, $userPhone), 'apiKey' => $this->apiKey, 'conversationId' => $conversationId, 'userId' => $userId, 'userEmail' => $userEmail, 'userIpAddress' => $userIpAddress, 'userPhone' => $userPhone, 'productApi' => true, 'productData' => [ 'name' => $productName, 'amount' => $productAmount, ], 'redirectUrl' => base_url() ] ); }
private function request($url, $data) { $curl = curl_init("https://api.paylith.com/v1/" . $url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($curl); curl_close($curl); return $response; } }
|