Laravel Omnipay - transactionReference 参数是必需的

Laravel Omnipay - The transactionReference parameter is required

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

他们已经有支付提供商 Stripe integrated. Now I'm trying to make this work with the payment provider Mollie

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

我的代码如下所示:

$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 时,我收到了错误。

更新:

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

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:

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

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

[error] => Array ( [type] => request [message] => The payment id is invalid )

Mollie 中的付款方式如下:

更新 3:

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

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

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

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

在该着陆页上,您将接到这样的电话:

$omnipay->completePurchase($data);

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

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

这可能与这张票有关:https://github.com/thephpleague/omnipay-eway/issues/13

要解决此检查,我建议使用

检查状态代码
if ($request->status() == 201) {
    //successful created
}

我的理论是它正在检查 200

函数定义在这里:

https://github.com/thephpleague/omnipay-mollie/blob/master/src/Message/AbstractResponse.php

  public function isSuccessful()
    {
        return !$this->isRedirect() && !isset($this->data['error']);
    }

它可能会失败,因为您希望重定向!

201 因为我下面的 Postman 测试