├── .gitignore ├── README.md ├── composer.json └── src ├── Bank.php ├── Exceptions └── MoneywaveException.php ├── Moneywave.php ├── MoneywaveApiClient.php ├── Resources ├── GetWalletBalance.php ├── PreviousCardToAccount.php ├── PreviousWalletToAccount.php ├── Resource.php ├── RetryFailedTransaction.php ├── TokenizeCard.php └── ValidateAccountNumber.php ├── Traits └── NeedsValidation.php └── Transactions ├── AccountToAccountTransaction.php ├── BulkWalletToAccountTransaction.php ├── CardToAccountTransaction.php ├── CardToWalletTransaction.php ├── TotalChargeToCardTransaction.php ├── Transaction.php └── WalletToAccountTransaction.php /.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | vendor/ 3 | composer.lock 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # moneywave-php 2 | [![Latest Stable Version](https://poser.pugx.org/hngx/moneywave-php/v/stable)](https://packagist.org/packages/hngx/moneywave-php) [![Total Downloads](https://poser.pugx.org/hngx/moneywave-php/downloads)](https://packagist.org/packages/hngx/moneywave-php) [![License](https://poser.pugx.org/hngx/moneywave-php/license)](https://packagist.org/packages/hngx/moneywave-php) [![Latest Unstable Version](https://poser.pugx.org/hngx/moneywave-php/v/unstable)](https://packagist.org/packages/hngx/moneywave-php) 3 | 4 | PHP wrapper for the [Moneywave API](http://moneywave.flutterwave.com/api) 5 | Please consult the official documentation for more details. 6 | 7 | ## Contents 8 | * [Configuration](#configuration) 9 | * [Usage: Dispatching Transactions/Resources](#usage1) 10 | * [Usage: Handling Responses](#usage2) 11 | * [Usage: Errors](#usage3) 12 | * [Installation](#installation) 13 | * [Bugs](#bugs) 14 | 15 | 16 | ## Configuration 17 | To carry out a transaction or access a resource, you will need an instance of the moneywave client 18 | This will be used for your API calls. 19 | 20 | ```php 21 | $mw = new \HngX\Moneywave\Moneywave($yourApiKey, $yourSecretKey); 22 | ``` 23 | 24 | ## Usage: Dispatching Transactions/Resources 25 | ### Performing Transactions 26 | To perform a transaction, there are 3 simple steps: 27 | 28 | 1. Create the transaction. 29 | All transactions take the moneywave client instance as a constructor argument. The `WalletToAccountTransaction` and `BulkWalletToAccountTransaction` transactions also take a second parameter: the wallet password 30 | 31 | 2. Set the appropriate details 32 | All the fields listed for each transaction in [the docs](https://moneywave.flutterwave.com/api) are available as properties on the transaction class (via magic methods), so you can set them individually. Alternatively, you could use the `setDetails()` function to set them in one go. 33 | **Caution**: be sure to use the *exact* parameter names (including capitalisation) as described at https://moneywave.flutterwave.com/api. 34 | The following fields are automatically set for you on each transaction: 35 | 36 | | Field | Default | 37 | | --------- | ----------------------------------------------------------------------------- | 38 | | apiKey | the API key used when creating the `Moneywave` client | 39 | | secret | the secret key used when creating the `Moneywave` client | 40 | | currency | "NGN" | 41 | | lock | (for `WalletToAccountTransaction` and `BulkWalletToAccountTransaction`) the wallet password supplied in the constructor | 42 | 43 | 3. Dispatch the transaction by calling `dispatch()` 44 | 45 | Here is an example: 46 | ```php 47 | 48 | //we want to perform a wallet to account transfer 49 | $tran = new \HngX\Moneywave\Transactions\WalletToAccountTransaction($mw, $walletPassword); 50 | 51 | //set details 52 | $tran->amount = 25000; 53 | $tran->bankcode = \HngX\Moneywave\Bank::STERLING; 54 | $tran->accountNumber = "000056050"; 55 | $tran->senderName = "Johnson"; 56 | $tran->ref = 40; 57 | 58 | //then make the transaction 59 | $tran->dispatch(); 60 | 61 | //or you could do this in a batch 62 | $tran->setDetails(array( 63 | "amount" => 25000, 64 | "bankcode" => \HngX\Moneywave\Bank::STERLING, 65 | "accountNumber" => "000056050", 66 | "senderName" => "Johnson", 67 | "ref" => 40 68 | ))->dispatch(); 69 | ``` 70 | 71 | #### Available Transaction Types 72 | ``` 73 | AccountToAccountTransaction 74 | CardToAccountTransaction 75 | CardToWalletTransaction 76 | TotalChargeToCardTransaction 77 | WalletToAccountTransaction 78 | BulkWalletToAccountTransaction 79 | ``` 80 | 81 | #### Available bank codes 82 | Here is the list of banks currently supported by the Moneywave API. Their codes are available as constants in the `\HngX\Moneywavw\Bank` class: 83 | 84 | ``` 85 | FCMB // FIRST CITY MONUMENT BANK PLC 86 | UNITY // UNITY BANK PLC 87 | STANBIC_IBTC // STANBIC IBTC BANK PLC 88 | STERLING // STERLING BANK PLC 89 | STANBIC_MOBILE // STANBIC Mobile PLC 90 | PAYCOM // PAYCOM 91 | ECOBANK_MOBILE // ECOBANK MOBILE 92 | FBN_MOBILE // FBN MOBILE 93 | PARKWAY // PARKWAY 94 | GTBANK_MOBILE // GTBank Mobile Money 95 | ZENITH_MOBILE // ZENITH Mobile 96 | ACCESS_MOBILE // ACCESS Mobile 97 | ASO // Aso Savings and Loans 98 | ACCESS // ACCESS BANK NIGERIA 99 | AFRIBANK // AFRIBANK NIGERIA PLC 100 | DIAMOND // DIAMOND BANK PLC 101 | ECOBANK // ECOBANK NIGERIA PLC 102 | ENTERPRISE // ENTERPRISE BANK LIMITED 103 | FIDELITY // FIDELITY BANK PLC 104 | FIRST // FIRST BANK PLC 105 | GTBANK // GTBANK PLC 106 | HERITAGE // HERITAGE BANK 107 | KEYSTONE // KEYSTONE BANK PLC 108 | SKYE // SKYE BANK PLC 109 | STANDARD_CHARTERED // STANDARD CHARTERED BANK NIGERIA LIMITED 110 | UNION // UNION BANK OF NIGERIA PLC 111 | UBA // UNITED BANK FOR AFRICA PLC 112 | WEMA // WEMA BANK PLC 113 | ZENITH // ZENITH BANK PLC 114 | 115 | ``` 116 | 117 | ### Accessing a Resource 118 | The same 3 steps apply: 119 | 120 | 1. Create the resource. 121 | All resources take the moneywave client instance as their only constructor argument. 122 | 123 | 2. Set the appropriate details, if any. The `GetWalletBalance` do not need any extra data 124 | All the fields listed for each resource in [the docs](https://moneywave.flutterwave.com/api) are available as properties on the resource class (via magic methods), so you can set them individually. Alternatively, you could use the `setDetails()` function to set them in one go. 125 | **Caution**: be sure to use the *exact* parameter names (including capitalisation) as described at https://moneywave.flutterwave.com/api. 126 | The following fields are automatically set for you on each resource: 127 | 128 | | Field | Default | 129 | | --------- | ----------------------------------------------------------------------------- | 130 | | apiKey | the API key used when creating the `Moneywave` client | 131 | | secret | the secret key used when creating the `Moneywave` client | 132 | 133 | 3. Dispatch the resource by calling `dispatch()`. 134 | 135 | Here is an example: 136 | ```php 137 | //we want to check our wallet balance 138 | $bal=new \HngX\Moneywave\Resources\GetWalletBalance($mw); 139 | $bal->dispatch(); 140 | ``` 141 | #### Available Resource Types 142 | ``` 143 | GetWalletBalance 144 | PreviousCardToAccount 145 | PreviousWalletToAccount 146 | RetryFailedTransaction 147 | ValidateAccountNumber 148 | TokenizeCard 149 | ``` 150 | ## Usage: Handling Responses 151 | After dispatching a transaction or resource, you may access the full response by calling `getResponse()` on the object. 152 | ```php 153 | $tran->getResponse(); 154 | 155 | /* 156 | [ 157 | "status" => "success", 158 | "data" => [ 159 | ...] 160 | ] 161 | */ 162 | ``` 163 | You can also find out the `status` alone by calling `getStatus()`. 164 | ```php 165 | $tran->getStatus(); // -> "success" or "error" 166 | ``` 167 | You may also call `successful()` directly to test if the `status` of the response was `success`: 168 | Caution: According to Moneywave, "success" does not neccessarily mean The transaction has gone through. Consult the official docs for more details 169 | 170 | ```php 171 | if ($tran->successful()) { 172 | //yay! 173 | } else { 174 | print_r($tran->getResponse()); 175 | } 176 | ``` 177 | 178 | #### Validating Transactions 179 | According to the docs, the two transaction types `AccountToAccountTransaction` and `CardToAccountTransaction` may also need validation after being dispatched. To do that, simply call `validate()` on the transaction object with the appropriate data: 180 | ```php 181 | $tran = new \HngX\Moneywave\AccountToAccountTransaction($mw); 182 | $tran->setDetails([ 183 | "firstname" => "Donald", 184 | "lastname" => "Trump", 185 | ... 186 | ]) 187 | ->dispatch(); 188 | if ($tran->successful()){ 189 | $tran->validate([ 190 | "transactionRef" => $tran->getResponse()["data"]["ref"], 191 | "authType" => "OTP", 192 | "authValue" => "7489", 193 | ]); 194 | } 195 | ``` 196 | Note: after this, calling `getResponse()` or `getStatus()` will return the response or status for the validation process 197 | 198 | ## Usage: Errors 199 | You will get an instance of `\HngX\MoneywaveException` if you do anything naughty. 200 | 201 | ## Installation 202 | 203 | ``` 204 | composer require hngx/moneywave-php 205 | ``` 206 | ## Bugs 207 | If you notice any bugs, please create a new issue. We will attend to it promptly. 208 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hngx/moneywave-php", 3 | "description": "PHP wrapper for the Moneywave API", 4 | "license": "MIT", 5 | "keywords": ["moneywave", "flutterwave", "fintech"], 6 | "authors": [ 7 | { 8 | "name": "Shalvah Adebayo", 9 | "email": "shalvah.adebayo@gmail.com" 10 | }, 11 | { 12 | "name": "Stephen Afam-Osemene", 13 | "email": "stephenafamo@gmail.com" 14 | }, 15 | { 16 | "name": "Ifeoluwa Arowosegbe", 17 | "email": "iifeoluwa.ao@gmail.com" 18 | } 19 | ], 20 | "require": { 21 | "php": ">=5.4", 22 | "guzzlehttp/guzzle": "^6.2" 23 | }, 24 | "require-dev": {}, 25 | "autoload": { 26 | "psr-4": { 27 | "HngX\\Moneywave\\": "src" 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Bank.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 22 | $this->secretkey = $secretKey; 23 | 24 | $this->baseUrl = "https://moneywave.herokuapp.com"; 25 | $this->client = new Client([ 26 | 'base_uri' => $this->baseUrl, 27 | ]); 28 | $this->accessToken = $this->getAccessToken(); 29 | if ($this->accessToken) { 30 | $this->client = new Client([ 31 | 'base_uri' => $this->baseUrl, 32 | 'header' => [ 33 | 'Authorization' => $this->accessToken, 34 | 'Content-Type' => 'application/x-www-form-urlencoded', 35 | 'Accept' => 'application/json' 36 | ] 37 | ]); 38 | } 39 | } 40 | 41 | /* 42 | * Get Moneywave access token 43 | */ 44 | private function getAccessToken() 45 | { 46 | $response = $this->client->post('/v1/merchant/verify', [ 47 | 'form_params' => [ 48 | "apiKey" => $this->apiKey, 49 | "secret" => $this->secretkey] 50 | ]); 51 | $response = json_decode($response->getBody(), true); 52 | 53 | if ($response["status"] == "success") { 54 | return $response['token']; 55 | } else { 56 | throw new MoneywaveException("Authentication failed: " . print_r($response, true)); 57 | } 58 | } 59 | 60 | public function request($method, $url, $options) 61 | { 62 | return $this->client->request($method, "https://moneywave.herokuapp.com". $url, $options); 63 | } 64 | 65 | public function getClient() 66 | { 67 | return $this->client; 68 | } 69 | 70 | public function getToken() 71 | { 72 | return $this->accessToken; 73 | } 74 | 75 | public function getApiKey() 76 | { 77 | return $this->apiKey; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/MoneywaveApiClient.php: -------------------------------------------------------------------------------- 1 | moneywave = $moneywave; 30 | } 31 | 32 | public function __get($key) 33 | { 34 | if (array_key_exists($key, $this->data)) { 35 | return $this->data[$key]; 36 | } else { 37 | throw new MoneywaveException("Unknown property $key"); 38 | } 39 | } 40 | 41 | public function __set($key, $value) 42 | { 43 | if (array_key_exists($key, $this->data)) { 44 | $this->data[$key] = $value; 45 | } else if (in_array($key, $this->required) || in_array($key, $this->optional)) { 46 | $this->data[$key] = $value; 47 | } else { 48 | throw new MoneywaveException("Unknown property $key"); 49 | } 50 | } 51 | 52 | 53 | public function dispatch($method = "POST") 54 | { 55 | try { 56 | $result = $this->moneywave->request($method, $this->url, array( 57 | "form_params" => $this->data, 58 | "headers" => ["Authorization" => $this->moneywave->getToken()] 59 | )); 60 | $this->response = json_decode($result->getBody(), true); 61 | $this->responseCode = $result->getStatusCode(); 62 | $this->status = $this->response["status"]; 63 | } catch (RequestException $e) { 64 | $this->responseCode = $e->getCode(); 65 | $this->response = json_decode($e->getResponse()->getBody(), true); 66 | $this->status = $e->getMessage(); 67 | } 68 | return $this; 69 | } 70 | 71 | public function getResponse() 72 | { 73 | return $this->response; 74 | } 75 | 76 | public function getStatus() 77 | { 78 | return array( 79 | "status" => $this->status, 80 | "code" => $this->responseCode, 81 | ); 82 | } 83 | 84 | public function successful() 85 | { 86 | return $this->status == "success"; 87 | } 88 | 89 | public function setDetails(array $data) 90 | { 91 | $this->data = $data; 92 | return $this; 93 | } 94 | } -------------------------------------------------------------------------------- /src/Resources/GetWalletBalance.php: -------------------------------------------------------------------------------- 1 | required = array( 16 | "id" 17 | ); 18 | } 19 | 20 | public function __set($key, $value) 21 | { 22 | if ($key === "id") { 23 | $this->url = $this->url.$value; 24 | } else { 25 | throw new MoneywaveException("Unknown argument $key"); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /src/Resources/PreviousWalletToAccount.php: -------------------------------------------------------------------------------- 1 | required = array( 15 | "ref" 16 | ); 17 | } 18 | } -------------------------------------------------------------------------------- /src/Resources/Resource.php: -------------------------------------------------------------------------------- 1 | required = array( 16 | "id", 17 | ); 18 | $this->optional = [ 19 | "recipient_account_number", 20 | "recipient_bank", 21 | ]; 22 | } 23 | } -------------------------------------------------------------------------------- /src/Resources/TokenizeCard.php: -------------------------------------------------------------------------------- 1 | required = array( 16 | "card_no", 17 | "expiry_year", 18 | "expiry_month", 19 | "cvv", 20 | ); 21 | } 22 | 23 | public function getCardToken() 24 | { 25 | return $this->getResponse()["data"]["cardToken"]; 26 | } 27 | } -------------------------------------------------------------------------------- /src/Resources/ValidateAccountNumber.php: -------------------------------------------------------------------------------- 1 | required = array( 18 | "account_number", 19 | "bank_code" 20 | ); 21 | } 22 | } -------------------------------------------------------------------------------- /src/Traits/NeedsValidation.php: -------------------------------------------------------------------------------- 1 | moneywave->request("POST", $this->validationUrl, array( 14 | "form_params" => $data, 15 | "headers" => ["Authorization" => $this->moneywave->getToken()] 16 | )); 17 | $this->response = json_decode($result->getBody(), true); 18 | $this->responseCode = $result->getStatusCode(); 19 | $this->status = $this->response["status"]; 20 | } catch (RequestException $e) { 21 | $this->responseCode = $e->getCode(); 22 | $this->response = json_decode($e->getResponse()->getBody(), true); 23 | $this->status = $e->getMessage(); 24 | } 25 | return $this; 26 | } 27 | } -------------------------------------------------------------------------------- /src/Transactions/AccountToAccountTransaction.php: -------------------------------------------------------------------------------- 1 | required = array( 20 | "firstname", 21 | "lastname", 22 | "phonenumber", 23 | "email", 24 | "recipient_bank", 25 | "recipient_account_number", 26 | "card_no", 27 | "cvv", 28 | "expiry_year", 29 | "expiry_month", 30 | "amount", 31 | "fee", 32 | "redirecturl", 33 | ); 34 | $this->optional = array( 35 | "recipient", 36 | "recipient_id", 37 | "recipients", 38 | "pin", 39 | "chargeCurrency", 40 | "disburseCurrency", 41 | "charge_with", 42 | "card_last4", 43 | "sender_account_number", 44 | "sender_bank", 45 | "passcode", 46 | "card_id", 47 | "cycle", 48 | "startDate", 49 | "endDate", 50 | ); 51 | 52 | $this->data = [ 53 | "apiKey" => $mw->getApiKey(), 54 | "medium" => "web", 55 | ]; 56 | } 57 | } -------------------------------------------------------------------------------- /src/Transactions/BulkWalletToAccountTransaction.php: -------------------------------------------------------------------------------- 1 | required = array( 17 | "recipients", 18 | "senderName", 19 | "ref", 20 | ); 21 | $this->data = [ 22 | "apiKey" => $mw->getApiKey(), 23 | "currency" => "NGN", 24 | "lock" => $password, 25 | ]; 26 | } 27 | } -------------------------------------------------------------------------------- /src/Transactions/CardToAccountTransaction.php: -------------------------------------------------------------------------------- 1 | required = array( 21 | "firstname", 22 | "lastname", 23 | "phonenumber", 24 | "email", 25 | "recipient_bank", 26 | "recipient_account_number", 27 | "card_no", 28 | "cvv", 29 | "expiry_year", 30 | "expiry_month", 31 | "amount", 32 | "fee", 33 | "redirecturl", 34 | ); 35 | $this->optional = array( 36 | "recipient", 37 | "recipient_id", 38 | "recipients", 39 | "pin", 40 | "chargeCurrency", 41 | "disburseCurrency", 42 | "charge_with", 43 | "card_last4", 44 | "sender_account_number", 45 | "sender_bank", 46 | "passcode", 47 | "card_id", 48 | "cycle", 49 | "startDate", 50 | "endDate", 51 | ); 52 | 53 | $this->data = [ 54 | "apiKey" => $mw->getApiKey(), 55 | "medium" => "web", 56 | ]; 57 | } 58 | } -------------------------------------------------------------------------------- /src/Transactions/CardToWalletTransaction.php: -------------------------------------------------------------------------------- 1 | required = array( 16 | "firstname", 17 | "lastname", 18 | "phonenumber", 19 | "email", 20 | "card_no", 21 | "cvv", 22 | "expiry_year", 23 | "expiry_month", 24 | "amount", 25 | "fee", 26 | "redirecturl", 27 | 28 | ); 29 | $this->optional = [ 30 | "chargeCurrency", 31 | "disburseCurrency", 32 | "charge_with", 33 | "card_last4", 34 | "sender_account_number", 35 | "sender_bank", 36 | ]; 37 | $this->data = [ 38 | "recipient" => "wallet", 39 | "apiKey" => $mw->getApiKey(), 40 | "medium" => "web", 41 | ]; 42 | } 43 | } -------------------------------------------------------------------------------- /src/Transactions/TotalChargeToCardTransaction.php: -------------------------------------------------------------------------------- 1 | required = array( 17 | "amount" => "", 18 | "fee" => "" 19 | ); 20 | } 21 | 22 | 23 | } -------------------------------------------------------------------------------- /src/Transactions/Transaction.php: -------------------------------------------------------------------------------- 1 | required = array( 25 | "lock" => $password, 26 | "amount", 27 | "bankcode", 28 | "accountNumber", 29 | "senderName", 30 | "ref", 31 | ); 32 | 33 | $this->data = [ 34 | "currency" => "NGN", 35 | "apiKey" => $mw->getApiKey(), 36 | ]; 37 | } 38 | } --------------------------------------------------------------------------------