Skip to content
This repository has been archived by the owner on Oct 18, 2018. It is now read-only.

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehedi Hassan authored and Mehedi Hassan committed Jan 26, 2017
0 parents commit 935f9ef
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 0 deletions.
25 changes: 25 additions & 0 deletions composer.json
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
}
104 changes: 104 additions & 0 deletions src/Bkash.php
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;
}
}
}
32 changes: 32 additions & 0 deletions src/BkashServiceProvider.php
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;
});
}
}
18 changes: 18 additions & 0 deletions src/Facades/Bkash.php
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';
}
}
9 changes: 9 additions & 0 deletions src/config/bkash.php
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)
];

0 comments on commit 935f9ef

Please sign in to comment.