-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from njoguamos/Add-Transaction-Status-Endpoint
Add transaction status endpoint
- Loading branch information
Showing
15 changed files
with
285 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace NjoguAmos\Pesapal\DTOs; | ||
|
||
use Spatie\LaravelData\Dto; | ||
|
||
class TransactionError extends Dto | ||
{ | ||
public function __construct( | ||
public ?string $error_type = null, | ||
public ?string $code = null, | ||
public ?string $message = null, | ||
public ?string $call_back_url = null, | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace NjoguAmos\Pesapal\DTOs; | ||
|
||
use Spatie\LaravelData\Dto; | ||
|
||
class TransactionStatusResponse extends Dto | ||
{ | ||
public function __construct( | ||
public float $amount, | ||
public string $created_date, | ||
public string $payment_status_description, | ||
public string $call_back_url, | ||
public string $message, | ||
public string $merchant_reference, | ||
public mixed $currency, | ||
public TransactionError $error, | ||
public int $status_code, | ||
public int $status, | ||
public string $payment_method = "", | ||
public ?string $description = null, | ||
public string $confirmation_code = "", | ||
public string $payment_account = "", | ||
public string $payment_status_code = "", | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
enum IpnStatus: int | ||
{ | ||
case Inactive = 0; | ||
case Inactive = 0; | ||
|
||
case Active = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace NjoguAmos\Pesapal\Enums; | ||
|
||
enum TransactionStatus: int | ||
{ | ||
case COMPLETE = 200; | ||
case INCOMPLETE = 500; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace NjoguAmos\Pesapal\Enums; | ||
|
||
enum TransactionStatusCode: int | ||
{ | ||
case INVALID = 0; | ||
case COMPLETED = 1; | ||
case FAILED = 2; | ||
case REVERSED = 3; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace NjoguAmos\Pesapal\Requests; | ||
|
||
use JsonException; | ||
use NjoguAmos\Pesapal\DTOs\TransactionError; | ||
use NjoguAmos\Pesapal\DTOs\TransactionStatusResponse; | ||
use Saloon\Enums\Method; | ||
use Saloon\Http\Request; | ||
use Saloon\Http\Response; | ||
|
||
class GetPesapalTransactionStatus extends Request | ||
{ | ||
protected Method $method = Method::GET; | ||
|
||
public function __construct(public string $orderTrackingId) | ||
{ | ||
} | ||
|
||
public function resolveEndpoint(): string | ||
{ | ||
return '/api/Transactions/GetTransactionStatus'; | ||
} | ||
|
||
protected function defaultQuery(): array | ||
{ | ||
return [ | ||
'orderTrackingId' => $this->orderTrackingId | ||
]; | ||
} | ||
|
||
/** | ||
* @throws JsonException | ||
*/ | ||
public function createDtoFromResponse(Response $response): TransactionStatusResponse | ||
{ | ||
$data = $response->json(); | ||
|
||
return new TransactionStatusResponse( | ||
amount: $data['amount'], | ||
created_date: $data['created_date'], | ||
payment_status_description: $data['payment_status_description'], | ||
call_back_url: $data['call_back_url'], | ||
message: $data['message'], | ||
merchant_reference: $data['merchant_reference'], | ||
currency: $data['currency'], | ||
error: $data['error'] ? new TransactionError( | ||
error_type: $data['error']['error_type'], | ||
code: $data['error']['code'], | ||
message: $data['error']['message'], | ||
call_back_url: $data['error']['call_back_url'], | ||
) : null, | ||
status_code: $data['status_code'], | ||
status: $data['status'], | ||
payment_method: $data['payment_method'], | ||
description: $data['description'], | ||
confirmation_code: $data['confirmation_code'], | ||
payment_account: $data['payment_account'] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
{ | ||
"statusCode": 200, | ||
"headers": { | ||
"Date": "Mon, 18 Mar 2024 13:22:15 GMT", | ||
"Date": "Mon, 18 Mar 2024 15:25:46 GMT", | ||
"Content-Type": "application\/json; charset=utf-8", | ||
"Content-Length": "318", | ||
"Content-Length": "328", | ||
"Connection": "keep-alive", | ||
"Cache-Control": "no-cache", | ||
"Pragma": "no-cache", | ||
"Expires": "-1", | ||
"X-AspNet-Version": "4.0.30319", | ||
"X-Powered-By": "ASP.NET", | ||
"CF-Cache-Status": "DYNAMIC", | ||
"Set-Cookie": "__cf_bm=tSKV1RSqq4T3iONXHtLVyom4qWEJMKKJdL7Xhg0yJk4-1710768135-1.0.1.1-m6pyYyfmIKKbndye.uyza5.Qqk9EdNQo_UByAqrdmfu.VXai0RZiS3cJPhB69R.SVmyfFEruPPfM.izK4aZL4w; path=\/; expires=Mon, 18-Mar-24 13:52:15 GMT; domain=.pesapal.com; HttpOnly; Secure; SameSite=None", | ||
"Set-Cookie": "__cf_bm=TMcbslOMXuGR4UHpnH84yzxHFueA8vNd_uAMSz_LwUg-1710775546-1.0.1.1-buzIBVOpfawq917VWQug09OCAjsF8odkr6UGRJARTFZ8FW0lxYDncd1DRhb4.R9_GENgAII0jbi8xJAQcFSg2A; path=\/; expires=Mon, 18-Mar-24 15:55:46 GMT; domain=.pesapal.com; HttpOnly; Secure; SameSite=None", | ||
"Server": "cloudflare", | ||
"CF-RAY": "866587ce6a8bb19c-NBO" | ||
"CF-RAY": "86663cbb5b73b195-NBO" | ||
}, | ||
"data": "{\"id\":4263,\"url\":\"https:\/\/bednar.com\/beatae-soluta-voluptatibus-rerum-numquam.html\",\"created_date\":\"2024-03-18T13:22:15.5582123Z\",\"ipn_id\":\"473c5154-2aec-4c5c-81ca-dd759e7754fe\",\"notification_type\":0,\"ipn_notification_type_description\":\"GET\",\"ipn_status\":1,\"ipn_status_decription\":\"Active\",\"error\":null,\"status\":\"200\"}" | ||
"data": "{\"id\":4278,\"url\":\"http:\/\/www.padberg.com\/dolores-quia-porro-debitis-architecto-quia-repellat\",\"created_date\":\"2024-03-18T15:25:46.2652354Z\",\"ipn_id\":\"1da86d1c-1e8c-4183-bdfd-dd759463e4ce\",\"notification_type\":0,\"ipn_notification_type_description\":\"GET\",\"ipn_status\":1,\"ipn_status_decription\":\"Active\",\"error\":null,\"status\":\"200\"}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
{ | ||
"statusCode": 200, | ||
"headers": { | ||
"Date": "Mon, 18 Mar 2024 13:22:14 GMT", | ||
"Date": "Mon, 18 Mar 2024 15:25:45 GMT", | ||
"Content-Type": "application\/json; charset=utf-8", | ||
"Content-Length": "563", | ||
"Content-Length": "564", | ||
"Connection": "keep-alive", | ||
"Cache-Control": "no-cache", | ||
"Pragma": "no-cache", | ||
"Expires": "-1", | ||
"X-AspNet-Version": "4.0.30319", | ||
"X-Powered-By": "ASP.NET", | ||
"CF-Cache-Status": "DYNAMIC", | ||
"Set-Cookie": "__cf_bm=yqPIIAwpoHWV20dRfvYL3xT7KFrOcZKBCIScGoL1CnA-1710768134-1.0.1.1-Cp9O07TlMP9CTVlcbLuwkbzGv9BKXPR3kmpJZSIWWSI8rKZuEjiqIskGq6i8viKD6kU7lq1E8LVCu7B2EWARXw; path=\/; expires=Mon, 18-Mar-24 13:52:14 GMT; domain=.pesapal.com; HttpOnly; Secure; SameSite=None", | ||
"Set-Cookie": "__cf_bm=w90xIwC6czVEyR9EeDPt1wzz6lrfKVvHLuW8.nQlhbg-1710775545-1.0.1.1-L0EgE93GdXR3H2odZyz826x5l2B2KG46C1WmuX0R.xQIU5PTzcBo3BCyD4xxO970AHgYDBr50ulsdG01yw_Ctg; path=\/; expires=Mon, 18-Mar-24 15:55:45 GMT; domain=.pesapal.com; HttpOnly; Secure; SameSite=None", | ||
"Server": "cloudflare", | ||
"CF-RAY": "866587c4fabf1b5f-NBO" | ||
"CF-RAY": "86663cb80af31b5f-NBO" | ||
}, | ||
"data": "{\"token\":\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3VzZXJkYXRhIjoiZWQ2MTkwMGYtZGNiMy00NjM2LWIxNGUtY2U1MGQwYzk2M2I1IiwidWlkIjoicWtpbzFCR0dZQVhUdTJKT2ZtN1hTWE5ydW9ac3JxRVciLCJuYmYiOjE3MTA3NjgxMzQsImV4cCI6MTcxMDc3MTczNCwiaWF0IjoxNzEwNzY4MTM0LCJpc3MiOiJodHRwOi8vY3licWEucGVzYXBhbC5jb20vIiwiYXVkIjoiaHR0cDovL2N5YnFhLnBlc2FwYWwuY29tLyJ9.a43PZJpsdO0J_fnUMweaD5Kko8HOWEzFmrMCiAYQvGk\",\"expiryDate\":\"2024-03-18T14:22:14.718041Z\",\"error\":null,\"status\":\"200\",\"message\":\"Request processed successfully\"}" | ||
"data": "{\"token\":\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3VzZXJkYXRhIjoiZWQ2MTkwMGYtZGNiMy00NjM2LWIxNGUtY2U1MGQwYzk2M2I1IiwidWlkIjoicWtpbzFCR0dZQVhUdTJKT2ZtN1hTWE5ydW9ac3JxRVciLCJuYmYiOjE3MTA3NzU1NDUsImV4cCI6MTcxMDc3OTE0NSwiaWF0IjoxNzEwNzc1NTQ1LCJpc3MiOiJodHRwOi8vY3licWEucGVzYXBhbC5jb20vIiwiYXVkIjoiaHR0cDovL2N5YnFhLnBlc2FwYWwuY29tLyJ9.aoSsLyrovYoUXKeyqKfF3EA-Ra8hCkN3kkgvhnFdYEc\",\"expiryDate\":\"2024-03-18T16:25:45.7793772Z\",\"error\":null,\"status\":\"200\",\"message\":\"Request processed successfully\"}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"statusCode": 200, | ||
"headers": { | ||
"Date": "Mon, 18 Mar 2024 15:25:47 GMT", | ||
"Content-Type": "application\/json; charset=utf-8", | ||
"Content-Length": "819", | ||
"Connection": "keep-alive", | ||
"Cache-Control": "no-cache", | ||
"Pragma": "no-cache", | ||
"Expires": "-1", | ||
"X-AspNet-Version": "4.0.30319", | ||
"X-Powered-By": "ASP.NET", | ||
"CF-Cache-Status": "DYNAMIC", | ||
"Set-Cookie": "__cf_bm=WXB8x1wV3imG1BOzwTv.B.KIDmE9LEn.nFUxn_mRQCc-1710775547-1.0.1.1-1CasNIeXi5LQbByo9ubtlDZXKxJtnay7_YQ4kvoOsUaVqSLfFak01QLLTbs5U10u82_bP12E0jq4ZiDZ3BlkNw; path=\/; expires=Mon, 18-Mar-24 15:55:47 GMT; domain=.pesapal.com; HttpOnly; Secure; SameSite=None", | ||
"Server": "cloudflare", | ||
"CF-RAY": "86663cc19fa3b195-NBO" | ||
}, | ||
"data": "{\"payment_method\":\"\",\"amount\":10.00,\"created_date\":\"2024-03-18T18:25:46.75\",\"confirmation_code\":\"\",\"order_tracking_id\":\"96a5e1d9-f711-4423-82ce-dd758f972713\",\"payment_status_description\":\"INVALID\",\"description\":null,\"message\":\"Request processed successfully\",\"payment_account\":\"\",\"call_back_url\":\"http:\/\/www.zemlak.com\/?OrderTrackingId=96a5e1d9-f711-4423-82ce-dd758f972713&OrderMerchantReference=98771cd2-e240-3656-9e10-eb2f3d687ab2\",\"status_code\":0,\"merchant_reference\":\"98771cd2-e240-3656-9e10-eb2f3d687ab2\",\"payment_status_code\":\"\",\"currency\":\"KES\",\"error\":{\"error_type\":\"api_error\",\"code\":\"payment_details_not_found\",\"message\":\"Pending Payment\",\"call_back_url\":\"http:\/\/www.zemlak.com\/?OrderTrackingId=96a5e1d9-f711-4423-82ce-dd758f972713&OrderMerchantReference=98771cd2-e240-3656-9e10-eb2f3d687ab2\"},\"status\":\"500\"}" | ||
} |
Oops, something went wrong.