gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 21:00:36 25 4
gpt4 key购买 nike

我正在尝试在我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com