使用Omnipay将PayPal REST API集成到Laravel中 - 卡参数是必需的


Integrating PayPal REST API into Laravel using Omnipay - The card parameter is required

我正在使用L5,并希望将我购买的PayPal集成到该系统中。沙盒已经设置好,我可以使用真正的PayPal API包进行所有付款,但是由于我想尝试使用Omnipay进行此操作,因此我有点挣扎:

当我执行此代码时:

Route::get('test', function()
{
$gateway = Omnipay::create('PayPal_Rest');
$gateway->setClientId('{my id}');
$gateway->setSecret('{my secret}');
$gateway->setTestMode(true);
$params = array(
    'cancelUrl' => 'http://webshop.app',
    'returnUrl' => 'http://webshop.app/testresp',
    'name'  => 'Your Purchase',
    'description' => 'Your Description',
    'amount' => '15.99',
    'currency' => 'EUR'
);
Session::put('params', $params);
Session::save();
$resp = $gateway->purchase($params)->send();
if ($resp->isSuccessful()) {
    // payment was successful: update database
    print_r($resp);
} elseif ($resp->isRedirect()) {
    // redirect to offsite payment gateway
     $resp->redirect();
} else {
    // payment failed: display message to customer echo
     $resp->getMessage();
}
});

我明白这个: InvalidRequestException in AbstractRequest.php line 122: The card parameter is required

似乎我必须使用客户的信用卡信息发起购买,我不想收集这些信息(因此首先使用PayPal)。有没有办法在不使用信用卡的情况下使用该 API?

我不喜欢使用 Express API,因为我不希望我的代码中包含我的PayPal用户名和密码。有几个原因。

卡数组字段是必填字段。 不需要插入信用卡号,但您需要提供一些信息。

来自官方文档:

即使是异地网关也使用信用卡对象,因为通常需要将客户帐单或运输详细信息传递到网关。

查看我的 omnipay-PayPal 网关代码分支的以下分支:https://github.com/delatbabel/omnipay-paypal/tree/accept-paypal-payments

这包括允许您不通过信用卡并PayPal进行付款处理的代码。

我已经提交了一个 PR,但它还没有合并到主要的全付PayPal存储库中。