Skip to content

Commit dbbb99e

Browse files
add the poll transaction method
1 parent 3e12dfc commit dbbb99e

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

.gitignore

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
# Node artifact files
77
node_modules/
88
dist/
9-
<<<<<<< HEAD
109
Index.php
11-
=======
12-
test.ts
13-
>>>>>>> dev-sean
1410

1511
# Compiled Java class files
1612
*.class
@@ -26,10 +22,7 @@ test.ts
2622

2723
# Maven
2824
target/
29-
<<<<<<< HEAD
3025
dist/
31-
=======
32-
>>>>>>> dev-sean
3326

3427
# JetBrains IDE
3528
.idea/
@@ -56,9 +49,3 @@ Thumbs.db
5649
*.mov
5750
*.wmv
5851

59-
<<<<<<< HEAD
60-
=======
61-
62-
.github/
63-
Index.php
64-
>>>>>>> dev-sean

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ Send of the payment
4646
$response = $pesepay->makeSeamlessPayment($payment, 'Online Transaction', $AMOUNT, $requiredFields, 'MERCHANT_REFERENCE(OPTIONAL)');
4747

4848
if ($response->success()) {
49-
# Save the reference number (used to check the status of a transaction)
49+
# Save the reference number and/or poll url (used to check the status of a transaction)
5050
$referenceNumber = $response->referenceNumber();
51+
$pollUrl = $response->pollUrl();
5152

5253
} else {
5354
#Get Error Message
@@ -67,7 +68,7 @@ Initiate the transaction
6768
$response = $pesepay->initiateTransaction($transaction);
6869

6970
if ($response->success()) {
70-
# Save the reference number (used to check the status of a transaction)
71+
# Save the reference number and/or poll url (used to check the status of a transaction)
7172
$referenceNumber = $response->referenceNumber();
7273
$pollUrl = $response->pollUrl();
7374
# Get the redirect url and redirect user to complete transaction
@@ -80,6 +81,7 @@ if ($response->success()) {
8081
```
8182

8283
### Check Payment Status
84+
#### Method 1: Using referenceNumber
8385
```php
8486
$response = $pesepay->checkPayment($referenceNumber);
8587

@@ -94,3 +96,18 @@ if ($response->success()) {
9496
$errorMessage = $response->message();
9597
}
9698
```
99+
#### Method 2: Using poll url
100+
```php
101+
$response = $pesepay->pollTransaction($pollUrl);
102+
103+
if ($response->success()) {
104+
105+
if ($response->paid()) {
106+
# Payment was successfull
107+
}
108+
109+
} else {
110+
# Get error message
111+
$errorMessage = $response->message();
112+
}
113+
```

src/Pesepay.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ public function __construct($integrationKey, $encryptionKey) {
4040
$this->encryptionKey = $encryptionKey;
4141
}
4242

43-
public function checkPayment($referenceNumber) {
44-
$url = self::CHECK_PAYMENT_URL.'?referenceNumber='.$referenceNumber;
43+
public function pollTransaction($pollUrl) {
4544

46-
$response = $this->initCurlRequest("GET", $url);
45+
$response = $this->initCurlRequest("GET", $pollUrl);
4746

4847
if ($response instanceof ErrorResponse)
4948
return $response;
@@ -58,6 +57,11 @@ public function checkPayment($referenceNumber) {
5857
return new Response($referenceNumber, $pollUrl, null, $paid);
5958
}
6059

60+
public function checkPayment($referenceNumber) {
61+
$url = self::CHECK_PAYMENT_URL.'?referenceNumber='.$referenceNumber;
62+
return $this->pollTransaction($url);
63+
}
64+
6165
public function initiateTransaction($transaction) {
6266
if ($this->resultUrl == null)
6367
throw new \InvalidArgumentException('Result url has not beeen specified.');

0 commit comments

Comments
 (0)