Paypal + symfony

Massimiliano Arione
Massimiliano ArionePHP developer at freelance
Paypal + symfony payments made simple Massimiliano Arione September, 27th 2011
About me ,[object Object],[object Object],[object Object],[object Object]
the flow my server Paypal server
the REAL flow my server Paypal server
plugins ,[object Object],[object Object],[object Object]
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
1 of 11

Recommended

Open expo Novembre 2014 by
Open expo Novembre 2014Open expo Novembre 2014
Open expo Novembre 2014manuraynaud
230 views14 slides
Perl gui by
Perl guiPerl gui
Perl guiumnix
681 views16 slides
BDD revolution - or how we came back from hell by
BDD revolution - or how we came back from hellBDD revolution - or how we came back from hell
BDD revolution - or how we came back from hellMateusz Zalewski
113 views34 slides
symfony & jQuery (phpDay) by
symfony & jQuery (phpDay)symfony & jQuery (phpDay)
symfony & jQuery (phpDay)Massimiliano Arione
1.2K views25 slides
From Node.js noob to not so noob by
From Node.js noob to not so noobFrom Node.js noob to not so noob
From Node.js noob to not so noobreybango
1.1K views63 slides
NationJS: Node Noob to not so Noob by
NationJS: Node Noob to not so Noob NationJS: Node Noob to not so Noob
NationJS: Node Noob to not so Noob reybango
1.1K views53 slides

More Related Content

What's hot

Elegant Error-Handling for a More Civilized Age by
Elegant Error-Handling for a More Civilized AgeElegant Error-Handling for a More Civilized Age
Elegant Error-Handling for a More Civilized AgeVarun Sharma
682 views24 slides
Mojolicious by
MojoliciousMojolicious
MojoliciousLenz Gschwendtner
963 views24 slides
Oop php 5 by
Oop php 5Oop php 5
Oop php 5phpubl
759 views18 slides
JAVASCRIPT NÃO-OBSTRUTIVO com jQuery by
JAVASCRIPT NÃO-OBSTRUTIVO com jQueryJAVASCRIPT NÃO-OBSTRUTIVO com jQuery
JAVASCRIPT NÃO-OBSTRUTIVO com jQueryZigotto Tecnologia
381 views17 slides
Html hacking - when javascript is just not good enough by
Html hacking - when javascript is just not good enoughHtml hacking - when javascript is just not good enough
Html hacking - when javascript is just not good enoughEoin Keary
486 views7 slides
WordPress: From Antispambot to Zeroize by
WordPress: From Antispambot to ZeroizeWordPress: From Antispambot to Zeroize
WordPress: From Antispambot to ZeroizeYoav Farhi
787 views21 slides

What's hot(18)

Elegant Error-Handling for a More Civilized Age by Varun Sharma
Elegant Error-Handling for a More Civilized AgeElegant Error-Handling for a More Civilized Age
Elegant Error-Handling for a More Civilized Age
Varun Sharma682 views
Oop php 5 by phpubl
Oop php 5Oop php 5
Oop php 5
phpubl759 views
Html hacking - when javascript is just not good enough by Eoin Keary
Html hacking - when javascript is just not good enoughHtml hacking - when javascript is just not good enough
Html hacking - when javascript is just not good enough
Eoin Keary486 views
WordPress: From Antispambot to Zeroize by Yoav Farhi
WordPress: From Antispambot to ZeroizeWordPress: From Antispambot to Zeroize
WordPress: From Antispambot to Zeroize
Yoav Farhi787 views
Cloud Entwicklung mit Apex by Aptly GmbH
Cloud Entwicklung mit ApexCloud Entwicklung mit Apex
Cloud Entwicklung mit Apex
Aptly GmbH429 views
Rajashekaran vengalil building cross browser html5 websites by suniltomar04
Rajashekaran vengalil building cross browser html5 websitesRajashekaran vengalil building cross browser html5 websites
Rajashekaran vengalil building cross browser html5 websites
suniltomar04249 views
Daily Deals from Buy.com by drocallaghan
Daily Deals from Buy.comDaily Deals from Buy.com
Daily Deals from Buy.com
drocallaghan21 views
Testing ASP.net Web Applications using Ruby by Ben Hall
Testing ASP.net Web Applications using RubyTesting ASP.net Web Applications using Ruby
Testing ASP.net Web Applications using Ruby
Ben Hall2.2K views
Gravity Forms Hooks & Filters by iamdangavin
Gravity Forms Hooks & FiltersGravity Forms Hooks & Filters
Gravity Forms Hooks & Filters
iamdangavin6K views
An overview of Domain Specific Languages in PHP by troelskn
An overview of Domain Specific Languages in PHPAn overview of Domain Specific Languages in PHP
An overview of Domain Specific Languages in PHP
troelskn5.3K views
Let jQuery Rock Your World by Matt Gifford
Let jQuery Rock Your WorldLet jQuery Rock Your World
Let jQuery Rock Your World
Matt Gifford5.1K views
Pluginが広げるRailsの魅力 by Yoji Shidara
Pluginが広げるRailsの魅力Pluginが広げるRailsの魅力
Pluginが広げるRailsの魅力
Yoji Shidara2.1K views

