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

标签 php laravel payment omnipay mollie

我正在尝试在我的 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 在后台发布最终付款状态的页面;和
  • 消费者在付款后返回的页面。

完整流程在 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();
}

接收网络钩子(Hook):

$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
}

消费者返回的页面:

// 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.

关于php - 响应对象 - 使用 Mollie 和 Omnipay 付款,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43775616/

相关文章:

php - digital ocean LAMP 堆栈不工作

javascript - 如何将变量从twig传递到js?

php - 在 Laravel 4 中上传多个文件

php - 智能地将数百万个文件存储在基于日期的文件夹中

php - 比特币支付,OP_RETURN 参数

payment - Braintree API : How can I tell which payment_method is associated with my nonce?

php - 测试网址在 payumoney 中不起作用

php - 拉维尔 : Eloquent Skip records

php - 在 php 中从 mysql 求和值

php - 拉维尔 4 : protecting routes provided by a controller