Omnipay paypal integration with laravel 4

不问归期 提交于 2019-12-02 18:21:16

As per your points

1-) Here you will give credentials of one to whome money will be transferred. And buyer will give his credentials on PayPal site he will be redirected.

2-) After having gateway object and setting credentials you will call the purchase() method of omnipay as follow

$response = $gateway->purchase(
                    array(
                        'cancelUrl' => 'www.xyz.com/cancelurl',
                        'returnUrl' => 'www.xyz.com/returnurl', 
                        'amount' => 25,
                        'currency' => 'USD'
                    )
            )->send();

$response->redirect();

This will redirect User to paypal site where he will give his credentials and do a transaction. After successful transaction at paypal user will be redirect to the URL that you have specified in returnurl. And at returnurl you will create same gateway object as you did above as stated below.

 $gateway = Omnipay::create('PayPal_Express');
 $gateway->setUsername('XXXXX');
 $gateway->setPassword('XXXX');
 $gateway->setSignature('XXXXX');


  $response = $gateway->completePurchase(
                    array(
                        'cancelUrl' => 'www.xyz.com/cancelurl',
                        'cancelUrl' => 'www.xyz.com/cancelurl',
                        'returnUrl' => 'www.xyz.com/returnurl', 
                        'amount' => 25,
                        'currency' => 'USD'
                    )
            )->send();


    $data = $response->getData(); // this is the raw response object
    echo '<pre>';
    print_r($data);

The completePurchase method will complete the transaction and you will get response in array.

NOTE when user is redirected on return url, the URL also contains transaction_id and payer_id. :-) I hope it is quite simple.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!