我正在使用这个数据包:
https://github.com/barryvdh/laravel-omnipay
在我的 Controller 中我添加了:
$params = [
'amount' => '10',
'issuer' => 22,
'description' => 'desc',
'returnUrl' => URL::action('PurchaseController@returnApi', [43]),
];
$response = Omnipay::purchase($params)->send();
if ($response->isSuccessful()) {
// payment was successful: update database
print_r($response);
} elseif ($response->isRedirect()) {
// redirect to offsite payment gateway
return $response->getRedirectResponse();
} else {
// payment failed: display message to customer
echo $response->getMessage();
}
这是我的 omnipay.php 配置文件:
<?php
return array(
/** The default gateway name */
'gateway' => 'PayPal_Express',
/** The default settings, applied to all gateways */
'defaults' => array(
'testMode' => true,
),
/** Gateway specific parameters */
'gateways' => array(
'PayPal_Express' => array(
'username' => '',
'landingPage' => array('billing', 'login'),
),
),
);
但是得到这个错误:
call_user_func_array() expects parameter 1 to be a valid callback, class 'Omnipay\Common\GatewayFactory' does not have a method 'purchase'
谁能帮我设置一下? 我在 paypal 上创建了应用程序并了解了它的详细信息,但不知道如何使用此 API 进行设置...
最佳答案
我建议您从 PayPal Express 切换到 PayPal REST。它更新并且有更好的文档。
我已经查看了 laravel-omnipay 包,但看不到它的用例。我会直接编码到 omnipay 包。
我建议您为每笔交易创建一个唯一的交易 ID,并将其作为 returnUrl 和 cancelUrl 的 URL 的一部分提供,以便您可以识别您在返回和取消处理程序中处理的交易。
我认为您对 laravel-omnipay 包中的示例过于字面意思了。您在那里不需要或不想要那些 echo 语句。您应该捕获来自 purchase() 的响应,即使它是 redirectResponse 并对其进行 getTransactionReference() 检查,因为稍后您将需要该交易引用,例如用于交易查询。您应该将其存储在调用 purchase() 之前创建的交易记录中。
关于paypal - 如何使用 Laravel 设置 Omnipay?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35364542/