如何在Laravel 5中使用Omnipay?

3

我有测试代码,但是如何将它配置为使用PayPal进行付款?

这是测试代码,但如果我想要用PayPal怎么办?我该怎么做?

$cardInput = [
        'number'      => '4444333322221111',
        'firstName'   => 'MR. WALTER WHITE',
        'expiryMonth' => '03',
        'expiryYear'  => '16',
        'cvv'         => '333',
    ];

    $card = Omnipay::creditCard($cardInput);
    $response = Omnipay::purchase([
        'amount'    => '100.00',
        'returnUrl' => 'http://bobjones.com/payment/return',
        'cancelUrl' => 'http://bobjones.com/payment/cancel',
        'card'      => $cardInput
    ])->send();

    dd($response->getMessage());

这是文档:https://github.com/ignited/laravel-omnipay,感谢。
1个回答

2
我建议您查看OmniPay文档,以了解如何为不同的提供程序创建付款,这将为您提供参考点。
需要注意的是,除非您在美国,否则您的用户将被重定向到PayPal输入其信用卡详细信息等。
例如,它可能看起来像这样:
public function postPayment() 
    {
            $params = array(
                    'cancelUrl'     => 'http://localhost/cancel_order',
                    'returnUrl'     => 'http://localhost/payment_success', 
                    'name'      => //Fetch product name,
                    'description'   => //Fetch product description, 
                    'amount'    => //Fetch product price,
                    'currency'  => //Fetch the currency
            );

            Session::put('params', $params);
            Session::save();  

        $gateway = Omnipay::create('PayPal_Express');
        $gateway->setUsername('paypal account');
        $gateway->setPassword('paypal password');
        $gateway->setSignature('paypal-signature');

        $gateway->setTestMode(true);

        $response = $gateway->purchase($params)->send();

接下来,您只需使用响应来确定如何处理付款。

虽然这篇指南是为Laravel 4.2编写的,但这篇指南可能会帮助您学习如何使用OmniPay。


如果我们需要为postPayment()编写单元测试,该怎么办? - Kapil Verma

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接