prestaPaypalPlugin - 0.0.4

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'));
 
// Warning : you must be in an action method for this line
sfContext::getInstance()->getConfiguration()->loadHelpers('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 � prompt for an address, but do not require one
// 1 � do not prompt for an address
// 2 � prompt for an address, and require one
$paypalData["no_shipping"]      = 1;
// Passthrough variable never presented to the payer.
$paypalData["custom"]           = $id_invoice;
// The URL to which the payer's browser is redirected after completing the payment
$paypalData["return"]           = url_for('invoice/listInvoice', true);
// A URL to which the payer's browser is redirected if payment is cancelled
$paypalData["cancel_return"]    = url_for('invoice/cancelPaypal?id_invoice='.$this->o_order->getIdInvoiceSite(), true);
// The URL to which PayPal posts information about the transaction, in the form of Instant Payment Notification messages.
$paypalData["notify_url"]       = url_for('general/paypalNotify', true);
 
// Do not prompt payers to include a note with their payments
$paypalData["no_note"]          = '1';
// The currency of prices for trial periods and the subscription. The default is USD.
$paypalData["currency_code"]    = sfConfig::get('app_paypal_currency');
// Transaction-based tax override variable. 
// Set this to a flat tax amount to apply to the transaction regardless of the buyer's location. 
// This value overrides any tax settings set in your account profile. 
// Valid only for Buy Now and Add to Cart buttons. 
// Default � Profile tax settings, if any, apply.
$paypalData["tax"]              = _calc_montant_TVA( $this->o_order->getOfferValueHt(), $this->o_order->getTvaValue() );
// The language of the login or sign-up page that subscribers see when they click the Subscribe button
$paypalData["lc"]               = 'FR';
// Type of button. For example, PP-BuyNowBF.
$paypalData["bn"]               = sfConfig::get('app_paypal_bn');
// Host for payement.  For example, https://www.paypal.com/cgi-bin/webscr
$paypalData["host"]             = sfConfig::get('app_paypal_host'); 
// The picture used for the button. For example, https://www.paypal.com/fr_FR/FR/i/btn/btn_buynow_LG.gif
$paypalData["button"]           = sfConfig::get('app_paypal_button');
 
// Don't need to load paypal's api
$payment_form                   = new prestaPaypal();
$this->paypal_form              = $payment_form->getFormStandardPayment($paypalData);
 
// In <view>Success.php :
// echo $paypal_form->render();

HTML Variables for Website Payments Standard : here

Notices

The prestaPaypalPlugin use the PHP Paypal's API Version 4.3.7.

Changelog

2012-03-20 | 0.0.4-beta

  • Update plugin package.xml to allow installation for sf1.3/1.4
  • [trac ticket #17] improve README file for sf1.4+ use

2010-03-30 | 0.0.3-beta

  • Update plugin package.xml to allow installation for sf1.3/1.4