Implement Snap Redirect
masterSnap Redirect requires the customer to be redirected to a payment page hosted by Midtrans.
Workflow:
- Backend: Call
\Midtrans\Snap::createTransaction($params)to get a transaction object. - Redirect: Access the
redirect_urlproperty from the response and redirect the user's browser to that URL.
$params = array(
'transaction_details' => array(
'order_id' => rand(),
'gross_amount' => 10000,
)
);
try {
// Get Snap Payment Page URL
$paymentUrl = \Midtrans\Snap::createTransaction($params)->redirect_url;
// Redirect to Snap Payment Page
header('Location: ' . $paymentUrl);
}
catch (Exception $e) {
echo $e->getMessage();
}