movie rental service

New Symfony sfPaypalDirectPlugin Contribution

April 24, 2007 – 1:28 am

After having the joy of writing ThemBid.com using Symfony we decided it was time to make a contribution.  We have released a new version of a plugin to support Paypal’s Website Payment Pro.  I developed it with flexibility in mind so if you take the class file in the tar file, it can be used with any other system since the class itself doesn’t have any Symfony specific stuff.  The link to the plugin’s page is located here.

  1. 21 Responses to “New Symfony sfPaypalDirectPlugin Contribution”

  2. I’m not able to get your plugin to work. Not sure if you could elaborate on anything more, but what version of the paypal sdk are you using? I have the paypal PHP NVP samples working fine with my api key, etc..

    By joe on May 3, 2007

  3. Hi Joe,
    I am using PayPal_PHP_SDK_v4_3_0. This is what I did to install it:

    1) Download and extract
    https://www.paypal.com/IntegrationCenter/sdk/PayPal_PHP_SDK_v4_3_0.tar.gz

    2) I moved the php-sdk/lib directory to my project data directory at data/PayPal. Please note that data/PayPal did not exist so ph-sdk/lib got renamed to data/PayPal

    $ ls data/PayPal
    HTTP  Log  Log.php  Multi.php  Net  PayPal  PayPal.php
    
    $ ls php-sdk/lib/
    HTTP  Log  Log.php  Multi.php  Net  PayPal  PayPal.php
    

    3) Then I create the constructor like this:

    $cc = new sfPaypalDirect(sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'PayPal');
    

    Please let me know if that helps.

    By isaldana on May 3, 2007

  4. Hey isaldana,
    Ok, it’s good to know that I had it setup somewhat correctly. I realized I was passing the ‘credit card number’ just as ” and it’s not passing back an error, saying this in invalid. On this note, how is the error reporting? I know this plugin is very early in it’s development, and definately like what I see so far!

    Also, I’m not sure how much you’ve done with the PayPal’s API.. but I have another question (maybe a little off-subject..), do you know if it’s possible to store a user’s billing information with paypal when they sign up, and to maybe just store like a “third_party_token_id” thing to charge that user’s account?

    Thanks for the quick response!
    Joe

    By joe on May 3, 2007

  5. Hi Joe,

    You can do something like:

    if ( !$cc->chargeDirect() )
    {
        $this->error = $cc->getErrorString();
    }
    

    You can then display the $error variable in your template. The error is what PayPal’s API gives, so it tells you exactly what the error is such as missing credit card number, expiration dates, etc.

    If you are using Express Checkout, after you call:

    $cc->chargeExpressCheckout($this->getRequestParameter('token'));
    

    you can call $cc->getBillingFirstName(), $cc->getBillingEmail(), etc. to get the data that Paypal returned about the buyer.

    I know you cannot store credit card number information on your server but address and email I dont see a problem.

    By isaldana on May 3, 2007

  6. Hey again,
    I have my $error variable being set as you mentioned. It’s not reporting properly, atleast in the test mode. ‘$cc->getErrorString’ doesn’t catch any errors, if the ‘credit card number’ is blank / invalid. However, it does catch an error if the ‘credit card type’ isn’t passed.. ? So, I have $error atleast being set, so I can post a generic error of “Invalid Credit Card”..

    if(!$cc->chargeDirect()){
    $error = $cc->getErrorString();
    // set $error to not empty
    $error .=” “;
    }
    return $error;

    Also, I changed ‘$this->api_action’ to ‘Authorization’, not ‘Authorize’.. this works atleast for the sandbox / testing mode..

    private function setActionAuthorize()
    {
    // $this->api_action = ‘Authorize’;
    $this->api_action = ‘Authorization’;
    }

    By joe on May 7, 2007

  7. Hey Joe,
    If I specify a blank credit card I get the following error:

    This transaction cannot be processed. Please enter a valid credit card number and type.

    I have the following code:

      private function charge_cc($desc, $total)
      {
      	$error = '';
      	$cc = new sfPaypalDirect(sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'PayPal');
    
      	$cc->setUserName(sfConfig::get('mod_registration_paypal_username'));
      	$cc->setPassword(sfConfig::get('mod_registration_paypal_password'));
      	$cc->setSignature(sfConfig::get('mod_registration_paypal_signature'));
      	$cc->setTestMode(sfConfig::get('mod_registration_paypal_test'));
    
      	$cc->setTransactionTotal($total);
      	$cc->setTransactionDescription($desc);
    
      	$cc->setBillingFirstName($this->getRequestParameter('firstname'));
      	$cc->setBillingLastName($this->getRequestParameter('lastname'));
    	$cc->setBillingStreet1($this->getRequestParameter('address'));
    	$cc->setBillingStreet2($this->getRequestParameter('address2'));
      	$cc->setBillingCity($this->getRequestParameter('city'));
      	$cc->setBillingState($this->getRequestParameter('state'));
      	$cc->setBillingZip($this->getRequestParameter('zip'));
    
      	$cc->setCardType($this->getRequestParameter('cctype'));
      	$cc->setCardNumber($this->getRequestParameter('cc'));
      	$cc->setCardVerificationNumber($this->getRequestParameter('ccv'));
      	$cc->setCardExpirationMonth($this->getRequestParameter('expmonth'));
      	$cc->setCardExpirationYear($this->getRequestParameter('expyear'));
      	$cc->setBuyerIP($_SERVER['REMOTE_ADDR']);
    
      	if ( !$cc->chargeDirect() )
      	{
      		$error = $cc->getErrorString();
      	}
    	return $error;
      }
    

    Thanks for the patch. I have confirmed it and will be uploading the change to Symfony’s site soon. Thanks!!!

    By isaldana on May 7, 2007

  8. Ok, sorry about that first issue I spoke of - I was received that error because I was sending the Credit Card Type as “Mastercard” not “MasterCard”. It’s perfect now. I just got it working on Paypal’s Live site. :)

    My next issue is figuring out how charge users, without re-entering their credit card information. The express checkout stuff isn’t feasible, because I don’t want users going off to paypal.com.

    I know it’s illegal to store their CC info, but any idea on how other companies rebill your account? Are those companies just allowed to store their CC info?

    By joe on May 9, 2007

  9. The way we’ve done it in the past is to send the user an email letting them know their subscription expired and a link to renew. If you want recurring payments so you can trigger them after the subscription expires you need to use Payflow Pro but its much more expensive.

    By isaldana on May 9, 2007

  10. Some suggestions:
    - Import the project to symfony svn
    - Include the paypal SDK in the plugin package
    - Set sandbox/live through symfony yaml files

    Nice plugin…

    By Rimenes Ribeiro on May 16, 2007

  11. Hello.

    I try to use t\your plugin and gets the error “Security header is not valid”.
    I think that it’s because my preferences.

    Can you please explain what values can be ‘mod_registration_paypal_signature’ and ‘mod_registration_paypal_test’. Also i have no found any variables to set up certificate file.

    By Stanislav on Jul 25, 2007

  12. I am having a heck of a time getting this to work. Using the sample SOAP SDK from Paypal works without a hitch. Using the “To use the Direct Payment method you can do something like the following:” section found on http://trac.symfony-project.com/trac/wiki/sfPaypalDirectPlugin as a starting place.

    Here is my actions.class.conf

    error = $this->charge_cc(’Membership fee’, ‘6′);
    }

    private function charge_cc($desc, $total)
    {
    $error = ”;
    $cc = new sfPaypalDirect(sfConfig::get(’sf_data_dir’).DIRECTORY_SEPARATOR.’PayPal’);
    // Setup API’s credentials
    $cc->setUserName(’paypal_api1.xxxxxx’);
    $cc->setPassword(’XXXXXXX’);
    $cc->setSignature(’XXXXXXX’);
    $cc->setTestMode(’false’);

    $cc->setTransactionTotal(’5.00′);
    $cc->setTransactionDescription(’test’);

    $cc->setBillingFirstName(’Kevin’);
    $cc->setBillingLastName(’XXXXX’);
    $cc->setBillingStreet1(’My Real Address’);
    $cc->setBillingStreet2(”);
    $cc->setBillingCity(’My Real City’);
    $cc->setBillingState(’XX’);
    $cc->setBillingZip(’XXXXX’);

    $cc->setCardType(’visa’);
    $cc->setCardNumber(’My Real CC Number’);
    $cc->setCardVerificationNumber(’My Real Verification Number’);
    $cc->setCardExpirationMonth(’My Real Expiration Month’);
    $cc->setCardExpirationYear(’My Real Expiration Year’);
    //$cc->setBuyerIP(’192.168.1.1′);

    if ( !$cc->chargeDirect() )
    {
    $error = $cc->getErrorString();
    }
    return $error;
    }
    }

    By Kevin on Aug 10, 2007

  13. Does this plugin work for the UK as well?

    By Eric on Sep 6, 2007

  14. Does your plugin support IPN ? If not, how can I add this support ?

    By leroy on Sep 6, 2007

  15. @Eric
    It should. You can use the setBillingCountry() function to set your billing country.

    By isaldana on Sep 7, 2007

  16. @leroy

    I think IPN is similar to express checkout is. Paypal sends you a token then you retrieve the information. I will look into and add support in the near future.

    By isaldana on Sep 7, 2007

  17. Ok, I’ve another question: the only possible currency is USD, because it hard codered in source code?

    $BasicAmountType->setattr(’currencyID’, ‘USD’);

    This is not too hard to add the opportunity to set another currency.

    By leroy on Sep 8, 2007

  18. Hello,

    on chargeDirect() method, my screen went blank at line $BasicAmountType =& PayPal::getType(’BasicAmountType’);

    I was already had a try and catch block but it still doesnt give me any error message. Do you know what went wrong with PayPal::getType(’BasicAmountType’)????

    thanks

    By David Dinh on Dec 7, 2007

  19. How would I setup subscription/recurring charge?

    Thanks,
    Hemant

    By Hemant on Feb 8, 2008

  20. hello,

    thanks for your helpfull plugin

    i have a question about this
    the plugin sends you to a paypal page where you havte to login or create an account
    is there a solution to integrate in the plugin to let the user pay without account ?

    thanks !

    By Francois on Feb 12, 2008

  21. here is sense to use
    $this->getController()->genUrl(’registration/cancelpaypal’, true)
    instead
    url_for(’registration/cancelpaypal’, true)
    in action.
    at this way you don’t need to load helper

    By Ivan Zgoniaiko on Jun 18, 2008

  22. A STRANGE THING…..

    $cc = new sfPaypalDirect(sfConfig::get(’sf_data_dir’).DIRECTORY_SEPARATOR.’PayPal’);

    This look having a problem: it’s not ’sf_data_dir’ but sf_symfony_data_dir.

    By changing that, it works, when it didn’t worked with ’sf_data_dir’.

    Julien

    By julien on Jun 25, 2008

Post a Comment