forked from bukakios21/tokopay-php-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokopay.lib.php
61 lines (57 loc) · 2.15 KB
/
tokopay.lib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
class Tokopay
{
public $merchantId = 'M240509URZTI530';
public $secretKey = '5bc43dda41b1893283f01d3e2c5ba567076fbe7ac80840576a701fdc9dfa23ca';
public $apiUrl = "https://api.tokopay.id";
public function __construct($merchantId, $secretKey)
{
$this->merchantId = $merchantId;
$this->secretKey = $secretKey;
}
public function generateSignature($refId){
//signature formula md5(merchant_id:secret:ref_id)
$formula = $this->merchantId.":".$this->secretKey.":".$refId;
$signatureTrx = md5($formula);
return $signatureTrx;
}
public function createOrder($nominal, $ref_id, $kodeChannel){
//this simple order, referece to api docs https://docs.tokopay.id/order/create-order-simple
$mid = $this->merchantId;
$secret = $this->secretKey;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $this->apiUrl."/v1/order?merchant=$mid&secret=$secret&ref_id=$ref_id&nominal=$nominal&metode=$kodeChannel",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
public function createAdvanceOrder($data = []){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $this->apiUrl.'/v1/order',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 60,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>json_encode($data),
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
}