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

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

问题描述

我想将Omnipay paypal集成到laravel 4中.我已经经历了,但是我不明白该怎么做.我没有找到任何文档.我已经通过. 我已经使用Composer安装了它.现在,我对以下问题感到困惑.

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. 此处将提供谁的凭据?一个正在购买的人或将要转移资金的那个人.在任何一种情况下,都会提供他人的凭据?

  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?

用户将如何进行交易?我已经看到了其购买和购买完成功能,但无法理解它.在正常的Paypal集成中,我们通常将用户重定向到Paypal,在该用户完成交易然后返回.我该怎么办?

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-)在这里,您将给一个凭证,以便将资金转入谁.买方将在PayPal网站上提供其凭据,并将其重定向.

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-)在拥有网关对象并设置凭据后,您将按照以下方式调用omnipay的purchase()方法

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();

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

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);

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

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

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

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天全站免登陆