Return form result from external PHP - forms

I have a post type form with action to an external PHP that calculates a shipping tax.
<form id="shipping_costs" autocomplete="off" method="post" action="tarif.php" target="blank">
<input type="hidden" name="serviciu" value="Standard">
All the inputs are hidden and the website that receives all the values calculates the tax.
How can I retrieve the resulted amount into my website?
Also, the website I work on is using smarty.

Related

Finding PayPal Buy Now Button redirection link

I am trying to make a program that can scrape a site and search for PayPal buy now button redirection links.
I can scrape the site but I realize that when you hit the button, it does not contain the URL that you will be redirected to make purchase. How would I go about finding the button redirection link, or even how would I have the site scrape and click on the button to at least have the redirect site appear? Would I somehow have to make the scraper hit the form and submit?
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top"><input name="cmd" type="hidden" value="_s-xclick" /><br />
<input name="hosted_button_id" type="hidden" value="PUEGWVJXLH4FQ" /><br />
<input alt="PayPal - The safer, easier way to pay online!" name="submit" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" type="image" /><br />
<img loading="lazy" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" alt="" width="1" height="1" border="0" /></form>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">_______________________________________________________</p>
</form>
Go to https://www.paypal.co/buttons, log in, and (after logging in) create a new simple Buy Now button with no dropdown options nor text fields (which require HTML) -- and once the button is created and you are viewing the generated code, switch over to the "E-mail" tab above it.
The link in that E-mail tab will have a hosted button ID, which you can swap out / use to dynamically generate the Buy Now "redirection link" you're asking for. When loaded in a browser, that link will initiate a checkout, same as clicking the button.
There are several other types of PayPal payment buttons, including:
Unhosted Buy Now buttons (which are not saved at PayPal, and do not have a hosted_button_id). These buttons use a redirection link or form post that will include HTML variables to set up the payment.
Newer smart buttons, generated via https://www.paypal.com/buttons/smart or similar -- these do not have redirection URL, and instead use JS to open a mini window for payment approval.
Another way to construct a working URL is to begin with the form's action parameter https://www.paypal.com/cgi-bin/webscr, add ? to begin a GET string, and add all the inputs from the form that have a name, in with the syntax name=value, separated by '&' .... so for example:
https://www.paypal.com/cgi-bin/webscr?hosted_button_id=PUEGWVJXLH4FQ&anothername=anothervalue&...

Can I test my IPN listener VB.NET code under localhost (ASP.NET Web Forms)?

The 'Local development testing' section of PayPal's IPN Testing page implies that it is possible to test your IPN listener code via localhost, using a test page to simulate a message from PayPal.
My TestIPN.aspx page contains the following markup, which appears to follow the example provided by PayPal, but when I open it in Firefox under localhost (via Visual Studio 2019) and click the Submit Query button I get a 'File not found' error for https://localhost:44390/PayPal/IPNHandler.aspx.vb.
Needless to say, IPNHandler.aspx.vb does exist in my PayPal folder (using "PayPal/IPNHandler.aspx" in the form tag on my test page makes no difference). I also get the same error when I run it on my live site.
Any guidance on how to debug this problem would be much appreciated.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Test IPN message</title>
</head>
<body>
<!--
<form target="_new" method="post" action="https://www.YourDomain.com/Path/YourIPNHandler.php">
-->
<form target="_new" method="post" action="PayPal/IPNHandler.aspx.vb">
<input type="hidden" name="receiver_email" value="admin%40mysite.co.uk"/>
<input type="hidden" name="business" value="admin%40mysite.co.uk"/>
<input type="hidden" name="first_name" value="Fred"/>
<input type="hidden" name="last_name" value="Bloggs"/>
<input type="hidden" name="payer_email" value="fred.bloggs%40gmail.com"/>
<input type="hidden" name="address_city" value="Southampton"/>
<input type="hidden" name="payment_type" value="instant"/>
<input type="hidden" name="payment_date" value="19:54:19 Apr 12, 2021 GMT"/>
<input type="hidden" name="payment_status" value="Completed"/>
<input type="hidden" name="mc_currency" value="GBP"/>
<input type="hidden" name="mc_gross" value="5.00"/>
<input type="hidden" name="custom" value="25"/>
<input type="submit"/>
</form>
</body>
</html>
I get a 'File not found' error for https://localhost:44390/PayPal/IPNHandler.aspx.vb
Is that the correct port? What happens if you put https://localhost:44390/PayPal/IPNHandler.aspx.vb in the URL bar? Use a URL that works to the handler on your localhost, which does not return a 404. Set the action accordingly.
Consider something like https://ngrok.com for testing as well.
Why are you integrating IPN anyway? It's 20 or so years old, and not required for current PayPal Checkout integrations you should be using instead...
Follow the Set up standard payments guide and make 2 routes on your server, one for 'Create Order' and one for 'Capture Order', documented here. Both routes should return only JSON data (no HTML or text). Inside the 2nd route, when the capture API is successful you should store its resulting payment details in your database (particularly purchase_units[0].payments.captures[0].id, which is the PayPal transaction ID) and perform any necessary business logic (such as sending confirmation emails or reserving product) immediately before forwarding your return JSON to the frontend caller.
Pair those 2 routes with the frontend approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server

