This blog - now archived - is read-only.
New blog: Mohammad Emran Hasan.

PHP Payment Library for Paypal, Authorize.net and 2Checkout

Update: This library has gone through full re-write and the uploaded version can be found here.

If you are like me, whenever you need to work with a 3rd party API or a gateway, you’d first search in Google for a possible wrapper for it in PHP. When it comes to supporting payment gateways, you get bunch of libraries in the search results who are fundamentally different. Some of them are old PHP 3/4 ones, some are new, some may need PEAR, etc.

As they were not required together in one single project, I used them whenever needed. But in one project, I needed them all. I thoughts it’s a chance and decided to stop using them and wrote my own ones where I can use the same methods for all the gateways.

So, here is an abstract PaymentGateway library which is being extended to be used for three popular payment gateways (Paypal, Authorize.net, and 2Checkout) in order to provide you with a similar way of using them. Note that the libraries are for basic usage only and do not contain options for recurring payments. Without much babble, let’s see a few examples of how you can use them.

Download
No download available for this version.

Paypal

In order to process payments using Paypal, you’ll need to follow these steps:

1. Send the required information to Paypal (snippet 1). Be sure to specify your Paypal email where you want to receive the funds, the success and failure pages, the IPN page, and the product information. The example has the test mode ON, which you will not need in real scenario.

2. Create a payment success page where Paypal will send your customer after payment.

3. Create a payment failure page where Paypal will send your customer after failed payment.

4. Create a IPN page where Paypal will send payment notification in the background. Make sure you use/remove the test mode in conjunction with step 1. (snippet 2)

Snippet 1


// Include the paypal library
include_once ('Paypal.php');

// Create an instance of the paypal library
$myPaypal = new Paypal();

// Specify your paypal email
$myPaypal->addField('business', 'YOUR_PAYPAL_EMAIL');

// Specify the currency
$myPaypal->addField('currency_code', 'USD');

// Specify the url where paypal will send the user on success/failure
$myPaypal->addField('return', 'http://YOUR_HOST/payment/paypal_success.php');
$myPaypal->addField('cancel_return', 'http://YOUR_HOST/payment/paypal_failure.php');

// Specify the url where paypal will send the IPN
$myPaypal->addField('notify_url', 'http://YOUR_HOST/payment/paypal_ipn.php');

// Specify the product information
$myPaypal->addField('item_name', 'T-Shirt');
$myPaypal->addField('amount', '9.99');
$myPaypal->addField('item_number', '001');

// Specify any custom value
$myPaypal->addField('custom', 'muri-khao');

// Enable test mode if needed
$myPaypal->enableTestMode();

// Let's start the train!
$myPaypal->submitPayment();

Snippet 2


// Include the paypal library
include_once ('Paypal.php');

// Create an instance of the paypal library
$myPaypal = new Paypal();

// Log the IPN results
$myPaypal->ipnLog = TRUE;

// Enable test mode if needed
$myPaypal->enableTestMode();

// Check validity and write down it
if ($myPaypal->validateIpn()) {
    if ($myPaypal->ipnData['payment_status'] == 'Completed') {
        file_put_contents('paypal.txt', 'SUCCESS');
    }
} else {
    file_put_contents('paypal.txt', "FAILURE\n\n" . $myPaypal->ipnData);
}

Authorize.net

In order to process payments using Authorize.net, you’ll need to follow these steps:

1. Send the required information to Authorize.net(snippet 3). Be sure to specify your Authorize.net login and secret key, the success/failure pages, the IPN page, and the product information. The example has the test mode ON, which you will not need in real scenario.

2. Create a payment success/failure page where Authorize.net will send your customer after payment.

3. Create a IPN page where Authorize.net will send payment notification in the background. Make sure you use/remove the test mode in conjunction with step 1. (snippet 4)

4. In order to set the secret key, log into your authorize.net merchant account. Go to “MD5 Hash” menu and set a secret word to desired values and use that in the “setUserInfo” function showed in the example.

Snippet 3

<!--?php </p-->

// Include the paypal library
include_once ('Authorize.php');

// Create an instance of the authorize.net library
$myAuthorize = new Authorize();

// Specify your authorize.net login and secret
$myAuthorize->setUserInfo('YOUR_LOGIN', 'YOUR_SECRET_KEY');

// Specify the url where authorize.net will send the user on success/failure
$myAuthorize->addField('x_Receipt_Link_URL', 'http://YOUR_HOST/payment/authorize_success.php');

// Specify the url where authorize.net will send the IPN
$myAuthorize->addField('x_Relay_URL', 'http://YOUR_HOST/payment/authorize_ipn.php');

