Skip to content
This repository has been archived by the owner on Jan 10, 2020. It is now read-only.

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
Proper billing link
properly wraps try catch
  • Loading branch information
mlantz committed Mar 20, 2016
1 parent 1711453 commit 1c714b7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
23 changes: 9 additions & 14 deletions src/Billing/app/Http/Controllers/User/BillingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ public function getSubscribe(Request $request)
*/
public function postSubscribe(Request $request)
{
$inputs = $request->all();
$creditCardToken = $inputs['stripeToken'];

try {
$inputs = $request->all();
$creditCardToken = $inputs['stripeToken'];
Auth::user()->meta->newSubscription('main', env('SUBSCRIPTION'))->create($creditCardToken);
return redirect('user/billing/details')->with('message', 'You\'re now subscribed!');
} catch (Exception $e) {
Expand Down Expand Up @@ -75,10 +74,9 @@ public function getChangeCard(Request $request)
*/
public function postChangeCard(Request $request)
{
$inputs = $request->all();
$creditCardToken = $inputs['stripeToken'];

try {
$inputs = $request->all();
$creditCardToken = $inputs['stripeToken'];
Auth::user()->meta->updateCard($creditCardToken);
return redirect('user/billing/details')->with('message', 'Your subscription has been updated!');
} catch (Exception $e) {
Expand Down Expand Up @@ -110,9 +108,8 @@ public function getCoupon(Request $request)
*/
public function postCoupon(Request $request)
{
$inputs = $request->all();

try {
$inputs = $request->all();
Auth::user()->meta->coupon($inputs['coupon']);
return redirect('user/billing/details')->with('message', 'Your coupon was used!');
} catch (Exception $e) {
Expand Down Expand Up @@ -146,9 +143,8 @@ public function getInvoices(Request $request)
*/
public function getInvoiceById($id, Request $request)
{
$user = $request->user();

try {
$user = $request->user();
$response = $user->meta->downloadInvoice($id, [
'vendor' => config("invoice.company"),
'street' => config("invoice.street"),
Expand All @@ -173,11 +169,10 @@ public function getInvoiceById($id, Request $request)
*/
public function cancelSubscription(Request $request)
{
$user = $request->user();
$invoice = $user->meta->upcomingInvoice();
$date = Carbon::createFromTimestamp($invoice->date);

try {
$user = $request->user();
$invoice = $user->meta->upcomingInvoice();
$date = Carbon::createFromTimestamp($invoice->date);
$user->meta->subscription('main')->cancel();
return redirect('user/billing/details')->with('message', 'Your subscription has been cancelled! It will be availale until '.$date);
} catch (Exception $e) {
Expand Down
7 changes: 4 additions & 3 deletions src/Billing/app/Http/billing-routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
|--------------------------------------------------------------------------
*/

Route::group(['middleware' => 'web'], function() {
Route::post('failed/payment', 'Laravel\Cashier\WebhookController@handleWebhook');
});
Route::post(
'stripe/webhook',
'\Laravel\Cashier\Http\Controllers\WebhookController@handleWebhook'
);

0 comments on commit 1c714b7

Please sign in to comment.