Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payment integration #317

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,10 @@ MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
MAILCHIMP_APIKEY = ea5072cae56749ce8e619be267a7119e-us5
MAILCHIMP_LIST_ID = 313064917c

RAVE_PUBLIC_KEY=FLWPUBK_TEST-2632b2661e8fb72e6cce1f4482169959-X
RAVE_SECRET_KEY=FLWSECK_TEST-0dc7495ac8531f128c392aa75a8b2b78-X
RAVE_TITLE="Start NG"
RAVE_ENVIRONMENT="staging"
RAVE_LOGO="https://res.cloudinary.com/sgnolebagabriel/image/upload/v1572346080/startng/Logo_2_ee1iqv.png"
RAVE_PREFIX="startdotng"
RAVE_SECRET_HASH=
13 changes: 7 additions & 6 deletions app/Http/Controllers/CourseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,13 @@ public function registerCourses($id)
return back()->with('error', 'You Have Previously Registered for the Course');
}
else{
$add_course = new RegisteredCourses;
$add_course->course_id = $id;
$add_course->user_id = auth()->user()->id;
$add_course->progress = 0;
$add_course->save();
return back()->with('success', 'Registration was Succesful');
$course = Course::find($id);
$user = User::find(auth()->user()->id);
$data = array(
'course' => $course,
'user' => $user
);
return view("user.payment")->with($data);
}
}
else{
Expand Down
74 changes: 74 additions & 0 deletions app/Http/Controllers/RaveController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Rave;
use App\Course;
use App\RegisteredCourses;

class RaveController extends Controller
{

/**
* Initialize Rave payment process
* @return void
*/
public function initialize()
{
//This initializes payment and redirects to the payment gateway
//The initialize method takes the parameter of the redirect URL
Rave::initialize(route('callback'));
}

/**
* Obtain Rave callback information
* @return void
*/
public function callback()
{
$data = Rave::verifyTransaction(request()->txref);

$chargeResponsecode = $data->data->chargecode;
$chargeAmount = $data->data->amount;
$chargeCurrency = $data->data->currency;
$course_id = $data->data->meta[0]->metavalue;

$course = Course::find($course_id);

$amount = $course->price;
$currency = "NGN";
if (($chargeResponsecode == "00" || $chargeResponsecode == "0") && ($chargeAmount == $amount) && ($chargeCurrency == $currency)) {
// transaction was successful...
// please check other things like whether you already gave value for this ref
// if the email matches the customer who owns the product etc
//Give Value and return to Success page


$add_course = new RegisteredCourses;
$add_course->course_id = $id;
$add_course->user_id = auth()->user()->id;
$add_course->progress = 0;
$add_course->save();
return back()->with('success', 'Registration was Succesful');

} else {
//Dont Give Value and return to Failure page

return redirect('/failed');
}

//dd($data);
// Get the transaction from your DB using the transaction reference (txref)
// Check if you have previously given value for the transaction. If you have, redirect to your successpage else, continue
// Comfirm that the transaction is successful
// Confirm that the chargecode is 00 or 0
// Confirm that the currency on your db transaction is equal to the returned currency
// Confirm that the db transaction amount is equal to the returned amount
// Update the db transaction record (includeing parameters that didn't exist before the transaction is completed. for audit purpose)
// Give value for the transaction
// Update the transaction to note that you have given value for the transaction
// You can also redirect to your success page from here
}
}
2 changes: 1 addition & 1 deletion app/Http/Middleware/VerifyCsrfToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ class VerifyCsrfToken extends Middleware
* @var array
*/
protected $except = [
//
'rave/callback'
];
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"php": "^7.2",
"fideloper/proxy": "^4.0",
"intervention/image": "^2.5",
"kingflamez/laravelrave": "^1.1",
"laracasts/flash": "^3.0",
"laravel/framework": "^5.8",
"laravel/tinker": "^1.0",
Expand Down
Loading