function anvena($token) { $api = new Instamojo('b0702bd721ad77f700aa98e4b5a8832a', 'aec9d4a72e40263ea010f35beae47f96'); try { $response = $api->linkCreate(array('title' => 'Hello API', 'description' => 'Create a new Link easily', 'base_price' => Sesson::price, 'currency' => 'INR', 'redirect_url' => 'http://localhost:8000/sucess' . $token)); print_r($response); } catch (Exception $e) { print 'Error: ' . $e->getMessage(); } }
/** * This function is used to upload songs to server * Creates payment link and redirect it to instamojo page */ function uploadSong(Request $request) { if (!Auth::check()) { return 'Please login'; } $this->user_destination = 'uploads/' . Auth::user()->username; if (Input::file('track') === null) { return Redirect::back()->withErrors(['File not found']); } $file = Input::file('track'); if (!$file->getClientOriginalName() || !$file->getClientOriginalExtension() || !$file->getClientSize() || !$file->getClientMimeType()) { return Redirect::back()->withErrors(['File properties mismatch']); } $allowed_audio_format = array('mp3', 'wav', 'ogg', 'wma', 'aac'); if (!in_array($file->getClientOriginalExtension(), $allowed_audio_format)) { return Redirect::back()->withErrors(['Audio format not supported. Please choose any one format: mp3/wav/ogg/wma/aac']); } if ($file->getClientSize() > 8388608) { $this->common->log('warning', $this->file_name, 'File exceeds 8MB ' . __LINE__); return Redirect::back()->withErrors(['File size exceeds limit. Max file size: 8MB']); } $filename = uniqid() . '-' . $file->getClientOriginalName(); $file->move($this->user_destination, $filename); $song_id = DB::table('upload_details')->insertGetId(['user_id' => Auth::user()->id, 'file_name' => $filename, 'file_destination' => $this->user_destination, 'season_name' => $this->common->getCurrentSeasonDetails()[0]->name, 'season_id' => $this->common->getCurrentSeasonDetails()[0]->id, 'status' => 1, 'payment_status' => 0, 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s")]); $api = new Instamojo($this->config->getImojoConfig()['api_key'], $this->config->getImojoConfig()['auth_token']); try { $create_payment_res = $api->paymentRequestCreate(array("purpose" => $this->common->getPaymentDetails()['purpose'], "amount" => $this->common->getPaymentDetails()['amount'], "send_email" => $this->common->getPaymentDetails()['send_email'], "email" => Auth::user()->email, "redirect_url" => $this->common->getPaymentDetails()['redirect_url'])); if ($create_payment_res && $create_payment_res['id']) { DB::table('transactions')->insert(['user_id' => Auth::user()->id, 'song_id' => $song_id, 'payment_request_id' => $create_payment_res['id'], 'name' => Auth::user()->name, 'email' => Auth::user()->email, 'amount' => $this->common->getPaymentDetails()['amount'], 'shorturl' => $create_payment_res['shorturl'], 'longurl' => $create_payment_res['longurl'], 'redirect_url' => $this->common->getPaymentDetails()['redirect_url'], 'webhook' => $this->common->getPaymentDetails()['webhook'], 'payment_request_status' => $create_payment_res['status'], 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s")]); $this->common->log('info', $this->file_name, 'Inserted to transactions table successfully - ' . __LINE__); return redirect()->away($create_payment_res['longurl']); } else { $this->common->log('error', $this->file_name, 'Invalid payment link ' . __LINE__); // send mail here to admin echo "send mail to admin"; } } catch (\Exception $e) { $this->common->log('error', $this->file_name, 'Payment link not created - ' . __LINE__); print 'Error: ' . $e->getMessage(); // send mail to admin echo "send mail to admin-> exception"; } return redirect()->route('activity'); }