SagePay Protocol 3.00 PHP Server Integration Query String POST - php

I am a beginner PHP developer and trying to integrate sagepay with my site that would allow customers to access a link on my website 'www.example.com/payment' and fill out a form with the amount they owe me and a corresponding invoice number which I have assigned to them and their account number, their billing details, address, full name, postcode and delivery address which should then create a query string sent to the SagePay server.
Below, I have got an example of the form I will be putting in the site:
<form action="https://test.sagepay.com/gateway/service/vspform-register.vsp" method="post" id="SagePayForm" name="SagePayForm">
<input type="hidden" name="Vendor" value="Vendorname" />
<input type="hidden" name="VPSProtocol" value="3.00" />
<input type="hidden" name="TxType" value="PAYMENT" />
<input type="hidden" name="Currency" value="GBP"><br />
<input type="hidden" name="NotificationURL" value="http://example.com/payment/"
<input type="number" name="VendorTxCode" placeholder="Invoice Number" value="123456"><br />
<input type="number" name="Amount" placeholder="Amount" value="250"><br />
<input type="text" name="Description" placeholder="Description of Invoice" value="Payment for your services"><br />
<input type="text" name="BillingFirstnames" placeholder="Firstname(s)" value="Fname Mname"><br />
<input type="text" name="BillingSurname" placeholder="Surname" value="Surname"><br />
<input type="text" name="BillingAddress1" placeholder="Address Line 1" value="BillAddress Line 1"><br />
<input type="text" name="BillingAddress2" placeholder="Surname" value="BillAddress Line 2"><br />
<input type="text" name="BillingCity" placeholder="City" value="BillCity"><br />
<input type="text" name="BillingPostCode" placeholder="Post/Zip Code" value="W1A 1BL"><br />
<input type="text" name="BillingCountry" placeholder="Country" value="United Kingdom"><br /><br />
<input type="text" name="DeliveryFirstnames" placeholder="Firstname(s)" value="Fname Mname"><br />
<input type="text" name="DeliverySurname" placeholder="Surname" value="Surname"><br />
<input type="text" name="DeliveryAddress1" placeholder="Address Line 1" value="BillAddress Line 1"><br />
<input type="text" name="DeliveryAddress2" placeholder="Surname" value="BillAddress Line 2"><br />
<input type="text" name="DeliveryCity" placeholder="City" value="BillCity"><br />
<input type="text" name="DeliveryPostCode" placeholder="Post/Zip Code" value="W1A 1BL"><br />
<input type="text" name="DeliveryCountry" placeholder="Country" value="United Kingdom"><br />
<input type="submit" name="submit" value="Submit">
</form>
I keep getting the INVALID status error with the error code: 5030 which says: 5030 : We could not process your message, please check your integration settings or contact the support team
Any guidance will be appreciated. Thanks

I recommend starting out with http://www.sagepay.co.uk/file/9981/download-document/VspPHPKit.zip

Direct api:
https://github.com/colinbm/sagepay-php
Very simple to use.

Related

PHP Rest service using one html form?

