Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
prinx committed Dec 1, 2020
1 parent c89864a commit f5136e1
Showing 1 changed file with 31 additions and 36 deletions.
67 changes: 31 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ class MobileMoneyCallbackController extends Controller

Everything is the same except the code will be in a method instead of directly in the file.

Now, we must register the callback functions that will be run on success, failure or some defined custom condition of the mobile money transaciton. The callback will receive the `$payload` and the `$callback` instance.
Now, we must register the callback functions that will be run on success, failure or some defined custom condition of the mobile money transaciton. The callback will receive the `$callback` instance.

```php
$callback->success(function ($payload, $callback) {
$callback->success(function ($callback) {
// Transaction was successful. Do stuff.
})->failure(function ($payload, $callback) {
})->failure(function ($callback) {
// Transaction failed. Do stuff.
});
```
Expand All @@ -128,9 +128,9 @@ The full code will be:
```php
$callback = new Callback();

$callback->success(function ($payload, $callback) {
$callback->success(function ($callback) {
//
})->failure(function ($payload, $callback) {
})->failure(function ($callback) {
//
})->process();
```
Expand All @@ -141,7 +141,7 @@ In case you have only one callback function that will be run whether the transac
```php
$callback = new Callback;

$callback->process(function ($payload, $callback) {
$callback->process(function ($callback) {
//
});
```
Expand All @@ -161,15 +161,15 @@ use Txtpay\Callback;

$callback = new Callback;

$callback->on('000', function ($payload, $callback) {
$callback->on('000', function ($callback) {
//
})->on('101', function ($payload, $callback) {
})->on('101', function ($callback) {
//
})->on(['code' => '000', 'phone' => '233...'], function ($payload, $callback) {
})->on(['code' => '000', 'phone' => '233...'], function ($callback) {
//
})->success(function ($payload, $callback){
})->success(function ($callback){
// We can still chain the success or failure methods.
})->failure(function ($payload, $callback) {
})->failure(function ($callback) {
//
})->process();
```
Expand All @@ -184,58 +184,64 @@ A payload is sent to the callback URL. It contains 8 parameters:

#### code

The code of the transaction.
The code of the request.

```php
$callback->getCode();
$requestCode = $callback->getCode();
```

#### status

```php
$callback->getStatus(); // approved, declined...
$requestStatus = $callback->getStatus(); // approved, declined...
```

#### details

The detail message of the status.

```php
$callback->getDetails();
$requestDetails = $callback->getDetails();
```

#### id

The transaction ID.

```php
$callback->getId();
$transactionId = $callback->getId();
```

#### network
#### phone

The phone number to which the request was made.

```php
$callback->getNetwork(); // MTN, AIRTEL, VODAFONE, ...
$phone = $callback->getPhone(); // 233...
```

#### phone
#### network

The phone number.
The network to which belong the phone number.

```php
$callback->getPhone(); // 233...
$network = $callback->getNetwork(); // MTN, AIRTEL, VODAFONE, ...
```

#### amount

The amount of the transaction.

```php
$callback->getAmount();
$amount = $callback->getAmount();
```

#### currency

The currency in which the transaction was made.

```php
$callback->getCurrency(); // GHS
$currency = $callback->getCurrency(); // GHS
```

You can get all the payload array by calling the `getPayload` method without parameter.
Expand All @@ -257,7 +263,7 @@ $transactionCode = $callback->getPayload('code');
You can get the message associated to the request by calling the `message` method of the callback instance.

```php
$payload = $callback->getMessage();
$message = $callback->getMessage();
```

The message is associated to the code in the payload.
Expand All @@ -284,27 +290,16 @@ These are the possible messages:
The callback instance is automatically passed to the closure. You can then use it as below:

```php
$callback->success(function ($payload, $callback) {
$callback->success(function ($callback) {
$message = $callback->getMessage();
});
```

Or you can ignore the passed instance and directly use `$this` in the closure.

```php
$callback->success(function ($payload) {
$message = $this->getMessage();
});
```

You can also completely ignore the callback parameters:

```php
$callback->success(function () {
$payload = $this->getPayload();
$message = $this->getMessage();

// ...
});
```

Expand Down

0 comments on commit f5136e1

Please sign in to comment.