Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

omnipay paypal express not returning address

I am using the omnipay setup here: https://github.com/adrianmacneil/omnipay to process a paypal express checkout.

The process works fine in that the user is redirected to paypal -> they login and choose to pay -> they get returned to my site at which point I capture the payment.

The problem I've got is that I need to capture the address they have entered into paypal as their billing / shipping address.

To send the user across to paypal I have the following:

$gateway = GatewayFactory::create('PayPal_Express');
$gateway->setUsername('XX-USERNAME_XX');
$gateway->setPassword('XX_PASSWORDXX');
$gateway->setSignature('XX_SIG_XX');
$gateway->setTestMode(true);

$response = $gateway->purchase(
    array(
        'cancelUrl'=>'http://www.XXX.co.uk/',
        'returnUrl'=>'http://www.XXX.co.uk/paypalexpress_confirm',
        'amount' =>  $totalamount,
        'currency' => 'GBP'
    )
)->send();

$response->redirect(); 

When the user is returned I have the following:

$gateway = GatewayFactory::create('PayPal_Express');
$gateway->setUsername('XX-USERNAME_XX');
$gateway->setPassword('XX_PASSWORDXX');
$gateway->setSignature('XX_SIG_XX');
$gateway->setTestMode(true);

$response = $gateway->completePurchase(
    array(
        'cancelUrl'=>'http://www.XXX.co.uk/',
        'returnUrl'=>'http://www.XXX.co.uk/paypalexpress_confirm',
        'amount' =>  $totalamount,
        'currency' => 'GBP'
    )
    )->send();

    echo $responsemsg=$response->getMessage(); 

    echo '<br><br><br>';
    $data = $response->getData(); 
    print_r($data);

Nothing in the response message or the raw data contains the customer address.

Has anyone got this working as i'm struggling and it's the final step to complete the transaction.

like image 364
Stuh_blue Avatar asked Oct 03 '22 14:10

Stuh_blue


2 Answers

For those who are trying to get this work it's as Adrian said.

You first do the normal omnipay paypal payment and then afterwards:

  1. get the token you were given
  2. preform a second call to paypal using the call getexpresscheckoutdetails method
  3. this returns all the info you need

API info here: https://cms.paypal.com/uk/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_GetExpressCheckoutDetails

The php script paypal provide to do it all for you:

https://cms.paypal.com/cms_content/ES/es_ES/files/developer/nvp_ECGetExpressCheckout_php.txt

like image 51
Stuh_blue Avatar answered Oct 12 '22 10:10

Stuh_blue


omnipay\paypal\ProGateway.php add new function

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

omnipay\paypal\src\Message add new file FetchExpressCheckoutRequest.php

namespace Omnipay\PayPal\Message;
class FetchExpressCheckoutRequest extends AbstractRequest
{
    public function getData()
    {
        $data = $this->getBaseData('GetExpressCheckoutDetails');

        $this->validate('transactionReference');
        $data['TOKEN'] = $this->getTransactionReference();
        $url = $this->getEndpoint()."?USER={$data['USER']}&PWD={$data['PWD']}&SIGNATURE={$data['SIGNATURE']}&METHOD=GetExpressCheckoutDetails&VERSION={$data['VERSION']}&TOKEN={$data['TOKEN']}";
        parse_str (file_get_contents( $url ),$output);
        $data = array_merge($data,$output);
        return $data;
    }
}

Usage:

$response = $gateway->completePurchase($params)->send();
$data = $response->getData();
$gateway->fetchExpressCheckoutDetail(array('transactionReference'=>$data['TOKEN']))->getData();

It will be not the best. But it works. :)

like image 24
kei. Avatar answered Oct 12 '22 10:10

kei.