Iforte Payment Gateway Development
I'm not seeing any tutorial about this, so I might as well make one.
Documentation - https://developer.mcpayment.id/
With so many methods, they do not give you an explanation on which one to use, basically if you want a page that is right out of the bat with all the payment available then focus on "Generate payment link" others don't matter.
https://developer.mcpayment.id/#0c7fd900-6884-4a7c-ac7e-183a3559346e
private function iforte(Order $order) {
$curl = curl_init();
$domain = 'https://' . $_SERVER['HTTP_HOST'];
$header = array(
'Authorization: Basic ' . base64_encode(env('IFORTE_MERCHANT_ID') . ":" . env('IFORTE_SECRET')),
'x-req-signature: ' . hash('sha256', env('IFORTE_HASH_KEY') . $order->id . $order->id),
'x-version: v3',
'Content-Type: application/json'
);
$post = '{
"order_id": "'. $order->id. '",
"external_id": "' . $order->id . '",
"amount": ' . $order->total_price . ',
"description": "' . $order->ads . '",
"contact_us": {
"phone" :"' . $order->phone_number . '",
"email" :"' . $order->user->email . '"
},
"customer_details": {
"full_name": "' . $order->user->name . '",
"email": "' . $order->user->email . '",
"phone": "' . $order->phone_number . '",
"address": "-",
"is_email_show": false,
"is_phone_show": false
},
"item_details": [
{
"item_id": "' . $order->ads . '-' . $order->user_id . '-' . $order->id . '",
"name": "' . $order->ads . '",
"amount": ' . $order->total_price . ',
"qty": 1
}
],
"selected_channels": [
{"channel":"CARD", "acq": "BRICC" },
{"channel":"DANA"},
{"channel":"OVO"},
{"channel":"SHOPEEPAY"},
{"channel":"LINKAJA"},
{"channel":"QRIS"},
{"channel":"VIRGO"},
{
"channel": "VA",
"acq": "CIMB",
"payment_system": "CLOSED",
"is_multi_use": false
},
{
"channel": "VA",
"acq": "PERMATA",
"payment_system": "CLOSED",
"is_multi_use": false
}
],
"save_card": false,
"callback_url": "'. $domain.'/checkout/notification",
"success_redirect_url": "'. $domain.'/checkout/success",
"failed_redirect_url": "'. $domain.'/checkout/error"
}';
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api-stage.mcpayment.id/payment-page/payment',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $post,
CURLOPT_HTTPHEADER => $header,
));
$response = curl_exec($curl);
curl_close($curl);
//echo $response;
return json_decode($response,true);
}
then check if it successfully generates the link then redirects to that link
if (!empty($payment['response_message']) && $payment['response_message'] == 'Success') {
return redirect($payment['data']['payment_url']);
}
All payment gateway need notification to pass, it would be something like this, don't forget the validation this is only to show you how it works.
public function notification(Request $request) {
$post = $request->all();
if (!empty($post['transaction_id']) && !empty($post['transaction_status'])) {
$order = Order::where('transaction_id', $post['transaction_id'])->first();
if (empty($order)) {
return response()->json(['error' => $post['response_message']], 401);
}
if ($post['transaction_status'] == 'SUCCESS') {
$order->is_paid = 1;
$order->save();
}
$args = [
'order_id' => $order->id,
'transaction_id' => $post['transaction_id'],
'log_response' => json_encode($post),
'transaction_status' => $post['transaction_status'],
'response_message' => $post['response_message'],
'payment_method' => $post['payment_method'],
'payment_channel' => $post['payment_channel'],
'paid_date' => $post['paid_date'] ?? '',
'fee' => $post['fee'] ?? '',
'amount' => $post['amount'],
];
PaymentNotification::create($args);
return response()->json(['success' => $post['response_message']], 200);
}
return response()->json(['error' => $post['response_message']], 401);
}