1. Go to this page and download the library: Download firmantr3/laravel-midtrans library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Firmantr3\Midtrans\Facade\Midtrans;
// somewhere in your controller
$notification = Midtrans::notification();
/**
* $notificationArray = $notification->toArray();
* $notificationObject = $notification->toObject();
**/
$transaction = $notification->transaction_status;
$fraud = $notification->fraud_status;
error_log("Order ID $notification->order_id: "."transaction status = $transaction, fraud staus = $fraud");
if ($transaction == 'capture') {
if ($fraud == 'challenge') {
// TODO Set payment status in merchant's database to 'challenge'
}
else if ($fraud == 'accept') {
// TODO Set payment status in merchant's database to 'success'
}
}
else if ($transaction == 'cancel') {
if ($fraud == 'challenge') {
// TODO Set payment status in merchant's database to 'failure'
}
else if ($fraud == 'accept') {
// TODO Set payment status in merchant's database to 'failure'
}
}
else if ($transaction == 'deny') {
// TODO Set payment status in merchant's database to 'failure'
}
use Firmantr3\Midtrans\Facade\Midtrans;
// somewhere in your controller
$status = Midtrans::status($orderId);
var_dump($status);
use Firmantr3\Midtrans\Facade\Midtrans;
// somewhere in your controller
$approve = Midtrans::approve($orderId);
var_dump($approve);
use Firmantr3\Midtrans\Facade\Midtrans;
// somewhere in your controller
$cancel = Midtrans::cancel($orderId);
var_dump($cancel);
use Firmantr3\Midtrans\Facade\Midtrans;
// somewhere in your controller
$cancel = Midtrans::cancel($orderId);
var_dump($cancel);
use Firmantr3\Midtrans\Facade\Midtrans;
Midtrans::shouldReceive('getSnapToken')
->once()
->with(['parameters'])
->andReturn('My Token');
$myToken = Midtrans::getSnapToken(['parameters'])); // returns "My Token"