Viewing file: InstamojoController.php (3.27 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace App\Http\Controllers\Payment;
use App\Http\Controllers\Controller; use App\Http\Traits\PaymentTrait; use Illuminate\Http\Request;
class InstamojoController extends Controller { use PaymentTrait;
public function pay(Request $request) { $plan = session('plan'); $converted_amount = currencyConversion($plan->price); $amount = currencyConversion($plan->price, null, 'INR', 1);
session(['order_payment' => [ 'payment_provider' => 'instamojo', 'amount' => $amount, 'currency_symbol' => '₹', 'usd_amount' => $converted_amount, ]]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://test.instamojo.com/api/1.1/payment-requests/'); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt( $ch, CURLOPT_HTTPHEADER, [ 'X-Api-Key:'.config('templatecookie.im_key'), 'X-Auth-Token:'.config('templatecookie.im_secret'), ] ); $payload = [ 'purpose' => 'Payment for the plan you bought', 'amount' => $amount, 'phone' => '9888888888', 'buyer_name' => auth('user')->user()->name, 'redirect_url' => route('instamojo.success'), 'send_email' => true, 'webhook' => 'http://www.example.com/webhook/', 'send_sms' => true, 'email' => auth('user')->user()->email, 'allow_repeated_payments' => false, ]; curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload)); $response = curl_exec($ch); curl_close($ch); $response = json_decode($response);
return redirect($response->payment_request->longurl); }
public function success(Request $request) { $input = $request->all();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://test.instamojo.com/api/1.1/payments/'.$request->get('payment_id')); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt( $ch, CURLOPT_HTTPHEADER, [ 'X-Api-Key:'.config('templatecookie.im_key'), 'X-Auth-Token:'.config('templatecookie.im_secret'), ] );
$response = curl_exec($ch); $err = curl_error($ch); curl_close($ch);
if ($err) { return back()->with('error', 'Payment was failed'); } else { $data = json_decode($response); }
if ($data->success == true) { if ($data->payment->status == 'Credit') {
// Here Your Database Insert Login session(['transaction_id' => $request->get('payment_id') ?? null]);
// Here Your Database Insert Login $this->orderPlacing(); } else { \Session::put('error', 'Payment Failed, Try Again!!');
return redirect()->route('payment'); } } } }
|