响应对象-使用Mollie和Omnipay付款 [英] Response object - Payment with Mollie and Omnipay

查看:141
本文介绍了响应对象-使用Mollie和Omnipay付款的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to create a payment with Omnipay and Mollie in my Laravel project. I'm using the following 2 libraries:

  • https://github.com/barryvdh/laravel-omnipay
  • https://github.com/thephpleague/omnipay-mollie

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

I'm doing the following in my code:

$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()...)行.

The payment works. When the payment is done he goes back to the function fallback. But I don't know what to put in this function and how to go back to the line if($response->isSuccesfull()...).

付款后我需要做的最重要的事情是:

The most important thing I need to do after the payment is :

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

return $this->completeOrder($event_id);

有人可以帮我弄清楚如何使用后备功能吗?

Can someone help me figure out how to work with the fallback function and above?

推荐答案

使用Mollie的典型设置包括三个单独的页面:

A typical setup using Mollie consists of three separate pages:

  • 用于创建付款的页面;
  • Mollie在后台将最终付款状态过帐到的页面;和
  • 消费者付款后返回的页面.

Mollie文档.还要查看该页面上的流程图​​.

The full flow is described in the Mollie docs. Also take a look at the flow diagram at that page.

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

DISCLAIMER: I've never used Omnipay myself and did not test the following code, but it should at least give you an idea how to set up your project.

创建付款:

$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();
}

接收Webhook:

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

这篇关于响应对象-使用Mollie和Omnipay付款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