-
-
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 #10 from njoguamos/Support-Order-Request-Endpoint
Support Submit Order Request Endpoint
- Loading branch information
Showing
17 changed files
with
2,350 additions
and
221 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,7 +162,6 @@ use NjoguAmos\Pesapal\Models\PesapalIpn; | |
$ips = PesapalIpn::all(); | ||
``` | ||
|
||
|
||
```php | ||
[ | ||
[ | ||
|
@@ -186,6 +185,63 @@ $ips = PesapalIpn::all(); | |
] | ||
``` | ||
|
||
### Submit Order Request Endpoint | ||
|
||
To submit an order request, you can use the `createOrder` method in the `Pesapal` class. You will need to construct a DTO for `PesapalOrderData` and `PesapalAddressData` as shown below. | ||
|
||
> **info** You must provide a registered `PesapalIpn`. | ||
|
||
```php | ||
use NjoguAmos\Pesapal\Enums\ISOCountryCode; | ||
$ipnId = PesapalIpn::latest()->first()->ipn_id; | ||
|
||
$orderData = new PesapalOrderData( | ||
id: fake()->uuid(), | ||
currency: ISOCurrencyCode::KES, | ||
amount: fake()->randomFloat(nbMaxDecimals: 2, min: 50, max: 500), | ||
description: 'Test order', | ||
callbackUrl: fake()->url(), | ||
notificationId: $ipnId, | ||
cancellationUrl: fake()->url(), | ||
redirectMode: RedirectMode::PARENT_WINDOW, | ||
); | ||
|
||
// All fields are optional except either phoneNumber or emailAddress | ||
$billingAddress = new PesapalAddressData( | ||
phoneNumber: '0700325008', | ||
emailAddress: '[email protected]', | ||
countryCode: ISOCountryCode::KE | ||
firstName: 'Amos', | ||
middleName: 'Njogu' | ||
// lastName: '' | ||
line2: "Gil House, Nairobi, Tom Mboya Street", | ||
// city: "", | ||
// state: "", | ||
// postalCode: "", | ||
// zipCode: "", | ||
); | ||
|
||
$order = Pesapal::createOrder( | ||
orderData: $orderData, | ||
billingAddress: $billingAddress, | ||
); | ||
``` | ||
|
||
If the response was successful, your response should be as follows. | ||
|
||
```php | ||
[ | ||
"order_tracking_id" => "b945e4af-80a5-4ec1-8706-e03f8332fb04", | ||
"merchant_reference" => "TEST1515111119", | ||
"redirect_url" => "https://cybqa.pesapal.com/pesapaliframe/PesapalIframe3/Index/?OrderTrackingId=b945e4af-80a5-4ec1-8706-e03f8332fb04", | ||
"error" => null, | ||
"status" => "200" | ||
] | ||
``` | ||
|
||
You can now re-direct the user to the `redirect_url` to complete the payment. | ||
|
||
## Testing | ||
|
||
> **Info** Where possible, the tests uses real [sandbox credentials](https://developer.pesapal.com/api3-demo-keys.txt), and as such the request is not mocked. This ensures the stability of the package. Where it is impossible to use real credentials, the request is mocked. Therefore you must be connected to the internet to run the some of the tests. | ||
|
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
Oops, something went wrong.