SlideShare a Scribd company logo
Paypal + symfony payments made simple Massimiliano Arione September, 27th 2011
About me 2001: PHP developer 2006: GrUSP member 2009: member of GrUSP steering committee  2010: PUG Rome president :-)
the flow my server Paypal server
the REAL flow my server Paypal server
plugins sfPaymentPlugin sfPaymentPayPalPlugin sfWebBrowserPlugin
configuration # apps/frontend/config/app.yml all :    sf_payment_paypal_plugin :      business :      pay@garak.it      test :        business :    pippo_12636_biz@gmail.com      return :        @paypal_paid      cancel_return : @paypal_cancelled      notify :        @paypal_ipn
Model // lib/model/Purchase.class.php public function getTransaction() {   $ gateway  = new sfPaymentPayPal();   $gateway->fields['no_shipping'] = 1;   $gateway->fields['item_number'] = $this->getId();   $ transaction  = new sfPaymentTransaction($ gateway );   if (sfConfig::get('sf_environment') != 'prod')   {     $ transaction ->enableTestMode();   }   $ transaction ->setAmount($this->getPrice());   $ transaction ->setCurrency('EUR');   $ transaction ->setProductName($this->getName());      return $ transaction ; }
Controller // apps/frontend/modules/my_module/actions/actions.class.php public function executeBuy() {   $purchase = new Purchase;    $this-> transaction  = $purchase->getTransaction(); }
View // apps/frontend/modules/my_module/templates/buySuccess.php      <form method=&quot;post&quot; action=&quot;<?php echo $ transaction ->getGateway()->gatewayUrl ?>&quot;>   <input type=&quot;submit&quot; value=&quot;pay&quot; />   <?php foreach ($ transaction ->getGateway()->fields as $fname => $fvalue): ?>   <input type=&quot;hidden&quot; name=&quot;<?php echo $fname ?>&quot; value=&quot;<?php echo $fvalue ?>&quot; />   <?php endforeach ?> </form>
IPN controller // apps/frontend/modules/paypal/actions/actions.class.php public function executeIpn(sfWebRequest $request) {   $gateway = new sfPaymentPayPal();   $ transaction  = new sfPaymentTransaction($gateway);   if (sfConfig::get('sf_environment') != 'prod') $ transaction ->enableTestMode();   if ($ transaction ->validateIpn($request->getPostParameters()))   {     $purchase = PurchaseTable::getInstance()->find($request->getParameter('item_number'));     $this->forward404Unless($purchase, 'purchase not found');     if (!$purchase->isComplete())     {       if ($ transaction ->isCompleted()) $purchase->setComplete($request->getParameter('txn_id'));       else $purchase->setIncomplete();     }   }   else    {       $purchase->setInvalid();    }   return sfView::NONE; }
Thanks! Massimiliano Arione @ garakkio blog.garak.it

More Related Content

PDF
Open expo Novembre 2014
PPT
Perl gui
PDF
BDD revolution - or how we came back from hell
PPT
symfony & jQuery (phpDay)
PPTX
From Node.js noob to not so noob
PPTX
NationJS: Node Noob to not so Noob
PDF
How to Sell ANYTHING with WordPress + WooCommerce
PDF
10 PHP Snippets to Increase WooCommerce Sales
Open expo Novembre 2014
Perl gui
BDD revolution - or how we came back from hell
symfony & jQuery (phpDay)
From Node.js noob to not so noob
NationJS: Node Noob to not so Noob
How to Sell ANYTHING with WordPress + WooCommerce
10 PHP Snippets to Increase WooCommerce Sales

What's hot (17)

PDF
Elegant Error-Handling for a More Civilized Age
PDF
Mojolicious
PPT
Oop php 5
PDF
JAVASCRIPT NÃO-OBSTRUTIVO com jQuery
PPTX
Html hacking - when javascript is just not good enough
PDF
WordPress: From Antispambot to Zeroize
PDF
Cloud Entwicklung mit Apex
PDF
Payments On Rails
PPTX
Rajashekaran vengalil building cross browser html5 websites
PDF
Daily Deals from Buy.com
PPTX
Testing ASP.net Web Applications using Ruby
PDF
Gravity Forms Hooks & Filters
ODP
An overview of Domain Specific Languages in PHP
PDF
Stripe on Atmoph
PDF
Let jQuery Rock Your World
PDF
Pluginが広げるRailsの魅力
PPT
Introduction to turbo c
Elegant Error-Handling for a More Civilized Age
Mojolicious
Oop php 5
JAVASCRIPT NÃO-OBSTRUTIVO com jQuery
Html hacking - when javascript is just not good enough
WordPress: From Antispambot to Zeroize
Cloud Entwicklung mit Apex
Payments On Rails
Rajashekaran vengalil building cross browser html5 websites
Daily Deals from Buy.com
Testing ASP.net Web Applications using Ruby
Gravity Forms Hooks & Filters
An overview of Domain Specific Languages in PHP
Stripe on Atmoph
Let jQuery Rock Your World
Pluginが広げるRailsの魅力
Introduction to turbo c
Ad

