Closed Greatlegend12 closed 4 years ago
Try this
public function handleGatewayCallback()
{
$paymentDetails = Paystack::getPaymentData();
$user = User::find(Auth::id());
$user->column_name = date("Y-m-d H:i:s",strtotime($paymentDetails['data']['paidAt']));
$user->another_column_name= $paymentDetails['data']['plan_object']['name'];
$user->save();
return redirect ( route ('welcome'));
}
If you have any question let me know.
I used it, I got this error
see full detail call back
Can I see your code This is the way it work, I assume you're saving into the user table and you have registered your method in your route So to get the data, I pass the payment data into a new variable $paymentDetails = Paystack::getPaymentData();
I get the user info, $user = User::find(Auth::id());
This save the data into the column, there are 3 level First level is data, to get data id $paymentDetails['data']['id'] ; $paymentDetails['data']['authorization'] ['last4'] $paymentDetails['data']['forst_name']
You can save it like this $user->another_column_name= $paymentDetails['data']['authorization'] ['last4'] $user->save();
Paste your code here and your route, if you have any error.
These are my codes, i created a table I called payments. Cant save, I'm getting error 500 as in the screenshot
Have you registered your callback URL on paystack https://dashboard.paystack.com/#/settings/developer https://websitename.com/payment/callback
Please note that your code will save into user database.
Yes, have registered my callback on paystack
Please change to return redirect ( route ('home'));
I want to save the details in 'payments' table, not the user table
You need to create a relationship between user table and payment table. Then import your model. You can now use orm or query to create a new record at each instances.
How do I create the relationship, please help
In user model, do this public function payments(){ return $this->hasMany(Payment::class); }
In Payment model, do this public function user() { return $this->belongsTo(User::class); }
I don't think you need a relationship here Just do this
Payment::create([
'user_id' => Auth::id()
other details
]);
I got the array of information in the above screenshot after integration and making payments. Trying to add them to the database and update and and user information, I'm finding it hard. Please help me out.