PHP 5.3.10 global behaviour

I'm having trouble with a global variable, I think it might be pulling its data from a HTML Form Input, but I can't find any documentation on the web about global var pulling data from a HTML Form Input.
Thanks.
When a form is submitted the method tag specifies if it is a POST or GET request. Depending on what method your form is using your form values can either be in your $_POST or $_GET Super global.
Example:
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
After the submit button on the form is clicked the form contents can be found by referencing the name attribute in the super global(In this case the POST).
$_POST['name']
$_POST['email']
For documentation see
http://php.net/manual/en/reserved.variables.post.php
This applies to PHP 4 >= 4.1.0, PHP 5, PHP 7 ie. fits PHP 5.3.

can't POST item price in paypal sandbox

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="YYHZM9FTBZQGW">
<input type="hidden" name="amount" value="20.00">
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
this is a paypal sandbox button. all i want to do is to post the TOTAL price of all the product the user buy in my website.
I created a button with nothing to post because basically i want to post dynamically in the future using a php variable so I think I don't need to set up the item price, name, quantity in the sandbox create button features. how am i suppose to do that.
this is the output. I want the item price to be not editable same as with description and quantity
The reason you can't override the amount dynamically, is because you have a so-called 'PayPal hosted button'.
With a hosted button, the amount is stored on PayPal's side and can't be overwritten with the 'amount' variable.
You'll either want to use a non-hosted button, or use the BMUpdateButton API call to dynamically update the button's amount.
An example request for BMUpdateButton would look as follows:
USER=Your API username
PWD=Your API password
SIGNATURE=Your API signature
VERSION=82.0
HOSTEDUBTTONID=The value of <input type="hidden" name="hosted_button_id" value="">
BUTTONTYPE=The type of button. E.g. BUYNOW
BUTTONCODE=The type of code you want to get back. E.g. HOSTED
L_BUTTONVAR0=amount=The new amount with a period as separator
L_BUTTONVAR1=item_name=Optional: a new item name if you wish
Similary, you could also use the BMCreateButton API to create a new button, or use the BMButtonSearch API to search through a list of all your stored hosted buttons (to find the hosted_button_id of your button automatically, for example)
The reason to use a hosted button is because it's more secure. A non-hosted, unencrypted button would basically leave the amounts open to manipulation. Fraudulent transactions waiting to happen.

Add multiple items to Paypal in single form using hosted_button_id

I want to setup a single form on a site to purchase multiple products via PayPal. The products are set in the PayPal account and each has a hosted_button_id.
The form would contain a series of descriptions and quantity fields, all initially set to zero. The customer could then add desired quantities against each product and submit the form with a single 'Buy now' button.
Is this possible with PayPal? I don't particularly want a 'cart' experience and I don't want to pass product prices (instead using the data stored at PayPal).
thanks
In the end I concluded you can't do this.
I tried everything, including AJAXing the submission and send the submission via a hidden iFrame to keep the user on my site. Nothing worked. It seems PayPal are very keen to enforce their approved shopping workflow when using their cart.
You can do this, but you'll need to do some server-side programming. You build an "encrypted button" programmatically, and submit that to PayPal.
My store page at https://secure.entrian.com/store/store.html does it - it prompts for some information, sends that to the server to be turned into an encrypted button, and then submits that to PayPal.
The JavaScript looks like this, where $license_name and $quantity are the fields that I'm prompting for, and formgen.py is a server-side Python script that builds and signs the request using OpenSSL according to PayPal's documentation:
$paypal_form.submit(function () {
var response = $.ajax({
type: "GET",
url: 'formgen.py?' + serialize({
licenseName: $license_name.val(),
quantity: $quantity.val()
}),
async: false
}).responseText;
if (response.indexOf('PKCS7') >= 0) {
$encrypted.val(response);
} else {
$payment_errors.text(response).show(easing_duration);
return false;
}
return true;
}
The form looks like this (simplified rather):
<form id="paypal-form" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="upload" value="1">
<input type="hidden" id="encrypted" name="encrypted" value="">
<button id="buynow" class="submit-button btn" type="submit">Buy Now</button>
</form>
That <input name="encrypted" ...> gets populated with the AJAX response before the form gets submitted to PayPal.