Reputation: 205
How to store unique $payment->transaction_id = Input::get('transact');
No more transaction_id
should store with same number
Please suggest me.
public function ddclback()
{
if(Input::get('statuscode') == 2){
//Save data into the Database
$payment = new Payment;
$payment->order_id = Input::get('orderid');
$payment->amount = (Input::get('base_amount', 0))?Input::get('base_amount'):Input::get('amount');
$payment->amount = $payment->amount/100;
$payment->cc_fee = Input::get('processing_fee', 0);
$payment->payment_type = 'CCD-'.Input::get('currency');
$payment->currency = Input::get('currency');
$payment->exchange_rate = $this->getExchangeRate( Input::get('currency') );
$payment->gateway = 'DIBS';
$payment->payment_date = date('Y-m-d'); //\Carbon\Carbon::today()->toDateString();
$payment->card_type = Input::get('paytype');
$payment->transaction_id = Input::get('transact');
$payment->customer_ip = $_SERVER['REMOTE_ADDR'];
$payment->save();
Order::ccid(Input::get('orderid'));
Order::upord(Input::get('orderid'));
}
}
Upvotes: 0
Views: 197
Reputation: 3083
You should check with where clause before insert record into DB.
Try below code:
public function ddclback() {
if (Input::get('statuscode') == 2) {
$exist = $this->checkExist(Input::get('orderid'), Input::get('transact')); // check if exist it will return true/ false
if (!$exist) {
//Save data into the Database if not exist
$payment = new Payment;
$payment->order_id = Input::get('orderid');
$payment->amount = (Input::get('base_amount', 0)) ? Input::get('base_amount') : Input::get('amount');
$payment->amount = $payment->amount / 100;
$payment->cc_fee = Input::get('processing_fee', 0);
$payment->payment_type = 'CCD-' . Input::get('currency');
$payment->currency = Input::get('currency');
$payment->exchange_rate = $this->getExchangeRate(Input::get('currency'));
$payment->gateway = 'DIBS';
$payment->payment_date = date('Y-m-d'); //\Carbon\Carbon::today()->toDateString();
$payment->card_type = Input::get('paytype');
$payment->transaction_id = Input::get('transact');
$payment->customer_ip = $_SERVER['REMOTE_ADDR'];
$payment->save();
Order::ccid(Input::get('orderid'));
Order::upord(Input::get('orderid'));
}
}
}
public function checkExist($orderId, $transactionId) {
$existRecord = Payment::where('order_id', $orderId)->where('transaction_id', $transactionId)->get()->toArray();
if ($existRecord) {
return true;
} else {
return false;
}
}
Upvotes: 1