This repository has been archived by the owner on Oct 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mehedi Hassan
authored and
Mehedi Hassan
committed
Jan 26, 2017
0 parents
commit 935f9ef
Showing
5 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "mehedi/bkash", | ||
"description": "Bkash payment gateway", | ||
"keywords": ["bkash", "payment", "gateway", "php", "laravel"], | ||
"homepage": "https://github.com/MehediDracula/Bkash", | ||
"type": "package", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Mehedi Hassan", | ||
"email": "MehediDracula@gmail.com" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.5.9", | ||
"illuminate/support": "5.0.* || 5.1.* || 5.2.* || 5.3.* || 5.4.*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Mehedi\\Bkash\\": "src/" | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
namespace Mehedi\Bkash; | ||
|
||
use Exception; | ||
|
||
class Bkash | ||
{ | ||
/** | ||
* Bkash api base url. | ||
* | ||
* @var string | ||
*/ | ||
protected $base_url = 'http://www.bkashcluster.com:9080/dreamwave/merchant/trxcheck/sendmsg'; | ||
|
||
/** | ||
* Check bkash payment transaction. | ||
* | ||
* @param string $transactionId | ||
* @return bool | ||
* @throws Exception | ||
*/ | ||
public function check($transactionId) | ||
{ | ||
$fields = [ | ||
'user' => config('bkash.username'), | ||
'pass' => config('bkash.password'), | ||
'msisdn' => config('bkash.mobile'), | ||
'trxid' => $transactionId | ||
]; | ||
|
||
$response = $this->callApi($fields); | ||
|
||
return $this->apiResponse($response); | ||
} | ||
|
||
/** | ||
* Call the bkash api. | ||
* | ||
* @param array $fields | ||
* @return array | ||
*/ | ||
protected function callApi($fields) | ||
{ | ||
$ch = curl_init(); | ||
|
||
curl_setopt($ch, CURLOPT_URL, $this->base_url); | ||
curl_setopt($ch, CURLOPT_POST, 1); | ||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields)); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
|
||
$response = curl_exec($ch); | ||
|
||
curl_close($ch); | ||
|
||
return json_decode($response); | ||
} | ||
|
||
/** | ||
* @param array $response | ||
* @return bool | ||
* @throws Exception | ||
*/ | ||
protected function apiResponse($response) | ||
{ | ||
switch ($response->trxStatus) { | ||
case '0010': | ||
case '0011': | ||
throw new Exception('Transaction is pending, please try again later.'); | ||
break; | ||
|
||
case '0100': | ||
throw new Exception('Transaction ID is valid but transaction has been reversed.'); | ||
break; | ||
|
||
case '0111': | ||
throw new Exception('Transaction is failed.'); | ||
break; | ||
|
||
case '1001': | ||
throw new Exception('Invalid MSISDN input. Try with correct mobile no.'); | ||
break; | ||
|
||
case '1002': | ||
throw new Exception('Invalid transaction ID.'); | ||
break; | ||
|
||
case '1003': | ||
throw new Exception('Authorization Error, please contact site admin.'); | ||
break; | ||
|
||
case '1004': | ||
throw new Exception('Transaction ID not found.'); | ||
break; | ||
|
||
case '9999': | ||
throw new Exception('System error, could not process request. Please contact site admin.'); | ||
break; | ||
|
||
case '0000': | ||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Mehedi\Bkash; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
|
||
class BkashServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Bootstrap the application services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
$this->publishes([ | ||
__DIR__ . '/config/bkash.php' => config_path('bkash.php'), | ||
]); | ||
} | ||
|
||
/** | ||
* Register the application services. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
$this->app->singleton('bkash', function () { | ||
return new Bkash; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Mehedi\Bkash\Facades; | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
|
||
class Bkash extends Facade | ||
{ | ||
/** | ||
* Get the binding in the IoC container | ||
* | ||
* @return string | ||
*/ | ||
protected static function getFacadeAccessor() | ||
{ | ||
return 'bkash'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
return [ | ||
'username' => env('BKASH_USERNAME', null), | ||
|
||
'password' => env('BKASH_PASSWORD', null), | ||
|
||
'mobile' => env('BKASH_MOBILE', null) | ||
]; |