SlideShare a Scribd company logo
1 of 11
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

More Related Content

What's hot

JAVASCRIPT NÃO-OBSTRUTIVO com jQuery
JAVASCRIPT NÃO-OBSTRUTIVO com jQueryJAVASCRIPT NÃO-OBSTRUTIVO com jQuery
JAVASCRIPT NÃO-OBSTRUTIVO com jQuery
Zigotto Tecnologia
 
Rajashekaran vengalil building cross browser html5 websites
Rajashekaran vengalil building cross browser html5 websitesRajashekaran vengalil building cross browser html5 websites
Rajashekaran vengalil building cross browser html5 websites
suniltomar04
 
Daily Deals from Buy.com
Daily Deals from Buy.comDaily Deals from Buy.com
Daily Deals from Buy.com
drocallaghan
 
Gravity Forms Hooks & Filters
Gravity Forms Hooks & FiltersGravity Forms Hooks & Filters
Gravity Forms Hooks & Filters
iamdangavin
 

What's hot (18)

Elegant Error-Handling for a More Civilized Age
Elegant Error-Handling for a More Civilized AgeElegant Error-Handling for a More Civilized Age
Elegant Error-Handling for a More Civilized Age
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Oop php 5
Oop php 5Oop php 5
Oop php 5
 
JAVASCRIPT NÃO-OBSTRUTIVO com jQuery
JAVASCRIPT NÃO-OBSTRUTIVO com jQueryJAVASCRIPT NÃO-OBSTRUTIVO com jQuery
JAVASCRIPT NÃO-OBSTRUTIVO com jQuery
 
Html hacking - when javascript is just not good enough
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
 
WordPress: From Antispambot to Zeroize
WordPress: From Antispambot to ZeroizeWordPress: From Antispambot to Zeroize
WordPress: From Antispambot to Zeroize
 
Cloud Entwicklung mit Apex
Cloud Entwicklung mit ApexCloud Entwicklung mit Apex
Cloud Entwicklung mit Apex
 
Payments On Rails
Payments On RailsPayments On Rails
Payments On Rails
 
Rajashekaran vengalil building cross browser html5 websites
Rajashekaran vengalil building cross browser html5 websitesRajashekaran vengalil building cross browser html5 websites
Rajashekaran vengalil building cross browser html5 websites
 
scope or not?
scope or not?scope or not?
scope or not?
 
Daily Deals from Buy.com
Daily Deals from Buy.comDaily Deals from Buy.com
Daily Deals from Buy.com
 
Testing ASP.net Web Applications using Ruby
Testing ASP.net Web Applications using RubyTesting ASP.net Web Applications using Ruby
Testing ASP.net Web Applications using Ruby
 
Gravity Forms Hooks & Filters
Gravity Forms Hooks & FiltersGravity Forms Hooks & Filters
Gravity Forms Hooks & Filters
 
An overview of Domain Specific Languages in PHP
An overview of Domain Specific Languages in PHPAn overview of Domain Specific Languages in PHP
An overview of Domain Specific Languages in PHP
 
Stripe on Atmoph
Stripe on AtmophStripe on Atmoph
Stripe on Atmoph
 
Let jQuery Rock Your World
Let jQuery Rock Your WorldLet jQuery Rock Your World
Let jQuery Rock Your World
 
Pluginが広げるRailsの魅力
Pluginが広げるRailsの魅力Pluginが広げるRailsの魅力
Pluginが広げるRailsの魅力
 
Introduction to turbo c
Introduction to turbo cIntroduction to turbo c
Introduction to turbo c
 

Similar to Paypal + symfony

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...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
Kirill Chebunin
 
Разработка приложений для Android Honeycomb: ActionBar & Fragments
Разработка приложений для Android Honeycomb: ActionBar & FragmentsРазработка приложений для Android Honeycomb: ActionBar & Fragments
Разработка приложений для Android Honeycomb: ActionBar & Fragments
Alexey Ustenko
 
Building Web Interface On Rails
Building Web Interface On RailsBuilding Web Interface On Rails
Building Web Interface On Rails
Wen-Tien Chang
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Course
mussawir20
 
Rails 3 And The Real Secret To High Productivity Presentation
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
railsconf
 
Liferay Training Struts Portlet
Liferay Training Struts PortletLiferay Training Struts Portlet
Liferay Training Struts Portlet
Saikrishna Basetti
 

Similar to Paypal + symfony (20)

symfony & jQuery (PUG)
symfony & jQuery (PUG)symfony & jQuery (PUG)
symfony & jQuery (PUG)
 
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...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4
 
The Basics Of Page Creation
The Basics Of Page CreationThe Basics Of Page Creation
The Basics Of Page Creation
 
Разработка приложений для Android Honeycomb: ActionBar & Fragments
Разработка приложений для Android Honeycomb: ActionBar & FragmentsРазработка приложений для Android Honeycomb: ActionBar & Fragments
Разработка приложений для Android Honeycomb: ActionBar & Fragments
 
Zend Form Tutorial
Zend Form TutorialZend Form Tutorial
Zend Form Tutorial
 
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
 
State Machines to State of the Art
State Machines to State of the ArtState Machines to State of the Art
State Machines to State of the Art
 
Smarter Interfaces with jQuery (and Drupal)
Smarter Interfaces with jQuery (and Drupal)Smarter Interfaces with jQuery (and Drupal)
Smarter Interfaces with jQuery (and Drupal)
 
Os Nixon
Os NixonOs Nixon
Os Nixon
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
 
Ajax Applications with RichFaces and JSF 2
Ajax Applications with RichFaces and JSF 2Ajax Applications with RichFaces and JSF 2
Ajax Applications with RichFaces and JSF 2
 
Rugalytics | Ruby Manor Nov 2008
Rugalytics | Ruby Manor Nov 2008Rugalytics | Ruby Manor Nov 2008
Rugalytics | Ruby Manor Nov 2008
 
WordPress Standardized Loop API
WordPress Standardized Loop APIWordPress Standardized Loop API
WordPress Standardized Loop API
 
Building Web Interface On Rails
Building Web Interface On RailsBuilding Web Interface On Rails
Building Web Interface On Rails
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Course
 
Rails 3 And The Real Secret To High Productivity Presentation
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
 
Liferay Training Struts Portlet
Liferay Training Struts PortletLiferay Training Struts Portlet
Liferay Training Struts Portlet
 
HTML::FormFu talk for Sydney PM
HTML::FormFu talk for Sydney PMHTML::FormFu talk for Sydney PM
HTML::FormFu talk for Sydney PM
 
HTML::FormHandler
HTML::FormHandlerHTML::FormHandler
HTML::FormHandler
 

More from Massimiliano Arione

Gestione delle dipendenze con Composer
Gestione delle dipendenze con ComposerGestione delle dipendenze con Composer
Gestione delle dipendenze con Composer
Massimiliano Arione
 

More from Massimiliano Arione (20)

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

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 

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? :-)