I've been asking a lot of questions as of late related to creating RESTful services with PHP. My question is this:
Can all services (GET, POST, PUT, DELETE) be done from a single web form using radio buttons?
This is what I am picturing in my head:
<form action="MyService.php" method="GET">
<label for="username">Username</label>
<input type="text" name="username" id="username" /><br />
<label for="password">Password</label>
<input type="password" name="password" id="password" /><br />
<label for="id">Task ID</label>
<input type="text" name="id" id="id"/><br />
<label for="desc">Task Description</label>
<input type="text" name="desc" id="desc"/><br />
<label>
<input type="radio" name="service" value="getRadio" checked/> GET
</label>
<label>
<input type="radio" name="service" value="postRadio" /> POST<br />
</label>
<input type="hidden" name="REQUEST_METHOD" value="GET"/><br />
<input type="hidden" name="REQUEST_METHOD" value="POST"/><br />
<input type="hidden" name="REQUEST_METHOD" value="PUT"/><br />
<input type="hidden" name="REQUEST_METHOD" value="DELETE"/><br />
<input type="submit" name="submit" value="ACTION"/>
</form>
It's incomplete so far, but what I'm thinking of trying to do is have radio button selections for each service, then outline my php file like this:
$request = $_SERVER["REQUEST_METHOD"]
switch($request) {
case 'GET':
// logic for GET based on radio button selected
break;
case 'POST':
// logic for POST based on radio button selected
break;
// and then PUT and DELETE
}
Is this doable? If so, am I on the right track, or do I need to make changes?
if you want to use the forms, and providing it does work as seems by this spec, then you can use some javascript to change the method of your form onsubmit.
<form action="MyService.php" method="GET" onsubmit='this.method = this.service.value'>
<label for="username">Username</label>
<input type="text" name="username" id="username" /><br />
<label for="password">Password</label>
<input type="password" name="password" id="password" /><br />
<label for="id">Task ID</label>
<input type="text" name="id" id="id"/><br />
<label for="desc">Task Description</label>
<input type="text" name="desc" id="desc"/><br />
<label>
<input type="radio" name="service" value="GET" checked/> GET
</label>
<label>
<input type="radio" name="service" value="POST" /> POST<br />
</label>
<label>
<input type="radio" name="service" value="PUT" /> PUT
</label>
<label>
<input type="radio" name="service" value="DELETE" /> DELETE<br />
</label>
<input type="hidden" name="REQUEST_METHOD" value="GET"/><br />
<input type="hidden" name="REQUEST_METHOD" value="POST"/><br />
<input type="hidden" name="REQUEST_METHOD" value="PUT"/><br />
<input type="hidden" name="REQUEST_METHOD" value="DELETE"/><br />
<input type="submit" name="submit" value="ACTION"/>
</form>

Sage Pay form integration encoding

<html>
<form name="pp_form" action="https://test.sagepay.com/Simulator/VSPServerGateway.asp?Service=VendorRegisterTx" method="post">
<input name="VPSProtocol" type="hidden" value=2.23 />
<input name="TxType" type="hidden" value=PAYMENT />
<input name="Vendor" type="hidden" value="myusername" />
<input name="VendorTxCode" type="hidden" value="thevendortxcode" />
<input name="Amount" type="hidden" value="30" />
<input name="Currency" type="hidden" value="GBP" />
<input name="Description" type="hidden" value="Test payment" />
<input name="NotificationURL" type="hidden" value="myurl" />
BillingFirstnames: <input name="BillingFirstnames" type="text" /><br>
BillingSurname: <input name="BillingSurname" type="text" /><br>
BillingAddress1: <input name="BillingAddress1" type="text" /><br>
BillingCity: <input name="BillingCity" type="text" /><br>
BillingPostCode: <input name="BillingPostCode" type="text" /><br>
BillingCountry: <input name="BillingCountry" type="text" /><br>
DeliverySurname: <input name="DeliverySurname" type="text" /><br>
DeliveryFirstnames: <input name="DeliveryFirstnames" type="text" /><br>
DeliveryAddress1: <input name="DeliveryAddress1" type="text" /><br>
DeliveryCity: <input name="DeliveryCity" type="text" /><br>
DeliveryPostCode: <input name="DeliveryPostCode" type="text" /><br>
DeliveryCountry: <input name="DeliveryCountry" type="text" /><br>
<p>Click here to submit
<input type="submit" value="here">
</p>
</form>
</html>
This form currently works using the simulator. Clearly, none of this is being encoded. Firstly, will this work on the test/live environment? Secondly, am I allowed to do it this way and if not, how can I correct it?
Thanks
Alex
It's not going to work. Firstly, the simulator is so far out of date that it doesn't even support protocol 3.00 (earlier ones are deprecated and will cease to function in the live environment from July). Some key features are also missing.
Secondly, you appear to want to use the Server protocol. The registration post for this consists of the values you have above as name-value pairs, posted as the request body to https://test.sagepay.com/gateway/service/vspserver-register.vsp
I recommend having a look at the Server protocol document on sagepay.co.uk - using the simulator isn't going to help.

$_POST returns empty on form submit in wordpress

