2015-02-17 46 views
0

我找澄清使用網絡掛接控制器的條紋出納的作爲Laravel文檔描述,我無法確認我的應用程序接收網絡掛接事件:條紋出納網絡掛接

http://laravel.com/docs/5.0/billing#handling-failed-payments

該文檔建議一個路由指向網絡掛接控制器是這樣的:

Route::post('stripe/webhook', 'Laravel\Cashier\[email protected]'); 

的URI的路徑必須進行修改是URI在我的條紋設置。在測試環境中,我使用ngrok來公開本地服務器。

我在尋找的澄清是什麼URI應該爲測試和生產。爲了測試,我應該只使用ngrok轉發url(例如,http://3a4bfceb.ngrok.com),還是需要在公共目錄中有一個腳本來處理來自Stripe的webhook事件。

我不知道控制器是否能夠處理好與handlePayload功能接收數據,或者如果我需要添加額外的PHP腳本(例如webhook.php)的東西如如在條紋文檔描述:

// Set your secret key: remember to change this to your live secret key in production 
// See your keys here https://dashboard.stripe.com/account 
Stripe::setApiKey("sk_test_xxxxxxxxxxxxxxxxxxxxxxx"); 

// Retrieve the request's body and parse it as JSON 
$input = @file_get_contents("php://input"); 
$event_json = json_decode($input); 

// Do something with $event_json 

http_response_code(200); // PHP 5.4 or greater 

如果任何人都可以使用的檢測和生產URI,以及是否額外的處理腳本需要,除了出納WebhookController.php提供幫助,我將不勝感激。

+0

它會很好地工作ngrok,在我的經驗。 – ceejayoz 2015-02-17 21:32:35

回答

0

關於URI本地/測試和生產URI是類似的信息(假定ngrok使用):

本地/測試:http://3a4bfceb.ngrok.com/laravel/public/stripewebhooks

生產:http://website.com/stripewebhooks

在兩個路線例將是:

Route::post('stripewebhooks','Laravel\Cashier\[email protected]'); 

WebhookController.php(這是出納包的一部分)處理所有的傳入事件,所以不需要創建如stripewebhooks.php這樣的文件,其中包含file_get_contents 200條響應代碼,如條帶文檔中所述,用於沒有收銀員的實現。

1

ngrok將工作當然但這是手工測試這是不是真的,你應該如何測試;)

你可以閱讀一些關於本地這裏測試條網絡掛接:enter link description here

它使用一個包專門設計用於啓用自動webhook測試,無需通過ngrok或其他任何方式暴露您的本地環境。

(全面披露:我的夥伴和我寫的博客文章,並提到包兩者)