3

I have successfully integrated PayPal express into my website. Now, I want to use PayPal Pro so users can input their card number on the site. I have my sandbox to accept PayPal Pro payments but the process seems different.

In PayPal Express I use purchase() to redirect the user to PayPal to make the payment. Once they return I use completePurchase() to actually take the money from them.

What's the difference in PayPal Pro? Looking at the ProGateway.php file there is no completePurchase() method available. Looks like in it's place (compared to ExpressGateway.php is capture.php and when I call that it's telling me the The transactionReference parameter is required. So, not sure if that's what I should be calling

Here is the entire ProGateway.php file for anyone that may can tell me which methods I use.

public function getDefaultParameters()
{
    return array(
        'username' => '',
        'password' => '',
        'signature' => '',
        'testMode' => false,
    );
}

public function getUsername()
{
    return $this->getParameter('username');
}

public function setUsername($value)
{
    return $this->setParameter('username', $value);
}

public function getPassword()
{
    return $this->getParameter('password');
}

public function setPassword($value)
{
    return $this->setParameter('password', $value);
}

public function getSignature()
{
    return $this->getParameter('signature');
}

public function setSignature($value)
{
    return $this->setParameter('signature', $value);
}

public function authorize(array $parameters = array())
{
    return $this->createRequest('\Omnipay\PayPal\Message\ProAuthorizeRequest', $parameters);
}

public function purchase(array $parameters = array())
{
    return $this->createRequest('\Omnipay\PayPal\Message\ProPurchaseRequest', $parameters);
}

public function capture(array $parameters = array())
{
    return $this->createRequest('\Omnipay\PayPal\Message\CaptureRequest', $parameters);
}

public function refund(array $parameters = array())
{
    return $this->createRequest('\Omnipay\PayPal\Message\RefundRequest', $parameters);
}

public function fetchTransaction(array $parameters = array())
{
    return $this->createRequest('\Omnipay\PayPal\Message\FetchTransactionRequest', $parameters);
}

} `

Lynx
  • 1,462
  • 5
  • 32
  • 59

1 Answers1

3

First I will point you at my own fork of the omnipay-paypal gateway: https://github.com/delatbabel/omnipay-paypal -- there are 2 branches on that fork which I have submitted as PRs to the main phpleague branch but they haven't been merged yet. You might want to take a look at the code in the accept-paypal-payments branch.

By "integrate PayPal Pro" I think you mean to use the REST gateway which has pretty much superseded the original PayPal PRO API. So you should be looking at using the RestGateway class not the ProGateway class. That is the best way to allow customers to enter their card details on the site.

In PayPal Pro (original gateway or REST) you do not need to call completePurchase to take their money -- the purchase() call will do that.

There is one additional method being authorize(), and after doing that you can use a capture(). That is where you want to take someone's card details at some point, and at a later point (perhaps when the order is complete), call capture() to complete the sale and take their money. In my repo I have added more extensive API comments and code examples so you can see how this works.

Also in my repo (on the accept-paypal-payments branch, not merged into the main omnipay one) you can give people the option of paying via credit card or using their paypal account. In that case you simply don't provide a credit card number or token, and the customer can then be redirected to the PayPal web site to log in with their PayPal login id and password for payment. As per the Express Gateway you need to provide callback API endpoints for PayPal to redirect your customer to once the purchase succeeds (or fails).

I should also point out that accepting credit card details on your own site and then forwarding to PayPal (what PayPal refer to as "Direct credit card payment") are only supported in the UK and the USA. If you're outside those two countries then this will work fine in sandbox but not in production.

delatbabel
  • 3,601
  • 24
  • 29
  • First, thanks for the detailed explanation. Secondly, yes I am in the USA so everything should be fine. According to you, I should use REST instead of just PayPal Pro? So, if i do use REST the methods I will have to call in order for this to work is authorize(), capture(), and purchase()? My only thought is when using Express purchase() doesn't actually take money but completePurchase() does? I think that's where my confusion is. Because I have Express working perfectly i just want to offer the onsite option. – Lynx Feb 11 '15 at 14:34
  • Yes, you should use REST instead of pro. You only need capture after authorize, not after purchase. It is correct that purchase express does not take money, but REST it does. – delatbabel Feb 11 '15 at 15:04
  • If you check out branch mentioned of my fork of repository you will see some code examples with both authorize and purchase. – delatbabel Feb 11 '15 at 15:10
  • OK, that sounds good. Now, in Paypal itself would I just use the Virtual terminal business type? – Lynx Feb 11 '15 at 15:22
  • Hrm, not sure. I think that I covered setting up the rest api keys in the api documentation but I didn't explore using the virtual terminal type – delatbabel Feb 11 '15 at 15:24
  • OK, so I did setup the REST API and got it going. When I do the authorize() I get the Authorize transaction was successful! echo. So now, do I just replace that echo with a redirect to another method that I can then use capture() with? Looking at your comments it seems to look like authorize will actually take that payment. https://github.com/delatbabel/omnipay-paypal/blob/master/src/RestGateway.php#L129 – Lynx Feb 11 '15 at 20:25
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/70750/discussion-between-delatbabel-and-lynx). – delatbabel Feb 12 '15 at 01:41
  • @delatbabel, Is it workable with latest laravel? I want to integrate Paypal Pro in laravel application. I tried with omnipay but it returns fail. Thanks in advance !!! – Chirag Shah Jan 24 '19 at 08:39
  • I'm trying to save the card details for future payment. Is it doable with this? Thanks in advance. – Yudi Sep 28 '20 at 13:39