15

I am new to Paypal integration with PHP, i have searched in the internet i am not able to get correct one to implement in my website.

Can anyone help to to integration of paypal for my website with step by step including the test account creation .

Thanks in advance.

Antoniraj
  • 159
  • 1
  • 1
  • 4

3 Answers3

8

When I made my first paypal script one of the most useful things that I did was to log every piece of information that came through. I just dumped everything into a text file whenever Paypal called the confirmation page. It was incredibly helpfull to see what they were passing over and to debug. Paypal sends a POST of the transaction.

$dumpfile = "=== post fields\n";
foreach($_POST as $k=>$v)
    $dumpfile .= "[$k] => $v\n";

$dumpfile .= "=== http request headers\n";
foreach(apache_request_headers() as $k=>$v)
    $dumpfile .= "[$k] => $v\n";

file_put_contents('pathToAWritableFile', $dumpfile);

I hope this saves you some headache. As a side note, I still keep all the paypal request info in a database in case the purchase logic fails after I update the paypal confirmation script, that has saved me a couple of times.

Here's a tut on how to handle the callback from paypal.

Adam
  • 1,080
  • 1
  • 9
  • 17
6

https://developer.paypal.com/ is a great place to start.

They offer guides and code libraries and examples there.

Dean Rather
  • 31,756
  • 15
  • 66
  • 72
5

All what you need is learning how PayPal uses and recreate account mail on sandbox.paypal.com in other word https://developer.paypal.com/. For creating testing (sandbox) account with virtual money you need for main account on sandbox register on a developer.paypal.com.

After processing you should configure properly of data on PayPal account and step on guides of sandbox developer. For example how is checking out of buyers uses (look code ECSetExpressCheckout).

First look of guide PayPal (this is general):

Looking for paypal payments tutorial

This is main site how manipulate with PayPal:

https://cms.paypal.com/ca/cgi-bin/?cmd=_render-content&content_ID=developer/library_code

You want manipulate for success payment (look at ECSetExpressCheckout, MOSTLY COMMON FOR TRANSACTIONS):

Source code here: https://cms.paypal.com/cms_content/CA/en_US/files/developer/nvp_ECSetExpressCheckout_php.txt

Focus on code:

$paymentAmount = urlencode('30'); // 30 USD if you set on sandbox default
$currencyID = urlencode('USD');                         // or other currency code ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')
$paymentType = urlencode('Order');          

$returnURL = urlencode("my_return_url"); // YOUR URL IF SUCCESS
$cancelURL = urlencode('my_cancel_url'); // YOUR URL IF FAILED

If you need check a transaction after payment grab via TRANSACTION_ID with GetTransactionDetails function: https://cms.paypal.com/cms_content/CA/en_US/files/developer/nvp_GetTransactionDetails_php.txt

Community
  • 1
  • 1
Marin Sagovac
  • 3,932
  • 5
  • 23
  • 53