<?php
class Api
{
//Nomor merchant
private $mch_id = 10085;
//APIKEY merchant
private $mch_key = 'slrkogmvo13hb92d8i5111bxm8q8euc7';
//Membuat tanda tangan (sign)
private function sign($data, $Md5key)
{
ksort($data);
$md5str = "";
foreach ($data as $key => $val) {
if (!empty($val)) {
$md5str = $md5str . $key . "=" . $val . "&";
}
}
return strtoupper(md5($md5str . "key=" . $Md5key));
}
//Request CURL
protected function curl($url, $data = [], $method = 'POST')
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
if (1 == strpos("$" . $url, "https://")) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$res = curl_exec($curl);
if (curl_errno($curl)) {
return 'ERROR_200' . curl_error($curl);
}
curl_close($curl);
return $res;
}
//Request pay-in
public function ds()
{
$param = [
"memberId" => $this->mch_id,
"type" => 'bank',
"orderId" => 'E2021090512312314',
"dstCode" => 'PERMATA',
"amount" => 50000,
"dateTime" => date("Y-m-d H:i:s"),
"name" => 'xinmiti',
"phone" => '088291448849',
"email" => 'gotocode@gmail.com',
"notifyUrl" => 'http://www.yourdomain.com/demo/notifyurl.php'
];
$param["sign"] = $this->sign($param, $this->mch_key);
return $this->curl('http://pay.xxxxxx.com/Pay_Index.html', $param);
}
}
//Instansiasi request
$api = new Api();
$res = $api->ds();
echo print_r($res);