From 5678bb53d4325e99bad7f8afa3bc194903c0b5ef Mon Sep 17 00:00:00 2001 From: Ariful Islam Date: Tue, 20 Jun 2023 22:47:51 +0600 Subject: [PATCH] feat: Added Verify Payment Functionality --- composer.json | 3 ++- readme.md | 47 ++++++++++++++++++++++++++++++++++++++++++---- src/Paystation.php | 25 ++++++++++++++++++++++-- 3 files changed, 68 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 39f94c6..5fa2368 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,8 @@ "guzzlehttp/guzzle": "^6.3|^7.2", "php": ">=7.3", "ext-curl": "*", - "ext-mbstring": "*" + "ext-mbstring": "*", + "ext-json": "*" }, "autoload": { "psr-4": { diff --git a/readme.md b/readme.md index eb2aaa6..41512f1 100644 --- a/readme.md +++ b/readme.md @@ -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
 
 use Xenon\Paystation\Exception\PaystationPaymentParameterException;
@@ -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());
 }
+
+ +## Step:2 Verify Payment +
+ $config = [
+    'merchantId' => 'xxx',
+    'password' => 'xxxx'
+ ];
+$pay = new Paystation($config);
+$status  = $pay->verifyPayment("invoice_number","trx_id"); //this will retrieve response as json
+
+### sample json response for transaction verification(Success) +
+    {
+        "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"
+        }
+    }
+
+ +### sample json response for transaction verification(Failed) +
+{
+    "status_code": "1006",
+    "status": "failed",
+    "message": "Transaction not found in system"
+}
 
#### 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 diff --git a/src/Paystation.php b/src/Paystation.php index 4896cad..43770d5 100644 --- a/src/Paystation.php +++ b/src/Paystation.php @@ -17,7 +17,7 @@ class Paystation private array $paymentParams = []; /** - * @param array $paymentParams + * @param array $config */ public function __construct(array $config) { @@ -44,6 +44,8 @@ public function getConfig(): array } /** + * @return void + * @throws PaystationException * @throws PaystationPaymentParameterException * @throws \JsonException */ @@ -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 @@ -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"); - } }