Form Fields: Name and Phone Not Passed Along with Request in Paystack - laravel

I am trying to implement Paystack in Laravel; I'm using their suggested documentation for Laravel. The issue is that the amount and email get passed onto the Paystack database, but the customer's name and phone details aren't. How do I get it to be passed along to Paystack?
I have configured the checkout process as mentioned in the documentation based on https://github.com/unicodeveloper/laravel-paystack. I'm using Windows 10 and running Laravel 5.6 and PHP 7.3.
<form class="needs-validation" action="{{ route('pay') }}" method="POST">
<div class="row">
<div class="col-md-6 mb-3">
<label for="first_name">First name</label>
<input type="text" class="form-control" id="first_name"
placeholder="first name" value="" name="first_name" required="">
</div>
<div class="col-md-6 mb-3">
<label for="last_name">Last name</label>
<input type="text" class="form-control" id="last_name"
placeholder="last Name" name="last_name" value="" required="">
</div>
</div>
<div class="mb-3">
<label for="email">Email <span class=" text-danger"> * </span>
</label>
<input type="email" class="form-control" id="email" name="email"
placeholder="you#example.com" required>
</div>
{{ csrf_field() }}
<hr class="mb-4">
<button class="btn btn-success btn-lg btn-block" type="submit"
value="Pay Now!">
<i class="fa fa-plus-circle fa-lg"></i> Complete Payment!
</button>
</form>
I expected that after the payment is complete, the customer data should contain the customer email, and name. But it returns only the email in the customer array.

you have to implement it yourself, before the pay button try to have a form like this
<form action="/myform" method="post">
<input type="text" name="fullname">
<input type="number" name="phone_number">
<button>submit</button>
</form>
Route::post('/myform','controllerhere#form1')->name('name');
Route::get('/pay','controller#function')->name('pay');
Route::post('/pay','controller#function')->name('pay');
then your controller to look like this
public function form1(Request $request){
$request->validate([....]);
save the form and return redirect to your payment form like this
..
return redirect('/pay');
}
then payments can be made, please the above codes are just samples to help

Alternatively if you check the https://github.com/unicodeveloper/laravel-paystack package, there is a commented section in the paystack.php; this contains a sample of how to add custom_fields to the metadata.
`<input type="hidden" name="metadata" value="{{ json_encode($array) }}" >`
$array = [ 'custom_fields' => [
['display_name' => "Cart Id", "variable_name" => "cart_id", "value" => "2"],
['display_name' => "Sex", "variable_name" => "sex", "value" => "female"],
]
]
Edit this to add name of the customer and amount then if you dd($paymentdatails) you will see the details in metadata.

Related

Cant get https to work properly on ngrok. need https to test pyament api webhook

