Sage Pay form integration encoding - php

<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.

Related

SagePay Protocol 3.00 PHP Server Integration Query String POST

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.

PHP Form URL vars

I was wondering if it would be possible to have a variable in the URL created when submitting a form?
form:
<form class="register_form" action="action.php" method="get">
Team Name*: <input type="text" name="teamname" required />
Team Region*: <input type="text" name="teamregion" maxlength="4" required />
Team Leader*: <input type="text" name="teamleader" maxlength="16" required />
Team Members: <input type="text" name="teammembers" />
<input name="register_submit" type="submit" value="Register" />
</form>
I'd like the link to end up as: http://.../action.php?do=register
My reasoning for this is so that I can use action.php for more than one thing using if statements. Thanks ^^
Just append the variable you want to the action link.
<form class="register_form" action="action.php?do=register" method="get">
Team Name*: <input type="text" name="teamname" required />
Team Region*: <input type="text" name="teamregion" maxlength="4" required />
Team Leader*: <input type="text" name="teamleader" maxlength="16" required />
Team Members: <input type="text" name="teammembers" />
<input name="register_submit" type="submit" value="Register" />
</form>
Or you can add a hidden field to your form:
<input type="hidden" name="do" value="register" />
Sure, the form action URL can have a query string:
<form class="register_form" action="action.php?do=register" method="POST">
The form data will be sent via POST but do will still be available via GET.
You need to add this to the form
<input type="hidden" name="do" value="register">
Yes, it is possible. You can use any one of following methods
1) You can set the name of your submit button "do"; As the value of your submit button is "Register"
<input type="submit" name="do" value="Register" />
OR
2) You can add a hidden field to your form
<input type="hidden" name="do" value="register" />

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');
...
});
});

Add more (sets of) fields to form by jQuery

It is easy to add more fields to a html form by jQuery. Then, we can serialize the fields, if the have the same name but what if we have a set of fields? For example
<input type="text" name="movie1_name" />
<input type="text" name="movie1_director" />
<input type="text" name="movie1_year" />
Now I want to add a new set of fields by jQuery as
<input type="text" name="movie2_name" />
<input type="text" name="movie2_director" />
<input type="text" name="movie2_year" />
and so forth. I process the form with PHP to insert movies into mysql database with three columns of (name, director, year). In the above-mentioned example, it is hard to serialize the fields to create appropriate $_POST arrays. How should I serialize jquery-added sets of movies?
<input type="text" name="movie_name[]" />
<input type="text" name="movie_director[]" />
<input type="text" name="movie_year[]" />
<input type="text" name="movie_name[]" />
<input type="text" name="movie_director[]" />
<input type="text" name="movie_year[]" />
Nothing else. On the server you will get (in case of POST) array in $_POST['movie_name'], $_POST['movie_director'] and $_POST['movie_year'];. Elements with the same index are from the same set of inputs.
What kind of problem with serialization do you have?
<form>
<input type="text" name="movie_name[]" />
<input type="text" name="movie_director[]" />
<input type="text" name="movie_year[]" />
<hr />
<input type="text" name="movie_name[]" />
<input type="text" name="movie_director[]" />
<input type="text" name="movie_year[]" />
<br />
<input type='button' id='serialize' value='Click me' />
</form>
and js code:
$('#serialize').click(function(){
alert($('form').serialize());
});
when you want to submit the data just write
$.post('script.php', $('form').serialize(), function() {alert('Saved');});
ps: if you are afraid to lose something, just compare count($_POST['movie_name']), count($_POST['movie_director']) and count($_POST['movie_year']).
or you can add indexes
<input type="text" name="movie_name[0]" />
<input type="text" name="movie_director[0]" />
<input type="text" name="movie_year[0]" />
<input type="text" name="movie_name[1]" />
<input type="text" name="movie_director[1]" />
<input type="text" name="movie_year[1]" />
Based on useful discussion with Cheery, I came to conclusion that the best and safest way is to use
<input type="text" name="movie_name[i]" />
<input type="text" name="movie_director[i]" />
<input type="text" name="movie_year[i]" />
where we define each i with jQuery to serialize the fields SAFELY. This way, we can be sure that serialized arrays are parallel and well matched, without misplacing.
You can do something like this:
<input type="text" name="movie1_name" />
<input type="text" name="movie1_director" />
<input type="text" name="movie1_year" />
// OTHER:
<input type="text" name="movie2_name" />
<input type="text" name="movie2_director" />
<input type="text" name="movie2_year" />
And do this to all... In Jquery, you create a function that create field as needed... I'm not the best in JQuery so I can't help you for this but the way I told you worked fine for me with PHP...

Auto login to Google Analytics?

I have tried following similar steps as mentioned on this Auto login to Google Analytic to impress clients page
<form id="googleanalyticslogin" action="https://www.google.com/accounts/ServiceLoginBoxAuth" method="post">
<input type="text" name="Email" class="gaia le val" id="Email" size="18" value="me#gmail.com" />
<input type="password" name="Passwd" class="gaia le val" id="Passwd" size="18" value="Passw0rd" />
<input type="checkbox" name="PersistentCookie" value="yes" />
<input type="hidden" name="rmShown" value="1" />
<input type="hidden" name="continue" value="http://www.google.com/analytics/home/?et=reset&hl=en-US" />
<input type="hidden" name="service" value="analytics" />
<input type="hidden" name="nui" value="1" />
<input type="hidden" name="hl" value="en-US" />
<input type="hidden" name="GA3T" value="oCGYxIWWGUE" />
<input type="hidden" name="GALX" value="3Jces-nq404" />
<input type="submit" />
</form>
but when I submit form I get Your browser's cookie functionality is turned off. Please turn it on.
Any ideas how to sort it out? Or is there any alternative way to login?
Thank you for your help.
You have to use OAuth to access analytics try taking a look at this
http://code.google.com/p/gapi-google-analytics-php-interface/
that will allow you to not only login but pull analytics straight from the site.

Categories