响应对象 - 使用 Mollie 和 Omnipay 付款

Response object - Payment with Mollie and Omnipay

我正在尝试在我的 Laravel 项目中使用 Omnipay 和 Mollie 创建付款。我正在使用以下 2 个库:

我在我的代码中执行以下操作:

$gateway = Omnipay\Omnipay::create('Mollie');

$gateway->setApiKey('test_gSDS4xNA96AfNmmdwB3fAA47zS84KN');

$params = [
    'amount' => $ticket_order['order_total'] + $ticket_order['organiser_booking_fee'],
    'description' => 'Bestelling voor klant: ' . $request->get('order_email'),
    'returnUrl' => URL::action('EventCheckoutController@fallback'),
];


$response = $gateway->purchase($params)->send();

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

    return $this->completeOrder($event_id);
}

付款有效。付款完成后,他返回到函数回退。但是我不知道在这个函数中放什么以及如何返回到if($response->isSuccesfull()...)行。

付款后最重要的事情是:

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

return $this->completeOrder($event_id);

谁能帮我弄清楚如何使用回退功能及以上功能?

使用 Mollie 的典型设置由三个单独的页面组成:

  • 创建付款的页面;
  • Mollie 在后台发布最终支付状态的页面;和
  • 消费者returns付款后的页面。

the Mollie docs 中描述了完整流程。另请查看该页面上的流程图​​。

免责声明:我自己从未使用过 Omnipay,也没有测试以下代码,但它至少应该让您了解如何设置您的项目。

正在创建付款:

$gateway = Omnipay\Omnipay::create('Mollie');
$gateway->setApiKey('test_gSDS4xNA96AfNmmdwB3fAA47zS84KN');

$params = [
    'amount' => $ticket_order['order_total'] + $ticket_order['organiser_booking_fee'],
    'description' => 'Bestelling voor klant: ' . $request->get('order_email'),
    'notifyUrl' => '', // URL to the second script
    'returnUrl' => '', // URL to the third script
];

$response = $gateway->purchase($params)->send();

if ($response->isRedirect()) {
    // Store the Mollie transaction ID in your local database
    store_in_database($response->getTransactionReference());
    // Redirect to the Mollie payment screen
    $response->redirect();
} else {
    // Payment failed: display message to the customer
    echo $response->getMessage();
}

接收网络钩子:

$gateway = Omnipay\Omnipay::create('Mollie');
$gateway->setApiKey('test_gSDS4xNA96AfNmmdwB3fAA47zS84KN');

$params = [
    'transactionReference' => $_POST['id'],
];

$response = $gateway->fetchTransaction($params);

if ($response->isPaid()) {
    // Store in your local database that the transaction was paid successfully
} elseif ($response->isCancelled() || $response->isExpired()) {
    // Store in your local database that the transaction has failed
}

消费者returns访问的页面:

// Check the payment status of your order in your database. If the payment was paid
// successfully, you can display an 'OK' message. If the payment has failed, you
// can show a 'try again' screen.

// Most of the time the webhook will be called before the consumer is returned. For
// some payment methods however the payment state is not known immediately. In
// these cases you can just show a 'payment is pending' screen.