Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Can you give me an example for a simple PayPal payment?

Posted on 2014-07-21
18
1,769 Views
Last Modified: 2016-03-24
My client wants to offer a simple payment mechanism to the visitors of his website. The idea is simple: he prepares a link to a specific page, the link contains the amount the visitor has to pay, the link is sent to the visitor (e.g. by mail), the visitor clicks OK and then control should be transferred to PayPal where the actual transaction is handled in a secure way.

Example of a URL (simplified):
     www.somesite.xyz/payment.php?amount=1000&visitor=WileyC

When the link is clicked, a page opens, asking the visitor to click OK if everything is correct,

Here's what I don't know, where it becomes fuzzy for me, and where I need your help.

When OK is clicked, the server should put a lot of data in an HTML form (presumably) and send it to PayPal. PayPal then handles the transaction and reports back OK or Not OK.

Can this be done, and if so, how? Documentation? Good PHP examples??

TIA!
0
Comment
Question by:Sjef Bosman
  • 9
  • 4
  • 3
  • +1
18 Comments
 
LVL 52

Assisted Solution

by:Scott Fell, EE MVE
Scott Fell,  EE MVE earned 400 total points
ID: 40208564
The simplest way is for your client to log into paypal, go to request money, create email invoice.  He can do it right on the fly and an invoice will be sent to his client.

Otherwise, you have some coding to do.   Which method of integration do you need?  https://developer.paypal.com/docs/classic/products/

https://developer.paypal.com/docs/classic/training/
0
 
LVL 46

Author Comment

by:Sjef Bosman
ID: 40208596
Hi Scott, thanks. My client doesn't want to open PayPal every time he wants to send an invoice. Coding isn't a problem, the whole site is in PHP and XML/HTML.
Gotta go now, I'll explain in more detail in 2 hours.
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 40208620
ALGO:

Create a link say http://site.com/paypal.php?yourkey=value&email=id
When client clicks on the link via email . it would be redirected to paypal.php of your server, which will validate the key & value and later fetch the data from db that has to posted to paypal.
Please note:Client would not be able to trace that it has been redirected via paypal.php and not directly to paypal

Please use key , value pair for validation and security concern.

Please provide the solution what you have found if possible
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 100 total points
ID: 40208711
The simplest example is a Buy Now Button.
https://developer.paypal.com/docs/classic/paypal-payments-standard/ht_create-pps-buttons/

If you need more than that, it seems that you're looking at a fairly significant choice in terms of time and money.  Either learn to be a PayPal developer (can take months) or hire a PayPal developer (costs money).

To learn:
https://developer.paypal.com/webapps/developer/docs/api/

If you're outside USA:
https://developer.paypal.com/webapps/developer/docs/faq/#non-US-dev

To hire:
https://www.paypal-portal.com/developer/directory/
0
 
LVL 46

Author Comment

by:Sjef Bosman
ID: 40208724
@insoftservice: I don't understand your comment. I think you more or less copied my question, i.e. I asked for what you described: the file paypal.php. I'd like a sample server-side paypal.php. I did a similar thing with SystemPay, and that was fairly easy... I just can't seem to find my 'thing' in the PayPal documentation.
0
 
LVL 46

Author Comment

by:Sjef Bosman
ID: 40208780
@Ray: thanks. I looked into the Buy Now idea, but it's not what I'm looking for. Everything will be fixed: the amount, the shipping, codes, etc. That's not what I want. I'd like to do the calculations of the URL in my code, and then send PayPal the calculated link. Is there such a possibility?

Caution: there is no on-line shop, nothing else, so the logic behind the button should send a simple URL to PayPal that opens a PayPal screen to the website visitor, which should do the rest of the transaction.
0
 
LVL 46

Author Comment

by:Sjef Bosman
ID: 40208803
In fact, the code that generates the button for SystemPay also generates a form with many hidden fields. These fields contain data plus an encrypted key that matches the data. When clicked the button sends the form data to SystemPay, which responds with a payment page. I could show you part of the code, but it's of no importance if PayPal doesn't have this capability.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40208814
I do think you need to break down in more detail where exactly you need help and which method  you want to use.  

A) he prepares a link to a specific page, the link contains the amount the visitor has to pay,