I have a form:
<form action="<?php echo the_permalink(); ?>" method="POST">
<input type="text" name="name" value="" placeholder="Your First and Last Name *" />
<?php echo $firstnameError; ?>
<input type="text" name="email" value="" placeholder="Yoyr Email" />
<?php echo $emailError; ?>
<br>
<input type="text" name="company" value="" placeholder="Your Company Name" />
<input type="text" name="phone" value="" placeholder="Your Phone number" />
<textarea name="project" rows="4" cols="50" placeholder="Describe the scope of work and the most important features of the project *'"></textarea>
<?php echo $addressError; ?>
<br>
<input type="radio" name="budget" value="1500" />
<input type="radio" name="budget" value="2500" />
<input type="radio" name="budget" value="5000" />
<input type="radio" name="budget" value="10000" />
<input type="radio" name="budget" value="100001" />
<input type="radio" name="budget" value="not sure" />
<input type="hidden" name="submit" value="1" />
<input type="submit" value="SUbmit" />
</form>
It actions to the same page, but when I do print_r($_POST); it does not print anything, i.e. no value in $_POST.
What could be the reason(s) for this? I studied a few questions on SO on this but none gave me the answer I was looking for.
If your passing the name as a Post value, wordpress DOSNT like this!
change this
<input type="text" name="name" value="" placeholder="Your First and Last Name *" />
to
<input type="text" name="thename" value="" placeholder="Your First and Last Name *" />
changing the name to thename, Will work guaranteed! ;)
<form action="<?php the_permalink(); ?>" method="POST">
You don't need to echo the_permalink().
This works for me:
<?php print_r($_POST);?>
<form action="" method="POST">
<input type="text" name="name" value="" placeholder="Your First and Last Name *" /><?php echo $firstnameError; ?><input type="text" name="email" value="" placeholder="Yoyr Email"/><?php echo $emailError; ?><br>
<input type="text" name="company" value="" placeholder="Your Company Name"/><input type="text" name="phone" value="" placeholder="Your Phone number"/>
<textarea name="project" rows="4" cols="50"placeholder="Describe the scope of work and the most important features of the project *'"></textarea><?php echo $addressError; ?><br>
<input type="radio" name="budget" value="1500" /><input type="radio" name="budget" value="2500" /><input type="radio" name="budget" value="5000" /><input type="radio" name="budget" value="10000" /><input type="radio" name="budget" value="100001" /><input type="radio" name="budget" value="not sure" />
<input type="hidden" name="submit"value="1"/>
<input type="submit" value="SUbmit" />
</form>
change this
acton="<?php echo the_permalink(); ?>"
to
action="<?php echo the_permalink(); ?>"
I found same problem in my project and solution is in $_POST, maybe you use lower case in your code, change it to upper case.
change $_post to $_POST !
SOLUTION:
due to request problems, in wordpress sites instead of
<form action="http://example.com/">...
You may need to point the .php file.. example:
<form action="http://example.com/index.php">...
//////p.s. echo is automatically done with the_permalink() [same is: echo get_permalink()

Append variables to url after form submit

