Skip to content

Commit

Permalink
Naming conventions improved & curl check added
Browse files Browse the repository at this point in the history
  • Loading branch information
introwit committed Nov 20, 2016
1 parent 1c724d8 commit 5a571f9
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 55 deletions.
106 changes: 57 additions & 49 deletions src/Mojo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Lubus\Mojo;

use Lubus\Mojo\Models\MojoTransactionDetails;
use Lubus\Mojo\Models\MojoPaymentDetails;
use Lubus\Mojo\Models\MojoRefundDetails;
use Illuminate\Http\Request;
use App\Http\Requests;
Expand Down Expand Up @@ -90,21 +90,21 @@ public static function updateDB($details)
$user = User::where('email',$details->email)->first();
$user_id = $user->id;

MojoTransactionDetails::create(['user_id' => $user_id,
'buyer_email' => $details->email,
'buyer_name' => $details->buyer_name,
'buyer_phone' => $details->phone,
'currency' => $details->payment->currency,
'amount' => $details->amount,
'fees' => $details->payment->fees,
'longurl' => $details->longurl,
'payment_id' => $details->payment->payment_id,
'payment_request_id' => $details->id,
'purpose' => $details->purpose,
'shorturl' => $details->shorturl,
'request_status' => $details->status,
'payment_status' => $details->payment->status,
]);
MojoPaymentDetails::create(['user_id' => $user_id,
'buyer_email' => $details->email,
'buyer_name' => $details->buyer_name,
'buyer_phone' => $details->phone,
'currency' => $details->payment->currency,
'amount' => $details->amount,
'fees' => $details->payment->fees,
'longurl' => $details->longurl,
'payment_id' => $details->payment->payment_id,
'payment_request_id' => $details->id,
'purpose' => $details->purpose,
'shorturl' => $details->shorturl,
'request_status' => $details->status,
'payment_status' => $details->payment->status,
]);
DB::commit();
return true;
}
Expand All @@ -118,56 +118,63 @@ public static function updateDB($details)

public static function setupCURL($endPoint,$key,$token)
{
$c_init = curl_init();

curl_setopt($c_init, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c_init, CURLOPT_URL, $endPoint);
curl_setopt($c_init, CURLOPT_HEADER, FALSE);
curl_setopt($c_init, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($c_init, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($c_init, CURLOPT_HTTPHEADER,[
"X-Api-Key: $key",
"X-Auth-Token: $token"]
);

return $c_init;
if (extension_loaded("curl"))
{
$c_init = curl_init();

curl_setopt($c_init, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c_init, CURLOPT_URL, $endPoint);
curl_setopt($c_init, CURLOPT_HEADER, FALSE);
curl_setopt($c_init, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($c_init, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($c_init, CURLOPT_HTTPHEADER,[
"X-Api-Key: $key",
"X-Auth-Token: $token"]
);

return $c_init;
}
else
{
dd("Curl is not loaded");
}
}

public static function allTransactions()
public static function allPayments()
{
return $allTransactionDetails = MojoTransactionDetails::all();
return $allPaymentDetails = MojoPaymentDetails::all();
}

public static function allTransactionsFor(User $user)
public static function allPaymentsFor(User $user)
{
return $userSpecificDetails = MojoTransactionDetails::where('user_id',$user->id)->get();
return $userSpecificDetails = MojoPaymentDetails::where('user_id',$user->id)->get();
}

public static function failedPayments()
{
return $failedPayments = MojoTransactionDetails::where('payment_status','!=','credit')->get();
return $failedPayments = MojoPaymentDetails::where('payment_status','!=','credit')->get();
}

public static function successfulPayments()
{
return $successfulPayments = MojoTransactionDetails::where('payment_status','credit')->get();
return $successfulPayments = MojoPaymentDetails::where('payment_status','credit')->get();
}

public static function myAndMojosIncome()
{
return $totalIncome = MojoTransactionDetails::sum('amount');
return $totalIncome = MojoPaymentDetails::sum('amount');
}

public static function myIncome()
{
$a = MojoTransactionDetails::sum('amount');
$f = MojoTransactionDetails::sum('fees');
$a = MojoPaymentDetails::sum('amount');
$f = MojoPaymentDetails::sum('fees');
return $earnings = $a - $f;
}

public static function mojosIncome()
{
return $mojoShare = MojoTransactionDetails::sum('fees');
return $mojoShare = MojoPaymentDetails::sum('fees');
}

public static function refund($payment_id,$type,$reason)
Expand All @@ -191,20 +198,21 @@ public static function refund($payment_id,$type,$reason)
$finalResponse = json_decode($response);
$refund = $finalResponse->refund;

$inst = MojoTransactionDetails::where('payment_id',$payment_id)->first();
$inst = MojoPaymentDetails::where('payment_id',$payment_id)->first();
$user_id = $inst->user_id;

MojoRefundDetails::create(['user_id' => $user_id,
'payment_id' => $payment_id,
'status' => $refund->status,
'type' => $refund->type,
'body' => $refund->body,
'refund_amount' => $refund->refund_amount,
'total_amount' => $refund->total_amount,
]);
$refund_record = MojoRefundDetails::create(['user_id' => $user_id,
'refund_id' => $refund->refund_id,
'payment_id' => $payment_id,
'status' => $refund->status,
'type' => $refund->type,
'body' => $refund->body,
'refund_amount' => $refund->refund_amount,
'total_amount' => $refund->total_amount,
]);

DB::commit();
return $refund;
return $refund_record;
}

catch(Exception $e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateMojoTransactionDetailsTable extends Migration
class CreateMojoPaymentDetailsTable extends Migration
{
/**
* Run the migrations.
Expand All @@ -13,7 +13,7 @@ class CreateMojoTransactionDetailsTable extends Migration
*/
public function up()
{
Schema::create('mojo_transaction_details', function (Blueprint $table) {
Schema::create('mojo_payment_details', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users');
Expand Down Expand Up @@ -41,6 +41,6 @@ public function up()
*/
public function down()
{
Schema::dropIfExists('mojo_transaction_details');
Schema::dropIfExists('mojo_payment_details');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function up()
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users');
$table->string('refund_id');
$table->string('payment_id');
$table->string('status');
$table->string('type');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use Illuminate\Database\Eloquent\Model;

class MojoTransactionDetails extends Model
class MojoPaymentDetails extends Model
{
protected $table = 'mojo_transaction_details';
protected $table = 'mojo_payment_details';

protected $fillable = ['user_id','buyer_email','buyer_name','buyer_phone','currency','amount','fees','longurl','payment_id',
'payment_request_id','purpose','shorturl','request_status','payment_status',];
Expand Down
2 changes: 1 addition & 1 deletion src/models/MojoRefundDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MojoRefundDetails extends Model
{
protected $table = 'mojo_refund_details';

protected $fillable = ['user_id','payment_id','status','type','body','refund_amount','total_amount',];
protected $fillable = ['user_id','refund_id','payment_id','status','type','body','refund_amount','total_amount',];
}

?>

0 comments on commit 5a571f9

Please sign in to comment.