sagepayForm-php icon indicating copy to clipboard operation
sagepayForm-php copied to clipboard

Post Input Name Value

Open OllyAlpha opened this issue 8 years ago • 6 comments

Hi Timur, Hoping you can help. I'm using your simple Sage Pay form which is awesome but unfortunaltely i'm having an issue posting the input/name value to Sage Pay.

If i set the value as you have done in your example: $sagePay->setCurrency('EUR'); $sagePay->setAmount('100'); $sagePay->setDescription('Lorem ipsum'); $sagePay->setBillingSurname('Mustermann'); etc all works well and it goes to sage pay with no errors.

but

Is there a way of having the value of the input field post to Sage Pay so it's dynamic? For example: $sagePay->setAmount($_POST['Amount']); $sagePay->setDescription($_POST['Description']); $sagePay->setBillingFirstnames($_POST['BillingFirstnames']); $sagePay->setBillingSurname($_POST['BillingSurname']);

Would really appreciate any help on this...?

OllyAlpha avatar Apr 26 '16 15:04 OllyAlpha

Hey,

of course you can, dont see why not? Maybe show me more code so i can see whats the problem you are having?

tolzhabayev avatar Apr 27 '16 08:04 tolzhabayev

Hey Timur,

I thought it might be but haven't managed to get it working yet. I've added an example of the form that i'm using but you can see the idea that i'm going for.


<form method="post" action="https://test.sagepay.com/gateway/service/vspform-register.vsp" id="sagepay" data-abide novalidate>
 <label for="fname">First Name
<input type="text" id="fname" onfocusout="updater();" name="BillingFirstnames" placeholder="First Name" required>
 </label>
<label for="lname">Surname
<input type="text" id="lname" onfocusout="updater();" name="BillingSurname" placeholder="Surname" required>
</label>
<label for="email">Email
<input type="email" id="email" pattern="email" onfocusout="updater();" name="CustomerEMail" placeholder="Email" required>
</label>
etc etc
</form>
<?php                                                                                                                                                
require_once('slib/SagePay.php');                                                   
$sagePay = new SagePay();
$sagePay->setCurrency('GBP');
$sagePay->setAmount($_POST['Amount']);
$sagePay->setDescription($_POST['Description']);
$sagePay->setBillingFirstnames($_POST['BillingFirstnames']);
$sagePay->setBillingSurname($_POST['BillingSurname']);
$sagePay->setCustomerEMail($_POST['CustomerEMail']);
$sagePay->setBillingPhone($_POST['BillingPhone']);
$sagePay->setDeliveryPhone($_POST['DeliveryPhone']);
$sagePay->setBillingAddress1($_POST['BillingAddress1']);
$sagePay->setBillingAddress2($_POST['BillingAddress2']);
$sagePay->setBillingCity($_POST['BillingCity']);
$sagePay->setBillingCountry('GB');
$sagePay->setBillingPostCode($_POST['BillingPostCode']);
$sagePay->setDeliveryFirstnames($_POST['DeliveryFirstnames']);
$sagePay->setDeliverySurname($_POST['DeliverySurname']);
$sagePay->setDeliveryAddress1($_POST['DeliveryAddress1']);
$sagePay->setDeliveryAddress2($_POST['DeliveryAddress2']);
$sagePay->setDeliveryCity($_POST['DeliveryCity']);
$sagePay->setDeliveryCountry('GB');
$sagePay->setDeliveryPostCode($_POST['DeliveryPostCode']);
$sagePay->setSuccessURL('http://www.vendorname.co.uk/success.php');
$sagePay->setFailureURL('http://www.vendorname.co.uk/fail.php');
?>

<input type="hidden" name="VPSProtocol" value="3.00">
<input type="hidden" name="TxType" value="AUTHENTICATE">
<input type="hidden" name="Vendor" value="vendorname">
<input type="hidden" name="Crypt" value= "<?php echo $sagePay->getCrypt(); ?>">

OllyAlpha avatar Apr 27 '16 08:04 OllyAlpha

Looks fine to me, and below this code you should do:


<form method="POST" id="SagePayForm" action="*https://test.sagepay.com/gateway/service/vspform-register.vsp*">
    <input type="hidden" name="VPSProtocol" value= "3.00">
    <input type="hidden" name="TxType" value= "PAYMENT">
    <input type="hidden" name="Vendor" value= "*YOURVERNODID*">
    <input type="hidden" name="Crypt" value= "<?php echo $sagePay->getCrypt(); ?>">
    <input type="submit" value="continue to SagePay">
</form>

tolzhabayev avatar Apr 27 '16 08:04 tolzhabayev

Thats what I thought. Let me give it another whirl and see if I can get it going. Will keep you posted.

Thanks for taking a look.

OllyAlpha avatar Apr 27 '16 09:04 OllyAlpha

Hey OllyAlpha, did you get this working? I have been trying for 2 days to get it working like this but it just wont pull the values from the $_POST inputs and add them?

I can only get it working if I hard code the values into the following like this: $sagePay->setAmount('100'); instead of this: $sagePay->setAmount($_POST['Amount']);

brianrevie avatar Aug 26 '21 09:08 brianrevie

I can only get it working if I hard code the values into the following like this: $sagePay->setAmount('100'); instead of this: $sagePay->setAmount($_POST['Amount']);

try debugging / printing the value of $_POST['Amount'] before you use it. It might be emtpy. Check case sensitivity, etc.

I would also recommend considering this library which is more up to date: https://github.com/thephpleague/omnipay-sagepay

tolzhabayev avatar Aug 26 '21 16:08 tolzhabayev