Similar to Paypal + symfony (20)

PPT
symfony & jQuery (PUG)
PPT
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
PDF
Curso Symfony - Clase 4
ODP
The Basics Of Page Creation
ODP
Разработка приложений для Android Honeycomb: ActionBar & Fragments
ODP
Zend Form Tutorial
PPTX
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
ODP
State Machines to State of the Art
PPT
Smarter Interfaces with jQuery (and Drupal)
PPT
Os Nixon
PPT
Ajax Applications with RichFaces and JSF 2
PDF
Rugalytics | Ruby Manor Nov 2008
PPT
WordPress Standardized Loop API
PDF
Building Web Interface On Rails
PPT
Php Crash Course
PDF
Rails 3 And The Real Secret To High Productivity Presentation
PPT
Liferay Training Struts Portlet
PDF
HTML::FormFu talk for Sydney PM
ODP
HTML::FormHandler
PPTX
Chekout demistified
symfony & jQuery (PUG)
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
Curso Symfony - Clase 4
The Basics Of Page Creation
Разработка приложений для Android Honeycomb: ActionBar & Fragments
Zend Form Tutorial
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
State Machines to State of the Art
Smarter Interfaces with jQuery (and Drupal)
Os Nixon
Ajax Applications with RichFaces and JSF 2
Rugalytics | Ruby Manor Nov 2008
WordPress Standardized Loop API
Building Web Interface On Rails
Php Crash Course
Rails 3 And The Real Secret To High Productivity Presentation
Liferay Training Struts Portlet
HTML::FormFu talk for Sydney PM
HTML::FormHandler
Chekout demistified
Ad

More from Massimiliano Arione (20)

PDF
Typed models pug roma febbraio 2020
PPTX
Pipelines!
PDF
Il nostro amico Stan
PDF
PSR7 - interoperabilità HTTP
PDF
Disinstallare fos user bundle e vivere felici
PDF
MAGA - PUG Roma giugno 2017
PDF
PHP7 e Rich Domain Model
PDF
PHP on the desktop
PDF
Scrivere e leggere log con elastic
PDF
The metrics
PDF
Managing frontend libs in your Symfony project
PDF
Translating symfony docs
PDF
Managing frontend libs in your php project
PDF
Gestire librerie di frontend in php
PDF
PHP, non lo stesso vecchio linguaggio
PDF
Gestione delle dipendenze con Composer
PDF
Migrare da symfony 1 a Symfony2
PDF
Case study OmniAuto.it
ODP
Symfony: un framework per il web
ODP
Sviluppo rapido di applicazioni con PHP
Typed models pug roma febbraio 2020
Pipelines!
Il nostro amico Stan
PSR7 - interoperabilità HTTP
Disinstallare fos user bundle e vivere felici
MAGA - PUG Roma giugno 2017
PHP7 e Rich Domain Model
PHP on the desktop
Scrivere e leggere log con elastic
The metrics
Managing frontend libs in your Symfony project
Translating symfony docs
Managing frontend libs in your php project
Gestire librerie di frontend in php
PHP, non lo stesso vecchio linguaggio
Gestione delle dipendenze con Composer
Migrare da symfony 1 a Symfony2
Case study OmniAuto.it
Symfony: un framework per il web
Sviluppo rapido di applicazioni con PHP

Recently uploaded (20)

PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Big Data Technologies - Introduction.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Spectroscopy.pptx food analysis technology
PPT
Teaching material agriculture food technology
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Spectral efficient network and resource selection model in 5G networks
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
“AI and Expert System Decision Support & Business Intelligence Systems”
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Digital-Transformation-Roadmap-for-Companies.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Big Data Technologies - Introduction.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Chapter 3 Spatial Domain Image Processing.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Reach Out and Touch Someone: Haptics and Empathic Computing
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Machine learning based COVID-19 study performance prediction
Spectroscopy.pptx food analysis technology
Teaching material agriculture food technology
Encapsulation_ Review paper, used for researhc scholars
Spectral efficient network and resource selection model in 5G networks

