Solved

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

Posted on 2014-07-21
18
1,681 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 100 total points
Comment Utility
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
Comment Utility
@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
Comment Utility
@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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 46

Author Comment

by:Sjef Bosman
Comment Utility
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
Comment Utility
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
Comment Utility
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 108

Expert Comment

by:Ray Paseur
Comment Utility
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
Comment Utility
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 108

Expert Comment

by:Ray Paseur
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Often people are aiming at development of perfect Magento websites. Though, it is easier said than done. You know what’s much easier? To ruin everything. It can be done in seconds. Many of us experimented with design, tried to change some values dir…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now