I just started implementing the mollie api to handle payments on my website.
You need a url to redirect to and a url as a webhook to update payment states.
I'm still developing the website locally, but localhost as a url isn't an option ofcourse.
I installed ngrok and tried the HTTPS URL assigned to me when running the ngrok http command.
when i access my website with the HTTP link everything looks fine, But when i go to my website via the HTTPS link my website fails to load in my own css scripts and chrome tells me the website is not secure, but my ssl certificate is valid (probably not secure because its self-signed)?
i tried to test the api anyhow by ordering something on the (broken https) website but after confirming the order i get a 419 error response (i develop my website in laravel 8).
So sorry if i left out crucial information, i'm the biggest noob when it comes to networking and i didn't even know where to begin.
EDIT: Here is additional information on what my problem is.
Im testing the payment api from mollie in my laravel controller where i create an order.
public function order(CreateOrderRequest $request){
$baseUrl = 'https://xxxx-xxx-xx-xxx-xx.ngrok.io/';
$payment = $this->mollie->payments->create([
"amount" => [
"currency" => "EUR",
"value" => "10.00"
],
"description" => "My first API payment",
"redirectUrl" => $baseUrl."/order/besteld",
"webhookUrl" => $baseUrl."/order/betaalupdate/".$id,
]);
dd($payment);
return redirect()->to($payment->getCheckoutUrl(), 303);
}
this controller is called from the route:
Route::post('/winkelwagen/bestellen/bevestig', [CartController::class, 'order'])->name('orderConfirmed');
which is called from the following form:
<form action="{{route('orderConfirmed')}}" method="post" class="d-block">
#csrf
<div class="row">
<div class="col-12 col-lg-6">
<h4 class="fat-title display-4 text-center mt20 text-white"><span class="text-color-light">AFLEVER</span>ADRESS</h4>
<hr class="hrdark mb40 mt40">
<div class="row">
<div class="col-12 col-md-6 mb20">
<label for="naam" class="fat-title">Volledige Naam</label>
<input id="naam" type="text" class="form-control" placeholder="Mary Fuego" name="naam"
#if($user != null) value="{{$user->naam}}" #endif required>
</div>
<div class="col-12 col-md-6 mb20">
<label for="email" class="fat-title">Email</label>
<input id="email" type="email" class="form-control" placeholder="Example#fuego.nl" name="email"
#if($user != null) value="{{$user->email}}" #endif required>
</div>
<div class="col-12 col-md-6 mb20">
<label for="tel" class="fat-title">Telefoonnummer</label>
<input id="tel" type="tel" class="form-control" placeholder="0612345678" name="tel">
</div>
<div class="col-12 col-md-6 mb20">
<label for="plaats" class="fat-title">Plaats</label>
<input id="plaats" class="form-control" type="text" placeholder="Holten" name="plaats" required>
</div>
<div class="col-6 col-md-3 mb20">
<label for="postcode" class="fat-title">Postcode</label>
<input id="postcode" class="form-control" type="text" minlength="4" maxlength="6" placeholder="7451PJ" name="postcode" required>
</div>
<div class="col-6 col-md-3 mb20">
<label for="huisnummer" class="fat-title">Huisnummer</label>
<input id="huisnummer" class="form-control" type="text" placeholder="1" min="1" name="huisnummer" required>
</div>
<div class="col-6 col-md-3 mb20">
<label for="toevoeging" class="fat-title">Toev. (opt.)</label>
<input id="toevoeging" class="form-control" type="text" placeholder="A" min="1" name="toevoeging">
</div>
<div class="col-6 col-md-3 mb20">
<label for="straat" class="fat-title">Straat</label>
<input id="straat" class="form-control" type="text" placeholder="Handelsweg" name="straat" required>
</div>
#if($user != null)
<div class="col-12 mb20">
<button class="btn darkgraybg text-white w-100 btn-widetxt"
data-bs-toggle="dropdown" aria-expanded="false" type="button">laad adress</button>
<div class="dropdown-menu softgreybg pb20 pt20 pr20 pl20">
<label for="addresscopy" class="fat-title">Adress</label>
<select class="form-select form-control" id="addresscopy" onchange="loadAdress(parseInt(this.value))">
<option value="0">Geen Adress Laden</option>
#foreach($addresses as $address)
<option value="{{$address->id}}">{{$address->plaats}} {{$address->straat}} {{$address->huisnummer}} {{$address->toevoeging}}</option>
#endforeach
</select>
</div>
</div>
<input type="hidden" name="user_id" value="{{$user->id}}">
#endif
</div>
</div>
<div class="col-12 col-lg-6">
<h4 class="fat-title display-4 text-center mt20 text-white"><span class="text-color-light">BETAAL</span>METHODE</h4>
<hr class="hrdark mb40 mt40">
<button type="submit" class="btn btn-orange btn-widetxt w-100">
BESTELLEN
</button>
</div>
</div>
</form>
After submitting this form on the https page i get a 419 PAGE EXPIRED, which isnt logged. After submitting it via http i get an error in the mollie client that i have to have an SSL

I can't get back()->withInput() to work, the documentation seems a little sparse on how it should work

I'm using blade templates and this is how my form looks:
<form action="{{ route("user-sessions.store") }}" method="POST">
#csrf
<div class="form-group">
<label for="e-mail">E-mail Address</label>
<input name="email_address" class="form-control" type="email" />
</div>
<div class="form-group">
<label for="password">Password</label>
<input name="password" class="form-control" type="password" />
</div>
<div class="form-group">
<input class="btn btn-primary" type="submit" />
</div>
</form>
Does back()->withInput() only work with {{ Form::open() }}? If so, the 7.x documentation doesn't say that it seems. I would think if you need a 3rd party library to get this to work, the documentation should say so. If that's not the issue, then what am I doing wrong?
I'm using Laravel 7.x.
if you use html collective, it automatically puts old values in form inputs. But when use pure html to create form inputs you have to use old method for input values. like this:
<form action="{{ route("user-sessions.store") }}" method="POST">
#csrf
<div class="form-group">
<label for="e-mail">E-mail Address</label>
<input name="email_address" class="form-control" type="email" value="{{old('email_address')}}"/>
</div>
<div class="form-group">
<label for="password">Password</label>
<input name="password" class="form-control" type="password" value="{{old('password')}}"/>
</div>
<div class="form-group">
<input class="btn btn-primary" type="submit" />
</div>
</form>

How to upload the pdf or doc file in laravel

