namespace App\Model;
use Tartan\Larapay\Transaction;
class Transaction extends Model implements TransactionInterface
{
// set order reference Id
public function setReferenceId($referenceId, $save = true){}
// check if you transaction is ready for requesting payment token
public function checkForRequestToken(){}
// check if transaction is ready for requesting verify transaction
public function checkForVerify(){}
// check if transaction is ready for requesting inqury transaction (if supported by gateway)
public function checkForInquiry(){}
// check if transaction is ready for requesting reverse transaction (if supported by gateway)
public function checkForReverse(){}
// check if transaction is ready for requesting settle/... transaction (if needed by gateway)
public function checkForAfterVerify(){}
// update transaction by paid card number (if provided by gateway)
public function setCardNumber($cardNumber){}
// mark transaction as verified
public function setVerified(){}
// mark transaction as settled/...
public function setAfterVerified(){}
// mark transaction as completed
public function setSuccessful($flag){}
// mark transaction as reversed
public function setReversed(){}
// get transaction amount
public function getAmount(){}
// set transactions's paid tme
public function setPaidAt($time = 'now'){}
// set transaction's extra details
public function setExtra($key, $value, $save = false){}
}
public function payOnline (Request $request, Transaction $transaction)
{
// check if the selected payment is active or not from your gateways table
$paymentGateway = Gateway::activeGate()
->where('slug', $request->input('by_online_gateway'))
->first();
if (empty($paymentGateway)) {
return view('gateway.notfound');
}
// get some additional parameters for updating transaction
$parameters = [
'description' => $request->input('by_online_description', ''),
'bank' => $request->input('by_online_gateway'),
];
// update transaction payment method
$transaction = $this->transactionsRepository->setTransactionPaid(
$transaction, TransactionPayment::ONLINE, $parameters
);
// make larapay payment gateway instance
$paymentGatewayHandler = Larapay::make($paymentGateway->slug, $transaction);
// set payment params
$paymentParams = [
'order_id' => $transaction->getBankOrderId(),
'redirect_url' => route('payment.callback', [
'bank' => $paymentGateway->slug,
'transactionId' => $transaction->guid
]),
'amount' => $transaction->amount,
'submit_label' => trans('larapay::larapay.goto_gate')
];
try {
// get goto gate form
$form = $paymentGatewayHandler->form($paymentParams);
} catch (\Exception $e) {
// could not generate goto gate form
Log::emergency($paymentGateway->slug . ' #' . $e->getCode() . '-' . $e->getMessage());
Session::flash('alert-danger', trans('trans.could_not_create_goto_bank_form', ['gateway' => $paymentGateway->name]));
return redirect()->back()->withInput();
}
if (is_null($form)) {
return redirect()->back()->withInput();
}
// view goto gate view
return view('gateway.gotogate', [
'gateway' => $paymentGateway,
'form' => $form,
]);
}