prestaPaypalPlugin - 0.0.2

Shortcut for Paypal API usage

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to the Plugins Home

Signin


Forgot your password?
Create an account

Tools

Stats

advanced search
Information Readme Releases Changelog Contribute
Show source

prestaPaypalPlugin

The prestaPaypalPlugin provides an easy way to integrate paypal on your website. The PHP Paypal's API: SOAP Interface is included. This plugin is largely inspired from sfPaypalDirectPlugin developped by Isaac Saldana.

Features

  • Express checkout
  • Direct payment
  • Website payment standard

License

The prestaPaypal plugin is licensed under the MIT License.

Installation

  • Install the plugin:

    $ symfony plugin:install prestaPaypalPlugin
    $ symfony cc

First

First of all, you must create a developer account for testing on the sandbox : https://developer.paypal.com/. Next step, generate your business account to recieve payements and user account to do payements.

The prestaPaypal constructor takes the path where you install Paypal's API. I don't recommend putting it on lib since you don't want it to be automatically loaded on every page view.

Direct Payment method

// Setup API's credentials
$cc = new prestaPaypal( sfConfig::get('sf_plugins_dir').DIRECTORY_SEPARATOR.'prestaPaypalPlugin'.DIRECTORY_SEPARATOR.'sdk'.DIRECTORY_SEPARATOR.'lib' );
 
// Your PayPal ID or an email address associated with your PayPal account. Email addresses must be confirmed.
$cc->setUserName(sfConfig::get('mod_registration_paypal_username'));
$cc->setPassword(sfConfig::get('mod_registration_paypal_password'));
// API signature
// How to get a signature ? https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_NVPAPIBasics
$cc->setSignature(sfConfig::get('mod_registration_paypal_signature'));
// Usefull in development environment
$cc->setTestMode(sfConfig::get('mod_registration_paypal_test'));
// Amount payement incl. taxes
$cc->setTransactionTotal($total);
// A description for the transaction
$cc->setTransactionDescription($desc);
 
// Client information :
$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']);
 
// Do payement
if ( !$cc->chargeDirect() )
{
    $error = $cc->getErrorString();
}
return $error;

Express Checkout

$cc = new prestaPaypal( sfConfig::get('sf_plugins_dir').DIRECTORY_SEPARATOR.'prestaPaypalPlugin'.DIRECTORY_SEPARATOR.'sdk'.DIRECTORY_SEPARATOR.'lib' );
 
// Setup API's credentials
// Your PayPal ID or an email address associated with your PayPal account. Email addresses must be confirmed.
$cc->setUserName(sfConfig::get('mod_registration_paypal_username'));
$cc->setPassword(sfConfig::get('mod_registration_paypal_password'));
// API signature
// How to get a signature ? https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_NVPAPIBasics
$cc->setSignature(sfConfig::get('mod_registration_paypal_signature'));
// Usefull in development environment
$cc->setTestMode(sfConfig::get('mod_registration_paypal_test'));
 
sfLoader::loadHelpers(array('Url'));
// A URL to which the payer's browser is redirected if payment is cancelled
$cc->setCancelURL(url_for('registration/cancelpaypal', true));
 
// The URL to which the payer's browser is redirected after completing the payment
$cc->setReturnURL(url_for('registration/chargepaypal', true));
 
// Amount payement incl. taxes
$cc->setTransactionTotal('39.95');
$cc->setTransactionDescription('Registration');
 
// The express url well-formed
$goto = $cc->GetExpressUrl();
if ( $goto )
{
        $this->redirect($goto);
}
else
{
        return $this->renderText('Error: ' . $cc->getErrorString());
}

Website payment standard

//paypal payment method
// We construct datas to send to paypal
$paypalData = array();
// _xclick, _donations, _cart, ...
$paypalData["cmd"]              = sfConfig::get('app_paypal_cmd');
// Your PayPal ID or an email address associated with your PayPal account. Email addresses must be confirmed.
$paypalData["business"]         = sfConfig::get('app_paypal_business');
// Name of the item or a name for the entire Shopping Cart
$paypalData["item_name"]        = $offer_label;
// Price of the item or the total price of all items in the shopping cart.
$paypalData["amount"]           = $offer_value;
// The cost of shipping this item
$paypalData["shipping"]         = 0;
// 0