airtimerewards / ar-connect-sdk
PHP SDK for using AR Connect.
Installs: 19 640
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^7.4 || ^8.0
- guzzlehttp/guzzle: ^6.0 || ^7.0
- moneyphp/money: ^3.0 || ^4.0
- psr/log: ^1.0 || ^2.0 || ^3.0
Requires (Dev)
- alexeyshockov/guzzle-psalm-plugin: ^0.3.1
- friendsofphp/php-cs-fixer: ^2.15
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^4
- dev-main
- 3.1.0
- 3.0.0
- 2.1.0
- v2.0.0
- v1.1.0
- v1.1.0-rc.1
- v1.1.0-beta.2
- v1.1.0-beta.1
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v1.0.0-rc.1
- dev-feature/psr-logger
- dev-feature/php-8
- dev-feature/github-actions
- dev-feature/guzzle-7
- dev-fix/tests
- dev-refactor/client-interface
- dev-refactor/ar-connect-client-interface
- dev-feature/eligibility-check
- dev-hotfix/nullable-pin
- dev-feature/set-pin-related-values-in-credit-json
This package is auto-updated.
Last update: 2024-10-21 16:58:44 UTC
README
AR Connect SDK
This package offers a client for interacting with AR Connect.
1. Requirements
This SDK requires PHP 7.1 or later. Additionally you must be registered with AR Connect to be able to use an API. Finally, you will need an environment set up and an API key for that environment.
2. Installation
The recommended installation is to use composer, and run the command:
$ composer require airtimerewards/ar-connect-sdk
3. Usage
The AR Connect client provides methods for interacting with the AR Connect API.
3.1 Instantiating a client
To instantiate a client, use the factory method and pass in your environment ID and API key.
Important: The API key must be for the environment that has been specified. Errors will occur if they do not match.
<?php use AirtimeRewards\ARConnect\ARConnectClient; $client = ARConnectClient::createClient('api-key', 'environment-id', $logger);
3.2 Retrieving Data to Make a Credit
Before making a credit you need to find some information about the account for which the credit is being applied: the
mobile phone network and whether it's a pay-as-you-go (prepaid) or a monthly contract (postpaid). This can be done by
calling the getNetworks()
method. This method accepts an optional MSISDN (international standard mobile phone
number with the country-code prefix) getNetworks('447700900000')
which when passed, will return only networks
applicable to that mobile account.
<?php use AirtimeRewards\ARConnect\ARConnectClient; $client = ARConnectClient::createClient('api-key', 'environment-id', $logger); $networks = $client->getNetworks(); // returns a collection of networks $filteredNetworks = $client->getNetworks('447700900000'); // returns a collection of networks for UK mobile number 07700 900 000
Once the network has been selected, you can get information about what credit types are supported for this network. The credit types contain information about the minimum, maximum and increments of credit values available.
<?php use AirtimeRewards\ARConnect\ARConnectClient; $client = ARConnectClient::createClient('api-key', 'environment-id', $logger); $creditTypes = $client->getCreditTypesForNetwork($network);
All the information required to apply a credit has now been collected.
3.3 Applying a credit
A credit can be applied by calling the createCredit()
method with the following information:
- MSISDN
- Network
- Subscription type (
Credit::SUBSCRIPTION_TYPE_POSTPAID
orCredit::SUBSCRIPTION_TYPE_PREPAID
) - The value of the credit (an instance of
Money\Money
, see PHP Money) - Whether an SMS should be sent to the account once credited
- An optional unique reference. This is highly recommended as it will prevent a credit being accidentally applied multiple times.
<?php use AirtimeRewards\ARConnect\ARConnectClient; use AirtimeRewards\ARConnect\Credit; use Money\Money; use Money\Currency; $client = ARConnectClient::createClient('api-key', 'environment-id', $logger); $creditValue = new Money(1000, new Currency('GBP')); // £10 of credit $credit = $client->createCredit( '447700900000', $network, Credit::SUBSCRIPTION_TYPE_POSTPAID, $creditValue, true, 'client-reference' );
An instance of AirtimeRewards\ARConnect\Credit
will be returned. It is recommended that the ID of the credit is
stored so that it can be used for reference and retrieval at a future date (e.g. for checking the latest status of
the credit).