B) the link is sent to the visitor (e.g. by mail),

C) the visitor clicks OK and then control should be transferred to PayPal where the actual transaction is handled in a secure way.


There are multiple options here.   One would be to create an invoice.  https://developer.paypal.com/docs/api/  
https://developer.paypal.com/docs/api/#create-an-invoice
Then send the invoice
https://developer.paypal.com/docs/api/#send-an-invoice

You will see on that page, there is also a link to a php sdk  https://github.com/paypal/rest-api-sdk-php

In the samples you can see the create invoice https://github.com/paypal/rest-api-sdk-php/blob/master/sample/invoicing/CreateInvoice.php
<?php

require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Invoice;
use PayPal\Api\MerchantInfo;
use PayPal\Api\BillingInfo;
use PayPal\Api\InvoiceItem;
use PayPal\Api\Phone;
use PayPal\Api\Address;
use PayPal\Api\Currency;
use PayPal\Api\PaymentTerm;
use PayPal\Api\ShippingInfo;

$invoice = new Invoice();

$invoice
	->setMerchantInfo(new MerchantInfo())
	->setBillingInfo(array(new BillingInfo()))
	->setItems(array(new InvoiceItem()))
	->setNote("Medical Invoice 16 Jul, 2013 PST")
	->setPaymentTerm(new PaymentTerm())
	->setShippingInfo(new ShippingInfo());

$invoice->getMerchantInfo()
	->setEmail("PPX.DevNet-facilitator@gmail.com")
	->setFirstName("Dennis")
	->setLastName("Doctor")
	->setbusinessName("Medical Professionals, LLC")
	->setPhone(new Phone())
	->setAddress(new Address());

$invoice->getMerchantInfo()->getPhone()
	->setCountryCode("001")
	->setNationalNumber("5032141716");

$invoice->getMerchantInfo()->getAddress()
	->setLine1("1234 Main St.")
	->setCity("Portland")
	->setState("OR")
	->setPostalCode("97217")
	->setCountryCode("US");

$billing = $invoice->getBillingInfo();
$billing[0]
	->setEmail("example@example.com");

$items = $invoice->getItems();
$items[0]
	->setName("Sutures")
	->setQuantity(100)
	->setUnitPrice(new Currency());

$items[0]->getUnitPrice()
	->setCurrency("USD")
	->setValue(5);

$invoice->getPaymentTerm()
	->setTermType("NET_45");

$invoice->getShippingInfo()
	->setFirstName("Sally")
	->setLastName("Patient")
	->setBusinessName("Not applicable")
	->setPhone(new Phone())
	->setAddress(new Address());

$invoice->getShippingInfo()->getPhone()
	->setCountryCode("001")
	->setNationalNumber("5039871234");

$invoice->getShippingInfo()->getAddress()
	->setLine1("1234 Main St.")
	->setCity("Portland")
	->setState("OR")
	->setPostalCode("97217")
	->setCountryCode("US");

print(var_dump($invoice->toArray()));

try {
	$invoice->create($apiContext);
} catch (PayPal\Exception\PPConnectionException $ex) {
	echo "Exception: " . $ex->getMessage() . PHP_EOL;
	var_dump($ex->getData());
	exit(1);
}
?>
<html>
<head>
	<title>Direct Credit card payments</title>
</head>
<body>
	<div>
		Created Invoice:
		<?php echo $invoice->getId();?>
	</div>
	<pre><?php var_dump($invoice->toArray());?></pre>
	<a href='../index.html'>Back</a>
</body>
</html>

Open in new window

and send
https://github.com/paypal/rest-api-sdk-php/blob/master/sample/invoicing/SendInvoice.php
<?php

require __DIR__ . '/../bootstrap.php';

use PayPal\Api\Invoice;

try {
	$invoice = Invoice::get("INV2-9DRB-YTHU-2V9Q-7Q24", $apiContext);

	$sendStatus = $invoice->send($apiContext);
} catch (PayPal\Exception\PPConnectionException $ex) {
	echo "Exception: " . $ex->getMessage() . PHP_EOL;
	var_dump($ex->getData());
	exit(1);
}

?>
<html>
<head>
	<title>Send Invoice</title>
