Skip to content

Commit

Permalink
Merge pull request #10 from njoguamos/Support-Order-Request-Endpoint
Browse files Browse the repository at this point in the history
Support Submit Order Request Endpoint
  • Loading branch information
njoguamos authored Mar 18, 2024
2 parents 6180fbb + 7e50597 commit c1fb957
Show file tree
Hide file tree
Showing 17 changed files with 2,350 additions and 221 deletions.
58 changes: 57 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ use NjoguAmos\Pesapal\Models\PesapalIpn;
$ips = PesapalIpn::all();
```


```php
[
[
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"php": "^8.1 | ^8.2 | ^8.3",
"illuminate/contracts": "^10.0",
"saloonphp/saloon": "^3.7.0",
"spatie/laravel-data": "^4.4",
"spatie/laravel-package-tools": "^1.16.3"
},
"require-dev": {
Expand Down
Loading

0 comments on commit c1fb957

Please sign in to comment.