Skip to content

Commit

Permalink
Merge pull request #14 from smileidentity/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ArlonTM authored Jun 23, 2022
2 parents 997ff4f + f3b4b59 commit 7cd090c
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 139 deletions.
43 changes: 35 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,44 @@
# smile-identity-core-php
# Smile Identity PHP Server Side

The Official Smile Identity PHP library
Smile Identity provides the best solutions for real time Digital KYC, identity verification, user onboarding, and user authentication across Africa. Our server side libraries make it easy to integrate us on the server-side. Since the library is server-side, you will be required to pass the images (if required) to the library.
If you haven’t already, sign up for a free Smile Identity account, which comes with Sandbox access.

## Dependencies

* Composer build tool

## Documentation

For extensive instructions on usage of the library and sample codes, please refer to the [official Smile Identity documentation](https://docs.smileidentity.com/server-to-server/php)

## Installation

Download smile-identity-core-php repo to a directory on your server where PHP and Composer is installed.
### Installing from the Repository

Download [smile-identity-core-php repository](https://github.com/smileidentity/smile-identity-core-php) to a directory on your server where PHP and Composer is installed.

In that directory, run `composer install`

### Installing from Packagist

View the package on [Packagist](https://packagist.org/packages/smile-identity/smile-identity-core).

Alternatively, the package can be searched locally from a composer-based project by typing the command `composer search <PACKAGE_NAME>` in the command line where `PACKAGE_NAME` can the full name of the package (in this case `smile-identity/smile-identity-core`) or any part of the name distinct enough to return a match.

In the project's directory, run `composer install smile-identity/smile-identity-core`

## License

MIT License

## Documentation

In that directory run `composer install`
For extensive instructions on usage of the library and sample codes, please refer to the official Smile [Identity documentation](https://docs.smileidentity.com/server-to-server/php).

### Usage
## Getting Help

Edit the example_core.php file and replace sections marked with <>
For usage questions, the best resource is [our official documentation](docs.smileidentity.com). However, if you require further assistance, you can file a [support ticket via our portal](https://portal.smileidentity.com/partner/support/tickets) or visit the [contact us page](https://portal.smileidentity.com/partner/support/tickets) on our website.

### Run tests
## Contributing

In same directory run `vendor/bin/phpunit tests`
Bug reports and pull requests are welcome on GitHub at https://github.com/smileidentity/smile-identity-core-php
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
"homepage" : "https://github.com/smileidentity/smile-identity-core-php",
"license" : "MIT",
"authors" : [{
"name" : "Smile Identity",
"email" : "[email protected]"
}],
"name" : "Smile Identity",
"email" : "[email protected]"
}
],
"require" : {
"php" : ">=7.4",
"ext-curl" : "*",
"ext-json" : "*",
"ext-openssl" : "*",
"ext-zip": "*",
"ext-zip" : "*",
"guzzlehttp/guzzle" : "^7.0",
"letsdrink/ouzo-goodies" : "~1.0"
},
Expand Down
26 changes: 13 additions & 13 deletions example_core.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
$default_callback,
$api_key,
$sid_server
);
);

// Create required tracking parameters
// Every communication between your server and the Smile Identity servers contain these parameters.
Expand All @@ -33,10 +33,10 @@
// 4 for registering a user with just a selfie
// 8 for updating an registered photo
'job_type' => <1 | 2 | 4 | 8>,
// You can add as many key value pairs as you line but all MUST be strings.
// You can add as many key value pairs as you line but all MUST be strings.
'optional_info' => 'PHP Test Data',
'signature' => <true | false>
);
);

// Create options
$options = array(
Expand All @@ -48,7 +48,7 @@
'return_history' => <true | false>,
// If you want signed links to the images used in processing the job to be returned
'return_image_links' => <true | false>
);
);

// Create image list
// image_type_id Integer
Expand All @@ -61,16 +61,16 @@
$selfie_image_detail = array(
'image_type_id' => 0, // Selfie image jpg or png
'image' => $selfie_filename
);
);
// ID card image can be omitted if selfie comparison to issuer image is desired
$id_card_image_detail = array(
'image_type_id' => 1, // ID card image jpg or png
'image' => $id_card_filename
);
);
$image_details = array(
$selfie_image_detail,
$id_card_image_detail
);
);

// Create ID number info
// Only required fields need to be filled in. The rest should be blank strings
Expand All @@ -84,7 +84,7 @@
'id_number' => '<valid id number>', // Always required
'dob' => '<DOB in ISO 8601 format>', // yyyy-mm-dd
'entered' => '<true | false>' // MUST BE A STRING
);
);

// submit_job returns an array with at least a Boolean using the key "success" and the Smile Identity job number.
// If options.return_job_status is true it will add to the array the returned job_status information.
Expand All @@ -100,7 +100,7 @@
$default_callback, // Used if $use_async is true otherwise should be ""
$api_key,
$sid_server
);
);

// If use_async is false $result contains the returned ID information
// If true then the ID information will be sent to the callback specified - >> RECOMMENDED <<
Expand All @@ -116,9 +116,9 @@
'user_id' => '<put unique job ID here',
// Job Type Integer
'job_type' => 5,
// You can add as many key value pairs as you line but all MUST be strings.
// You can add as many key value pairs as you line but all MUST be strings.
'optional_info' => 'PHP Test Data'
);
);

