I am intergrating paypal payment gateway on my application, before user first leave my site for paypal, I saved all the necessary information, and set payment_status
to be 0
, when user returns, if payment is sucessful, it returns to a new page where it gets the paymentId
, and payerID
, plus sets the paymentstatus
to 1
.
the thing is that if i set the database value for paymentID
and PaymentId
to null
, it doesnt save.
if i dont set it to anything i.e leave it blank, it would save, but retruns an error:
Integrity constraint violation: 1048 Column 'PayerID' cannot be null (SQL: update `paypal_officers` set `paymentId` = , `PayerID` = , `updated_at` = 2018-07-15 07:29:21 where `id` = 1)
i cant seem to figure out what the problem is.
Here is the method that does the saving.
public function getPaymentStatus(Input $input)
{
/** Get the payment ID before session clear **/
$payment_id = Session::get('paypal_payment_id');
$insert_the_user_id = PaypalOfficer::findorFail(\session()->get('receivers_main_info_id'));
$insert_the_user_id->update([
'paymentId' => Input::get('paymentId'),
'PayerID' => Input::get('PayerID'),
'payment_status' => 1,
]);
$insert_the_user_id->save();
/** clear the session payment ID **/
Session::forget('paypal_payment_id');
if (empty(Input::get('PayerID')) || empty(Input::get('token'))) {
\Session::put('error', 'Payment failed');
return Redirect::to('account/send-money/paypal/send')->with('payer_id', $payment_id);;
}
$payment = Payment::get($payment_id, $this->_api_context);
$execution = new PaymentExecution();
$execution->setPayerId(Input::get('PayerID'));
/**Execute the payment **/
$result = $payment->execute($execution, $this->_api_context);
if ($result->getState() == 'approved') {
\Session::put('success', 'Payment success');
return Redirect::to('account/send-money/paypal/stagged/paypal')->with('payer_id', $result);
}
\Session::put('error', 'Payment failed');
return Redirect::to('account/send-money/paypal/send');
}
My Model
namespace App;
use Illuminate\Database\Eloquent\Model;
class PaypalOfficer extends Model
{
protected $fillable = [
'payment_status',
'paymentId',
'PayerID',
'user_id',
'amount',
'destination_account_number',
'destination_account_name',
'destination_bank_name',
'destination_phone_number',
'destination_country',
'destination_state',
'currency_symbol',
'receivers_name',
];
//
public function user(){
return $this->belongsTo(User::class);
}
}
Please what must i be missing in the code , anybody please!