I have this Landing Page that I need to pre-populate with form values after it is submitted. Essentially in the end I have to make the url look like this...
http://example.com/r.php?sid=xx&pub=xxxxx&c1=&c2=&c3=&append=1&firstname=Test&lastname=Smith&address=2211+Commerce+St.&city=Dallas&state=TX&zipcode=75080&email=test#test.com
What I currently have now for the form is...
<form name="regForm" method="get" action="http://example.com/r.php?sid=xx&pub=xxxx&c1=&c2=&c3=&append=1">
<input id="firstname" class="text" type="text" name="firstname"/><br>
<input id="lastname" class="text" type="text" name="lastname" /><br>
<input id="email" class="text" type="text" name="email" /><br>
<input id="address" class="text" type="text" /><br>
<input id="city" class="text" type="text"/><br>
<input id="zipcode" class="text" type="text" maxlength="5" name="zipcode" /><br>
<input type="submit" value="Send Me My FREE List" id="submitBtn2"/>
</form>
How do i create that URL above after the form is submitted? I have been racking my brain all day on this and can't figure it out, i feel like im close.
thanks for the help!
Include the extra parameters as hidden form fields instead of inline query parameters:
<form name="regForm" method="get" action="http://example.com/r.php">
<input type="hidden" name="sid" value="xx" />
<input type="hidden" name="pub" value="xxxx" />
<input type="hidden" name="c1" value="" />
<input type="hidden" name="c2" value="" />
<input type="hidden" name="c3" value="" />
<input type="hidden" name="append" value="1" />
<input id="firstname" class="text" type="text" name="firstname"/><br>
<input id="lastname" class="text" type="text" name="lastname" /><br>
<input id="email" class="text" type="text" name="email" /><br>
<input id="address" class="text" type="text" /><br>
<input id="city" class="text" type="text"/><br>
<input id="zipcode" class="text" type="text" maxlength="5" name="zipcode" /><br>
<input type="submit" value="Send Me My FREE List" id="submitBtn2"/>
</form>
The problem is the input field get variables are causing your url get variables to be truncated, put all your url parameters as hidden values.
<input id="pub" type="hidden" name="pub" value=""/>
<input id="sid" type="hidden" name="sid" value=""/>
I'm assuming that you like the URL that it generates except that you're missing the sid, pub, c1, c2, c3, and append variables. If so, just make hidden inputs like this:
<form id="regForm" ...>
<input id="sid" name="sid" value="" type="hidden" />
<input id="pub" name="pub" value="" type="hidden" />
...
</form>
If you know the values while you're creating the form, then you can do it on the server side. If you don't, then assuming you're using jQuery, you will have to do something like this:
$(function() {
$('#regForm').submit(function () {
$('#sid').val('myNewSidValue');
$('#pub').val('myNewPubValue');
...
});
});

Dynamic Form Handling in PHP, jQuery & HTML

Ugh! Any ideas?
Have a form which tracks user activity for given time intervals. Each time interval can have inputs for "location" & multiple "activities". So the form has a variable number of time intervals and a variable number of activities per interval.
How can I set this up in HTML for smooth processing PHP? EDIT: Additional intervals and activities can be added via jQuery.
My initial thought is convoluted so anyone have a better idea?
<!--Interval 1 with 4 activities-->
<input type="text" name="interval[]" />
<input type="text" name="location[]" />
<input type="text" name="activity[]" />
<input type="text" name="activity[]" />
<input type="text" name="activity[]" />
<input type="text" name="activity[]" />
<!--Interval 2 with 2 activities-->
<input type="text" name="interval[]" />
<input type="text" name="location[]" />
<input type="text" name="activity[]" />
<input type="text" name="activity[]" />
This is a nightmare on the server side.
You may need to isolate activities per location / interval. A solution would be to use an index for each interval, this involve to change the way you create the new html elements for each interval.
So the resulting code would be :
<!--Interval 1 with 4 activities-->
<input type="text" name="interval[1][]" />
<input type="text" name="location[1][]" />
<input type="text" name="activity[1][]" />
<input type="text" name="activity[1][]" />
<input type="text" name="activity[1][]" />
<input type="text" name="activity[1][]" />
<!--Interval 2 with 2 activities-->
<input type="text" name="interval[2][]" />
<input type="text" name="location[2][]" />
<input type="text" name="activity[2][]" />
<input type="text" name="activity[2][]" />
But it's not as smooth to manipulate as :
<!--Interval 1 with 4 activities-->
<input type="text" name="interval[1][interval]" value="interval id" /> // optional
<input type="text" name="interval[1][location]" value="location" />
<input type="text" name="interval[1][activity][]" value="activity" />
<input type="text" name="interval[1][activity][]" value="activity" />
<input type="text" name="interval[1][activity][]" value="activity" />
<input type="text" name="interval[1][activity][]" value="activity" />
<!--Interval 2 with 2 activities-->
<input type="text" name="interval[2][interval]" value="interval id" /> // optional
<input type="text" name="interval[2][location]" value="location" />
<input type="text" name="interval[2][activity][]" value="activity" />
<input type="text" name="interval[2][activity][]" value="activity" />
Which will give you a nice tree ( in the form of arrays of arrays ) to iterate over.
In order to do that, you need a javascript function that keep a track of the current interval index ans use that index to order the array of intervals.
Server side all you have to do is ( in case of POST method ) :
foreach ( $_POST['interval'] as $k => $interval ) {
echo $interval['interval'];
echo $interval['location'];
foreach ( $interval['activity'] as $id => $activity )
echo $activity;
}

Categories