// Create ID number info
// Only required fields need to be filled in. The rest should be blank strings
Expand All @@ -132,12 +132,12 @@
'id_number' => '<valid id number>', // Always required
'dob' => '<DOB in ISO 8601 format>', // yyyy-mm-dd
'entered' => '<true | false>' // MUST BE A STRING
);
);


//
$result = $sid_idapi->submit_job($partner_params, $id_info, $use_async);



?>
?>
1 change: 1 addition & 0 deletions lib/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class Config
{
const SDK_CLIENT = 'PHP';
const VERSION = '3.1.0';
const DEFAULT_JOB_STATUS_TIMEOUT = 20;
const DEFAULT_JOB_STATUS_SLEEP = 2;
Expand Down
34 changes: 16 additions & 18 deletions lib/IdApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ class IdApi

/**
* IdApi constructor.
* @param $partner_id
* @param $default_callback
* @param $api_key ,
* @param $sid_server
* @param string $partner_id the provided partner ID string
* @param string $default_callback
* @param string $api_key the partner-provided API key
* @param string $sid_server an integer value corresponding to the chosen server
* 0 for test/sandbox
* 1 for production
* @throws Exception
*/
public function __construct($partner_id, $default_callback, $api_key, $sid_server)
{
$this->partner_id = $partner_id;
$this->default_callback = $default_callback;
$this->sig_class = new Signature($api_key, $partner_id);
$this->sig_class = new Signature($partner_id, $api_key);
if (strlen($sid_server) == 1) {
if (intval($sid_server) < 2) {
$this->sid_server = Config::SID_SERVERS[intval($sid_server)];
Expand All @@ -53,30 +55,26 @@ public function setClient(Client $client): void
}

/**
* @param $partner_params
* @param $id_info
* @param $use_async
* @param $options
* Submits a job with specified partner parameters and ID information
* @param array $partner_params a key-value pair object containing partner's specified parameters
* @param array $id_info a key-value pair object containing user's specified ID information
* @param array $options a key-value pair object containing additional, optional parameters
* @return ResponseInterface
* @throws GuzzleException
* @throws Exception
*/
public function submit_job($partner_params, $id_info, $options): array
{
$user_async = array_value_by_key("user_async", $options);
$signature = array_value_by_key("signature", $options);

if ($signature) {
$sec_params = $this->sig_class->generate_signature();
} else {
$sec_params = $this->sig_class->generate_sec_key();
}
$sec_params = $this->sig_class->generate_signature();

$data = array(
'language' => 'php',
'callback_url' => $this->default_callback,
'partner_params' => $partner_params,
'partner_id' => $this->partner_id
'partner_id' => $this->partner_id,
'source_sdk' => Config::SDK_CLIENT,
'source_sdk_version' => Config::VERSION
);
$data = array_merge($data, $id_info, $sec_params);
$json_data = json_encode($data, JSON_PRETTY_PRINT);
Expand All @@ -88,4 +86,4 @@ public function submit_job($partner_params, $id_info, $options): array
$contents = $resp->getBody()->getContents();
return json_decode($contents, true);
}
}
}
22 changes: 16 additions & 6 deletions lib/Signature.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ class Signature

/**
* Signature constructor.
* @param $api_key
* @param $partner_id
* @param $api_key
*/
function __construct($api_key, $partner_id)
function __construct($partner_id, $api_key)
{
$this->api_key = $api_key;
$this->partner_id = $partner_id;
$this->timestamp = Clock::now()->getTimestamp();
}

/**
* Generates a sec_key for the provided timestamp or the current timestamp by default
* @param $timestamp
* @return array
* @deprecated deprecated since version 3.0.0
*/
function generate_sec_key($timestamp = null): array
{
Expand All @@ -39,7 +41,13 @@ function generate_sec_key($timestamp = null): array
return array("sec_key" => $sec_key, "timestamp" => $timestamp);
}

function confirm_sec_key($sec_key): bool
/**
* Confirms the sec-key against a newly generated sec-key based on the same timestamp
* @param string $sec_key
* @return bool
* @deprecated deprecated since version 3.0.0
*/
function confirm_sec_key($sec_key): bool
{
$sec_key_exploded = explode("|", $sec_key);
$encrypted = base64_decode($sec_key_exploded[0]);
Expand All @@ -50,18 +58,20 @@ function confirm_sec_key($sec_key): bool
}

/**
* Generates a signature for the provided timestamp or the current timestamp by default
* @param $timestamp
* @return array
*/
function generate_signature($timestamp = null): array
{
$timestamp = $timestamp != null ? $timestamp : Clock::now()->format(DateTimeInterface::ATOM);
$message = $timestamp . $this->partner_id . "sid_request";
$sec_key = base64_encode(hash_hmac('sha256', $message, $this->api_key, true));
return array("signature" => $sec_key, "timestamp" => $timestamp);
$signature = base64_encode(hash_hmac('sha256', $message, $this->api_key, true));
return array("signature" => $signature, "timestamp" => $timestamp);
}

/**
* Confirms the signature against a newly generated signature based on the same timestamp
* @param $timestamp
* @param string $signature
* @return bool
Expand All @@ -83,4 +93,4 @@ private function isTimestamp($timestamp): bool
return false;
}
}
}
}
Loading

0 comments on commit 7cd090c

Please sign in to comment.