// Specify the product information
$myAuthorize->addField('x_Description', 'T-Shirt');
$myAuthorize->addField('x_Amount', '9.99');
$myAuthorize->addField('x_Invoice_num', rand(1, 100));
$myAuthorize->addField('x_Cust_ID', 'muri-khao');

// Enable test mode if needed
$myAuthorize->enableTestMode();

// Let's start the train!
$myAuthorize->submitPayment();

Snippet 4


<!--?php </p-->

// Include the paypal library
include_once ('Authorize.php');

// Create an instance of the authorize.net library
$myAuthorize = new Authorize();

// Log the IPN results
$myAuthorize->ipnLog = TRUE;

// Specify your authorize login and secret
$myAuthorize->setUserInfo('YOUR_LOGIN', 'YOUR_SECRET_KEY');

// Enable test mode if needed
$myAuthorize->enableTestMode();

// Check validity and write down it
if ($myAuthorize->validateIpn()) {
    file_put_contents('authorize.txt', 'SUCCESS');
} else {
    file_put_contents('authorize.txt', "FAILURE\n\n" . $myPaypal->ipnData);
}

2Checkout

In order to process payments using 2Checkout, you’ll need to follow these steps:

1. Send the required information to 2Checkout(snippet 5). Be sure to specify your 2Checkout vendor id, the return page, and the product information. Please note that 2Checkout does not send IPN in the background, so you will need to handle the payment data in the return page. The example has the test mode ON, which you will not need in real scenario.

2. Create a return page where 2Checkout will send your customer after payment. This is also where you will need to retrieve and use the payment data. Make sure you use/remove the test mode in conjunction with step 1. (snippet 6)

3. In order to set the secret key, log into your 2checkout.com account and go to “Look and Feel” section. At the bottom enter the “Secret Word” and use it in the IPN verification process as shown in the example.

Snippet 5

<!--?php </p-->

// Include the paypal library
include_once ('TwoCo.php');

// Create an instance of the authorize.net library
$my2CO = new TwoCo();

// Specify your 2CheckOut vendor id
$my2CO->addField('sid', 'YOUR_VENDOR_ID');

// Specify the order information
$my2CO->addField('cart_order_id', rand(1, 100));
$my2CO->addField('total', '9.99');

// Specify the url where authorize.net will send the IPN
$my2CO->addField('x_Receipt_Link_URL', 'http://YOUR_HOST/payment/twoco_ipn.php');
$my2CO->addField('tco_currency', 'USD');
$my2CO->addField('custom', 'muri-khao');

// Enable test mode if needed
$my2CO->enableTestMode();

// Let's start the train!
$my2CO->submitPayment();

Snippet 6


<!--?php </p-->

// Include the paypal library
include_once ('TwoCo.php');

// Create an instance of the authorize.net library
$my2CO = new TwoCo();

// Log the IPN results
$my2CO->ipnLog = TRUE;

// Specify your authorize login and secret
$my2CO->setSecret('YOUR_SECRET_KEY');

// Enable test mode if needed
$my2CO->enableTestMode();

// Check validity and write down it
if ($my2CO->validateIpn()) {
    file_put_contents('2co.txt', 'SUCCESS');
} else {
    file_put_contents('2co.txt', "FAILURE\n\n" . $my2CO->ipnData);
}

Hope this will help you integrate the payment gateways in an easy manner. If you have any questions, or find any bug, have a suggestion, feel free to post them as comment here. Btw, this library is released under the MIT license.

Cheers!