</head>
<body>
	<div>Send Invoice:</div>
	<pre><?php var_dump($invoice);?></pre>
	<a href='../index.html'>Back</a>
</body>
</html>

Open in new window


I would get yourself a sandbox account and start with the samples.  Get those to work, then update with your own details.
0
 
LVL 46

Author Comment

by:Sjef Bosman
ID: 40208886
The A->B->C is correct, and the help I'd like to have is mostly related to A: how to prepare the page and the link. From your comments I kind of get the idea that PayPal doesn't support what I'm looking for.

I'll try to re-explain what I would like my code and PayPal to do (basically).

1. the client opens a hidden page on the site, enters the client's payment data (amout, reference, etc.)
2. the server responds with a (crypted) link that contains the payment data; the link is to the same website
3. the client copies the link into a mail and sends it to the visitor.

4. the visitor clicks the link and opens another hidden page on the website; this page displays the payment data that is enclosed in the crypted part of the link
5. on this same page, the server generates the Buy Now button
6. if the visitor accepts the transaction, he can click the Buy Now button; in that case the real payment info is sent to the bank.

So, as far as I can see, there is no need to send an invoice by PayPal, it's just a money transfer.

Hmm, I'll ask my client how the invoice is sent to the visitor. I suppose he intends to send his own.
0
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 0 total points
ID: 40208903
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40208933
The idea of the invoice does exactly what you outline, except it is much easier.  You can do this via the api or by logging into the paypal directly.  What you have outlined is really overly complex

If you are not logging any type of inventory and simply using the hidden page on his site to generate the request for payment/url, the easiest is my original idea of simply logging into his paypal account and generating an invoice that will auto email his customer.   It is very simple and I bill my own clients this way.

Otherwise, you still can do what you want, but it is more involved.  First you have to generate the items you want to sell or at least an amount.  Then the final amount you send to paypal's server to generate the button code (or a link).  Then you supply the button code back to your site or your client's customer who will then click the button or link and go to paypal.  

The reason it is done in this fashion is to prevent somebody from spoofing the amount.  If you were to manually generate a buy now button, notice the html generated does not include an amount, that is because it is saved on the paypal server.

You may want to look at the classic api and express checkout https://developer.paypal.com/docs/classic/products/express-checkout/
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40208966
do the calculations of the URL in my code, and then send PayPal the calculated link
Entirely feasible.  You can prepopulate any of the form fields you need to use PayPal.

Without getting into the technicalities, can you please describe the business aspects of the transaction?  For example, is it a purchase of a product, or a donation?
0
 
LVL 46

Author Comment

by:Sjef Bosman
ID: 40209002
My client produces wooden signs , elements, ornaments, etc. on demand, so there's always a quotation before anything is produced. There are therefore no prices on the website. The visitor places an order, and for the payment of this order the visitor can use PayPal, or send a cheque (only in France), or do a money transfer. Prices are around €200, that should be around $250 at the mo. The website isn't finished yet, and then there is the translation, but he hopes to open his shoppe on Sept. 1st.

The Adaptive Payments API seems what I need, what I read there is quite promising. Straightforward as well.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40209043
You might consider sending a PayPal invoice via email.  The client can pay directly with the link in the email.  And there is the "send money" feature of PayPal that can be used by the client, but that requires the client to understand the process, and it might be too much friction when compared to a web page that gives instructions and receives payments.
0
 
LVL 46

Author Comment

by:Sjef Bosman
ID: 40209460
Would you believe me if I told you that the client now says that he's willing to consider the PayPal invoicing system?? Argh...
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40209518
Like both Ray and I have suggested, if you can do this right from paypal it is super easy.  Otherwise, if you want to do this programmatically, I pointed you to the api http:#a40208814  You will still need to build the portion where you are updating rows of data to generate the amount due.
0
 
LVL 46

Author Closing Comment

by:Sjef Bosman
ID: 40222312
I think that Adaptive Payments are what I really meant to use, so that would be the solution to my question. The final solution to the problem is, hopefully, the PayPal invoice, as suggested by Scott. Thank you guysl!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

E-commerce is quite a gambling world, and you should never entrust your business to a lucky chance. In order to outrun your competitors in a race to attract as many customers as possible, you need to have a well thought-out strategy under your belt.…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to count occurrences of each item in an array.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question