Paypal + symfony

  • 1. Paypal + symfony payments made simple Massimiliano Arione September, 27th 2011
  • 2. About me 2001: PHP developer 2006: GrUSP member 2009: member of GrUSP steering committee 2010: PUG Rome president :-)
  • 3. the flow my server Paypal server
  • 4. the REAL flow my server Paypal server
  • 6. configuration # apps/frontend/config/app.yml all :   sf_payment_paypal_plugin :     business :      pay@garak.it     test :       business :    pippo_12636_biz@gmail.com     return :        @paypal_paid     cancel_return : @paypal_cancelled     notify :        @paypal_ipn
  • 7. Model // lib/model/Purchase.class.php public function getTransaction() {   $ gateway = new sfPaymentPayPal();   $gateway->fields['no_shipping'] = 1;   $gateway->fields['item_number'] = $this->getId();   $ transaction = new sfPaymentTransaction($ gateway );   if (sfConfig::get('sf_environment') != 'prod')   {     $ transaction ->enableTestMode();   }   $ transaction ->setAmount($this->getPrice());   $ transaction ->setCurrency('EUR');   $ transaction ->setProductName($this->getName());     return $ transaction ; }
  • 8. Controller // apps/frontend/modules/my_module/actions/actions.class.php public function executeBuy() {   $purchase = new Purchase;   $this-> transaction = $purchase->getTransaction(); }
  • 9. View // apps/frontend/modules/my_module/templates/buySuccess.php     <form method=&quot;post&quot; action=&quot;<?php echo $ transaction ->getGateway()->gatewayUrl ?>&quot;>   <input type=&quot;submit&quot; value=&quot;pay&quot; />   <?php foreach ($ transaction ->getGateway()->fields as $fname => $fvalue): ?>   <input type=&quot;hidden&quot; name=&quot;<?php echo $fname ?>&quot; value=&quot;<?php echo $fvalue ?>&quot; />   <?php endforeach ?> </form>
  • 10. IPN controller // apps/frontend/modules/paypal/actions/actions.class.php public function executeIpn(sfWebRequest $request) {   $gateway = new sfPaymentPayPal();   $ transaction = new sfPaymentTransaction($gateway);   if (sfConfig::get('sf_environment') != 'prod') $ transaction ->enableTestMode();   if ($ transaction ->validateIpn($request->getPostParameters()))   {     $purchase = PurchaseTable::getInstance()->find($request->getParameter('item_number'));     $this->forward404Unless($purchase, 'purchase not found');     if (!$purchase->isComplete())     {       if ($ transaction ->isCompleted()) $purchase->setComplete($request->getParameter('txn_id'));       else $purchase->setIncomplete();     }   }   else   {     $purchase->setInvalid();   }   return sfView::NONE; }
  • 11. Thanks! Massimiliano Arione @ garakkio blog.garak.it

Editor's Notes

  • #4: questo è il tipico flusso di un pagamento con Paypal, almeno dal punto di vista dell&apos;utente
  • #5: dal nostro punto di vista, quello dello sviluppatore, c&apos;è un fattore in più: abbiamo bisogno di fare una &amp;quot;conversazione&amp;quot; server2server con Paypal per utilizzare l&apos;IPN (Instant Payment Notification), che ci consente di sapere se l&apos;utente ha pagato, senza aspettare che torni sul nostro sito (dove potrebbe anche non tornare, dopo il pagamento)
  • #6: questi sono i 3 plugin che abbiamo bisogno di installare
  • #7: questa è la semplice configurazione che dobbiamo inserire in app.yml I valori vanno ovviamente adattati col proprio account di Paypal (sia quello vero che quello di sandbox). Le 3 rotte vanno definite, ovviamente con nomi a piacere.
  • #8: Sarebbe bene definire un modello in cui memorizzare anche nel nostro server le transazioni di Paypal, magari con un riferimento all&apos;ID della transazione di Paypal stesso. In questo esempio ho chiamato il modello &amp;quot;Purchase&amp;quot;. Questo metodo serve per ottenere un oggetto sfPaymentTransaction
  • #9: Nel controllore istanzio Purchase e ottengo l&apos;oggetto per la transazione
  • #10: La vista è molto semplice, l&apos;unica personalizzazione possibile è l&apos;etichetta del pulsante
  • #11: Questo è il cuore del funzioonamento: l&apos;azione a cui corrisponde la rotta @paypal_ipn vista prima. Qui gestiamo l&apos;interazione col server di Paypal e memorizziamo il risultato nel nostro modello Purchase.
  • #12: È tutto qui! Visto come è facile? :-)