From 5a571f978e8f0a53def8c66b8c5b13cfea8e1cc5 Mon Sep 17 00:00:00 2001 From: Harish Date: Sun, 20 Nov 2016 13:24:45 +0530 Subject: [PATCH] Naming conventions improved & curl check added --- src/Mojo.php | 106 ++++++++++-------- ...000_create_mojo_payment_details_table.php} | 6 +- ...00000_create_mojo_refund_details_table.php | 1 + ...tionDetails.php => MojoPaymentDetails.php} | 4 +- src/models/MojoRefundDetails.php | 2 +- 5 files changed, 64 insertions(+), 55 deletions(-) rename src/migrations/{0000_00_00_000000_create_mojo_transaction_details_table.php => 0000_00_00_000000_create_mojo_payment_details_table.php} (85%) rename src/models/{MojoTransactionDetails.php => MojoPaymentDetails.php} (76%) diff --git a/src/Mojo.php b/src/Mojo.php index 1be471d..e1bf7a3 100644 --- a/src/Mojo.php +++ b/src/Mojo.php @@ -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; @@ -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; } @@ -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) @@ -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) diff --git a/src/migrations/0000_00_00_000000_create_mojo_transaction_details_table.php b/src/migrations/0000_00_00_000000_create_mojo_payment_details_table.php similarity index 85% rename from src/migrations/0000_00_00_000000_create_mojo_transaction_details_table.php rename to src/migrations/0000_00_00_000000_create_mojo_payment_details_table.php index 15d1134..ee22a84 100644 --- a/src/migrations/0000_00_00_000000_create_mojo_transaction_details_table.php +++ b/src/migrations/0000_00_00_000000_create_mojo_payment_details_table.php @@ -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. @@ -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'); @@ -41,6 +41,6 @@ public function up() */ public function down() { - Schema::dropIfExists('mojo_transaction_details'); + Schema::dropIfExists('mojo_payment_details'); } } \ No newline at end of file diff --git a/src/migrations/0000_00_00_000000_create_mojo_refund_details_table.php b/src/migrations/0000_00_00_000000_create_mojo_refund_details_table.php index 2d80864..93087c0 100644 --- a/src/migrations/0000_00_00_000000_create_mojo_refund_details_table.php +++ b/src/migrations/0000_00_00_000000_create_mojo_refund_details_table.php @@ -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'); diff --git a/src/models/MojoTransactionDetails.php b/src/models/MojoPaymentDetails.php similarity index 76% rename from src/models/MojoTransactionDetails.php rename to src/models/MojoPaymentDetails.php index a36f3ef..511bee5 100644 --- a/src/models/MojoTransactionDetails.php +++ b/src/models/MojoPaymentDetails.php @@ -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',]; diff --git a/src/models/MojoRefundDetails.php b/src/models/MojoRefundDetails.php index 15315a4..4a6b87b 100644 --- a/src/models/MojoRefundDetails.php +++ b/src/models/MojoRefundDetails.php @@ -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',]; } ?> \ No newline at end of file