Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
arif98741 committed Oct 25, 2023
2 parents b323af5 + 7497ef9 commit faf4e07
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 50 deletions.
59 changes: 29 additions & 30 deletions readme.md
@@ -1,6 +1,21 @@
xenon/bkash-php is a Bkash PHP SDK for integrating bkash api in website easily. Follow below steps for better understanding.


<!-- TOC -->
* [Step 1: Installation](#step-1-installation)
* [Step 2: Format Configuration](#step-2-format-configuration)
* [Step 3: Exception](#step-3-exception)
* [Exception Handling](#exception-handling)
* [Create Payment Url](#create-payment-url)
* [If everything goes well then it will return below object. After that redirect to bkashURL from below object](#if-everything-goes-well-then-it-will-return-below-object-after-that-redirect-to-bkashurl-from-below-object)
* [Execute Payment](#execute-payment)
* [Query Payment](#query-payment)
* [After successful payment execution, it needs to call **searchTransaction()** method.](#after-successful-payment-execution-it-needs-to-call-searchtransaction-method)
* [Stargazers](#stargazers)
* [Forkers](#forkers)
* [Contributors](#contributors)
<!-- TOC -->

## Step 1: Installation
```
composer require xenon/bkash-php
Expand All @@ -21,26 +36,8 @@ $configuration = [
];
</pre>

## Step 3: Set Environment
create object from BkashPhp Class
<pre>
use Xenon\BkashPhp\BkashPhp;

$configuration = [
'config' => [
"app_key" => "app key goes here",
"app_secret" => "app secret goes here",
],
'headers' => [
"username" => "username goes here",
"password" => "password goes here",
]
];
$bkash = new BkashPhp($configuration);
$bkash->setEnvironment('sandbox'); //sandbox|production
</pre>

## Step 4: Exception
## Step 3: Exception
### Exception Handling
`use Xenon\BkashPhp\Handler\Exception\RenderBkashPHPException`

Expand All @@ -50,7 +47,7 @@ Always call below methods under try block. After any of this method failed or e
**executePayment()**<br>
**searchTransaction()**

### Create Payment Url
## Create Payment Url
Bkash payment gateway allows you to create payment url based on different parameters. Follow below code sample

<pre>
Expand Down Expand Up @@ -84,10 +81,10 @@ stdClass Object
[statusMessage] => Successful
[paymentID] => TR0011DVJQOkh169400XXX
[bkashURL] => https://sandbox.payment.bkash.com/redirect/tokenized/?paymentID=TR0011DVJQOkh1694007349990&hash=yaJMHgVb_BW_pJuxErXXXdf8-QFyHHG0bqkwBdUU(NLFwI(-ltH8z36kpnxtxa5Xs5tJxFxW5KoyKN5nWPisXXXXXXXXXXX50209&mode=0011&apiVersion=v1.2.0-beta
[callbackURL] => http://http://127.0.0.1/bkash-project/bkash-payment
[successCallbackURL] => http://http://127.0.0.1/bkash-project/bkash-payment?paymentID=TR0011DVJQOkh169400XXX&status=success
[failureCallbackURL] => http://http://127.0.0.1/bkash-project/bkash-payment?paymentID=TR0011DVJQOkh169400XXX&status=failure
[cancelledCallbackURL] => http://http://127.0.0.1/bkash-project/bkash-payment?paymentID=TR0011DVJQOkh169400XXX&status=cancel
[callbackURL] => http://example.com/callback
[successCallbackURL] => http://example.com/callback?paymentID=TR0011DVJQOkh169400XXX&status=success
[failureCallbackURL] => http://example.com/callback?paymentID=TR0011DVJQOkh169400XXX&status=failure
[cancelledCallbackURL] => http://example.com/callback?paymentID=TR0011DVJQOkh169400XXX&status=cancel
[amount] => 10
[intent] => sale
[currency] => BDT
Expand All @@ -97,7 +94,7 @@ stdClass Object
)
</pre>

### Execute Payment
## Execute Payment
After payment done customer will be redirected to merchant callback url having query string like below <br>
`"https://example.com?paymentID=TR0011ZCxlJhC1693137759378&status=success"`

Expand Down Expand Up @@ -134,8 +131,8 @@ stdClass Object
)
</pre>

### Query Payment
#### After successful payment execution, it needs to call **searchTransaction()** method.
## Query Payment
### After successful payment execution, it needs to call **searchTransaction()** method.
<pre>
use Xenon\BkashPhp\Handler\Exception\RenderBkashPHPException
use Xenon\BkashPhp\BkashPhp;
Expand Down Expand Up @@ -168,13 +165,15 @@ stdClass Object
)
</pre>

### Stargazers

## Stargazers
[![Stargazers repo roster for @arif98741/bkash-php](https://reporoster.com/stars/arif98741/bkash-php)](https://github.com/arif98741/bkash-php/stargazers)

### Forkers
## Forkers
[![Forkers repo roster for @arif98741/bkash-php](https://reporoster.com/forks/arif98741/bkash-php)](https://github.com/arif98741/bkash-php/network/members)

### Contributors
## Contributors

<a href="https://github.com/arif98741/bkash-php/graphs/contributors">
<img src="https://contrib.rocks/image?repo=arif98741/bkash-php" />
</a>
Expand Down
21 changes: 10 additions & 11 deletions src/BkashPhp.php
Expand Up @@ -15,16 +15,18 @@ class BkashPhp
/**
* @var mixed|true
*/
private string $environment = 'sandbox';
private string $environment;

/**
* @param array $configuration
* @param string $environment
* @throws RenderBkashPHPException
*/
public function __construct(array $configuration)
public function __construct(array $configuration, string $environment = 'sandbox')
{
$this->configuration = $configuration['config'];
$this->header = $configuration['headers'];
$this->environment = $environment;
$this->generateToken();
}

Expand All @@ -46,6 +48,7 @@ public function getConfig(): array
/**
* Set Environment. For testing use "sandbox"
* For live use "production"
* @deprecated
* @param string $sandboxEnvironment
* @return BkashPhp
* @throws RenderBkashPHPException
Expand Down Expand Up @@ -76,7 +79,7 @@ private function generateToken(): void
}

/**
* @return mixed
* @return string
*/
private function getToken()
{
Expand All @@ -87,9 +90,8 @@ private function getToken()
* @param array $paymentData
* @return object
* @throws RenderBkashPHPException
* @throws JsonException
*/
public function createTokenizedPayment(array $paymentData)
public function createTokenizedPayment(array $paymentData): object
{
$this->setHeader($this->getAuthorization());
return (new Payment)->createPayment($this, $paymentData);
Expand All @@ -110,12 +112,9 @@ public function executePayment(string $paymentId)
return (new Payment)->executePayment($this, $data);
}


public function queryPayment()
{

}

/**
* @throws RenderBkashPHPException
*/
public function searchTransaction(string $trxID)
{
$this->setHeader($this->getAuthorization());
Expand Down
4 changes: 2 additions & 2 deletions src/Handler/ErrorCode/Code.php
Expand Up @@ -2,13 +2,13 @@

namespace Xenon\BkashPhp\Handler\ErrorCode;

use Xenon\LaravelBDSms\Handler\ParameterException;
use Xenon\BkashPhpLaravel\Handler\Exception\ParameterException;

class Code
{
/**
* @param $key
* @return string|void
* @return string
* @throws ParameterException
*/
public function getExceptionMessage($key)
Expand Down
4 changes: 2 additions & 2 deletions src/Request/Payment.php
Expand Up @@ -27,7 +27,7 @@ public function createPayment(BkashPhp $param, array $paymentData): object
/**
* @param BkashPhp $param
* @param $paymentData
* @return void
* @return mixed
* @throws RenderBkashPHPException
*/
public function executePayment(BkashPhp $param, $paymentData)
Expand All @@ -43,7 +43,7 @@ public function executePayment(BkashPhp $param, $paymentData)
/**
* @param BkashPhp $param
* @param $paymentData
* @return void
* @return mixed
* @throws RenderBkashPHPException
*/
public function searchTransaction(BkashPhp $param, $paymentData)
Expand Down
21 changes: 16 additions & 5 deletions src/Request/Token.php
Expand Up @@ -2,6 +2,7 @@

namespace Xenon\BkashPhp\Request;

use Exception;
use Xenon\BkashPhp\Handler\Exception\RenderBkashPHPException;

class Token
Expand All @@ -11,11 +12,21 @@ class Token
*/
public static function getToken(object $object)
{
$tokenRequestObject = new BkashRequest($object);
$tokenResponse = $tokenRequestObject->post('tokenized/checkout/token/grant');
if ($tokenResponse->getStatusCode() === 200) {
return $tokenResponse->getContentsObject()->id_token;
try {
$tokenResponse = (new BkashRequest($object))->post('tokenized/checkout/token/grant');

if ($tokenResponse->getStatusCode() !== 200) {
throw new RenderBkashPHPException("Failed to generate token. Check credentials");
}

$contentsObject = $tokenResponse->getContentsObject();
if ($contentsObject->statusCode !== '0000') {
throw new RenderBkashPHPException("Code: {$contentsObject->statusCode}; {$contentsObject->statusMessage}");
}

return $contentsObject->id_token;
} catch (Exception $e) {
throw new RenderBkashPHPException("{$e->getMessage()}");
}
throw new RenderBkashPHPException("Failed to generate token. Check credentials");
}
}

0 comments on commit faf4e07

Please sign in to comment.