Skip to content

Commit

Permalink
Merge pull request #1 from arif98741/dev
Browse files Browse the repository at this point in the history
Paystation Payment Transaction Verification Added
  • Loading branch information
arif98741 authored Jun 20, 2023
2 parents 681e74c + 5678bb5 commit 5207092
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 7 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"guzzlehttp/guzzle": "^6.3|^7.2",
"php": ">=7.3",
"ext-curl": "*",
"ext-mbstring": "*"
"ext-mbstring": "*",
"ext-json": "*"
},
"autoload": {
"psr-4": {
Expand Down
47 changes: 43 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ xenon/paystation is a php library for Bangladeshi payment gateway provider. You
```
composer require xenon/paystation
```

### Sample Code

# Sample Code
## Step:1 Create Payment and Redirect to Payment Url
<pre>

use Xenon\Paystation\Exception\PaystationPaymentParameterException;
Expand All @@ -34,17 +33,57 @@ try {
'callback_url' => "http://www.yourdomain.com/success.php",
// 'checkout_items' => "orderItems"
]);
$pay->payNow();
$pay->payNow(); //will automatically redirect to gateway payment page
} catch (Exception $e) {
var_dump($e->getMessage());
}
</pre>

## Step:2 Verify Payment
<pre>
$config = [
'merchantId' => 'xxx',
'password' => 'xxxx'
];
$pay = new Paystation($config);
$status = $pay->verifyPayment("invoice_number","trx_id"); //this will retrieve response as json
</pre>

### sample json response for transaction verification(Success)
<pre>
{
"status_code": "200",
"status": "success",
"message": "Transaction found",
"data": {
"invoice_number": "ddsf648feebc415138XXXXX",
"trx_status": "Success",
"trx_id": "AFJ7IXXX",
"payment_amount": 1,
"order_date_time": "2023-06-19 11:57:04",
"payer_mobile_no": "01750XXXX",
"payment_method": "bKash",
"reference": "102030",
"checkout_items": null,
"cust_phone": "01700000001"
}
}
</pre>

### sample json response for transaction verification(Failed)
<pre>
{
"status_code": "1006",
"status": "failed",
"message": "Transaction not found in system"
}
</pre>


#### Important Methods
* setPaymentParams()
* payNow()
* verifyPayment()

This library is still in beta version and if you are interested to contribute this , we highly encourage you. Make a fork of this repository
and give send a pull request. If you face any issues or error during development or after deployment, you should crate an issue
Expand Down
25 changes: 23 additions & 2 deletions src/Paystation.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Paystation
private array $paymentParams = [];

/**
* @param array $paymentParams
* @param array $config
*/
public function __construct(array $config)
{
Expand All @@ -44,6 +44,8 @@ public function getConfig(): array
}

/**
* @return void
* @throws PaystationException
* @throws PaystationPaymentParameterException
* @throws \JsonException
*/
Expand All @@ -53,6 +55,26 @@ public function payNow()
$this->createPayment();
}

/**
* This is verification payment for payment
* This will accept invoice_number and trx_id as argent parameters
* @return \GuzzleHttp\Psr7\Response
* @throws \JsonException|PaystationException
*/
public function verifyPayment(string $invoiceNumber, string $transactionId)
{
$instance = PaystationPaymentRequest::getInstance();
$header = [
'token' => Token::getToken($this->config),
];
$instance->setHeaders($header);
$params = [
'invoice_number' => $invoiceNumber,
'trx_id' => $transactionId
];
$requestResponse = $instance->post('retrive-transaction', $header, $params);
return (new Response($requestResponse))->getJsonResponse();
}

/**
* @return void
Expand Down Expand Up @@ -110,7 +132,6 @@ private function validateParams()
}

throw new PaystationPaymentParameterException("Payment parameter '$requiredParamsString' $string required. For better understanding visit https://www.paystation.com.bd/documentation/#create-request-parameters");

}
}

Expand Down

0 comments on commit 5207092

Please sign in to comment.