【问题标题】:How do I get PayPal to work with Laravel PHP?如何让 PayPal 与 Laravel PHP 一起使用?
【发布时间】:2020-10-02 14:49:07
【问题描述】:

过去 5 年似乎没有人试图让 PayPal 与 PHP 上的 Laravel 网站合作,所以我现在强行询问。
我正在使用这个包:https://github.com/srmklive/laravel-paypal
我正在向 PayPal 发送这个:

array:6 [▼
  "items" => array:2 [▼
    0 => array:3 [▼
      "name" => "Product 1"
      "price" => 9.99
      "qty" => 1
    ]
    1 => array:3 [▼
      "name" => "Product 2"
      "price" => 4.99
      "qty" => 2
    ]
  ]
  "return_url" => "https://github.com/payment/success"
  "invoice_id" => "PAYPALDEMOAPP_1"
  "invoice_description" => "Order #PAYPALDEMOAPP_1 Invoice"
  "cancel_url" => "https://github.com/cart"
  "total" => 19.97
]

这些值当然纯粹是为了测试,但它们应该可以工作。
但是,我收到此错误:

array:3 [▼
  "type" => "error"
  "message" => ""
  "paypal_link" => null
]

我的代码如下所示:

public function start()
    {
        $provider = new ExpressCheckout();

        $data = [];
        $data['items'] = [
            [
                'name'  => 'Product 1',
                'price' => 9.99,
                'qty'   => 1,
            ],
            [
                'name'  => 'Product 2',
                'price' => 4.99,
                'qty'   => 2,
            ],
        ];

        $data['return_url'] = 'https://github.com/payment/success';
        $data['invoice_id'] = 'PAYPALDEMOAPP_' . 1;
        $data['invoice_description'] = "Order #{$data['invoice_id']} Invoice";
        $data['cancel_url'] = 'https://github.com/cart';

//        $data['return_url'] = url('/payment/success');
//        $data['cancel_url'] = url('/cart');

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

        $response = $provider->setExpressCheckout($data);

        dd($response);

        return redirect($response['paypal_link']);
    }

这些值与https://github.com/srmklive/laravel-paypal-demo/使用的值完全相同
这是一个工作演示!
我进一步调查了它,发现请求在包中发送,它向https://api-3t.sandbox.paypal.com/nvp发送一个POST请求,当我在邮递员中使用相同的postdata重新创建请求时,我得到ACK=Failure&L_ERRORCODE0=81002&L_SHORTMESSAGE0=Unspecified%20Method&L_LONGMESSAGE0=Method%20Specified%20is%20not%20Supported&L_SEVERITYCODE0=Error,这是我认为真实的错误。
如果有人可以提供帮助,那就太好了!

【问题讨论】:

    标签: php laravel paypal


    【解决方案1】:

    您链接的软件包很古老,就 PayPal API 而言已经过时了 2 代。不要使用它。

    这是当前的 PHP SDK(不是 laravel 特定的):https://github.com/paypal/Checkout-PHP-SDK

    它应该用于在您的服务器上创建两条路由,一条用于“设置事务”,另一条用于“捕获事务”。这是一个指南:https://developer.paypal.com/docs/checkout/reference/server-integration/

    这两条路由应该被这个前端代码调用:https://developer.paypal.com/demo/checkout/#/pattern/server

    【讨论】:

      【解决方案2】:

      仔细检查凭据是否配置正确。

      validate_ssl可能还需要设置为falsehttps://github.com/srmklive/laravel-paypal/issues/229#issuecomment-472755054

      【讨论】:

        猜你喜欢
        • 2021-09-03
        • 2011-11-18
        • 2022-11-10
        • 1970-01-01
        • 2010-12-01
        • 1970-01-01
        • 2012-06-03
        • 2017-06-25
        • 1970-01-01
        相关资源
        最近更新 更多