219 thoughts on “PHP Payment Library for Paypal, Authorize.net and 2Checkout

  1. Gus

    How do you implement this library for a small website with multiple items? What part of the code do we need to include next to the different items?

  2. Shimon

    Right in time when I started looking for it. I'll see if I will be able to add recurring payments for paypal since I need them too.

    Thank you!

  3. Pingback: HamzaED

  4. Pingback: PHP Payment Library for PayPal, Authorize.net and 2Checkout (2CO) | by Vernon Kesner

  5. Pingback: PHP Payment Library for Paypal, Authorize.net and 2Checkout (2CO)at Top 3K Mega List - Must Have Popular Website Links for Web Designer, IT Techie & Office Worker

  6. Pingback: Blog DirectoHosting.com » PHP Payment Library para Paypal, Authorize.net y 2Checkout (2CO)

  7. Pingback: Librería PHP para Paypal, Authorize.net y 2Checkout | dominios, diseño web, ecommerce - Mantis Technology Solutions Blog

  8. JP

    I must be missing something here. The payment posts to authnet…the log shows the post from the gateway…but the ipn response from gateway server is blank and i CANNOT get to the receipt page, obviously. I'm almost home, or so I think, but I can't get there on my own…please help.

  9. JP

    Ok, ok…i'm posting 'success' to the results log for an authorize.net payment, but
    IPN Response from gateway Server: is blank.
    I'm lost. Testing gives me a:

    An error occurred while trying to report this transaction to the merchant. An e-mail has been sent to the merchant informing them of the error. The following is the result of the attempt to charge your credit card.

    This transaction has been approved.
    It is advisable for you to contact the merchant to verify that you will receive the product or service.

    at the secure.authorize.net page.
    The merchant gets a receipt…the buyer gets a receipt…so everything appears to be working except I receive no e-mail informing me of the error, no IPN response from gateway Server, and i cannot get to my receipt page. Please help…Please!!

  10. Md Emran Hasan (phpfour)

    Hi JP,

    I did a search on the net and it seems a few other people have faced similar error. One of them contacted authorize.net and here goes their response:

    “Greetings from Authorize.Net!

    When Authorize.Net is responding back to a script on your server our system waits 10 seconds for a response. If we do not get a response in 10 seconds, our server will time out and display an error page. In this case the customer will see the transaction results on an error page that Authorize.net generates.

    If this happens we will either send an email to you indicating: “An error occurred while trying to report this transaction to the merchant. An email has been sent to the merchant informing them of the error. The following is a result of the attempt to charge your credit card”

    or

    The transaction will be declined within your Merchant Interface. The transaction detail will display (Unable to send notification to Customer).

    If the customer closes the browser window before we receive data from your script to print to the screen we will change the transaction response reason code to 52.

    To prevent these errors the first thing that you will need to look for is the order that your script executes. It is very important that something is printed to the screen before any other process is started. If your script prints to the screen first, we will recognize that you have received the transaction results.

    To resolve this issue:
    - Before doing anything else start writing to your receipt page. For example: print your page headers and the first part of the page body.
    - Check that your script permissions are correct and that it can accept an HTTPS POST.
    - Check that the script is not completing other functions before writing to the screen, such as writing to a database or sending emails.
    - Please check to see if there are different processes that are used in your script for approvals, declines, or errors. Check each process to be sure that they will write to the screen before any other functions.
    - Verify that your script is not using redirects upon receipt of the response from our servers. Redirects strongly are discouraged because they can potentially interfere with the process.”

    I think you might as well get in touch with them. Let me know if it gets resolved.

    Thanks

  11. Pingback: Gildus» Blog Archive » Librería PHP para Paypal, Authorize.net y 2Checkout

  12. Shimon

    Yeah I thought I'll start working with your library last week but didn't happen even to set up anything yet… Got some important updates going on.

    Thank's though I'll monitor your page. I should be subscribed to your RSS too.

  13. Shimon

    I think that my comment was lost so I'll try again – sorry if double.

    In short I didn't get a chance to even look at the library yet although was planning to do so last week. I monitor your page and if you come up with something sooner that'll be cool. If i happen to finish my part first i'll send you my updates to see if that'll be helpful for you.

    Thanks

  14. Darrell Greenhouse

    Thanks from the U.S.

    Just starting to review your work, but I believe it will save me a load of time.

    Thanks again

  15. Jason Brooks

    I tried to integrate your PayPal functionality into my checkout system and entered the business account email into the place where you asked for the email. Nonetheless, when I try to submit the payment to PayPal I get the following error: “We cannot process this transaction because there is a problem with the PayPal email address supplied by the seller…” When I created the business acount it forced creation of a username, password and signature; but I noticed your code does not require that. Please help.

  16. Pingback: 20 librerías PHP para usar cada día | aNieto2K

  17. Rich Pedley

    I'm another one that would like to see google checkout added but I don't want standard level 1 integration – and can't use level 2. level 2 requires a secure server, level 1 doesn't – but also doesn't integrate with your site – at all. Well it can do – but so far they haven't written instructions for the api that can grab the results of transactions.

  18. Pingback: PHP Libraries You Need to Know | JigishThakar.com

  19. Pingback: bilmeniz gereken 20 harika php kütüphanesi |

  20. Pingback: Seyfullah KILIÇ » 20 Adet PHP Kütüphanesi

  21. Karl

    Great work and very simplistic too. Its also a good way for beginers to see what is actually going on due to the simple codeflow. I have modified your code and added forms with checkboxes, and stored all common variables to a flat config file and am currently expanding on your initial work to allow balance checking and periodical payment cycles. Also added a paypal recurring billing facillity last night and will look into 2co and authorize for the same, though I am unfamiliar with their process. Paypal recurring is easy by changing the payment type and adding the relevant variables to pass over to paypal.

    Google checkout would be among my wish list as would Nochex. Nochex is great for UK sellers like me, though it hard to work with.

    More on this soon as I may release it when finalized and 100% stable.

  22. Paul

    Great idea and thanks so much for putting it out there.

    Question:

    in the Paypal version you have:
    $myPaypal->addField('custom', 'muri-khao');

    How do we get that custom value back in the IPN?
    Because when someone has paid obiviously I want to update X but I dont see how to get that value back.

  23. Austin Mount

    Had to change your Paypal.php to enable multiple items…

    parent::__construct();

    // Some default values of the class

    $this->gatewayUrl = 'https://www.paypal.com/cgi-bin/webscr&#39;;

    $this->ipnLogFile = 'paypal.ipn_results.log';

    // Populate $fields array with a few default

    $this->addField('rm', '2'); // Return method = POST

    $this->addField('cmd', '_cart');
    $this->addField('upload', '1');

    }

    then when you add items just append _# to the tags with # being the line item you're working with
    nice base class for paypal with the skeleton in place… was a great starting point for what I'm working on…
    thanks for the great start

  24. muhit

    Downloaded and trying to finding out clues. But Till it sames really awesome.Hope soon we ll have it for clickbank and goodlcheckout as well. :)

  25. Ambassador

    Given an existing Authorize.net account, can a single static web page (i.e., no shopping cart, just one single web page) be made to complete an e-commerce transaction via Authorize.net's “Secure Hosted Payment Form” and the “Snippet 3″ code listed here? Is it really that easy? Is that all there is to it?

  26. quantro

    thanks man…
    goo job i need this, but for me this script just on the halfway…
    i must modded it to be used with zend framework

  27. Pingback: Rex’s Lucky Day » Blog Archive » 20ä¸ªä½ åº”è¯¥çŸ¥é“çš„PHP库

  28. Jack

    Thanks, its indeed helpful.

    Could you please shed me some light on how to echo the custom value in the success page?

    // Specify any custom value
    $myPaypal->addField('custom', 'muri-khao');

    I just want to let the customer see the custom value after he returns from PayPal to the success notification page. Thanks again!

  29. Jack

    Hasan,

    Could you please give us more details? Which file needs to be modified so that the $myPaypal->ipnData['custom'] can be shown to the customer. Thank you!

    Best regards,
    Jack

  30. Pingback: links for 2009-05-18 | NeXt

  31. jigish

    hey Emran its gr8 work….
    can you please provide me authorize.net developer account credentials..
    if yes then please mail it to me, if you don't want to post it here

    that will be gr8 help
    thanks, and thanks again for this amazing work

  32. vishal

    your code who processing the payment using paypal does not pass multiple items . so send the solution of it as well as possible.

    1. monggos

      …….

      $myPaypal->addField(‘cmd’, ‘_cart’);
      $myPaypal->addField(‘upload’, ’1′);

      ……

      // 1st product added..
      $myPaypal->addField(‘item_number_1′, ‘XXXX’);
      $myPaypal->addField(‘item_name_1′, ‘Product 1′);
      $myPaypal->addField(‘amount_1′, 10.00);
      $myPaypal->addField(‘quantity_1′, 2);

      // 2nd
      $myPaypal->addField(‘item_number_2′, ‘YYYY’);
      $myPaypal->addField(‘item_name_2′, ‘Product 2′);
      $myPaypal->addField(‘amount_2′, 50.00);
      $myPaypal->addField(‘quantity_1′, 2);

  33. francesco

    Thank you very much for this useful class, i spent a whole afternoon figuring out how to do it, and then you arrived! ;=)

    I am experiencing just one problem, i am testing paypal local with sandbox, text file for ipn isn't created, do you think it is because i am not over internet with my website?

    Thanks!

  34. ZMax

    Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/www/xxxxx/xxxxxx/Authorize.php on line 25

    please help me?

  35. cubanhenry5

    Hello Austin,

    I don't understand how send multiple items with this change … pls can you explain me with a very little code example.

    thanks

  36. Pingback: 红楼 » 20个非常有用的PHP类库

  37. Pingback: 转:20个非常有用的PHP类库 - 晨榕爱老婆

  38. Pingback: 五彩世界 » 20个非常有用的PHP类库

  39. Pingback: 20ä¸ªä½ åº”è¯¥çŸ¥é“çš„PHP库 at Await-等待!

  40. Pingback: Coleção de Bibliotecas PHP | Marlon Pacheco

  41. Pingback: Handpicked Handy PHP Libraries | MinhD.net

  42. Pingback: 20 Great PHP Libraries You Need to Know | King F1

  43. Pingback: Kumpulan Pustaka PHP

  44. Vipin

    Md Emran Hasan

    Nice Code.

    Can u tell me plz the way to use the code through mysite or send me the form? I m beginner in this things.

    Waiting for your favorable reply soon.

    Thanks in advance,

    Vipin

  45. Emran Hasan

    @Jessica: Sorry, this version does not have the multiple product feature. It will be added in the next version. Right now you can have a look at the paypal documentation and use the addField function to setup the form.

  46. Jessica

    Thank you Emran, really appreciate your help.

    I’ll really really appreciate if you could let me know when the new version will be available.

    Thanks Again !!!!

  47. Pingback: 20 Great PHP Libraries You Need to Know | Jason的小窝

  48. Pingback: PHP Pay­ment Library for Pay­pal, Authorize.net and 2Checkout (2CO) | Md Emran Hasan « $my->desperate["info"]

  49. mumo

    Thanks for the wonderful piece of work, i really appreciate it… I have one question though, how can i now use the information from the IPN test page… Eg. if the transaction was successful, then i need to capture that info on my website. In short, i can i modify the IPN page to complete the recording of the transaction on my site. I wish to record the amount paid and all other relevant transaction details. Thanks for your help… Am a bit new to this…

  50. andy

    Hai,

    When i am trying to using your script i am not able to redirecting to my site automatically

  51. Pingback: 20 Great PHP Libraries You Need to Know - Niknok Seyer

  52. Pingback: 20个PHP常用类库 - 0682071班主页

  53. Curious

    Thanks Emran,

    I’m curious – have you added the recurring option to the class?

    Keep up the great work and make sure you use your class with a donate option! ;-)
    I’m sure people here and future downloaders will donate for you to keep this up-to-date.

    thanks again!

  54. harmeet

    really excellent writing,carry on man n please tell when your new version will be released with multiple item enabled specially in authorize.net,i have done it in PayPal ,i need it urgently,please help
    Thanks in advance

  55. Steve

    I find your scripts useful. However, I’m having a few problems using the paypal script.

    I updated all of the information in the paypal_start.php file to the correct paths and correct paypal email.

    However, when I go to the Paypal.php file and turn test mode to FALSE it still directs me to the Sandbox gateway.

    Is there any additional information I need to change or anything else I need to customized to get this working on my server?

  56. Pingback: 40+ Must-Bookmark PHP Classes & Libraries For Developing Faster | Site Design Tips

  57. Pingback: 45+ Best free PHP classes and libraries for Faster Development - kamran Bhutto

  58. Pingback: 45 + Best free PHP classes and libraries for faster development | Technology Blog

  59. IanLindsay

    Hi Emran,

    First thank you very much for this class and is really helpful.

    1. When you are going to release version to support Recurring Payment for Paypal ?

    2. You have an example of custom field for Paypal :
    // Specify any custom value
    $myPaypal->addField(‘custom’, ‘muri-khao’);

    Can we get back this custom field in IPN something like below example ?
    if ($myPaypal->ipnData['payment_status'] == ‘Completed’) {
    $custom = $myPaypal->ipnData['custom'];
    }

  60. Pingback: PHP Helps | The Michaeldon Roareth! - Mad rantings of an undiscovered dinosaur

  61. Pingback: Webnova: Diseño web, Desarrollo web, Programación, Web Design Argentina, Web Development Argentina » Archivo del weblog » Librerías populares de PHP y algo mas…

  62. Tommy M.

    Love this script! Covering the 3 major online payment gateways in one script… brilliant. Are there any other updates going to be made to this script, and if so can you tell when?
    Thanks!

  63. Djane

    BTW, in authorize.net, the test mode in the code does not work when you are not using a developer’s account… i just want to share because i had a hard time with that..=)

  64. Midge

    Hi Emran.

    We have a 501(c)3 organization that has an account set up with PayPal for contributions. It’s the “standard” setup, i.e. click the button and it goes to PayPal.

    The head of our group saw a website that used PayPal, but they person visiting the website could enter an amount right there instead of being redirected.

    Do you know of any snippet like that? What are your thought on it. Would that be secure? If so, where do we get the snippet for that.

    Thanks, Emran. Great job!

  65. Sharique Maqbool

    Quite informative. But i m not successfully able to integrate 2CO using authorize.net parameters on my website. Any possible solution?

  66. Pingback: 20个非常有用的PHP类库 | <?php 齐☆辉?>

  67. Emran Hasan

    Hello all, thanks for your comments and I’m happy to be able to help you guys.

    I’ve planned to post updates on the payment script is in the following week with better code interface and stability.

    Thanks

  68. Pingback: 20个非常有用的PHP类库 @ 席瑞斌的博客

  69. Parvez

    Hello Emran vai,
    I’ve added a extra security layer on IPN testing, here is my code:
    /**———————————————-
    * Fraud detection system by Parvez Akther
    * first take all ip form paypal and paypal sandbox
    * then compare ip with posting script
    * if match then proceed next
    * if not match generate mail with possible cause
    *————————————————–*/
    // Get the list of IP addresses for http://www.paypal.com and notify.paypal.com
    $paypal_iplist = gethostbynamel(‘www.paypal.com’);
    $paypal_iplist2 = gethostbynamel(‘notify.paypal.com’);
    $paypal_iplist = array_merge( $paypal_iplist, $paypal_iplist2 );

    $paypal_sandbox_hostname = ‘ipn.sandbox.paypal.com’;
    $remote_hostname = gethostbyaddr( $_SERVER['REMOTE_ADDR'] );

    $valid_ip = false;

    if( $paypal_sandbox_hostname == $remote_hostname ) {
    $valid_ip = true;
    $hostname = ‘www.sandbox.paypal.com’;
    }
    else {
    $ips = “”;
    // Loop through all allowed IPs and test if the remote IP connected here
    // is a valid IP address
    foreach( $paypal_iplist as $ip ) {
    $ips .= “$ip,n”;
    $parts = explode( “.”, $ip );
    $first_three = $parts[0].”.”.$parts[1].”.”.$parts[2];
    if( preg_match(“/^$first_three/”, $_SERVER['REMOTE_ADDR']) ) {
    $valid_ip = true;
    }
    }
    $hostname = ‘www.paypal.com’;
    }
    if(!$valid_ip){
    $this->lastError(“Error code 506. Possible fraud. Error with REMOTE IP ADDRESS = “.$_SERVER['REMOTE_ADDR'].”.
    The remote address of the script posting to this notify script does not match a valid PayPal ip addressn” );
    }

    If it worth to add on ur script you can add it.

    Thanks

  70. Sajid Ali

    Hy Dear Emran.

    i have am very beginner programmer in php
    my boss assign me payment integration task

    i read you library and understand it little bit.
    i have created test account with 2co and i received verdor id.
    now how to use it and how to integrate it
    please help me if u can
    i will be very thank full to you.
    if u reffer me some link where i can understand payment integration.
    setp by step if posible thanks

  71. Pingback: 20个非常有用的PHP类库 | Wang Jun's Blog

  72. Warren

    Hi Emran,

    Thanks for the simple code, i tweeted it :)

    Do you have an article on how to configure the VAT info? I really haven’t had too much time to sift through all the stuff and i haven’t taken a guess at it yet, but im betting it’s pretty easy?

    Would it be ‘unethical’ to consider your full order as a single item with paypal? i.e Order 3012419 – $250.00. Instead of posting all cart items individually?

    Thanks again

  73. Sonal

    Hi emran
    thanks,nice script…
    but i have a problem in running this script in test mode
    i have an account on https://test.authorize.net/ and api login and transaction key which i use in your script but i dont know why its giving me error”(87) Transactions of this market type cannot be processed on this system.”;

    Can u plz tell me whats a prbl its urgent and i dont have any idea remain…
    i also try code got from authorize.net professional site giving me same error…
    if u have any idea plz reply me as soon as possible..
    Thanks in advances…

  74. Kortex

    In 2checkout example :

    // Specify the url where authorize.net will send the IPN
    $my2CO->addField(‘x_Receipt_Link_URL’, ‘http://YOUR_HOST/payment/twoco_ipn.php’);

    authorize.net ?? twoco_ipn.php ?

    see Snippet 5…

  75. Pingback: 北方小镇 › 20个非常有用的PHP类库

  76. Pingback: 好用的PHP库 - 功夫熊猫的博客

  77. Pingback: PHP编程中常用到的PHP类库 | iXHTML.com

  78. Pingback: 20个PHP编程中常用到的PHP类库 | 长春PHP培训

  79. Pingback: [Mark]20个非常有用的PHP类库 « 虚伪的灵魂

  80. Pingback: PHP常用类库集锦,快速提高你的web开发效率 | 忘川彼岸

  81. WF

    I just tried to download this (which looks awesome by the way) and the link is not there. The word DOWNLOAD is not a link…nor is the ZIP file name… Just wanted to let you know. Also, is there a new version of this or is this the latest? ALl the comments and activity is early 2009. THANKS!

  82. Pingback: Bilmeniz gereken 20 harika php kütüphanesi | Erken Rezervasyon 2011 | Erken Rezervasyon Tatil | Erken Rezervasyon Otel

  83. Nitin

    Hi Friends,

    Thanks Md Emran Hasan for this wonderful script.

    Here is my code for adding multiple items…

    Step1:
    in paypal.php

    replace
    $this->addField(‘cmd’, ‘_xclick’);

    with
    $this->addField(‘cmd’, ‘_cart’);
    $this->addField(‘upload’, ’1′);

    Step2
    in paypal_start.php , You can loop through the add item code in following format

    for(X=1;X=10;X++)
    {
    $myPaypal->addField(‘item_name_X’, ‘T-Shirt’);
    $myPaypal->addField(‘amount_X’, ’9.99′);
    $myPaypal->addField(‘quantity_X’, ’1′);
    $myPaypal->addField(‘item_number_X’, ’001′);
    }

    FYI: Please note _(underscore) its very important for sending data to paypal.

    that’s it you multiple item form is ready.

    I hope it helps someone…

    Cheers
    Nitin

  84. NB

    Hi Md!
    First of all, thanks to share your great work!

    I can see that you send the data to paypal through a simple html form, Don’t you think that is unsecure way to send the data? I could create an html file with false data and send it to paypal, How can I prevent this?

    Could you give me an advice?

    Thanks and sorry for my english (i’m not an native english speaker).

    NB from Argentina.

  85. reypapz

    I’m newbie on authorize.net and getting this error on

    URL: https://test.authorize.net/gateway/transact.dll
    Error: The following errors have occurred.
    (13) The merchant login ID or password is invalid or the account is inactive.

    can anybody help me on this.I checked already my status on authorize and its active.

    regards

  86. Pingback: PHP Needs Better Beginners | Malt Blue

  87. Pingback: 20 你应该知道的PHP库

  88. Pingback: 【转载】20 你应该知道的PHP库 « 脆皮沙发

  89. Pingback: PHP库收藏 » ForNote

  90. Pingback: As 45 Melhores Bibliotecas php para um desenvolvimento mais rápido ( em inglês ) | Codeworks - Artigos

  91. Ananta

    I want to know should o make any configure to payal.com before make online payment gateway intregreation

  92. Michelle

    Is it possible to create a standard html page for the Redirect
    PHP Payment Library for Paypal, Authorize.net and 2Checkout?

    I can see that it starts with a echo “n”; and ends with a echo “n”;
    So is it possible to create a custom html page and convert it so that it works in your library?

    kind regards
    Michelle

  93. Pingback: php常用类(class)汇总 经典收藏

  94. Joe

    It would have been helpful if you had provided us with the html form example too. As I need to research which custom values to use in order to submit the information.

  95. Pingback: 部分PHP常用类库 | 流水博客

  96. Pingback: PHP: risorse su PayPal | Gabriele Romanato

  97. Pingback: 菜博 » 20个非常有用的PHP类库

  98. Pingback: 20个你应该知道的PHP类库 – Yuansir-web菜鸟 | LAMP学习笔记

  99. Pingback: 20 个非常有用的PHP库 « 捡破烂的程序员

  100. Pingback: Anonymous

  101. Necimal

    I know this is quite an old script, but just thought I would point out that there is a security issue in the 2checkout library IPN code. You verify it against the vendor_number that was submitted, not the configured. Therefore as far as I can see an attacker could change the submitted vendor number to their own in the original request, and pay themselves (or whoever they like), and your library would be none the wiser, and still mark the order as paid.

  102. Pingback: 20 你应该知道的PHP库 - YaoLei's Blog

  103. Pingback: 20个PHP常用类库 | 倔强的石头

  104. Pingback: 20个PHP常用类库 | 外贸建站|外贸seo|seo技术

  105. Pingback: 20个PHP常用类库 | 网络大学

  106. Pingback: WEB编程技术交流网 » 20个PHP常用类库

  107. Pingback: 20个PHP常用类库 | Magento UI

  108. Pingback: 20 你应该知道的PHP库

  109. Warpenstein

    Hint: The paypal_ipn.php has to be accessible from the internet even if you just want to try out the library with the sandbox, or it won’t work. While paypal_success.php and paypal_failure.php are called by the customer’s browser, the paypal_ipn.php will be called by Paypal directly once the customer paid. Obviously the service cannot reach the script on your machine if you supply an url like http://localhost/

    Greetings from germany,
    Warpenstein

  110. Peter

    Unfortunately validateIpn() method is no longer working with the current PayPal IPN, so this library is useless for PayPal.

  111. James

    Hello!

    Thank you for a great library.
    I am just wondering how I can port this to Codeigniter? Have you already done it?

    Thanks!

  112. Ramlal Solanki

    Dear sir Your code us very excellent.
    I have a little problem during authorize.

    A415 Error 13: The merchant login ID or password is invalid or the account is inactive.

    I have add correct info in that variable
    $myAuthorize->setUserInfo(”, ”);

  113. Vishnu

    Hello Emran Hasan,
    Nice work man, can u help me how to use paypal payment in normal mode rather than in sandbox. please help me. thank you

  114. Pingback: PHP编程中常用到20个的PHP类库 | 博客水木

  115. soulreafer

    I have an other IPN Script. It should work but i cant convert it to work with this script.
    can someone help me to fix the IPN part?

    $value) {
    $value = urlencode(stripslashes($value));
    $req .= “&$key=$value”;
    }
    // post back to PayPal system to validate
    $header = “POST /cgi-bin/webscr HTTP/1.0rn”;
    $header .= “Content-Type: application/x-www-form-urlencodedrn”;
    $header .= “Content-Length: ” . strlen($req) . “rnrn”;

    $fp = fsockopen (‘ssl://www.sandbox.paypal.com’, 443, $errno, $errstr, 30);

    if (!$fp) {
    // HTTP ERROR
    } else {
    fputs ($fp, $header . $req);
    while (!feof($fp)) {
    $res = fgets ($fp, 1024);
    if (strcmp ($res, “VERIFIED”) == 0) {

    // PAYMENT VALIDATED & VERIFIED!

    $text = “jon”; // Dateiinhalt
    $dateiname = “daten.txt”; // Name der Datei
    // Datei öffnen,
    // wenn nicht vorhanden dann wird die Datei erstellt.
    $handler = fOpen($dateiname , “a+”);
    // Dateiinhalt in die Datei schreiben
    fWrite($handler , $fp);
    fClose($handler); // Datei schließen

    }

    else if (strcmp ($res, “INVALID”) == 0) {

    // PAYMENT INVALID & INVESTIGATE MANUALY!

    $text = “non”; // Dateiinhalt
    $dateiname = “daten.txt”; // Name der Datei
    // Datei öffnen,
    // wenn nicht vorhanden dann wird die Datei erstellt.
    $handler = fOpen($dateiname , “a+”);
    // Dateiinhalt in die Datei schreiben
    fWrite($handler , $text);
    fClose($handler); // Datei schließen

    }
    }
    fclose ($fp);
    }
    ?>

  116. Pingback: 20个非常有用的PHP类库 | alaxs的家园

  117. Pingback: 20 个非常有用的PHP库 | 侯三儿

  118. Pingback: 常用的一些PHP类库收集整理 - CodeBox

  119. Israel

    I applied some of the fixes above, made some embellishments, and fleshed out the Google class that was started at http://code.google.com/p/phppayment/ but not really completed.

    I only focused on implementing the Paypal and Google modules, so if you’re using one of the others, make sure changes to the PaymentGateway class aren’t getting in your way. First commit to the repository is the same as the original zip file on this site.

    Code is available at:

    https://bitbucket.org/greenhollowtech/emran-payment/overview

  120. David

    For the PayPal script it requires that a user creates an account before they can purchase something. Is it possible to make it so they can purchase as a guest?

  121. Pingback: PHP库总结 来自 – 酷壳 – CoolShell.cn | 侯三儿

  122. Pingback: PHP资源汇总:PHP编程中常用到的PHP类库 « PHP爱好者

  123. zeshi

    We cannot process this transaction because there is a problem with the PayPal email address supplied by the seller. Please contact the seller to resolve the problem. If this payment is for an eBay listing, you can contact the seller via the “Ask Seller a Question” link on the listing page. When you have the correct email address, payment can be made at http://www.paypal.com.

  124. Pingback: 20个非常有用的PHP类库 | 我心飞翔

  125. Pingback: 20个很有用的PHP类库 | Yii中文网

  126. Shofiq

    hello Emran Bhai,

    This is a nice library you have put here and thank you so much for this.

    im trying to make it as a joomla library and everything is working fine except after user making payment,its not auto redirecting to my website rather user has to press return to “Seller name” site to get back into the site again.

    Ive enabled auto return to true in paypal setting also but with no luck.

    could you please tell me if theres anything im missing ?

  127. craig

    I downloaded this from gitHub (https://github.com/phpfour/php-payment) and assume that that is the latest version…however there are no examples for using Auth.net. The title says PayPal, Auth.net, and 2CO…but I only see examples for PayPal and 2CO. Am i not looking at the latest version (please let me know updated link) or has nobody made an Auth.net example? Thanks!

  128. JeweL

    Hello Imaran Hasan Vaia,
    Maybe you changed any plugin that’s why i can’t see the download link of the library. would you please fix this article. Thanks