2017-05-04 60 views
2

我正在嘗試使用Omnipay和Mollie在我的Laravel項目中創建付款。我使用下列2個庫:響應對象 - 與Mollie和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'), 
    'returnUrl' => URL::action('[email protected]'), 
]; 


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

有人可以幫助我弄清楚如何與回退功能及以上的工作?

+0

您可以更新您的問題做出更清楚的流動您正在使用?從你的其他問題我明白,這個PHP腳本被稱爲AJAX調用。此代碼創建付款。付款成功完成後,您需要另一個腳本才能撥打電話。 – Daan

+0

@Daan,我沒有再做AJAX請求了。這只是一個普通的POST請求。 – nielsv

+0

付款是否通過重定向到Mollie網關完成? – delatbabel

回答

2

使用莫利典型的設置由三個獨立的網頁:

  • 一個頁面創建付款;
  • 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(); 
} 

接收網絡掛接:

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