-
-
Notifications
You must be signed in to change notification settings - Fork 4
2. Accepting & processing payments
Harish Toshniwal edited this page Feb 13, 2017
·
5 revisions
- So our user has made it to the checkout page with his product, now he selects Instamojo & clicks the "Proceed to payment" button.
- That should trigger a POST request to a route so you define the route, controller & its method for that route.
- In that controller, make sure to add this at the top
use Lubusin\Mojo\Mojo;
- Then in the method processing the coming POST request from above, you can use
$instamojoFormUrl = Mojo::giveMeFormUrl($user,$amount,$purpose);
-
These 3 parameters are compulsory at instamojo's end so you should pass them in the specified order
- user: The user object, you cant get this easily by Auth::user()
- amount: The amount to be paid
- purpose: Purpose of payment, could be constants defined at your end like a string "purchase"
- OPTIONAL phone number as the fourth argument: If you do not pass the user/buyer's phone number as the fourth argument, the package will look for the phone number in the user object you pass. So if you do not store the phone number in the default users table and store it in some other table, make sure you pass the phone number as the fourth argument.
-
That returns you the URL of the Instamojo's payment form so on the next line you could do
return redirect($instamojoFormUrl);
-
After successful payment, instamojo will redirect the customer to the "redirect_url" you specified in your env file. So make sure you have the route added for that redirect URL pointing it to a controller method.
-
That redirect route should accept 2 optional parameters as instamojo appends the payment & request id in that route while redirecting, so your route may look something like this
Route::get('/yourRoute/{payment_id?}/{request_id?}','SomeController@methodName');
- In that method assigned (in this example that "methodName" method in "SomeController") you can do
$details = Mojo::giveMePaymentDetails();
- It returns you that payment's detail. So you can pass that details to your view where you can show your user the confirmation text something like: "The payment of {{ $details->amount }} was successful."
Documentation for using the instamojo WEBHOOK is on the next page