【问题标题】:How use Omnipay for Laravel 5?Laravel 5 如何使用 Omnipay?
【发布时间】:2016-03-18 11:07:41
【问题描述】:

我有测试代码,但如何配置它以使用 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

谢谢

【问题讨论】:

    标签: php laravel paypal configuration payment


    【解决方案1】:

    我建议您查看 OmniPay docs 以了解此类问题,因为它会为您提供如何为不同提供商创建付款的参考点。

    请务必注意,除非您在美国,否则您的用户将被重定向到 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();
    

    从那里您只需使用响应来确定如何处理付款。

    this guide 虽然是为 Laravel 4.2 编写的,但可能有助于指导您学习如何使用 OmniPay。

    【讨论】:

    • 如果我们需要为 postPayment() 编写单元测试怎么办?
    猜你喜欢
    • 2016-05-23
    • 2016-03-07
    • 2017-10-27
    • 2016-01-26
    • 2016-05-08
    • 2015-10-27
    • 2017-04-21
    • 2018-07-19
    • 2017-03-25
    相关资源
    最近更新 更多