Send data from Blade form view to external POST

Published 1 month ago by ThinkingMan

I am creating a simple donation form for my local church and have decided to integrate to Payeezy. So essentially church members will go to the church profile page, fill in their name, address and the amount they want to donate. This can send via POST to the Payeezy hosted page. (Sample code here https://support.payeezy.com/hc/en-us/articles/204011429-Sample-Code-Creating-a-Pay-Button-to-use-with-a-Hosted-Payment-Page)

I have this working in a non-Laravel HTML form. I think my problem is something with routing as I cannot pass the form field data to the First Data hosted page. It doesnt know the value that I entered on the form. I have hard coded all fields except the $x_amount listed below. This amount is filled in on the Church Profile Laravel Blade form then I call the route to the Payeezy POST form and am trying to pass the amount over. But the amount never passes. It just comes back with the error and the variable id.

So what am I doing wrong in trying to send via the POST? Since this is not posting in my application I wasnt using the POST methods in Laravel, just trying to hand over to the Payeezy page.

<?php
$x_login = "HARD CODED FOR NOW"; // Take from Payment Page ID in Payment Pages interface
$transaction_key = "HARD CODED FOR NOW"; // Take from Payment Pages configuration interface
$x_amount = $_POST["x_amount"];
$x_currency_code = "USD"; // Needs to agree with the currency of the payment page
$x_recurring_billing = "TRUE";
$x_recurring_billing_id = "HARD CODED FOR NOW";
$x_recurring_billing_amount = "HARD CODED FOR NOW";
$x_recurring_billing_start_date = "HARD CODED FOR NOW";
$x_recurring_billing_end_date = "HARD CODED FOR NOW";
srand(time()); // initialize random generator for x_fp_sequence
$x_fp_sequence = rand(1000, 100000) + 123456;
$x_fp_timestamp = time(); // needs to be in UTC. Make sure webserver produces UTC
Best Answer (As Selected By ThinkingMan)
ThinkingMan

Closing with no resolution but assumption that this other post will yield the result. https://laracasts.com/discuss/channels/laravel/guzzle-to-post-to-external-hosted-payment-page

ThinkingMan

Is anyone able to see my posts? I am wondering only because I am having issues accessing and a couple of my posts have not been replied to at all.

Snapey
Snapey
1 month ago (993,685 XP)

yes but you are not posting anything that can be commented on. You just show a load of variables being assigned in php.

jlrdw
jlrdw
1 month ago (244,950 XP)

Are you sure you're not supposed to go to that site and have them fill out the information there and that site is linked to the church. Kind of like the way PayPal works with a donate link.

In other words the donate Link in your church site opens another site for the actual donation if you can follow that.

I think you need a correct link.

I know PayPal gives you the code to grab and put in your view, but no routing is necessary it's just an external link.

If you're not grasping how to handle this you might want to talk to someone else in the computer industry that can help you locally.

ThinkingMan

The form on my site is allowed to post to the variables on the hosted payment page. As mentioned, I have this working with straight HTML and PHP. It is the pass in the Laravel MVC that I am trying to resolve. Obviously I am doing something wrong in Laravel. Will post some more code to illustrate. Thanks

jlrdw
jlrdw
1 month ago (244,950 XP)

I just ran your sample in one of my views, had no probem.

Just put the sample files in root and link in view like:

<a href="<?php echo DIR . 'Samplegge4payment.html'; ?>">click here</a>

Ran perfect

You could tweak as needed.

Don't use DIR it's a constant I setup for me, use your way of linking to root.

Cronix
Cronix
1 month ago (727,800 XP)

I think my problem is something with routing as I cannot pass the form field data to the First Data hosted page. It doesnt know the value that I entered on the form.

You're not showing us that though...so how can we help? As @snapey said, all you are doing is showing us variables being assigned values. You're not showing the form, or the route, or the controller method, etc. Show all of the relevant code.

jlrdw
jlrdw
1 month ago (244,950 XP)

@Cronix it's in a zip file on the site, the example. https://support.payeezy.com/hc/en-us/articles/204011429-Sample-Code-Creating-a-Pay-Button-to-use-with-a-Hosted-Payment-Page

It's just a html form

<html>
<h1>Payment Page</h1>
<br><form action="Samplegge4payment.php" method="post">
Payment Amount $<input name="x_amount" value="" type="text">
<input type="submit" value="Pay Now">
</form>
</html>

then

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>
Payment Pages: Sample PHP Payment Form
</title>
<style type="text/css">
label {
display: block;
margin: 5px 0px;
color: #AAA;
}
input {
display: block;
}
input[type=submit] {
margin-top: 20px;
}
</style>

</head>
<body>
<h1>Processing Please Wait...</h1>

<form action="https://demo.globalgatewaye4.firstdata.com/pay" method="POST" name="myForm" id="myForm">

<?php
$x_login = ""; // Take from Payment Page ID in Payment Pages interface
$transaction_key = ""; // Take from Payment Pages configuration interface
$x_amount = $_POST["x_amount"];
$x_currency_code = "USD"; // Needs to agree with the currency of the payment page
srand(time()); // initialize random generator for x_fp_sequence
$x_fp_sequence = rand(1000, 100000) + 123456;
$x_fp_timestamp = time(); // needs to be in UTC. Make sure webserver produces UTC

// The values that contribute to x_fp_hash
$hmac_data = $x_login . "^" . $x_fp_sequence . "^" . $x_fp_timestamp . "^" . $x_amount . "^" . $x_currency_code;
$x_fp_hash = hash_hmac('MD5', $hmac_data, $transaction_key);

echo ('<input name="x_login" value="' . $x_login . '" type="hidden">' );
echo ('<input name="x_amount" value="' . $x_amount . '" type="hidden">' );
echo ('<input name="x_fp_sequence" value="' . $x_fp_sequence . '" type="hidden">' );
echo ('<input name="x_fp_timestamp" value="' . $x_fp_timestamp . '" type="hidden">' );
echo ('<input name="x_fp_hash" value="' . $x_fp_hash . '" size="50" type="hidden">' );
echo ('<input name="x_currency_code" value="' . $x_currency_code . '" type="hidden">');

// create parameters input in html
foreach ($_POST as $a => $b) {
    echo "<input type='hidden' name='".htmlentities($a)."' value='".htmlentities($b)."'>";
}

?>

<input type="hidden" name="x_show_form" value="PAYMENT_FORM"/>
</form>

<script type='text/javascript'>document.myForm.submit();</script>

</body>
</html>

Form is external site:

<form action="https://demo.globalgatewaye4.firstdata.com/pay" method="POST" name="myForm" id="myForm">

OP just needs to properly place this stuff in a folder.

ThinkingMan

Thank you in advance everyone. I apologize for simple questions. I do have the HTML and PHP working much like @jlrdw has posted. Works no issue. But I am storing the values for the Church pay pages and some other variables that are needed for posting. I am building this in Laravel because the church can sign up members for historical reasons. That said here is the code thus far:

Here is the Church List/Profile Page

Donations Site - Church List Page

Donations

This will be the church list.

@if($churches)
    @foreach($churches as $church)
        <div class="card" style="width:400px">
            <img class="card-img-bottom" src="\storage\users\default.png" style="width:25%;" alt="Church image">
            <div class="card-body">
                <h4 class="card-title">{{$church->church_name}}</h4>
                <p class="card-text">{{$church->id}}</p>
                <p class="card-text">{{$church->user->name}}</p>
                <a href="{{route('profile',[$church->id])}}" class="btn btn-primary">Church Page</a>

                <form action="{{route('donate',[$church->id])}}" method="post">
                    <input class="form-control" type="text" placeholder="Name">
                    <input class="form-control" type="text" placeholder="Address 1">
                    <input class="form-control" type="text" placeholder="Address 2">
                    <input class="form-control" type="text" placeholder="Address 3">
                    <input class="form-control" type="text" placeholder="City">
                    <input class="form-control" type="text" placeholder="State">
                    <input class="form-control" type="text" placeholder="Zip">
                    <input class="form-control" name="x_amount" value="" placeholder="Payment Amount $" type="text">
                    <br>
                    <a href="{{route('donate',[$church->id])}}" class="btn btn-primary">Donate Route</a>
                    
                </form>

            </div>
            <br>
        </div>
        <br>
    @endforeach
@endif
</div>

Here is my Route

Route::get('churchpay/{id}', '[email protected]')->name('donate');

Here is the Church controller

public function donate($id)
{
    //
    $churches = Church::findOrFail($id);

    return view('churches.churchpay', compact('churches'));
}

Here is the Churchpay view (with detail to post to the Payeezy external site)

Church Donation Page label { display: block; margin: 5px 0px; color: #AAA; } input { display: block; } input[type=submit] { margin-top: 20px; }

{!! Form::model($churches, ['method'=>'GET', 'action'=>['[email protected]', $churches->id], 'files'=>true]) !!}
<div class="card card-body">
    <div class="card-body">
        <h1>Please wait for the secure donation page...</h1>
        <h4 class="card-title">{{$churches->church_name}}</h4>
    </div>
</div>
<br>
<?php
$x_login = "HCO-KW-EN-279"; // Take from Payment Page ID in Payment Pages interface
$transaction_key = "ioSB4gSXyyYiaS23BXc1"; // Take from Payment Pages configuration interface
$x_amount = $_POST["x_amount"];
$x_currency_code = "USD"; // Needs to agree with the currency of the payment page
$x_recurring_billing = "TRUE";
$x_recurring_billing_id = "MB-KW-EN-25-7722";
$x_recurring_billing_amount = "8.89";
$x_recurring_billing_start_date = "2018-08-01";
$x_recurring_billing_end_date = "2035-01-31";
srand(time()); // initialize random generator for x_fp_sequence
$x_fp_sequence = rand(1000, 100000) + 123456;
$x_fp_timestamp = time(); // needs to be in UTC. Make sure webserver produces UTC

// The values that contribute to x_fp_hash
$hmac_data = $x_login . "^" . $x_fp_sequence . "^" . $x_fp_timestamp . "^" . $x_amount . "^" . $x_currency_code;
$x_fp_hash = hash_hmac('MD5', $hmac_data, $transaction_key);

echo ('<input name="x_login" value="' . $x_login . '" type="hidden">' );
echo ('<input name="x_amount" value="' . $x_amount . '" type="hidden">' );
echo ('<input name="x_fp_sequence" value="' . $x_fp_sequence . '" type="hidden">' );
echo ('<input name="x_fp_timestamp" value="' . $x_fp_timestamp . '" type="hidden">' );
echo ('<input name="x_fp_hash" value="' . $x_fp_hash . '" size="50" type="hidden">' );
echo ('<input name="x_currency_code" value="' . $x_currency_code . '" type="hidden">');
echo ('<input name="x_recurring_billing_amount" value="' . $x_recurring_billing_amount . '" type="hidden">' );
echo ('<input name="x_recurring_billing" value="' . $x_recurring_billing . '" type="hidden">');
echo ('<input name="x_recurring_billing_id" value="' . $x_recurring_billing_id . '" type="hidden">');
echo ('<input name="x_recurring_billing_start_date" value="' . $x_recurring_billing_start_date . '" type="hidden">');
echo ('<input name="x_recurring_billing_end_date" value="' . $x_recurring_billing_end_date . '" type="hidden">');

// create parameters input in html
foreach ($_POST as $a => $b) {
    echo "<input type='hidden' name='".htmlentities($a)."' value='".htmlentities($b)."'>";
}

?>

<input type="hidden" name="x_show_form" value="PAYMENT_FORM"/>
document.myForm.submit();
Snapey
Snapey
1 month ago (993,685 XP)

Its your grandpa's php then...

ThinkingMan

Grandpas PHP?

jlrdw
jlrdw
1 month ago (244,950 XP)

He means old procedural Style. It looks like it would be hard to tie their code to keeping track of a donation.

If this site is like PayPal you could periodically download a report and the bookkeeper for the church could manually enter who made a donation in The Laravel app. I did similar with the Humane Society made small accounting application for the treasurer and bookkeeper.

Edit:

Why don't you use PayPal?

ThinkingMan

Yeah, thats what I thought he meant.

I guess I will just ask for an approach with laravel. I will take it from there.

ThinkingMan

@jlrdw because First Data is required by the church.

jlrdw
jlrdw
1 month ago (244,950 XP)

I guess I will just ask for an approach with laravel

You answered your own question.

Use a pay system that has an api or code integration to work with, like stripe, even paypal. But if they get a savings on the package use it. And just add a couple or 3 fields to get donatees info. But that can backfire also, they could change their mind.

There are ways to deal with your pay system. Don't over think the simple.

ThinkingMan

@jlrdw thanks for being constructive. Unfortunately I have to use what this church has provided. So will try to keep it simple.

Please sign in or create an account to participate in this conversation.