Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Payments and Payment Gateway / APIs

This is a forum for discussing SilverStripe can-do payments and their APIs / Gateways.

Moderators: martimiz, Sean, Normann, biapar, Willr, Ingo, swaiba, simon_w

PayPalPayment Class


Go to End
Reply

13 Posts   5539 Views

Avatar
Bambii7

12 July 2010 at 12:22am Community Member, 254 Posts

Hi all,
as you probably know the PayPalPayment class might need a few little tweaks.

I find on line 170 $inputs['currency_code'] = $this->Currency; needs to be updated manually, there doesn't seem to be a config setting for this (maybe I'm mistaken) I'm cool with this for personal use but would be more user friendly for the community if there was a config function. I can't see a config function on PayPalPayment or Payment. Also it should probably default to something if it hasn't been set. When going through to pay pal with this unset, paypal responded with "you have incomplete data".

And its taken me a few days to get my head around how this is all working, now I understand it its a very nice integration of PayPal into SS. But I'm getting payment status updated to Failure upon return of a successful transaction in PayPal sandbox. The reason is on line 256

                  if(isset($_REQUEST['payment_status']) && $_REQUEST['payment_status'] == 'Completed') {
                     $payment->Status = 'Success';
                     $payment->TxnRef = $_REQUEST['txn_id'];
                  }
                  else {
                     $payment->Status = 'Failure';   
                  }

This might just be a sandbox issue, but paypal is responding with
value="Pending" name="payment_status"
value="paymentreview" name="pending_reason"
Which I'm assuming is for unverified users? Any way would be great to expand upon this having a switch or something to update orders accordingly. And catch pending orders.

Oh and lastly, it appears alternative shipping address information isn't being posted to PayPal, not a biggie to fix. Out of interest here is the data getting posted to PayPal with "use different shipping address information" submitted

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" id="PaymentForm">
<input type="hidden" value="_cart" name="cmd">
<input type="hidden" value="1" name="upload">
<input type="hidden" value="Example product" name="item_name_1">
<input type="hidden" value="15.00" name="amount_1">
<input type="hidden" value="1" name="quantity_1">
<input type="hidden" value="mysandboxemail@paypal.com" name="business">
<input type="hidden" value="11-d6650e589e1885ca58893417366d59aa" name="custom">
<input type="hidden" value="" name="currency_code">
<input type="hidden" value="http://127.0.0.1/ss/testpaypal/paypal/complete?custom=11-d6650e589e1885ca58893417366d59aa" name="cancel_return">
<input type="hidden" value="http://127.0.0.1/ss/testpaypal/paypal/complete" name="return">
<input type="hidden" value="2" name="rm">
<input type="hidden" value="Default Admin" name="first_name">
<input type="hidden" value="Hope" name="last_name">
<input type="hidden" value="70" name="address1">
<input type="hidden" value="testing" name="address2">
<input type="hidden" value="Auckland" name="city">
<input type="hidden" value="US" name="country">
<input type="hidden" value="myemail@paypal.com" name="email">
<input type="submit" value="Submit">
</form>

Avatar
Bambii7

13 July 2010 at 1:34pm Community Member, 254 Posts

Little update

in /mysite/_config.php if
Payment::set_site_currency('USD');
is set.
Change line 170 on /payments/PayPalPayment.php
From
$inputs['currency_code'] = $this->Currency;
To
$inputs['currency_code'] = self::site_currency();

Then the currency is picked up and sent to paypal (or just hard code line 170)

Avatar
Bambii7

13 July 2010 at 3:09pm (Last edited: 13 July 2010 3:10pm), Community Member, 254 Posts

Another quick note.
I changed the complete function in the PayPalPayment_Handler class in /payments/code/PayPalPayment.php to

   function complete() {
      if(isset($_REQUEST['custom']) && $custom = $_REQUEST['custom']) {
         $params = explode('-', $custom);
         if(count($params) == 2) {
            if($payment = DataObject::get_by_id('PayPalPayment', $params[0])) {
               if($payment->AuthorisationCode == $params[1]) {
                  if(isset($_REQUEST['payment_status'])) {
                     $payment->Status = $_REQUEST['payment_status'];
                     $payment->Message = $_REQUEST['pending_reason'];
                     $payment->TxnRef = $_REQUEST['txn_id'];
                  } else {
                     $payment->Status = 'Failure';   
                  }
                  
                  $payment->write();
                  $payment->redirectToOrder();
               }
            }
         }
      }
   }

Which allows any payment_status. It's not ideal. I've been trying to source a list of response codes from Pay Pal. Ideally the payment status would get updated in the DB, then reference a paypal status list, and find the appropriate translation (if exists). This update at least catches the response code accordingly from paypal, and kind of lets the user know whats going on. Since its not notifying the admin or user via email at this point this is OK for me. I'm going to attempt a PayPal IPN class this avo, to notify admin and user when a payment clears.

Avatar
Bambii7

13 July 2010 at 3:48pm (Last edited: 13 July 2010 3:48pm), Community Member, 254 Posts

Finally the document I was looking for. https://www.paypalobjects.com/WEBSCR-630-20100621-1/en_US/pdf/PP_WebsitePaymentsStandard_IntegrationGuide.pdf

All Pay Pal 3rd party shopping cart variables can be found in there.

Avatar
GRiiDWeb

24 July 2010 at 8:46am Community Member, 60 Posts

Hi,
Please don't give up on this. I have the updated ecommerce module for 2.4 and the payment module. I can't get payment to perform and route to Paypal or to my Paypal account. If you have a set of code for the Paypal payment and where to put email or api, I'd be so grateful. This is my last stumbling block to having a complete an pretty stable platform.

Many thanks
Paul (GRiiD Web)

Avatar
Bambii7

2 August 2010 at 11:18am Community Member, 254 Posts

I did manage to get a pieced together PayPal Payment to work. But started to lose motivation, I was helping a friend out on a "free" website so my patience didn't last long. I'll find the code for you.

Avatar
GRiiDWeb

2 August 2010 at 9:55pm Community Member, 60 Posts

Hi,
Nicholas and Jez are working on a new version of ecommerce to work with SS 2.4. I've suggested that the payment configuration is not ideal to set up and there is no documentation to help.
This is part of their rewrite (hopefully) and they are aiming to have a release at the end of this month. I'm hoping this will be good for the likes of me, I'm not a proficiant PHP coder and need a little more help than others. It will be good news for those who have struggled with the 'old' ecommerce module.

Avatar
Bambii7

3 August 2010 at 1:56pm Community Member, 254 Posts

Yeah I'd like to help out with the eccomerce module as much as I can, but always over commit myself.
I thought I could attach files in this forum but looks like I can't.
Email me at work lex.hope@ecomcorp.co.nz and I'll attach my paypal/ecommerce code.
I didn't sort out an actual IPN. But it works with paypal, an order email is sent from ecommerce then I was relying on the Paypal email to come through and let the administrator sort it out (this was free work for a mate)

Go to Top