Omnipay paypal integration with laravel 4

落花浮王杯 提交于 2019-12-20 09:19:11

问题


I want to integrate Omnipay paypal in laravel 4. I have gone through but I was unable to understand how to do it. I didn't find any documentation. I have gone through this, this and this. I have installed it using Composer. Now I am confused in following questions.

$gateway = Omnipay::create('PayPal_Express');
$gateway->setUsername('XXXXX');
$gateway->setPassword('XXXX');
$gateway->setSignature('XXXXX');
  1. Whose credentials will be given here? The one who is buying or the one to whom money will be transferred. I either case where other's credentials will be given?

  2. How user will do transactions? I have seen its purchase and purchasecomplete functions but couldn't be able to understand it. In normal Paypal integration, we usually redirect users to Paypal where he or she completes the transaction and then comes back. How can I do this here?

Can someone direct me the complete documentation where I can read its whole flow?


回答1:


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.



来源:https://stackoverflow.com/questions/20756067/omnipay-paypal-integration-with-laravel-4

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