PHP code example of novadaemon / skyflow-php
1. Go to this page and download the library: Download novadaemon/skyflow-php library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
novadaemon / skyflow-php example snippets
declare(strict_types=1);
use Novadaemon\Skyflow\Exceptions\SkyflowException;
use Novadaemon\Skyflow\ServiceAccount\Token;
(SkyflowException $e) {
echo($e->getMessage());
}
declare(strict_types=1);
use Novadaemon\Skyflow\ServiceAccount\Token;
use Novadaemon\Skyflow\Exceptions\SkyflowException;
TOKEN_URI>',
'keyID' => '<KEY_ID>',
'privateKey' => '<PRIVATE_KEY>',
];
$token = Token::generateBearerTokenFromCredentials($credentials);
var_dump($token);
} catch (SkyflowException $e) {
echo($e->getMessage());
}
array (
'accessToken' => 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJodHRwczovL21hbmFnZS5za3lmbG93YXBpcy5jb20iLCJjbGkiOiJlNzVkZmNmMzMwN2Q0M2I2YjZlN2JhNTk2ZTU5ODgxNyIsImV4cCI6MTY3ODEyMzI1NCwiaWF0IjoxNjc4MTE5NjU3LCJpc3MiOiJzYS1hdXRoQG1hbmFnZS5za3lmbG93YXBpcy5jb20iLCJqdGkiOiJmZTZkYzRjNGY1YmM0OTllODhjOTc0ZmNjZGRjZGMyZCIsImtleSI6ImJlNjk0YTJlYTFmNjQ3ZDM5N2E1YzIwNWZlYjRmMzUxIiwic2NwIjpudWxsLCJzdWIiOiJUZXN0U2VydmljZSJ9.WXSqZh7fQwx9E1ngKKSD9jfPLNWLzE46CKWuZ0bovbZFTGLKcHy94z-SKb1qxtW-CedcbgbnK7Wjd-H20PusjbLGCcjPcAQt7pghUvdpLabuR8DIW0sbfTwen5JnhVupHp0_3tXwp8jJDGF6s8JExVA9DhMLoyusqC9wD_Gmemdj4dU_r4drKhiVYgnsbD8NgZyc6yfgWXrE51IoqLd9FsZ0rDDrys3ttwEbYLRXnr1NGGsftqI0-y4K2gu090BJ2wtDlQO61ZD8_KZSZSEpxr6ZYIMuYsG7SxvnkR6OMz1fVWbtptf1EzEk-ky2M2r5oGGYH_WFBakVk8wKHQy3og',
'tokenType' => 'Bearer',
)
use Novadaemon\Skyflow\Vault\Client;
use Novadaemon\Skyflow\ServiceAccount\Token;
ion (string $token): string {
if (Token::isExpired($token)) {
$token = Token::generateBearerToken('<YOUR_CREDENTIALS_FILE_PATH>');
return $token['accessToken'];
}
return $token;
};
#Initializing a Skyflow Client instance with the
$response = $client->getRecords(
table: 'cards',
ids: [
"1a8ec9d5-9be6-465d-a8ad-2797d7258a10",
"76c892f4-7523-4e74-ac82-afc7bdea7d74"
],
redaction: RedactionType::PLAIN_TEXT,
tokenization: false
);
array (
'records' =>
array (
0 =>
array (
'fields' =>
array (
'card_cvv' => '123',
'card_expiration' => '03/26',
'card_number' => '4242424242424242',
'skyflow_id' => '1a8ec9d5-9be6-465d-a8ad-2797d7258a10',
),
),
1 =>
array (
'fields' =>
array (
'card_cvv' => '234',
'card_expiration' => '12/24',
'card_number' => '4111111111111111',
'skyflow_id' => '76c892f4-7523-4e74-ac82-afc7bdea7d74',
),
),
),
)
array (
'error' =>
array (
'grpc_code' => 5,
'http_code' => 404,
'message' => 'No Records Found',
'http_status' => 'Not Found',
),
)
$response = $client->getRecordById(
table: 'consumers',
id: '76193681-d272-4ffe-80f9-6498398e4c7b',
fields: [
'first_name',
'last_name',
'email',
'phone',
]
);
array (
'fields' =>
array (
'email' => 'j******[email protected] ',
'first_name' => '*REDACTED*',
'last_name' => '*REDACTED*',
'phone' => 'XXXXXX0000',
),
)
array (
'error' =>
array (
'grpc_code' => 5,
'http_code' => 404,
'message' => 'No Records Found',
'http_status' => 'Not Found',
),
)
$records = [
[
"fields" => [
"card_number" => "5555555555554444",
"card_expiration" => "12/25",
"card_cvv" => "111",
]
],
[
"fields" => [
"card_number" => "5105105105105100",
"card_expiration" => "04/28",
"card_cvv" => "123",
]
],
];
$response = $client->insertRecords(
table: 'cards',
records: $records,
tokenization: true,
upsert: 'card_number'
);
array (
'records' =>
array (
0 =>
array (
'skyflow_id' => '76c892f4-7523-4e74-ac82-afc7bdea7d74',
'tokens' =>
array (
'card_cvv' => '19a364b9-0b39-4cad-a544-45c7ba1c52eb',
'card_expiration' => '1b4ab2f7-fdd8-48f2-8b50-eb97075eda2e',
'card_number' => '5554-3665-8198-3602',
),
),
1 =>
array (
'skyflow_id' => '1a8ec9d5-9be6-465d-a8ad-2797d7258a10',
'tokens' =>
array (
'card_cvv' => 'b5bade68-3a0d-4895-8c27-edd911c11e99',
'card_expiration' => '767eda0a-ed3a-4781-82d5-755207acf1e0',
'card_number' => '8080-3444-8671-2308',
),
),
),
)
array (
'error' =>
array (
'grpc_code' => 9,
'http_code' => 400,
'message' => 'Error Inserting Records due to unique constraint violation',
'http_status' => 'Bad Request',
'details' =>
array (
),
),
)
$record = [
'fields' => [
"email" => '[email protected] ',
"phone" => '+5478698765',
]
];
$response = $client->updateRecord(
table: 'consumers',
id: '76193681-d272-4ffe-80f9-6498398e4c7b',
record: $record,
tokenization: false
);
array (
'skyflow_id' => '76193681-d272-4ffe-80f9-6498398e4c7b',
'createdTime' => '',
'updatedTime' => '',
'tokens' =>
array (
'email' => '[email protected] ',
'phone' => '54df9553-6688-4359-a8ff-df5cbd9cfa55',
),
)
array (
'error' =>
array (
'grpc_code' => 3,
'http_code' => 400,
'message' => 'Invalid field present in JSON invalid-field',
'http_status' => 'Bad Request',
'details' =>
array (
),
),
)
$response = $client->deleteRecord('cards', 'e95834a2-cf1e-40ac-9f0d-0ea2c7920a8d');
array (
'skyflow_id' => 'e95834a2-cf1e-40ac-9f0d-0ea2c7920a8d',
'deleted' => true,
)
array (
'error' =>
array (
'grpc_code' => 5,
'http_code' => 404,
'message' => 'No Records Found',
'http_status' => 'Not Found',
),
)
#Delete all records from cards table
$response = $client->bulkDelete('cards');
array (
'RecordIDResponse' =>
array (
0 => '*',
),
)
array (
'error' =>
array (
'grpc_code' => 13,
'http_code' => 500,
'message' => 'Couldn\'t load data',
'http_status' => 'Internal Server Error',
'details' =>
array (
),
),
)
$params = [
['token' => 'aa3cc614-af50-4365-a7ac-82f83a79eef8'],
['token' => 'e77674ac-4a21-4318-8bdd-5ad20f1b47c7'],
['token' => '[email protected] ']
];
$response = $client->detokenize($params);
array (
'records' =>
array (
0 =>
array (
'token' => 'aa3cc614-af50-4365-a7ac-82f83a79eef8',
'valueType' => 'STRING',
'value' => '234',
),
1 =>
array (
'token' => 'e77674ac-4a21-4318-8bdd-5ad20f1b47c7',
'valueType' => 'STRING',
'value' => '12/24',
),
2 =>
array (
'token' => '[email protected] ',
'valueType' => 'STRING',
'value' => '[email protected] ',
),
),
)
array (
'error' =>
array (
'grpc_code' => 5,
'http_code' => 404,
'message' => 'Token not found for invalid-token',
'http_status' => 'Not Found',
'details' =>
array (
),
),
)
[
'token' => 'STRING' # The Skyflow token to be detokenized
'redaction' => 'STRING' # Redaction policy. Not
$params = [
[
'value' => '5105105105105100',
'table' => 'cards',
'column' => 'card_number'
],
];
$response = $client->tokenize($params);
array (
'records' =>
array (
0 =>
array (
'token' => '0782-1334-4999-6413',
),
),
)
array (
'error' =>
array (
'grpc_code' => 5,
'http_code' => 404,
'message' => 'Tokenize returns previously issued tokens for existing data. Provided value(s) do not exist in the provided table.column(s): card_number',
'http_status' => 'Not Found',
'details' =>
array (
),
),
)
$query = "SELECT * FROM cards WHERE card_number = '5105105105105100'";
$response = $client->query($query);
array (
'records' =>
array (
0 =>
array (
'fields' =>
array (
'card_cvv' => '*REDACTED*',
'card_expiration' => '*REDACTED*',
'card_number' => '5105105105105100',
'orders_skyflow_id' => NULL,
'skyflow_id' => '1084350b-d4a2-45b1-801f-2fd46bef0721',
),
),
),
)
array (
'error' =>
array (
'grpc_code' => 13,
'http_code' => 500,
'message' => 'ERROR (internal_error): Could not find Field car_number',
'http_status' => 'Internal Server Error',
'details' =>
array (
),
),
)
$headers = [
'Content-Type' => 'application/json',
'Authorization' => '<YOUR_CONNECTION_BASIC_AUTH>'
];
$body = [
'firstName' => 'Jesús',
'lastName' => 'García',
'email' => '[email protected] ',
'phone' => '54df9553-6688-4359-a8ff-df5cbd9cfa55',
];
$url = 'https://ebfc9bee4242.gateway.skyflowapis.com/v1/gateway/outboundRoutes/x2f47b94462a46989ac7b37817ef99bf/users/add';
$response = $client->invokeConnection(
connectionUrl: $url,
method: RequestMethodType::POST,
headers: $headers,
body: $body
);
array (
'email' => '[email protected] ',
'firstName' => 'Jesús',
'lastName' => 'García',
'phone' => '+5478698765'
)
bash
composer