I am trying to upload the pdf or doc file on the website made up in laravel. This is my blade page.
<form action="{{ route('file.upload.post') }}" method="POST" enctype="multipart/form-data">
#csrf
<div class="row">
<input type="text" class="form-control-file" name="title" id="title" aria-
describedby="fileHelp", placeholder="title">
<input type="text" class="form-control-file" name="firstName" id="firstName" aria-
describedby="fileHelp", placeholder="First Name">
<input type="text" class="form-control-file" name="lastName" id="lastName" aria-describedby="fileHelp", placeholder="Last Name">
<input type="text" class="form-control-file" name="isReviewed" id="isReviewed" aria-describedby="fileHelp", placeholder="isReviewed">
<div class="col-md-6">
<input type="file" name="paper" class="form-control">
</div>
<div class="col-md-6">
<button type="submit" class="btn btn-success">Upload</button>
</div>
</div>
</form>
This is my controller
public function fileUploadPost(Request $request)
{
$request->validate([
'firstName'=>'required',
'lastName'=>'required',
'isReviewed'=>'required',
'paper' => 'required|mimes:pdf,xlx,csv|max:2048',
]);
$Submission= new Submission;
$Submission->title= $request['title'];
$Submission->first_name= $request['firstName'];
$Submission->last_name= $request['lastName'];
$Submission->isReviewed= $request['isReviewed'];
$fileName= time().'.'.$request->paper->extension();
$old_path = Request::file('paper')->getPathName(); Storage::disk('Paper')->move($old_path,
public_path($fileName));
$Submission->save();
return back()
->with('success','You have successfully upload file.')
->with('file',$fileName);
}
I am getting an error saying that
Non-static method Illuminate\Http\Request::file() should not be called statically
to fix this i
use Illuminate\Support\Facades\Request
instead of
use Illuminate\Http\Request;
but then I get an error saying I cannot use validation. Any kind of help is appreciated.
You don't need to use the facade for this. You can still use the standard Illuminate\Http\Request class.
To get the file, you should use:
$request->file('paper')
rather than
Request::file('paper')

Edit db record with modal window