Similar to Paypal + symfony

symfony & jQuery (PUG) by
symfony & jQuery (PUG)symfony & jQuery (PUG)
symfony & jQuery (PUG)Massimiliano Arione
703 views19 slides
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I... by
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...Kirill Chebunin
751 views29 slides
Curso Symfony - Clase 4 by
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4Javier Eguiluz
2.1K views89 slides
The Basics Of Page Creation by
The Basics Of Page CreationThe Basics Of Page Creation
The Basics Of Page CreationWildan Maulana
473 views18 slides
Разработка приложений для Android Honeycomb: ActionBar & Fragments by
Разработка приложений для Android Honeycomb: ActionBar & FragmentsРазработка приложений для Android Honeycomb: ActionBar & Fragments
Разработка приложений для Android Honeycomb: ActionBar & FragmentsAlexey Ustenko
1.4K views25 slides
Zend Form Tutorial by
Zend Form TutorialZend Form Tutorial
Zend Form TutorialMichelangelo van Dam
6.7K views29 slides

Similar to Paypal + symfony(20)

ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I... by Kirill Chebunin
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
Kirill Chebunin751 views
Разработка приложений для Android Honeycomb: ActionBar & Fragments by Alexey Ustenko
Разработка приложений для Android Honeycomb: ActionBar & FragmentsРазработка приложений для Android Honeycomb: ActionBar & Fragments
Разработка приложений для Android Honeycomb: ActionBar & Fragments
Alexey Ustenko1.4K views
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009) by Michael Wales
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Michael Wales1.3K views
State Machines to State of the Art by Rowan Merewood
State Machines to State of the ArtState Machines to State of the Art
State Machines to State of the Art
Rowan Merewood3.8K views
Smarter Interfaces with jQuery (and Drupal) by aasarava
Smarter Interfaces with jQuery (and Drupal)Smarter Interfaces with jQuery (and Drupal)
Smarter Interfaces with jQuery (and Drupal)
aasarava3.6K views
Os Nixon by oscon2007
Os NixonOs Nixon
Os Nixon
oscon2007406 views
Using Geeklog as a Web Application Framework by Dirk Haun
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
Dirk Haun894 views
Ajax Applications with RichFaces and JSF 2 by Max Katz
Ajax Applications with RichFaces and JSF 2Ajax Applications with RichFaces and JSF 2
Ajax Applications with RichFaces and JSF 2
Max Katz3.1K views
Rugalytics | Ruby Manor Nov 2008 by Rob
Rugalytics | Ruby Manor Nov 2008Rugalytics | Ruby Manor Nov 2008
Rugalytics | Ruby Manor Nov 2008
Rob 21.2K views
WordPress Standardized Loop API by Chris Jean
WordPress Standardized Loop APIWordPress Standardized Loop API
WordPress Standardized Loop API
Chris Jean2.6K views
Building Web Interface On Rails by Wen-Tien Chang
Building Web Interface On RailsBuilding Web Interface On Rails
Building Web Interface On Rails
Wen-Tien Chang2.7K views
Php Crash Course by mussawir20
Php Crash CoursePhp Crash Course
Php Crash Course
mussawir209.2K views
Rails 3 And The Real Secret To High Productivity Presentation by railsconf
Rails 3 And The Real Secret To High Productivity PresentationRails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity Presentation
railsconf439 views
HTML::FormFu talk for Sydney PM by Dean Hamstead
HTML::FormFu talk for Sydney PMHTML::FormFu talk for Sydney PM
HTML::FormFu talk for Sydney PM
Dean Hamstead1.2K views
HTML::FormHandler by bbeeley
HTML::FormHandlerHTML::FormHandler
HTML::FormHandler
bbeeley3.1K views

