php - Laravel Omnipay - transactionReference 参数是必需的

标签 php laravel payment-gateway omnipay mollie

我正在使用名为 Attendize 的开源票务系统.

他们已经有了支付提供商 Stripe融合的。现在我正在尝试与支付提供商合作 Mollie .

问题是我一直被这个错误绊倒:

enter image description here

我的代码是这样的:

$transaction_data += [
    'transactionId' => $event_id . date('YmdHis'),
    'returnUrl' => route('showEventCheckoutPaymentReturn', [
        'event_id'              => $event_id,
        'is_payment_successful' => 1
    ]),
];

$apiKey = "test_gSDS4xNA96AfNmmdwB3fAA47******";
$gateway->setApiKey($apiKey);


$transaction = $gateway->purchase($transaction_data);

$response = $transaction->send();

if ($response->isSuccessful()) {

    session()->push('ticket_order_' . $event_id . '.transaction_id',
        $response->getTransactionReference());

    return $this->completeOrder($event_id);

} elseif ($response->isRedirect()) {
    /*
     * As we're going off-site for payment we need to store some data in a session so it's available
     * when we return
     */
    session()->push('ticket_order_' . $event_id . '.transaction_data', $transaction_data);
    Log::info("Redirect url: " . $response->getRedirectUrl());

    $return = [
        'status'       => 'success',
        'redirectUrl'  => $response->getRedirectUrl(),
        'message'      => 'Redirecting to ' . $ticket_order['payment_gateway']->provider_name
    ];

    // GET method requests should not have redirectData on the JSON return string
    if($response->getRedirectMethod() == 'POST') {
        $return['redirectData'] = $response->getRedirectData();
    }

    return response()->json($return);

} else {
    // display error to customer
    return response()->json([
        'status'  => 'error',
        'message' => $response->getMessage(),
    ]);
}

当我调试我的代码时,他会进入 elseif ($response->isRedirect()) {。我被重定向到 Mollie,并且可以成功付款。但是当我被重定向回 http://myurl.dev/e/1/checkout/success?is_payment_successful=1 时,我收到了错误。

更新:

在我的返回函数中,我有以下代码:

public function showEventCheckoutPaymentReturn(Request $request, $event_id)
{
    if ($request->get('is_payment_cancelled') == '1') {
        session()->flash('message', 'You cancelled your payment. You may try again.');
        return response()->redirectToRoute('showEventCheckout', [
            'event_id'             => $event_id,
            'is_payment_cancelled' => 1,
        ]);
    }

    $ticket_order = session()->get('ticket_order_' . $event_id);
    $gateway = Omnipay::create($ticket_order['payment_gateway']->name);

    $gateway->initialize($ticket_order['account_payment_gateway']->config + [
            'testMode' => config('attendize.enable_test_payments'),
        ]);

    $transaction = $gateway->completePurchase($ticket_order['transaction_data'][0]);

    $response = $transaction->send();

    if ($response->isSuccessful()) {
        session()->push('ticket_order_' . $event_id . '.transaction_id', $response->getTransactionReference());
        return $this->completeOrder($event_id, false);
    } else {
        session()->flash('message', $response->getMessage());
        return response()->redirectToRoute('showEventCheckout', [
            'event_id'          => $event_id,
            'is_payment_failed' => 1,
        ]);
    }

}

问题(错误)在于 $response = $transaction->send();

数组 $ticket_order['transaction_data'][0] 包含以下内容:

Array
(
    [amount] => 80
    [currency] => EUR
    [description] => Order for customer: niels@email.be
    [transactionId] => 120170529082422
    [returnUrl] => http://eventy.dev/e/1/checkout/success?is_payment_successful=1
)

更新 2:

我在返回函数中添加了 $gateway->setApiKey($apiKey);。但问题是我的回复成功。所以他没有进入$response->isSuccessful()。当我在他检查它是否成功之前转储我的 $response 变量时,它显示:https://pastebin.com/NKCsxJ7B .

你可以看到有这样的错误:

[错误] => 数组 ( [类型] => 请求 [消息] => 付款 ID 无效 )

Mollie 中的付款方式如下所示:

enter image description here

更新 3:

在我的返回函数中,我尝试像这样检查响应对象的状态:$response->status()。这给了我以下错误:

Call to undefined method Omnipay\Mollie\Message\CompletePurchaseResponse::status()

然后我尝试了 $response->getStatus() 但这没有给我任何返回。

最佳答案

@Daan 在他的评论中所说的是正确的,您是从着陆页收到错误,而不是创建交易的页面。

在该着陆页上,您将收到如下电话:

$omnipay->completePurchase($data);

在那个 @data 数组中,您需要包含 'transactionReference' 字段,它应该是您的 POST 参数之一>http://myurl.dev/e/1/checkout/success?is_payment_successful=‌ 1 收到 URL。

可能有用的调试辅助方法是打印出该 URL 处的代码或记录整个 $_POST 数组,您可以使用它来检查需要从该数组中提取哪些参数。它在网关之间略有不同。

关于php - Laravel Omnipay - transactionReference 参数是必需的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44150236/

相关文章:

php - 向 Symfony 中的现有实体添加列

php - 在 Laravel 中添加时间至今查询

laravel - laravel eloquent 中的条件选择语句

javascript - 将支付网关与 angularjs 应用程序和 spring 后端集成

javascript - 无法在支付网关的通用应用程序的 Web View 中运行 JavaScript 警报

php - 标签功能 - 存储两个表之间的关系(3NF)

PHP ZipArchive 在 Laravel 中不工作

php - 如何在 PHP 中调用当前的匿名函数?

php - 从多对多关系生成层次结构

php - 提前整合ccavenue