Skip to content

Instantly share code, notes, and snippets.

@hasanbasri1993
Created March 1, 2021 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hasanbasri1993/834413c0f9eb1d5d3eae4f6ca1eb0de6 to your computer and use it in GitHub Desktop.
Save hasanbasri1993/834413c0f9eb1d5d3eae4f6ca1eb0de6 to your computer and use it in GitHub Desktop.
function tripay_create($postData = false)
{
$order_items = [];
$post = $postData ? $postData : $this->request->getPost();
$apiKey = $this->apiKey;
$privateKey = $this->privateKey;
$merchantRef = $post['id_order'];
$amount = $post['biaya'] + 5000;
$method = $post['metode_bayar'];
if (isset($post['data']) and !isset($post['id_takhosus'])) {
$amount = 0;
foreach (json_decode($post['data']) as $row) {
$order = [
'sku' => $row[1],
'name' => $row[2],
'price' => $row[0],
'quantity' => 1
];
array_push($order_items, $order);
$amount += $row[0];
}
array_push($order_items,
[
'sku' => 1,
'name' => "Biaya Admin Server",
'price' => 5000,
'quantity' => 1
]);
$amount += 5000;
} else
$order_items = [
[
'sku' => $merchantRef,
'name' => $merchantRef,
'price' => $amount,
'quantity' => 1
]
];
$data = [
'method' => $method,
'merchant_ref' => $merchantRef,
'amount' => $amount,
'customer_name' => 'PSBDULIDO-' . $merchantRef,
'customer_phone' => isset($post['nomer_handphone']) ? $post['nomer_handphone'] : "082213542319",
'customer_email' => "sekretariat@daarululuumlido.com",
'order_items' => $order_items,
'callback_url' => base_url(isset($post['callback']) ? $post['callback'] : '/callback_daftar_program'),
'return_url' => base_url('/masuk'),
'signature' => hash_hmac('sha256', $this->merchantCode . $merchantRef . $amount, $privateKey)
];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_FRESH_CONNECT => true,
CURLOPT_URL => $this->url . "transaction/create",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer " . $apiKey
),
CURLOPT_FAILONERROR => false,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($data)
));
$response = curl_exec($curl);
$response = json_decode($response);
$err = curl_error($curl);
curl_close($curl);
return !empty($err) ? array("message" => $err) : $response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment