I am implementing Sagepay payment gateway in PHP, it is working fine with 2.23 protocol. But when i change it to 3.00 it gives my an error code: 3195, which means that the line item amount details do not add up correctly.
I have tried all the solutions but nothing helped me.
Here is some of my code which I am using currently:
$sagePay = new SagePay();
$sagePay->setCurrency('GBP');
$sagePay->setAmount($_SESSION['amount']);
$sagePay->setDescription($_SESSION['tripcode']);
$sagePay->setBillingSurname('Mustermann');
$sagePay->setBillingFirstnames('Amrinder');
$sagePay->setBillingCity('London');
$sagePay->setBillingPostCode('GL51 3AA');
$sagePay->setBillingAddress1('Bahnhofstr. 1');
$sagePay->setBillingCountry('de');
$sagePay->setDeliverySameAsBilling();
<form method="POST" id="SagePayForm" action="https://live.sagepay.com/gateway/service/vspform-register.vsp" style="display:none;">
<input type="hidden" name="VPSProtocol" value= "2.23">
<input type="hidden" name="TxType" value= "PAYMENT">
<input type="hidden" name="Vendor" value= "alpinetravelint">
<input type="hidden" name="Crypt" value= "<?php echo $sagePay->getCrypt(); ?>">
<input type="submit" value="continue to SagePay">
</form>
How can I resolve this problem?
The error refers to the basket field. You have the first item value as 100, tax as 10 and the line total as 100.
The fields in the basket are Quantity:Item Value:Item Tax:Item Total:Line Total
The item value should be the net amount if you are going to use the tax field, so your values should be 1:90.00:10.00:100.00:100.00
Related
I have created a non-hosted PayPal-Button with a text input to let users define an amount to pay. It's a subscription button.
Now the problem is that there must be a minimum amount to pay, say 101 (CHF - Swiss francs).
According to the docs of PayPal HTML-Variables I have the possibility to add the following vars in hidden inputs to my form to get it to work.
set_customer_limit with a value of max_limit_own
min_amount with a value of 101
The set_customer_limit is working but not the min_amount. Any amount is accepted.
I opened a ticket at the technical support, but no reply till now.
Here's my form:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<!-- //... -->
<input type="hidden" name="cancel_return" value="mydomain.com/cancel">
<input type="hidden" name="return" value="mydomain.com/paid">
<input type="hidden" name="token" value="<?php echo $token; ?>">
<input type="hidden" name="src" value="1">
<input type="text" name="a3" value="101.00">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="Y">
<input type="hidden" name="currency_code" value="CHF">
<input type="hidden" name="bn" value="PP-SubscriptionsBF:btn_subscribeCC_LG.gif:NonHostedGuest">
<!-- the concerned inputs -->
<input type="hidden" name="set_customer_limit" value="max_limit_own">
<input type="hidden" name="min_amount" value="101">
<!-- ---- -->
<input type="image" src="https://www.paypalobjects.com/de_DE/CH/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit" alt="Jetzt einfach, schnell und sicher online bezahlen – mit PayPal.">
<img alt="" border="0" src="https://www.paypalobjects.com/de_DE/i/scr/pixel.gif" width="1" height="1">
</form>
As for the moment, I just validate the minimum amount with JavaScript, which isn't really secure...
EDIT
As an idea, I could implement another form (submit it by AJAX, onchange, onkeyup, whatever), which sets the minimum amount given by the user before the PayPal-form and put it into the PayPal-input then (set to hidden again):
<input type="hidden" name="a3" value="<?php echo $_POST['pre_min_amount'] ?>">
That way I could validate the minimum amount with PhP, before submitting the PayPal-form. But that doesn't seem a clean way to me. Really Glad if anybody could give me a hint!
The answer of the PayPal technical support is: No it is not possible!
(Date of answering was 05/02/2015) Hopefully, this will be possible in the future. If so please post your answer!
I'd really suggest using the PayPal API for this kind of thing (including creating a developer account, byting thru the docs, etc).
So this "solution" is a quick & dirty workaround.
First, add a small form (I call it the min_amount -form for now) to the page (telling the user, he has to set the amount first):
<form id="min_amount" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<input type="text" id="pre_min_amount" name="pre_min_amount" value="101">
<input type="submit" value="Set min. Amount">
</form>
Then, add the whole PayPal form to a PHP variable with NowDoc and add the posted value from the min_amount-form to the a3 input:
$min_amount = 0;
$payPalForm = <<<SOME
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<!-- //... -->
<input type="hidden" name="a3" value="$min_amount">
</form>
SOME;
After submitting, check if the minimum amount is true and then only show the PayPal-form:
if (isset($_POST['pre_min_amount']) && is_numeric($_POST['pre_min_amount']) && floatval($_POST['pre_min_amount']) >= 101) {
$min_amount = htmlspecialchars($_POST['pre_min_amount']);
echo $payPalForm;
}
As I said, it's quick and dirty (no more time for this project), but you ensure to validate the minimum amount on the server-side, not just with Javascript. You could also submit the min_amount-form with an AJAX call, but then the return of this call is on the client-side, which isn't really secure either. (Sure you may also)
BTW, I am not proud of this solution at all, but sometimes, a programmers life is hard and I'm sure all you coders out there had to do some q&d code somehow, somewhere ;-)...
Update: 08/05/2015
All depends on the country in which the concerning account is registered. Full services guaranted by PayPal only in the USA and Canada
I'm using Paypal Express Checkout on my website and i receive this error:
SetExpressCheckout API call failed. Detailed Error Message: The totals of the cart item amounts do not match order amounts.Short Error Message: Transaction refused because of an invalid argument. See additional error messages for details.Error Code: 10413Error Severity Code: Error
When i enter a quantity of 1 everything is working fine but when i enter 2 or more i get the error.
I'm using SMARTY Templating.
<form class="pull-right" action="../Checkout/paypal_ec_redirect.php" method="POST">
<input type="hidden" name="L_PAYMENTREQUEST_0_NAME0" value="{$product_naam}"></input>
<input type="hidden" name="L_PAYMENTREQUEST_0_AMT0" value="{$product_productprijs}"></input>
<input type="hidden" name="L_PAYMENTREQUEST_0_QTY0" value="{$product_aantal}"></input>
<input type="hidden" name="PAYMENTREQUEST_0_ITEMAMT" value="{$product_subtotaal}"></input>
<input type="hidden" name="PAYMENTREQUEST_0_TAXAMT" value="{$product_btw}"></input>
<input type="hidden" name="PAYMENTREQUEST_0_AMT" value="{$product_totaalprijs}"></input>
<input type="hidden" name="currencyCodeType" value="EUR"></input>
<input type="hidden" name="paymentType" value="Sale"></input>
<input type="image" src="https://www.paypalobjects.com/webstatic/en_US/i/buttons/checkout-logo-large.png" alt="Check out with PayPal"></input>
</form>
</div>
</div>
</div>
Here is the PHP:
foreach ($getproduct as $row) {
$productaantal = $aantalbesteld;
$productnaam = $row['naam'];
$productprijs = $row['prijs'];
$btwtarief = $row['btw_tarief'];
$btwbedrag = ($productprijs*$aantalbesteld)/100*$btwtarief;
$subtotaal = ($productprijs*$aantalbesteld)-$btwbedrag;
$totaalprijs = $productprijs*$aantalbesteld;
}
//Product
$smarty->assign('product_naam', $productnaam);
$smarty->assign('product_aantal', $productaantal);
$smarty->assign('product_prijs', money_format('%.2n', $productprijs));
$smarty->assign('product_subtotaal', money_format('%.2n', $subtotaal));
$smarty->assign('product_btw', money_format('%.2n', $btwbedrag));
$smarty->assign('product_totaalprijs', money_format('%.2n', $totaalprijs));
$smarty->assign('product_bestelknop', 'Bestellen');
EDIT: Even this isn't working:
<form class="pull-right" action="../Checkout/paypal_ec_redirect.php" method="POST">
<input type="hidden" name="L_PAYMENTREQUEST_0_NAME0" value="{$product_naam}"></input>
<input type="hidden" name="L_PAYMENTREQUEST_0_AMT0" value="5.00"></input>
<input type="hidden" name="L_PAYMENTREQUEST_0_QTY0" value="2"></input>
<input type="hidden" name="PAYMENTREQUEST_0_ITEMAMT" value="10.00"></input>
<input type="hidden" name="PAYMENTREQUEST_0_TAXAMT" value="2.10"></input>
<input type="hidden" name="PAYMENTREQUEST_0_AMT" value="12.10"></input>
<input type="hidden" name="currencyCodeType" value="EUR"></input>
<input type="hidden" name="paymentType" value="Sale"></input>
<input type="image" src="https://www.paypalobjects.com/webstatic/en_US/i/buttons/checkout-logo-large.png" alt="Check out with PayPal"></input>
</form>
It says when they multiply quantity and amount it doesn't add up to what you specify as totalamount
$btwbedrag = ($productprijs*$aantalbesteld)/100*$btwtarief;
$subtotaal = ($productprijs*$aantalbesteld)-$btwbedrag;
$totaalprijs = $productprijs*$aantalbesteld;
Your VAT is calculated by taking 1% of the total price amount multiply by VAT rate. This assumes your product amounts are exclusive VAT.
Then in the next line you remove VAT from $subtotaal, why? It wasn't included in the first place. Or if it was then you should divide by 121 instead of 100.
$totaalprijs seems to be calculated assuming VAT is included already.
Did you check the values of your hidden fields in the source of your page?
When I changed the qty to 2, this is the request that is sent to PayPal.
paymentrequest_0_currencycode "EUR"
paymentrequest_0_amt "89.90"
paymentrequest_0_itemamt "71.02"
paymentrequest_0_taxamt "18.88"
paymentrequest_0_paymentaction "Sale"
paymentrequest_0_name "Sweaters van Superdry"
paymentrequest_0_qty "2"
Ideally, the request should be like this:
paymentrequest_0_itemamt=71.02
paymentrequest_0_taxamt=18.88
paymentrequest_0_amt=89.90
L_PAYMENTREQUEST_0_NAME0 = Sweaters van Superdry
L_PAYMENTREQUEST_0_AMT0= 35.51
L_PAYMENTREQUEST_0_QTY0= 2
This is causing the problem.
There is no paymentrequest_0_qty parameter.
You can test it here :
https://api-3t.sandbox.paypal.com/nvp?&user=us-30_api1.cri.com&pwd=EYFNSNUSV85CT34Z&signature=AH57zE.nAaElaFFAysViNA9TIte1AxtSpBjx2HLqHJOiu2js3l1Kd48i&version=70.0&METHOD=SetExpressCheckout&RETURNURL=http://www.paypal.com/test.php&CANCELURL=http://www.paypal.com/test.php&PAYMENTACTION=Sale&paymentrequest_0_itemamt=71.02&paymentrequest_0_taxamt=18.88&paymentrequest_0_amt=89.90&L_PAYMENTREQUEST_0_NAME0=Sweateranuperdry&L_PAYMENTREQUEST_0_AMT0=35.51&L_PAYMENTREQUEST_0_QTY0=2
Just click/copy-pasate the link above and see the reponse
i am using Virtual Merchant online payment.
i have one demo account :
https://demo.myvirtualmerchant.com/VirtualMerchantDemo/login.do
Account ID: 002549
User ID : 002549
Password : Abcd.1234gd
the submitting form code:
<form action="https://demo.myvirtualmerchant.com/VirtualMerchantDemo/process.do" method="POST">
<input type="hidden" name="ssl_amount" value="75.00">
<input type="hidden" name="ssl_merchant_id" value="002549">
<input type="hidden" name="ssl_user_id" value="002549">
<input type="hidden" name="ssl_pin" value="2R56WU">
<input type="hidden" name="ssl_transaction_type" value="ccsale">
<input type="hidden" name="ssl_show_form" value="true">
<input type="hidden" name="ssl_cvv2cvc2_indicator" value="1">
<input type="hidden" name="ssl_invoice_number" value="20131226">
<input type="hidden" name="ssl_customer_code" value="test demo">
<input type="hidden" name="ssl_email" value="demo#gmail.com">
<input type="submit" value="Pay Now" class="button1">
i got one test credit card number: 4005550000000019 from http://www.infomerchant.net/creditcardprocessing/credit_card_test_numbers.html
after submitting, the result is:
after clicking the process button, the result is :
the text is :
Error Code : 4000
Error Name : VID Not Supplied
Error Message : The VirtualMerchant ID was not supplied in the authorization request.
could you know how to fix it ? or any suggestion.
ssl_merchant_id: 002549
ssl_user_id: 002549
ssl_pin: 2R56WU (it is from demo account under menu: user=>change pin)
I encountered a similar issue. The culprit turned up on my end, before my form POSTed data to VirtualMerchant. Make sure the data/string(s) are properly encoded, without any stray white space.
I'm trying to add a "custom" value to the 3rd party checkout PayPal option. The problem I'm having is the PHP variable is being displayed on the screen. I'm passing the shopping cart values in a session variable.
if(isset($_SESSION['checkout'])){
$orderData = '<table border="1"><th style="width:80px">Item</th>
<th sytle="width:250px">Size</th>
<th style="width:60px">Quantity</th>';
for ($i=0; $i<count($_SESSION['checkout']); $i++){
$orderData .= '<tr><td style="text-align:center">'.$_SESSION['checkout'][$i][0].'</td><td style="text-align:center">'.$_SESSION['checkout'][$i][1].'</td><td style="text-align:center">'.$_SESSION['checkout'][$i][2].'</td></tr>';
}
}
I want that table to be passed along, and based on the PayPal documentation, all I need to do is include it. I'm echoing out the PayPal form like this:
echo '<form>
//other hidden values
<input type="hidden" name="custom" value="'.$orderData.'">
//input submit button here
</form>
And like I said, the input is supposed to be hidden, but it gets displayed before the PayPal button. How come?
UPDATE: Those code passes the amount perfectly:
<input type="hidden" name="amount" value="';?><?php if(isset($_SESSION['disc'])){print_r($_SESSION['disc']);}?><?php echo '">
It doesn't display on the page but the variable amount is correct in the page source.
UPDATE2: Here's my entire cart script:
echo '<div style="position:absolute; left:770px; top:50px">
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="myemail#example.com">
<input type="hidden" name="item_name" value="Merchandise">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="custom" value="'.$orderData.'">
<input type="hidden" name="return" value="backtomywebsite.com">
<input type="hidden" name="cancel_return" value="backtomywebsite.com">
<input type="hidden" name="amount" value="';?><?php if(isset($_SESSION[$disc])){print_r($_SESSION[$disc]);}?><?php echo '">
<input type="image" src="http://www.mywebsite.com/images/BuyNow.png" name="submit" alt="Make payments with PayPal - it\'s fast, free and secure!" width="300" height="204">
</form>
</div>';
The script works when instead of $orderData I have a print_r session with the item information. That information gets sent to my paypal account but it is in an array form and looks ugly. If there was a way to make everything (member information, order information) into a php variable and pass it into the custom field, that would be great. Anyway...here's what is on the screen:
Hope you're still willing to help me out.
What do you mean it gets displayed before the PayPal button? If you are viewing the source code of the page, you will see the value in the page.
If you are saying you are passing amount over, but are not seeing it you may be using the wrong variable. The variable amount is a valid PayPal variable but depending what button you are specifically using the amount varialbe is slightly different. I could not tell from your code as I didn't see what you were passing over for "cmd", but if you are using a buy now button or an add to cart button that the variable "amount" would be the correct variable to use. If you are usnig the cart upload method, then you want to use the variable "amount_x". So if I passed two items over, and the first one was 0.99 and the second was 1.99 I would pass over the variable/value of "amount_1=0.99" and "amount_2=1.99".
I am facing this problem from last month. First i was able to get value back from paypal.
Now I am not able to get back value from paypal.
I am using following code.
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" style="padding: 0; margin: 0;">
<input type="hidden" name="cmd" value="_xclick/" />
<input type="hidden" name="business" value="my_bussiness_id" />
<input type="hidden" name="quantity" value="1" />
<input type="hidden" name="item_name" value="item" />
<input type="hidden" name="item_number" value="1" />
<input type="hidden" name="amount" value="item_price" />
<input type="hidden" name="shipping" value="0" />
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="notify_url" value="Your_notify_url">
<input type="hidden" name="currency_code" value="GBP" />
<input type="hidden" name="rm" value="2" >
<input type="hidden" name="return" value="your return url">
<input type="image" border="0" name="paypal" src="images/btn_paypal_nl.gif" onClick="" />
</form>
Thanks in advance..
Kanji
There's actually two methods of getting the data back--a return URL that posts upon completion with return values (I've not been terribly lucky making that work) then a separate function that sends you a post upon completion of a transaction to a separate page on your site, where you can collect back all the variables you posted to the site. I suggest the latter because on a buy it now page there's a possibility of the user not being returned to the site because the return button UI is pretty weak on PayPal's end.
To set it up you'd log in to your PayPal account, click on myaccount > profile > website payment preferences. Enabling the "payment data transfer" will do the trick. Once you've got it setup correctly, upon completion of a transaction it'll send to the page of your choice a post of everything you sent it....remember, you can send in variables such as Name, Address, etc just by defining them properly in the form. All the variables available are found here
Don't forget to build a sandbox site to test! Good Luck.
What I have normally done is this:
You see where you got notify_url as a hidden tag, use that for paypal to send you information about the transaction.
The url you put down should be a file on your server that will then do some logic, i.e. update your database that everything was ok, send out notification email of order, etc, etc
When paypal talks to this page, altho cant see the process, everything is sent via $_POST.
What I do as a test is i loop thru the $_POST array and send myself an email so I know what values have been posted back to me.
//paypal variables
$message = "<h1>Paypal variables</h1>";
foreach($_POST as $key => $value)
{
$message.= $key . " - " . $value . "<br />";
}
Link below gives you more info.
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_admin_IPNIntro