I'm trying to edit some database record based on an ID that I'm saving into a button value.
#foreach ($employment as $empl)
<button data-toggle="modal" data-target="#edit-empl" href="#edit-empl" class="btn btn-default editbtn-modal" value="{{ $empl->id }}" type="button" name="editbtn">Edit</button>
<h3 class="profile-subtitle">{{ $empl->company }}</h3>
<p class="profile-text subtitle-desc">{{ $empl->parseDate($empl->from) }} - {{ $empl->parseDate($empl->to) }}</p>
#endforeach
As you can see here, I have an edit button with an id attached.
When I click edit I open a modal window to edit the fields and later on submit the form.
The thing is, I'm not sure how to get that id from the button into the modal window so I can compare the values and display the correct fields..
<form class="app-form" action="/profile/employment/edit/{id}" method="POST">
{{ csrf_field() }}
<input class="editID" type="hidden" name="editID" value="">
#foreach ($employment as $empl)
#if ($empl->id == buttonidhere)
<div class="form-group">
<label for="company">Company:</label>
<input type="text" name="company" value="{{ $empl->company }}">
</div>
<div class="form-group">
<label for="month">From:</label>
<input type="date" name="from" value="{{ $empl->from }}">
</div>
<div class="form-group">
<label for="to">To:</label>
<input type="date" name="to" value="{{ $empl->to }}">
</div>
#endif
#endforeach
<div class="row">
<div class="col-sm-6">
<input type="submit" class="btn btn-primary profile-form-btn" value="Save Changes">
</div>
</div>
</form>
I was able to pass the button value into the modal using javascript.. I put it into a hidden input but that doesn't help me at all because I can't get the input value in order to compare the values..
Solution 1: Using ajax
Step 1: Create a route in laravel which will return a JSON object containing employing data of requested employee.
For e.g,
/profile/employment/data/{empl_id}
Will get you employement data of id empl_id.
Step 2: Change your form as below
<form class="app-form" action="/profile/employment/edit/{id}" method="POST">
<input class="editID" type="hidden" name="editID" value="">
<div class="form-group">
<label for="company">Company:</label>
<input type="text" name="company" value="">
</div>
<div class="form-group">
<label for="month">From:</label>
<input type="date" name="from" value="">
</div>
<div class="form-group">
<label for="to">To:</label>
<input type="date" name="to" value="">
</div>
<div class="row">
<div class="col-sm-6">
<input type="submit" class="btn btn-primary profile-form-btn" value="Save Changes">
</div>
</div>
</form>
Step 3: Use javascript(jQuery) to get the data using ajax and load it into the form in modal.
jQuery code:
$(document).on("click", ".editbtn-modal", function() {
var id = $(this).val();
url = "/profile/employment/data/"+id;
$.ajax({
url: url,
method: "get"
}).done(function(response) {
//Setting input values
$("input[name='editID']").val(id);
$("input[name='company']").val(response.company);
$("input[name='to']").val(response.to);
$("input[name='from']").val(response.from);
//Setting submit url
$("modal-form").attr("action","/profile/employment/edit/"+id)
});
});
Solution 2: Using remote modal
Step 1:
Create another blade file for eg. editEmployee.blade.php and add the above form in it.
<form class="app-form" id="modal-form" action="/profile/employment/edit/{{ $empl->id }}" method="POST">
{{ csrf_field() }}
<input class="editID" type="hidden" name="editID" value="{{ $empl->id }}">
<div class="form-group">
<label for="company">Company:</label>
<input type="text" name="company" value="{{ $empl->company }}">
</div>
<div class="form-group">
<label for="month">From:</label>
<input type="date" name="from" value="{{ $empl->from }}">
</div>
<div class="form-group">
<label for="to">To:</label>
<input type="date" name="to" value="{{ $empl->to }}">
</div>
<div class="row">
<div class="col-sm-6">
<input type="submit" class="btn btn-primary profile-form-btn" value="Save Changes">
</div>
</div>
</form>
Step 2: Create a controller which would return the above form as HTML.
Tip: use render() function. example
Step 3: load the form into modal window before showing using javascript(jQuery)
considering your modal id is "emp-modal"
$(document).on("click", ".editbtn-modal", function() {
var id = $(this).val();
url = "/profile/employment/data/"+id;
$('#emp-modal').modal('show').find('.modal-body').load(url);
});
One solution would be to send the details you want the same way you send the id to the modal.
and the proper way to send variables to modal is to include this in the button that opens modal:
data-variablename="{{$your-variable}}"
use this jQuery to get the values of your variables to modal. where edit-empl is the id of your modal and data-target of your button
$('#edit-empl').on('show.bs.modal',function (e) {
var variablename= $(e.relatedTarget).data('variablename');
$(e.currentTarget).find('input[id="yourinputID"]').val(variablename);

Octobercms successful mail send returns empty alert

I am a newbie to Laravel and OctoberCMS.
I have successfully set up an info request form that sends me an email via Mailgun when submitted. Submission is handled by an AJAX handler.
The problem I have is that the process opens an alert box with an empty array on the form page.
Here is the page: http://imageweaversmarketing.com/
Click on 'CONTACT' in the top-right to move to the form.
Here is the partial with the form:
<div class="row">
<div class="col-lg-12">
<form data-request="onInfoRequest" name="sentMessage" id="contactForm" novalidate="">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Name *" id="name" required="" data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Your Email *" id="email" required="" data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Your Phone *" id="phone" required="" data-validation-required-message="Please enter your phone number.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<textarea class="form-control" placeholder="Your Message *" id="message" required="" data-validation-required-message="Please enter a message."></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<div class="clearfix"></div>
<div class="col-lg-12 text-center">
<div id="success"></div>
<button type="submit" class="btn btn-xl">
Send Message
</button>
</div>
</div>
</form>
</div>
Here is the PHP AJAX:
use Illuminate\Support\Facades\Mail;
public function onInfoRequest() {
$data = ['name' => 'test from function'];
Mail::send('mail.inforequest', $data, function ($message) {
$message->to('fake#hidden.com', 'Roger Creasy');
});
}
I appreciate any help.
I see you haven't used the data-request-success handler. That's necessary to show the output when mail is successful. Here's how I do it
function onSend()
{
// Collect input
$name = post('name');
$email = post('email');
// Form Validation
$validator = Validator::make(
[
'name' => $name,
'email' => $email
],
[
'name' => 'required',
'email' => 'required|email'
]
);
if ($validator->fails())
{
$messages = $validator->messages();
throw new ApplicationException($messages->first());
}
// All is well -- Submit form
$to = System\Models\MailSettings::get('sender_email');
$params = compact('name','email');
Mail::sendTo($to, 'temp.website::mail.newrequest', $params);
return true;
}
And on the form side I used
<form class="form-horizontal" data-request="onSend" data-request-success="alert('We have recieved your email.. we\'ll get back to you shortly')">
<div class="form-group">
<label class="col-md-4 control-label" for="name">Name</label>
<div class="col-md-5">
<input id="name" name="name" type="text" placeholder="Name" class="form-control input-md" required="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="email">Email</label>
<div class="col-md-5">
<input id="email" name="email" type="text" placeholder="Email ID" class="form-control input-md" required="">
</div>
</div>
</form>
So basically all you need is to add a data-request-success for it to work. Enjoy!
I had to get this completed. So, I gave up on a solution within October.
I am posting what I did as a workaround, in case it is helpful to someone else.
What I did is create a route resource, and direct it to a controller to handle the form. basically I went to the Laravel base structure and handled the form through its MVC.

Resources