贝宝(Paypal)在Laravel上的集成困难

时间:2018-08-01 05:23:13

标签: php laravel laravel-5 paypal paypal-sandbox

这是我第一次在我的项目中实现Paypal。我正在使用srmklive/laravel-paypal,并在文档中测试了以下代码

这是我的控制者:

class CheckoutController extends Controller
{
    protected $provider;
    public function __construct(){
        $this->provider = new ExpressCheckout();
    }

    public function getExpressCheckout(Request $request){
        $data = [];
        $data['items'] = [
          [
            'name' => 'Product 1',
            'price' => 9.99,
            'qty' => 1
          ],
          [
            'name' => 'Product 2',
            'price' => 4.99,
            'qty' => 2
          ]
        ];

        $data['invoice_id'] = 2;
        $data['invoice_description'] = "test";
        $data['return_url'] = url('/');
        $data['cancel_url'] = url('/cart');

        $total = 0;
        foreach($data['items'] as $item) {
            $total += $item['price']*$item['qty'];
        }

        $data['total'] = $total;

        //give a discount of 10% of the order amount
        $data['shipping_discount'] = round((10 / 100) * $total, 2);
        $response = $this->provider->setExpressCheckout($data);
        return redirect($response['paypal_link']);
    }
 }

这是我的路线:

Route::get('/paypal/ec-checkout', 'CheckoutController@getExpressCheckout')->name('checkout');

这是我的链接:

 <a href="{{ route('checkout') }}" class="btn btn-primary pull-right" style="margin-bottom:20px;">Checkout</a>

我的问题是,当我单击链接时,它将永久加载并且没有错误显示。我正在使用Laravel 5.6

0 个答案:

没有答案