what are the contents of the applyCoupon method? Seems like the issue is happening in there.
Cashier Invalid Coupon Code Errors
I am using Laravel 5.2/Cashier 6.0. I can configure a coupon code in Stripe and if I enter the valid coupon code, all is well. The problem I am having is when an invalid coupon (like BADCOUPON) is entered I receive the following error:
InvalidRequest in ApiRequestor.php line 103: No such coupon: BADCOUPON
My Form
{!! Form::open(array('route' => 'plans.coupon', 'class' => 'form-horizontal')) !!}
<input type="text" name="coupon" class="form-control" id="coupon">
<button class="btn btn-info" type="submit">Save</button>
{!! Form::close() !!}
My Routes
Route::get('/invoices', ['as' => 'invoices', 'uses' => 'SubscriptionsController@invoices']);
Route::post('/plans/coupon', ['as' => 'plans.coupon', 'uses' => 'SubscriptionsController@applyCoupon']);
My Controller
public function applyCoupon(Request $request){
$code = $request->get('coupon');
try{
Auth::user()->applyCoupon($code);
return redirect()->back()->withMessage('Coupon Applied');
} catch (Exception $e) {
return redirect()->back()->withError($e->getMessage());
}
}
I am thinking I should see the messages from the try/catch block, but ...
Any thoughts?
I figured out the problem. Actually, I had two:
The first was a namespacing problem and adding a slash in front of Exception resolved that issue.
try {
//
}
catch(\Exception $e) {
//
}
The second issue was that I was calling withError and not withErrors in the applyCoupon method.
Please or to participate in this conversation.