Omnipay paypal 与 laravel 4 的集成 [英] Omnipay paypal integration with laravel 4

查看:16
本文介绍了Omnipay paypal 与 laravel 4 的集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 laravel 4 中集成 Omnipay paypal.我经历过,但我无法理解如何去做.我没有找到任何文档.我已经通过这个这个这个.我已经使用 Composer 安装了它.现在我对以下问题感到困惑.

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

  1. 这里将提供谁的凭据?正在购买的人或将向其转移资金的人.我是否会提供其他人的凭据?

  2. 用户将如何进行交易?它的购买和购买功能我看过,但无法理解.在正常的 Paypal 集成中,我们通常将用户重定向到 Paypal,在那里他或她完成交易然后返回.我怎么能在这里做到这一点?

有人可以指导我完整的文档,我可以在其中阅读其整个流程吗?

解决方案

根据你的观点

1-) 在这里,您将提供收款人的凭据.买家将在 PayPal 网站上提供他的凭据,他将被重定向.

2-) 拥有网关对象并设置凭据后,您将调用 omnipay 的 purchase() 方法,如下所示

$response = $gateway->purchase(大批('cancelUrl' =>'www.xyz.com/cancelurl','returnUrl' =>'www.xyz.com/returnurl','金额' =>25,'货币' =>'美元'))-> 发送();$response->redirect();

这会将用户重定向到贝宝网站,他将在那里提供他的凭据并进行交易.在 paypal 交易成功后,用户将被重定向到您在 returnurl 中指定的 URL.在 returnurl 中,您将创建与上面相同的 gateway 对象,如下所述.

 $gateway = Omnipay::create('PayPal_Express');$gateway->setUsername('XXXXX');$gateway->setPassword('XXXX');$gateway->setSignature('XXXXX');$response = $gateway->completePurchase(大批('cancelUrl' =>'www.xyz.com/cancelurl','cancelUrl' =>'www.xyz.com/cancelurl','returnUrl' =>'www.xyz.com/returnurl','金额' =>25,'货币' =>'美元'))-> 发送();$data = $response->getData();//这是原始响应对象echo '

';打印_r($数据);

completePurchase 方法将完成交易,您将在数组中获得响应.

注意 当用户被重定向到返回 url 时,该 URL 还包含 transaction_id 和 payer_id.:-) 我希望它很简单.

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?

解决方案

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.

这篇关于Omnipay paypal 与 laravel 4 的集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