Laravel SDK

Paypack Laravel SDK is a wrapper around the Paypack REST API that can be easily integrated with PHP Laravel applications.

Requirements

  • PHP >= 7.4
  • Composer

Installation

composer require quarksgroup/paypack-php

Configuration

Include the paypack class at the beginning of your file to start using it.

<?php

use Paypack\Paypack;
$paypack = new  Paypack();

$paypack->config([
  'client_id' => env('PAYPACK_CLIENT_ID'),
  'client_secret' => env('PAYPACK_CLIENT_SECRET'),
]);

Laravel SDK have optional parameters that can be passed to the config method.

ParameterDescriptionDefault
webhook_modeOverrides webhook mode. It can be development or productiondevelopment when running localy and production while on server.
headersArray of headers to be sent with every request[]

Example

$paypack->config([
  'client_id' => env('PAYPACK_CLIENT_ID'),
  'client_secret' => env('PAYPACK_CLIENT_SECRET'),
  'webhook_mode' => env('PAYPACK_WEBHOOK_MODE'),    // optional
  'headers' => <headers array>,                    // optional
]);
To be able to receive webhooks, you need to have the same webhook mode on both the SDK and the Paypack dashboard. Transactions that are sent to the wrong webhook mode will be processed but will not be sent to your webhook.

Cashin

The Cashin method is used to request funds from a mobile money account.

$cashin = $paypack->Cashin([
    'phone' => "078xxxxxxx",
    'amount' => "100"
]);

print_r($cashin);

Response

{
  "amount": 1000,
  "created_at": "2005-11-09T21:19:07.459Z",
  "kind": "CASHIN",
  "ref": "d0bb2807-1d52-4795-b373-3feaf63dceb1",
  "status": "pending"
}

Cashout

The Cashout method is used to send funds to a mobile money account.

$cashout = $paypack->Cashout([
    'phone' => "078xxxxxxx",
    'amount' => "100"
]);

print_r($cashout);

Response

{
  "amount": 1000,
  "created_at": "2005-11-09T21:19:07.459Z",
  "kind": "CASHOUT",
  "ref": "d0bb2807-1d52-4795-b373-3feaf63dceb1",
  "status": "pending"
}

Transactions

The Transactions method is used to get a list of that have been processed.

$transactions = $paypack->Transactions([
  'offset' => "0",
    'limit' => "100"
]);

print_r($transactions);
If a transaction status is still pending, it will not be included in the transactions list. You can use the Events method to get a list of all transactions that have been created.

Optional parameters

ParameterDescriptionDefault
limitThe number of events to return. The maximum is 100.20
offsetThe number of events to skip before returning.0
kindThe kind of events to return. It can be CASHIN or CASHOUT.NULL
statusThe status of events to return. It can be successful, failed or pendingNULL
fromThe start date of events to return.NULL
toThe end date of events to return.NULL
clientThe client phone number of events to return.NULL
providerThe provider of events to return. It can be mtn or airtel.NULL

Response

{
  "cashin": 1000,
  "cashout": 1000,
  "fee": 23,
  "from": "2014-05-16T08:28:06",
  "kind": "CASHIN",
  "limit": 25,
  "offset": 0,
  "to": "2014-05-17T08:28:06",
  "total": 250,
  "transactions": [
    {
      "amount": 1000,
      "client": "078xxxxxxx",
      "fee": 23,
      "kind": "CASHOUT",
      "merchant": "IJOK9F",
      "provider": "mtn",
      "ref": "d0bb2807-1d52-4795-b373-3feaf63dceb1",
      "status": "pending",
      "timestamp": "2014-05-16T08:28:06.801064-04:00"
    }
  ]
}

Find a transaction

$transaction = $paypack->Transaction({transaction_ref});

print_r($transaction);
If the transaction is not found, it may be because it is still pending and has not been processed yet. You can use the Events method to get a list of all transactions that have been created.

Response

{
  "amount": 1000,
  "client": "078xxxxxxx",
  "fee": 23,
  "kind": "CASHOUT",
  "merchant": "IJOK9F",
  "ref": "d0bb2807-1d52-4795-b373-3feaf63dceb1",
  "status": "successful",
  "timestamp": "2014-05-16T08:28:06.801064-04:00"
}

Events

$events = $paypack->Events([
    'limit' => "10",
    'offset' => "0"
]);

print_r($events);

Optional parameters

ParameterDescriptionDefault
limitThe number of events to return. The maximum is 100.20
offsetThe number of events to skip before returning.0
kindThe kind of events to return. It can be CASHIN or CASHOUT.NULL
statusThe status of events to return. It can be successful, failed or pendingNULL
fromThe start date of events to return.NULL
toThe end date of events to return.NULL
clientThe client phone number of events to return.NULL
refThe reference of events to return.NULL

Response

{
  "amount": 1000,
  "client": "078xxxxxxx",
  "event-kind": "transaction:created",
  "kind": "CASHIN",
  "limit": 20,
  "offset": 0,
  "ref": "d0bb2807-1d52-4795-b373-3feaf63dceb1",
  "status": "failed",
  "total": 250,
  "transactions": [
    {
      "event_id": "bf76c3a8-cafe-11ec-9478-dead2ba023b5",
      "event_kind": "transaction:processed",
      "created_at": "2022-05-03T16:33:22.434606Z",
      "data": {
        "ref": "ajsfh44w3j-4h4r-28438-efnef-e9f44a5b4c2d",
        "kind": "CASHIN",
        "fee": 2.3,
        "merchant": "XXXXX",
        "client": "078xxxxxxx",
        "amount": 100,
        "status": "successful",
        "created_at": "2022-05-03T16:27:01.292808134Z",
        "processed_at": "2022-05-03T16:33:22.434351492Z"
      }
    }
  ]
}

Account Information

$profile = $paypack->me();

print_r($profile);

Response

{
  "balance": 1000,
  "email": "email@example.com",
  "id": "XXXXX",
  "in_rate": 0.05,
  "name": "Company Name",
  "out_rate": 0.05
}