More from Massimiliano Arione

Typed models pug roma febbraio 2020 by
Typed models   pug roma febbraio 2020Typed models   pug roma febbraio 2020
Typed models pug roma febbraio 2020Massimiliano Arione
149 views18 slides
Pipelines! by
Pipelines! Pipelines!
Pipelines! Massimiliano Arione
229 views24 slides
Il nostro amico Stan by
Il nostro amico Stan   Il nostro amico Stan
Il nostro amico Stan Massimiliano Arione
314 views34 slides
PSR7 - interoperabilità HTTP by
PSR7 - interoperabilità HTTPPSR7 - interoperabilità HTTP
PSR7 - interoperabilità HTTPMassimiliano Arione
765 views25 slides
Disinstallare fos user bundle e vivere felici by
Disinstallare fos user bundle e vivere feliciDisinstallare fos user bundle e vivere felici
Disinstallare fos user bundle e vivere feliciMassimiliano Arione
796 views23 slides
MAGA - PUG Roma giugno 2017 by
MAGA - PUG Roma giugno 2017MAGA - PUG Roma giugno 2017
MAGA - PUG Roma giugno 2017Massimiliano Arione
740 views29 slides

More from Massimiliano Arione(20)

Recently uploaded

Transcript: The Details of Description Techniques tips and tangents on altern... by
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...BookNet Canada
135 views15 slides
AMAZON PRODUCT RESEARCH.pdf by
AMAZON PRODUCT RESEARCH.pdfAMAZON PRODUCT RESEARCH.pdf
AMAZON PRODUCT RESEARCH.pdfJerikkLaureta
19 views13 slides
Microsoft Power Platform.pptx by
Microsoft Power Platform.pptxMicrosoft Power Platform.pptx
Microsoft Power Platform.pptxUni Systems S.M.S.A.
52 views38 slides
Tunable Laser (1).pptx by
Tunable Laser (1).pptxTunable Laser (1).pptx
Tunable Laser (1).pptxHajira Mahmood
24 views37 slides
The details of description: Techniques, tips, and tangents on alternative tex... by
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...BookNet Canada
126 views24 slides
Special_edition_innovator_2023.pdf by
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdfWillDavies22
17 views6 slides

Recently uploaded(20)

Transcript: The Details of Description Techniques tips and tangents on altern... by BookNet Canada
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...
BookNet Canada135 views
AMAZON PRODUCT RESEARCH.pdf by JerikkLaureta
AMAZON PRODUCT RESEARCH.pdfAMAZON PRODUCT RESEARCH.pdf
AMAZON PRODUCT RESEARCH.pdf
JerikkLaureta19 views
The details of description: Techniques, tips, and tangents on alternative tex... by BookNet Canada
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...
BookNet Canada126 views
Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2217 views
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson66 views
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by IttrainingIttraining
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
handbook for web 3 adoption.pdf by Liveplex
handbook for web 3 adoption.pdfhandbook for web 3 adoption.pdf
handbook for web 3 adoption.pdf
Liveplex22 views
STPI OctaNE CoE Brochure.pdf by madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb13 views
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab19 views

Paypal + symfony

  • 1. Paypal + symfony payments made simple Massimiliano Arione September, 27th 2011
  • 2.
  • 3. the flow my server Paypal server
  • 4. the REAL flow my server Paypal server
  • 5.
  • 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

  1. questo è il tipico flusso di un pagamento con Paypal, almeno dal punto di vista dell&apos;utente
  2. 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)
  3. questi sono i 3 plugin che abbiamo bisogno di installare
  4. 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.
  5. 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
  6. Nel controllore istanzio Purchase e ottengo l&apos;oggetto per la transazione
  7. La vista è molto semplice, l&apos;unica personalizzazione possibile è l&apos;etichetta del pulsante
  8. 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.
  9. È tutto qui! Visto come è facile? :-)