• 1000 таблица.
Код контроллера платежей
<?PHP
namespace App\Http\Controllers\razorpay;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Str;
use App\Payment;
use App\User;
use Auth;
use Redirect,Response;
use Carbon\Carbon;
use Illuminate\Support\Facades\Mail;
use DB;
class PaymentController extends Controller
{
public function show_products(){
return view('razorpay.payment');
}
public function view(Request $request){
$payments = DB::table("payments")
->orderBy('payments.created_at', 'DESC')
->get();
return view('admin.all-transaction', compact('payments'));
}
public function add(){
$users = DB::table("users")->get();
return view('admin.add-transaction', compact('users'));
}
public function getUser($id)
{
$users = DB::table("users")
->where("id",$id)
->get();
return json_encode($users);
}
public function pay_success(Request $request){
$validator = Validator::make($request->all(), [
'name' => 'required',
'email' => 'required|email',
'package' => 'required',
'months' => 'required',
'price' => 'required',
'subtotal' => 'required',
'discount' => 'required',
'grandtotal' => 'required',
]);
if ($validator->fails()) {
return response()->json(['error'=>$validator->errors()], 401);
}
$input = $request->all();
$input['payment_id'] = str_random(40);
$input['order_id'] = Str::random(40);
date_default_timezone_set('asia/calcutta');
$input['months'] = $request->months;
$expiry_date = Carbon::now()->addMonths($input['months']);
$input['expiry_date'] = $expiry_date;
$payment = Payment::create($input);
$arr = array('msg' => 'Payment successful.', 'status' => true);
return Response()->json($arr);
}
public function thank_you()
{
return view('razorpay.thankyou');
}
public function update_package()
{
$userinformations = User::where('id', Auth::id())->get();
//dd($userinformations);
return view('frontend.views.upgrade-package', compact('userinformations'));
}
public function update(Request $request, $id) {
/*$input = $request->all();
date_default_timezone_set('asia/calcutta');
$input['months'] = $request->months;
$expiry_date = Carbon::now()->addMonths($input['months']);
$input['expiry_date'] = $expiry_date;
DB::table('users')->where('id',$request->id)->update($input);
return response()->json($input);*/
date_default_timezone_set('asia/calcutta');
$months = $request->months;
$expiry_date = Carbon::now()->addMonths($months);
$request['expiry_date'] = $expiry_date;
$data = ['id'=>$request->id, 'name'=>$request->name, 'phone'=>$request->phone, 'country'=>$request->country, 'state'=>$request->state,
'purpose'=>$request->purpose, 'package'=>$request->package, 'months'=>$months, 'quantity'=>$request->quantity, 'amount'=>$request->amount, 'expiry_date'=>$expiry_date,];
DB::table('users')->where('id',$request->id)->update($data);
return response()->json($data);
}
}
Скрипт интеграции Razorpya
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
<script>
var SITEURL = 'pay-success';
//alert('SITEURL');
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$('body').on('click', '.buy_now', function(e){
var totalAmount = $('#grandtotal').val();
// var totalAmount = $(this).attr("data-amount");
//alert(totalAmount);
var product_id = $(this).attr("data-id");
var options = {
"key": "****************",
"amount": (totalAmount*100), // 2000 paise = INR 20
"name": "AddSpy",
"description": "Payment",
"image": "http://localhost:8000/frontend/images/addspy1.png",
"handler": function (response){
$.ajax({
url: SITEURL,
type: 'post',
dataType: 'json',
data: {
"_token": $('#token').val(),
razorpay_payment_id: response.razorpay_payment_id ,
totalAmount : totalAmount ,product_id : product_id,
user_id : $('#user_id').val(),
name : $('#name').val(),
email : $('#email').val(),
package : $('#package').val(),
months : $('#months').val(),
price : $("#price").val(),
subtotal : $("#subtotal").val(),
discount : $("#discount").val(),
grandtotal : $("#grandtotal").val(),
expiry_date : $('#expiry_date').val(),
},
success: function (msg) {
window.location.href = 'thank-you';
}
});
},
"prefill": {
"contact": '1234567890',
"email": 'xxxxxxxxx@gmail.com',
},
"theme": {
"color": "#528FF0"
}
};
var rzp1 = new Razorpay(options);
rzp1.open();
e.preventDefault();
});
</script>
Как интегрировать код веб-хуков, пожалуйста помогите мне.
Заранее спасибо.