Development

/plugins/sfPaymentPayPalPlugin/branches/0.1.2-jiap/modules/sfPaymentPayPal/actions/actions.class.php

You must first sign up to be able to contribute.

root/plugins/sfPaymentPayPalPlugin/branches/0.1.2-jiap/modules/sfPaymentPayPal/actions/actions.class.php

Revision 22348, 6.7 kB (checked in by jiappo, 4 years ago)

--

Line 
1 <?php
2 class sfPaymentPayPalActions extends sfActions
3 {
4   public function executeSample(sfWebRequest $request)
5   {
6     // instanciate transaction
7     $this->transaction = new sfPaymentPayPal();
8
9     // enable test mode if needed
10     //$this->transaction->enableTestMode();
11
12     // define transaction information:
13     // - currency
14     $this->transaction->setCurrency("USD");
15
16     // - product information
17           #for single item
18     /*
19     $products_sample = array("Symfony Book", "View Sonic VA226w", "Camera", "IPhone 3Gs", "PlayStation 3");
20     $this->transaction->setProduct('AAA000', $products_sample[rand(0, 4)], rand(1, 100));
21     $this->transaction->setShipping(20);
22     */
23           #for multiple items
24     $this->transaction->addProduct('AAA000', "Symfony Book", 20, rand(1, 10));
25     $this->transaction->addProduct('AAA001', "Camera", 145, rand(1, 5));
26     $this->transaction->addProduct('AAA002', "Playstation 3", 599, rand(1, 2));
27     $this->transaction->setShipping(50);
28   }
29
30   public function executeSuccess(sfWebRequest $request) {
31     //$this->getResponse()->setTitle(sfConfig::get('app_sf_payment_paypal_plugin_success_title', "Payment Gateway Tests - Paypal Success"), false);
32
33     /*
34   ### HERE WE HAVE SAME DATA FROM PAYPAL, AN EXAMPLE OF RETURN'S FORM
35
36      <form action="http://87.15.38.109/sfPaymentPayPal/success" name="merchant_return" id="merchantReturn" method="post">
37        <input type="hidden" value="3119.00" name="mc_gross"/>
38        <input type="hidden" value="Eligible" name="protection_eligibility"/>
39        <input type="hidden" value="confirmed" name="address_status"/>
40        <input type="hidden" value="000" name="item_number1"/>
41        <input type="hidden" value="001" name="item_number2"/>
42        <input type="hidden" value="9RLE5Q2KTLS7J" name="payer_id"/>
43        <input type="hidden" value="0.00" name="tax"/>
44        <input type="hidden" value="002" name="item_number3"/>
45        <input type="hidden" value="1 Main St" name="address_street"/>
46        <input type="hidden" value="08:03:53 Sep 10, 2009 PDT" name="payment_date"/>
47        <input type="hidden" value="Completed" name="payment_status"/>
48        <input type="hidden" value="windows-1252" name="charset"/>
49        <input type="hidden" value="95131" name="address_zip"/>
50        <input type="hidden" value="0.00" name="mc_shipping"/>
51        <input type="hidden" value="0.00" name="mc_handling"/>
52        <input type="hidden" value="Test" name="first_name"/>
53        <input type="hidden" value="90.75" name="mc_fee"/>
54        <input type="hidden" value="US" name="address_country_code"/>
55        <input type="hidden" value="Test User" name="address_name"/>
56        <input type="hidden" value="2.8" name="notify_version"/>
57        <input type="hidden" value="" name="custom"/>
58        <input type="hidden" value="verified" name="payer_status"/>
59        <input type="hidden" value="jiappo_1252593966_biz@gmail.com" name="business"/>
60        <input type="hidden" value="United States" name="address_country"/>
61        <input type="hidden" value="3" name="num_cart_items"/>
62        <input type="hidden" value="0.00" name="mc_handling1"/>
63        <input type="hidden" value="0.00" name="mc_handling2"/>
64        <input type="hidden" value="0.00" name="mc_handling3"/>
65        <input type="hidden" value="San Jose" name="address_city"/>
66        <input type="hidden" value="0.00" name="mc_shipping1"/>
67        <input type="hidden" value="jiappo_1252593861_per@gmail.com" name="payer_email"/>
68        <input type="hidden" value="A149-5E2jk0G7ZDmAglivPSW5nQlACu9YnoKrYa-nQJwg-9aoyNIvTxc" name="verify_sign"/>
69        <input type="hidden" value="0.00" name="mc_shipping2"/>
70        <input type="hidden" value="0.00" name="tax1"/>
71        <input type="hidden" value="0.00" name="mc_shipping3"/>
72        <input type="hidden" value="0.00" name="tax2"/>
73        <input type="hidden" value="0.00" name="tax3"/>
74        <input type="hidden" value="instant" name="payment_type"/>
75        <input type="hidden" value="9E6016792C888474W" name="txn_id"/>
76        <input type="hidden" value="User" name="last_name"/>
77        <input type="hidden" value="jiappo_1252593966_biz@gmail.com" name="receiver_email"/>
78        <input type="hidden" value="Symfony Book" name="item_name1"/>
79        <input type="hidden" value="CA" name="address_state"/>
80        <input type="hidden" value="90.75" name="payment_fee"/>
81        <input type="hidden" value="Camera" name="item_name2"/>
82        <input type="hidden" value="Playstation 3" name="item_name3"/>
83        <input type="hidden" value="10" name="quantity1"/>
84        <input type="hidden" value="Q4LRCYRTHK2VW" name="receiver_id"/>
85        <input type="hidden" value="16" name="quantity2"/>
86        <input type="hidden" value="cart" name="txn_type"/>
87        <input type="hidden" value="1" name="quantity3"/>
88        <input type="hidden" value="USD" name="mc_currency"/>
89        <input type="hidden" value="200.00" name="mc_gross_1"/>
90        <input type="hidden" value="2320.00" name="mc_gross_2"/>
91        <input type="hidden" value="US" name="residence_country"/>
92        <input type="hidden" value="599.00" name="mc_gross_3"/>
93        <input type="hidden" value="1" name="test_ipn"/>
94        <input type="hidden" value="Shopping Cart" name="transaction_subject"/>
95        <input type="hidden" value="3119.00" name="payment_gross"/>
96        <input type="submit" class="continue" value="Return to Giuseppe Castelluzzo's Test Store" name="merchant_return_link" id="merchantReturn"/>
97      </form>
98     */
99   }
100
101   public function executeCanceled(sfWebRequest $request) {
102
103   }
104
105   public function executeNotification(sfWebRequest $request) {
106     // create paypal library instance
107     $transaction = new sfPaymentTransaction();
108     $transaction->setAdapter(new sfPaymentPayPal($request->getPostParameters()));
109
110     // check validity
111     $dispatcher = sfContext::getInstance()->getEventDispatcher();
112     switch($transaction->validateNotification())
113     {
114       case(sfPaymentTransaction::$COMPLETED):
115         $dispatcher->notify(new sfEvent($this, 'transaction.completed', array('transaction' => $transaction)));
116         break;
117
118       case(sfPaymentTransaction::$PENDING):
119         $dispatcher->notify(new sfEvent($this, 'transaction.pending', array('transaction' => $transaction)));
120         break;
121
122       case(sfPaymentTransaction::$FAILED):
123         $dispatcher->notify(new sfEvent($this, 'transaction.failed', array('transaction' => $transaction)));
124         break;
125
126       case(sfPaymentTransaction::$INVALID):
127         $dispatcher->notify(new sfEvent($this, 'transaction.invalid', array('transaction' => $transaction)));
128         break;
129
130       default:
131         //HTTPERROR or UNKNOWERROR
132     }
133
134     $this->transaction->save();
135   }
136
137 }
Note: See TracBrowser for help on using the browser.