repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
creios/creiwork-framework | src/Util/JsonValidator.php | JsonValidator.validateJson | public function validateJson(string $json, string $schemaName): ValidationResult
{
$schemaDir = $this->config->get('schema-dir');
$schemaPath = $this->configDirectoryPath.$schemaDir.'/'.$schemaName.'.json';
if(!file_exists($schemaPath)){
throw new FileNotFoundException("File $schemaPath not found");
}
$schemaJsonString = file_get_contents($schemaPath);
$decodedJson = json_decode($json);
if ($decodedJson === false) {
$schema = json_decode($schemaJsonString);
// error decoding json
return (new ValidationResult())
->addError(new ValidationError($json,
[],
[],
$schema,
"Failed to decode JSON string")
);
}
return $this->dataValidation($decodedJson, $schemaJsonString);
} | php | public function validateJson(string $json, string $schemaName): ValidationResult
{
$schemaDir = $this->config->get('schema-dir');
$schemaPath = $this->configDirectoryPath.$schemaDir.'/'.$schemaName.'.json';
if(!file_exists($schemaPath)){
throw new FileNotFoundException("File $schemaPath not found");
}
$schemaJsonString = file_get_contents($schemaPath);
$decodedJson = json_decode($json);
if ($decodedJson === false) {
$schema = json_decode($schemaJsonString);
// error decoding json
return (new ValidationResult())
->addError(new ValidationError($json,
[],
[],
$schema,
"Failed to decode JSON string")
);
}
return $this->dataValidation($decodedJson, $schemaJsonString);
} | [
"public",
"function",
"validateJson",
"(",
"string",
"$",
"json",
",",
"string",
"$",
"schemaName",
")",
":",
"ValidationResult",
"{",
"$",
"schemaDir",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'schema-dir'",
")",
";",
"$",
"schemaPath",
"=",
"$",
"this",
"->",
"configDirectoryPath",
".",
"$",
"schemaDir",
".",
"'/'",
".",
"$",
"schemaName",
".",
"'.json'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"schemaPath",
")",
")",
"{",
"throw",
"new",
"FileNotFoundException",
"(",
"\"File $schemaPath not found\"",
")",
";",
"}",
"$",
"schemaJsonString",
"=",
"file_get_contents",
"(",
"$",
"schemaPath",
")",
";",
"$",
"decodedJson",
"=",
"json_decode",
"(",
"$",
"json",
")",
";",
"if",
"(",
"$",
"decodedJson",
"===",
"false",
")",
"{",
"$",
"schema",
"=",
"json_decode",
"(",
"$",
"schemaJsonString",
")",
";",
"// error decoding json",
"return",
"(",
"new",
"ValidationResult",
"(",
")",
")",
"->",
"addError",
"(",
"new",
"ValidationError",
"(",
"$",
"json",
",",
"[",
"]",
",",
"[",
"]",
",",
"$",
"schema",
",",
"\"Failed to decode JSON string\"",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"dataValidation",
"(",
"$",
"decodedJson",
",",
"$",
"schemaJsonString",
")",
";",
"}"
] | Validates JSON strings against a schema.
@param string $json
@param string $schemaName Name of the .json file providing the schema (without file extension)
@return ValidationResult | [
"Validates",
"JSON",
"strings",
"against",
"a",
"schema",
"."
] | train | https://github.com/creios/creiwork-framework/blob/5089578b44ef6af725ab0c8a2dfe691bfe07ffb6/src/Util/JsonValidator.php#L84-L106 |
agentmedia/phine-core | src/Core/Logic/Installation/BundleInstaller.php | BundleInstaller.ExecuteSql | function ExecuteSql()
{
$versionCompare = version_compare($this->installedVersion, $this->manifest->Version());
if ($versionCompare > 0)
{
$bundle = $this->manifest->BundleName();
throw new \Exception("Error instaling bundle $bundle: Previously installed version is greater than curren code version. Please re-install the bundle.");
}
else if ($versionCompare === 0)
{
return;
}
$engineFolder = $this->FindEngineFolder();
if (!$engineFolder)
{
return;
}
$this->ExecuteScripts($engineFolder);
} | php | function ExecuteSql()
{
$versionCompare = version_compare($this->installedVersion, $this->manifest->Version());
if ($versionCompare > 0)
{
$bundle = $this->manifest->BundleName();
throw new \Exception("Error instaling bundle $bundle: Previously installed version is greater than curren code version. Please re-install the bundle.");
}
else if ($versionCompare === 0)
{
return;
}
$engineFolder = $this->FindEngineFolder();
if (!$engineFolder)
{
return;
}
$this->ExecuteScripts($engineFolder);
} | [
"function",
"ExecuteSql",
"(",
")",
"{",
"$",
"versionCompare",
"=",
"version_compare",
"(",
"$",
"this",
"->",
"installedVersion",
",",
"$",
"this",
"->",
"manifest",
"->",
"Version",
"(",
")",
")",
";",
"if",
"(",
"$",
"versionCompare",
">",
"0",
")",
"{",
"$",
"bundle",
"=",
"$",
"this",
"->",
"manifest",
"->",
"BundleName",
"(",
")",
";",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Error instaling bundle $bundle: Previously installed version is greater than curren code version. Please re-install the bundle.\"",
")",
";",
"}",
"else",
"if",
"(",
"$",
"versionCompare",
"===",
"0",
")",
"{",
"return",
";",
"}",
"$",
"engineFolder",
"=",
"$",
"this",
"->",
"FindEngineFolder",
"(",
")",
";",
"if",
"(",
"!",
"$",
"engineFolder",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"ExecuteScripts",
"(",
"$",
"engineFolder",
")",
";",
"}"
] | Executes all necessary sql scripts | [
"Executes",
"all",
"necessary",
"sql",
"scripts"
] | train | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Installation/BundleInstaller.php#L52-L71 |
agentmedia/phine-core | src/Core/Logic/Installation/BundleInstaller.php | BundleInstaller.ExecuteScripts | private function ExecuteScripts($engineFolder)
{
$files = $this->SortFilesByVersion(Folder::GetFiles($engineFolder));
$completeSql = '';
foreach ($files as $file)
{
$sqlFile = Path::Combine($engineFolder, $file);
$completeSql .= "\r\n" . File::GetContents($sqlFile);
}
try
{
$this->CleanAllForeignKeys();
//$this->connection->StartTransaction();
$this->connection->ExecuteMultiQuery($completeSql);
}
catch (\Exception $exc)
{
//$this->connection->RollBack();
throw $exc;
//throw new \Exception("Error executing SQL in folder $engineFolder: " . $completeSql, null, $exc);
}
//$this->connection->Commit();
} | php | private function ExecuteScripts($engineFolder)
{
$files = $this->SortFilesByVersion(Folder::GetFiles($engineFolder));
$completeSql = '';
foreach ($files as $file)
{
$sqlFile = Path::Combine($engineFolder, $file);
$completeSql .= "\r\n" . File::GetContents($sqlFile);
}
try
{
$this->CleanAllForeignKeys();
//$this->connection->StartTransaction();
$this->connection->ExecuteMultiQuery($completeSql);
}
catch (\Exception $exc)
{
//$this->connection->RollBack();
throw $exc;
//throw new \Exception("Error executing SQL in folder $engineFolder: " . $completeSql, null, $exc);
}
//$this->connection->Commit();
} | [
"private",
"function",
"ExecuteScripts",
"(",
"$",
"engineFolder",
")",
"{",
"$",
"files",
"=",
"$",
"this",
"->",
"SortFilesByVersion",
"(",
"Folder",
"::",
"GetFiles",
"(",
"$",
"engineFolder",
")",
")",
";",
"$",
"completeSql",
"=",
"''",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"sqlFile",
"=",
"Path",
"::",
"Combine",
"(",
"$",
"engineFolder",
",",
"$",
"file",
")",
";",
"$",
"completeSql",
".=",
"\"\\r\\n\"",
".",
"File",
"::",
"GetContents",
"(",
"$",
"sqlFile",
")",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"CleanAllForeignKeys",
"(",
")",
";",
"//$this->connection->StartTransaction();",
"$",
"this",
"->",
"connection",
"->",
"ExecuteMultiQuery",
"(",
"$",
"completeSql",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exc",
")",
"{",
"//$this->connection->RollBack();",
"throw",
"$",
"exc",
";",
"//throw new \\Exception(\"Error executing SQL in folder $engineFolder: \" . $completeSql, null, $exc);",
"}",
"//$this->connection->Commit();",
"}"
] | Executes all necessary scripts in the engine folder
@param string $engineFolder The folder
@throws \Exception Raises error if any of the scripts fail | [
"Executes",
"all",
"necessary",
"scripts",
"in",
"the",
"engine",
"folder"
] | train | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Installation/BundleInstaller.php#L78-L101 |
agentmedia/phine-core | src/Core/Logic/Installation/BundleInstaller.php | BundleInstaller.CleanForeignKeys | private function CleanForeignKeys($table)
{
$foreignKeys = $this->connection->GetForeignKeys($table);
foreach ($foreignKeys as $foreignKey)
{
$this->connection->DropForeignKey($table, $foreignKey);
}
} | php | private function CleanForeignKeys($table)
{
$foreignKeys = $this->connection->GetForeignKeys($table);
foreach ($foreignKeys as $foreignKey)
{
$this->connection->DropForeignKey($table, $foreignKey);
}
} | [
"private",
"function",
"CleanForeignKeys",
"(",
"$",
"table",
")",
"{",
"$",
"foreignKeys",
"=",
"$",
"this",
"->",
"connection",
"->",
"GetForeignKeys",
"(",
"$",
"table",
")",
";",
"foreach",
"(",
"$",
"foreignKeys",
"as",
"$",
"foreignKey",
")",
"{",
"$",
"this",
"->",
"connection",
"->",
"DropForeignKey",
"(",
"$",
"table",
",",
"$",
"foreignKey",
")",
";",
"}",
"}"
] | Cleans all foreign keys of a table
@param strign $table The table name | [
"Cleans",
"all",
"foreign",
"keys",
"of",
"a",
"table"
] | train | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Installation/BundleInstaller.php#L119-L126 |
agentmedia/phine-core | src/Core/Logic/Installation/BundleInstaller.php | BundleInstaller.SortFilesByVersion | private function SortFilesByVersion(array $files)
{
$result = array();
$foreignKeysFile = '';
foreach ($files as $file)
{
if ($file == 'foreign-keys.sql')
{
$foreignKeysFile = $file;
continue;
}
$version = Path::RemoveExtension($file);
if ($this->installedVersion && version_compare($version, $this->installedVersion) <= 0)
{
continue;
}
$result[$version] = $file;
}
uksort($result, "version_compare");
if ($foreignKeysFile)
{
$result[] = $foreignKeysFile;
}
return $result;
} | php | private function SortFilesByVersion(array $files)
{
$result = array();
$foreignKeysFile = '';
foreach ($files as $file)
{
if ($file == 'foreign-keys.sql')
{
$foreignKeysFile = $file;
continue;
}
$version = Path::RemoveExtension($file);
if ($this->installedVersion && version_compare($version, $this->installedVersion) <= 0)
{
continue;
}
$result[$version] = $file;
}
uksort($result, "version_compare");
if ($foreignKeysFile)
{
$result[] = $foreignKeysFile;
}
return $result;
} | [
"private",
"function",
"SortFilesByVersion",
"(",
"array",
"$",
"files",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"foreignKeysFile",
"=",
"''",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"==",
"'foreign-keys.sql'",
")",
"{",
"$",
"foreignKeysFile",
"=",
"$",
"file",
";",
"continue",
";",
"}",
"$",
"version",
"=",
"Path",
"::",
"RemoveExtension",
"(",
"$",
"file",
")",
";",
"if",
"(",
"$",
"this",
"->",
"installedVersion",
"&&",
"version_compare",
"(",
"$",
"version",
",",
"$",
"this",
"->",
"installedVersion",
")",
"<=",
"0",
")",
"{",
"continue",
";",
"}",
"$",
"result",
"[",
"$",
"version",
"]",
"=",
"$",
"file",
";",
"}",
"uksort",
"(",
"$",
"result",
",",
"\"version_compare\"",
")",
";",
"if",
"(",
"$",
"foreignKeysFile",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"foreignKeysFile",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Sorts files by version
@param string[] $files The files
@return string[] Returns the sorted files | [
"Sorts",
"files",
"by",
"version"
] | train | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Installation/BundleInstaller.php#L156-L180 |
yuncms/yii2-oauth2 | frontend/controllers/ClientController.php | ClientController.actionIndex | public function actionIndex()
{
$query = Client::find()->where(['user_id' => Yii::$app->user->id])->orderBy(['created_at' => SORT_DESC]);
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
return $this->render('index', [
'dataProvider' => $dataProvider,
]);
} | php | public function actionIndex()
{
$query = Client::find()->where(['user_id' => Yii::$app->user->id])->orderBy(['created_at' => SORT_DESC]);
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
return $this->render('index', [
'dataProvider' => $dataProvider,
]);
} | [
"public",
"function",
"actionIndex",
"(",
")",
"{",
"$",
"query",
"=",
"Client",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'user_id'",
"=>",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"id",
"]",
")",
"->",
"orderBy",
"(",
"[",
"'created_at'",
"=>",
"SORT_DESC",
"]",
")",
";",
"$",
"dataProvider",
"=",
"new",
"ActiveDataProvider",
"(",
"[",
"'query'",
"=>",
"$",
"query",
",",
"]",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'index'",
",",
"[",
"'dataProvider'",
"=>",
"$",
"dataProvider",
",",
"]",
")",
";",
"}"
] | Lists all App models.
@return mixed | [
"Lists",
"all",
"App",
"models",
"."
] | train | https://github.com/yuncms/yii2-oauth2/blob/7fb41fc56d4a6a5f4107aec5429580729257ed3a/frontend/controllers/ClientController.php#L53-L62 |
yuncms/yii2-oauth2 | frontend/controllers/ClientController.php | ClientController.actionCreate | public function actionCreate()
{
$model = new Client();
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
} else if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->getSession()->setFlash('success', Yii::t('oauth2', 'Successful operation'));
return $this->redirect(['view', 'id' => $model->client_id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
} | php | public function actionCreate()
{
$model = new Client();
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
} else if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->getSession()->setFlash('success', Yii::t('oauth2', 'Successful operation'));
return $this->redirect(['view', 'id' => $model->client_id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
} | [
"public",
"function",
"actionCreate",
"(",
")",
"{",
"$",
"model",
"=",
"new",
"Client",
"(",
")",
";",
"if",
"(",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"isAjax",
"&&",
"$",
"model",
"->",
"load",
"(",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"post",
"(",
")",
")",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"response",
"->",
"format",
"=",
"Response",
"::",
"FORMAT_JSON",
";",
"return",
"ActiveForm",
"::",
"validate",
"(",
"$",
"model",
")",
";",
"}",
"else",
"if",
"(",
"$",
"model",
"->",
"load",
"(",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"post",
"(",
")",
")",
"&&",
"$",
"model",
"->",
"save",
"(",
")",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"getSession",
"(",
")",
"->",
"setFlash",
"(",
"'success'",
",",
"Yii",
"::",
"t",
"(",
"'oauth2'",
",",
"'Successful operation'",
")",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"[",
"'view'",
",",
"'id'",
"=>",
"$",
"model",
"->",
"client_id",
"]",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"render",
"(",
"'create'",
",",
"[",
"'model'",
"=>",
"$",
"model",
",",
"]",
")",
";",
"}",
"}"
] | Creates a new Rest model.
If creation is successful, the browser will be redirected to the 'view' page.
@return mixed | [
"Creates",
"a",
"new",
"Rest",
"model",
".",
"If",
"creation",
"is",
"successful",
"the",
"browser",
"will",
"be",
"redirected",
"to",
"the",
"view",
"page",
"."
] | train | https://github.com/yuncms/yii2-oauth2/blob/7fb41fc56d4a6a5f4107aec5429580729257ed3a/frontend/controllers/ClientController.php#L69-L83 |
SysControllers/Admin | public/assets/global/plugins/kcfinder/lib/class_input.php | input.filter | public function filter($subject) {
if ($this->magic_quotes_gpc) {
if (is_array($subject)) {
foreach ($subject as $key => $val)
if (!preg_match('/^[a-z\d_]+$/si', $key))
unset($subject[$key]);
else
$subject[$key] = $this->filter($val);
} elseif (is_scalar($subject))
$subject = $this->magic_quotes_sybase
? str_replace("\\'", "'", $subject)
: stripslashes($subject);
}
return $subject;
} | php | public function filter($subject) {
if ($this->magic_quotes_gpc) {
if (is_array($subject)) {
foreach ($subject as $key => $val)
if (!preg_match('/^[a-z\d_]+$/si', $key))
unset($subject[$key]);
else
$subject[$key] = $this->filter($val);
} elseif (is_scalar($subject))
$subject = $this->magic_quotes_sybase
? str_replace("\\'", "'", $subject)
: stripslashes($subject);
}
return $subject;
} | [
"public",
"function",
"filter",
"(",
"$",
"subject",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"magic_quotes_gpc",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"subject",
")",
")",
"{",
"foreach",
"(",
"$",
"subject",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"if",
"(",
"!",
"preg_match",
"(",
"'/^[a-z\\d_]+$/si'",
",",
"$",
"key",
")",
")",
"unset",
"(",
"$",
"subject",
"[",
"$",
"key",
"]",
")",
";",
"else",
"$",
"subject",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"filter",
"(",
"$",
"val",
")",
";",
"}",
"elseif",
"(",
"is_scalar",
"(",
"$",
"subject",
")",
")",
"$",
"subject",
"=",
"$",
"this",
"->",
"magic_quotes_sybase",
"?",
"str_replace",
"(",
"\"\\\\'\"",
",",
"\"'\"",
",",
"$",
"subject",
")",
":",
"stripslashes",
"(",
"$",
"subject",
")",
";",
"}",
"return",
"$",
"subject",
";",
"}"
] | Filter the given subject. If magic_quotes_gpc and/or magic_quotes_sybase
ini settings are turned on, the method will remove backslashes from some
escaped characters. If the subject is an array, elements with non-
alphanumeric keys will be removed
@param mixed $subject
@return mixed | [
"Filter",
"the",
"given",
"subject",
".",
"If",
"magic_quotes_gpc",
"and",
"/",
"or",
"magic_quotes_sybase",
"ini",
"settings",
"are",
"turned",
"on",
"the",
"method",
"will",
"remove",
"backslashes",
"from",
"some",
"escaped",
"characters",
".",
"If",
"the",
"subject",
"is",
"an",
"array",
"elements",
"with",
"non",
"-",
"alphanumeric",
"keys",
"will",
"be",
"removed"
] | train | https://github.com/SysControllers/Admin/blob/8f1df46aca422b87f2f522fbba610dcfa0c5f7f3/public/assets/global/plugins/kcfinder/lib/class_input.php#L67-L83 |
TiMESPLiNTER/tsFramework | src/ch/timesplinter/core/Core.php | Core.createHttpRequest | protected function createHttpRequest()
{
$protocol = (isset($_SERVER['HTTPS']) === true && $_SERVER['HTTPS'] === 'on') ? HttpRequest::PROTOCOL_HTTPS : HttpRequest::PROTOCOL_HTTP;
$uri = StringUtils::startsWith($_SERVER['REQUEST_URI'], '/index.php')?StringUtils::afterFirst($_SERVER['REQUEST_URI'], '/index.php'):$_SERVER['REQUEST_URI'];
$subFolder = StringUtils::afterFirst(getcwd(), $_SERVER['DOCUMENT_ROOT']);
$cleanPath = StringUtils::between($uri, $subFolder, '?');
$languages = array();
$langsRates = explode(',', isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : null);
foreach($langsRates as $lr) {
$lrParts = explode(';', $lr);
$languages[$lrParts[0]] = isset($lrParts[1])?(float)StringUtils::afterFirst($lrParts[1], 'q='):1.0;
}
$requestTime = new \DateTime();
$requestTime->setTimestamp($_SERVER['REQUEST_TIME']);
$httpRequest = new HttpRequest();
$httpRequest->setHost($_SERVER['SERVER_NAME']);
$httpRequest->setPath($cleanPath);
$httpRequest->setPort($_SERVER['SERVER_PORT']);
$httpRequest->setProtocol($protocol);
$httpRequest->setQuery($_SERVER['QUERY_STRING']);
$httpRequest->setURI($uri);
$httpRequest->setRequestTime($requestTime);
$httpRequest->setRequestMethod($_SERVER['REQUEST_METHOD']);
$httpRequest->setUserAgent(isset($_SERVER['HTTP_USER_AGENT'])?$_SERVER['HTTP_USER_AGENT']:null);
$httpRequest->setLanguages($languages);
$httpRequest->setAcceptLanguage(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])?$_SERVER['HTTP_ACCEPT_LANGUAGE']:null);
$httpRequest->setRemoteAddress($_SERVER['REMOTE_ADDR']);
$httpRequest->setReferrer(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
return $httpRequest;
} | php | protected function createHttpRequest()
{
$protocol = (isset($_SERVER['HTTPS']) === true && $_SERVER['HTTPS'] === 'on') ? HttpRequest::PROTOCOL_HTTPS : HttpRequest::PROTOCOL_HTTP;
$uri = StringUtils::startsWith($_SERVER['REQUEST_URI'], '/index.php')?StringUtils::afterFirst($_SERVER['REQUEST_URI'], '/index.php'):$_SERVER['REQUEST_URI'];
$subFolder = StringUtils::afterFirst(getcwd(), $_SERVER['DOCUMENT_ROOT']);
$cleanPath = StringUtils::between($uri, $subFolder, '?');
$languages = array();
$langsRates = explode(',', isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : null);
foreach($langsRates as $lr) {
$lrParts = explode(';', $lr);
$languages[$lrParts[0]] = isset($lrParts[1])?(float)StringUtils::afterFirst($lrParts[1], 'q='):1.0;
}
$requestTime = new \DateTime();
$requestTime->setTimestamp($_SERVER['REQUEST_TIME']);
$httpRequest = new HttpRequest();
$httpRequest->setHost($_SERVER['SERVER_NAME']);
$httpRequest->setPath($cleanPath);
$httpRequest->setPort($_SERVER['SERVER_PORT']);
$httpRequest->setProtocol($protocol);
$httpRequest->setQuery($_SERVER['QUERY_STRING']);
$httpRequest->setURI($uri);
$httpRequest->setRequestTime($requestTime);
$httpRequest->setRequestMethod($_SERVER['REQUEST_METHOD']);
$httpRequest->setUserAgent(isset($_SERVER['HTTP_USER_AGENT'])?$_SERVER['HTTP_USER_AGENT']:null);
$httpRequest->setLanguages($languages);
$httpRequest->setAcceptLanguage(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])?$_SERVER['HTTP_ACCEPT_LANGUAGE']:null);
$httpRequest->setRemoteAddress($_SERVER['REMOTE_ADDR']);
$httpRequest->setReferrer(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
return $httpRequest;
} | [
"protected",
"function",
"createHttpRequest",
"(",
")",
"{",
"$",
"protocol",
"=",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTPS'",
"]",
")",
"===",
"true",
"&&",
"$",
"_SERVER",
"[",
"'HTTPS'",
"]",
"===",
"'on'",
")",
"?",
"HttpRequest",
"::",
"PROTOCOL_HTTPS",
":",
"HttpRequest",
"::",
"PROTOCOL_HTTP",
";",
"$",
"uri",
"=",
"StringUtils",
"::",
"startsWith",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
",",
"'/index.php'",
")",
"?",
"StringUtils",
"::",
"afterFirst",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
",",
"'/index.php'",
")",
":",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
";",
"$",
"subFolder",
"=",
"StringUtils",
"::",
"afterFirst",
"(",
"getcwd",
"(",
")",
",",
"$",
"_SERVER",
"[",
"'DOCUMENT_ROOT'",
"]",
")",
";",
"$",
"cleanPath",
"=",
"StringUtils",
"::",
"between",
"(",
"$",
"uri",
",",
"$",
"subFolder",
",",
"'?'",
")",
";",
"$",
"languages",
"=",
"array",
"(",
")",
";",
"$",
"langsRates",
"=",
"explode",
"(",
"','",
",",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_LANGUAGE'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_LANGUAGE'",
"]",
":",
"null",
")",
";",
"foreach",
"(",
"$",
"langsRates",
"as",
"$",
"lr",
")",
"{",
"$",
"lrParts",
"=",
"explode",
"(",
"';'",
",",
"$",
"lr",
")",
";",
"$",
"languages",
"[",
"$",
"lrParts",
"[",
"0",
"]",
"]",
"=",
"isset",
"(",
"$",
"lrParts",
"[",
"1",
"]",
")",
"?",
"(",
"float",
")",
"StringUtils",
"::",
"afterFirst",
"(",
"$",
"lrParts",
"[",
"1",
"]",
",",
"'q='",
")",
":",
"1.0",
";",
"}",
"$",
"requestTime",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"requestTime",
"->",
"setTimestamp",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_TIME'",
"]",
")",
";",
"$",
"httpRequest",
"=",
"new",
"HttpRequest",
"(",
")",
";",
"$",
"httpRequest",
"->",
"setHost",
"(",
"$",
"_SERVER",
"[",
"'SERVER_NAME'",
"]",
")",
";",
"$",
"httpRequest",
"->",
"setPath",
"(",
"$",
"cleanPath",
")",
";",
"$",
"httpRequest",
"->",
"setPort",
"(",
"$",
"_SERVER",
"[",
"'SERVER_PORT'",
"]",
")",
";",
"$",
"httpRequest",
"->",
"setProtocol",
"(",
"$",
"protocol",
")",
";",
"$",
"httpRequest",
"->",
"setQuery",
"(",
"$",
"_SERVER",
"[",
"'QUERY_STRING'",
"]",
")",
";",
"$",
"httpRequest",
"->",
"setURI",
"(",
"$",
"uri",
")",
";",
"$",
"httpRequest",
"->",
"setRequestTime",
"(",
"$",
"requestTime",
")",
";",
"$",
"httpRequest",
"->",
"setRequestMethod",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
")",
";",
"$",
"httpRequest",
"->",
"setUserAgent",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_USER_AGENT'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'HTTP_USER_AGENT'",
"]",
":",
"null",
")",
";",
"$",
"httpRequest",
"->",
"setLanguages",
"(",
"$",
"languages",
")",
";",
"$",
"httpRequest",
"->",
"setAcceptLanguage",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_LANGUAGE'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_LANGUAGE'",
"]",
":",
"null",
")",
";",
"$",
"httpRequest",
"->",
"setRemoteAddress",
"(",
"$",
"_SERVER",
"[",
"'REMOTE_ADDR'",
"]",
")",
";",
"$",
"httpRequest",
"->",
"setReferrer",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_REFERER'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'HTTP_REFERER'",
"]",
":",
"null",
")",
";",
"return",
"$",
"httpRequest",
";",
"}"
] | Creates a HttpRequest object for the current request
@return HttpRequest | [
"Creates",
"a",
"HttpRequest",
"object",
"for",
"the",
"current",
"request"
] | train | https://github.com/TiMESPLiNTER/tsFramework/blob/b3b9fd98f6d456a9e571015877ecca203786fd0c/src/ch/timesplinter/core/Core.php#L95-L133 |
phospr/DoubleEntryBundle | Model/Journal.php | Journal.addPosting | public function addPosting(PostingInterface $posting)
{
$this->postings->add($posting);
$posting->setJournal($this);
} | php | public function addPosting(PostingInterface $posting)
{
$this->postings->add($posting);
$posting->setJournal($this);
} | [
"public",
"function",
"addPosting",
"(",
"PostingInterface",
"$",
"posting",
")",
"{",
"$",
"this",
"->",
"postings",
"->",
"add",
"(",
"$",
"posting",
")",
";",
"$",
"posting",
"->",
"setJournal",
"(",
"$",
"this",
")",
";",
"}"
] | Add posting
@author Tom Haskins-Vaughan <tom@tomhv.uk>
@since 0.8.0
@param PostingInterface $posting | [
"Add",
"posting"
] | train | https://github.com/phospr/DoubleEntryBundle/blob/d9c421f30922b461483731983c59beb26047fb7f/Model/Journal.php#L163-L167 |
phospr/DoubleEntryBundle | Model/Journal.php | Journal.post | public function post()
{
$this->setPostedAt(new \DateTime());
$this->ensureZeroSumOfPostings();
foreach ($this->getPostings() as $posting) {
$posting->post();
}
} | php | public function post()
{
$this->setPostedAt(new \DateTime());
$this->ensureZeroSumOfPostings();
foreach ($this->getPostings() as $posting) {
$posting->post();
}
} | [
"public",
"function",
"post",
"(",
")",
"{",
"$",
"this",
"->",
"setPostedAt",
"(",
"new",
"\\",
"DateTime",
"(",
")",
")",
";",
"$",
"this",
"->",
"ensureZeroSumOfPostings",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getPostings",
"(",
")",
"as",
"$",
"posting",
")",
"{",
"$",
"posting",
"->",
"post",
"(",
")",
";",
"}",
"}"
] | post()
Post all Postings for this Journal
@author Tom Haskins-Vaughan <tom@tomhv.uk>
@since 0.8.0 | [
"post",
"()"
] | train | https://github.com/phospr/DoubleEntryBundle/blob/d9c421f30922b461483731983c59beb26047fb7f/Model/Journal.php#L379-L388 |
phospr/DoubleEntryBundle | Model/Journal.php | Journal.debit | public function debit(Account $account, $amount)
{
// Income and Liabilities need the sign changed
if ($account->isIncome() || $account->isLiability()) {
$amount = -1*$amount;
}
$posting = new Posting();
$posting->setAccount($account);
$posting->setAmount($amount);
$this->addPosting($posting);
return $posting;
} | php | public function debit(Account $account, $amount)
{
// Income and Liabilities need the sign changed
if ($account->isIncome() || $account->isLiability()) {
$amount = -1*$amount;
}
$posting = new Posting();
$posting->setAccount($account);
$posting->setAmount($amount);
$this->addPosting($posting);
return $posting;
} | [
"public",
"function",
"debit",
"(",
"Account",
"$",
"account",
",",
"$",
"amount",
")",
"{",
"// Income and Liabilities need the sign changed",
"if",
"(",
"$",
"account",
"->",
"isIncome",
"(",
")",
"||",
"$",
"account",
"->",
"isLiability",
"(",
")",
")",
"{",
"$",
"amount",
"=",
"-",
"1",
"*",
"$",
"amount",
";",
"}",
"$",
"posting",
"=",
"new",
"Posting",
"(",
")",
";",
"$",
"posting",
"->",
"setAccount",
"(",
"$",
"account",
")",
";",
"$",
"posting",
"->",
"setAmount",
"(",
"$",
"amount",
")",
";",
"$",
"this",
"->",
"addPosting",
"(",
"$",
"posting",
")",
";",
"return",
"$",
"posting",
";",
"}"
] | debit()
Debits the given account by the given account. Takes into account
what type of account it is (Asset, Liability, Income, Expense)
@author Tom Haskins-Vaughan <tom@tomhv.uk>
@since 0.8.0
@param \HarvestCloud\CoreBundle\Entity\Account $account
@param decimal $amount
@return \HarvestCloud\CoreBundle\Entity\Posting | [
"debit",
"()"
] | train | https://github.com/phospr/DoubleEntryBundle/blob/d9c421f30922b461483731983c59beb26047fb7f/Model/Journal.php#L404-L418 |
Topolis/FunctionLibrary | src/Collection.php | Collection.getFromPath | public static function getFromPath($array, $path, $separator = "."){
$nodes = explode($separator, $path);
while($path && count($nodes) > 0){
$node = array_shift($nodes);
if(!is_array($array) || !isset($array[$node])){
throw new Exception(__METHOD__." - Not an array or node '$node' from path '$path' not found");
}
$array = $array[$node];
}
return $array;
} | php | public static function getFromPath($array, $path, $separator = "."){
$nodes = explode($separator, $path);
while($path && count($nodes) > 0){
$node = array_shift($nodes);
if(!is_array($array) || !isset($array[$node])){
throw new Exception(__METHOD__." - Not an array or node '$node' from path '$path' not found");
}
$array = $array[$node];
}
return $array;
} | [
"public",
"static",
"function",
"getFromPath",
"(",
"$",
"array",
",",
"$",
"path",
",",
"$",
"separator",
"=",
"\".\"",
")",
"{",
"$",
"nodes",
"=",
"explode",
"(",
"$",
"separator",
",",
"$",
"path",
")",
";",
"while",
"(",
"$",
"path",
"&&",
"count",
"(",
"$",
"nodes",
")",
">",
"0",
")",
"{",
"$",
"node",
"=",
"array_shift",
"(",
"$",
"nodes",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"array",
")",
"||",
"!",
"isset",
"(",
"$",
"array",
"[",
"$",
"node",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"__METHOD__",
".",
"\" - Not an array or node '$node' from path '$path' not found\"",
")",
";",
"}",
"$",
"array",
"=",
"$",
"array",
"[",
"$",
"node",
"]",
";",
"}",
"return",
"$",
"array",
";",
"}"
] | get a value from a multi dimensional tree-like array structure via a path string (ex.: "folder.folder.key")
@param array $array array to search
@param string $path path to traverse
@param string $separator (Optional) separator in path. Default: "."
@return array|mixed
@throws Exception if a node from $path is not found in $array | [
"get",
"a",
"value",
"from",
"a",
"multi",
"dimensional",
"tree",
"-",
"like",
"array",
"structure",
"via",
"a",
"path",
"string",
"(",
"ex",
".",
":",
"folder",
".",
"folder",
".",
"key",
")"
] | train | https://github.com/Topolis/FunctionLibrary/blob/bc57f465932fbf297927c2a32765255131b907eb/src/Collection.php#L17-L31 |
Topolis/FunctionLibrary | src/Collection.php | Collection.setFromPath | public static function setFromPath(&$array, $path, $value, $separator = "."){
$nodes = explode($separator, $path);
$array = self::setFromPath_r($array, $nodes, $value);
} | php | public static function setFromPath(&$array, $path, $value, $separator = "."){
$nodes = explode($separator, $path);
$array = self::setFromPath_r($array, $nodes, $value);
} | [
"public",
"static",
"function",
"setFromPath",
"(",
"&",
"$",
"array",
",",
"$",
"path",
",",
"$",
"value",
",",
"$",
"separator",
"=",
"\".\"",
")",
"{",
"$",
"nodes",
"=",
"explode",
"(",
"$",
"separator",
",",
"$",
"path",
")",
";",
"$",
"array",
"=",
"self",
"::",
"setFromPath_r",
"(",
"$",
"array",
",",
"$",
"nodes",
",",
"$",
"value",
")",
";",
"}"
] | set a value from a multi dimensional tree-like array structure via a path string (ex.: "folder.folder.key")
creating any needed array elements on the way.
@param array $array array to search
@param string $path path to traverse
@param mixed $value value to set. (if you set an array, it will be traversable via path too)
@param string $separator (Optional) separator in path. Default: "." | [
"set",
"a",
"value",
"from",
"a",
"multi",
"dimensional",
"tree",
"-",
"like",
"array",
"structure",
"via",
"a",
"path",
"string",
"(",
"ex",
".",
":",
"folder",
".",
"folder",
".",
"key",
")",
"creating",
"any",
"needed",
"array",
"elements",
"on",
"the",
"way",
"."
] | train | https://github.com/Topolis/FunctionLibrary/blob/bc57f465932fbf297927c2a32765255131b907eb/src/Collection.php#L41-L44 |
Topolis/FunctionLibrary | src/Collection.php | Collection.addFromPath | public static function addFromPath(&$array, $path, $value, $key = null, $separator = "."){
try{
$target = self::getFromPath($array, $path, $separator);
} catch(Exception $e) {
$target = array();
}
if(!is_array($target))
throw new Exception(__METHOD__." - element at path '$path' is no array");
if($key !== null)
$target[$key] = $value;
else
$target[] = $value;
self::setFromPath($array, $path, $target, $separator);
} | php | public static function addFromPath(&$array, $path, $value, $key = null, $separator = "."){
try{
$target = self::getFromPath($array, $path, $separator);
} catch(Exception $e) {
$target = array();
}
if(!is_array($target))
throw new Exception(__METHOD__." - element at path '$path' is no array");
if($key !== null)
$target[$key] = $value;
else
$target[] = $value;
self::setFromPath($array, $path, $target, $separator);
} | [
"public",
"static",
"function",
"addFromPath",
"(",
"&",
"$",
"array",
",",
"$",
"path",
",",
"$",
"value",
",",
"$",
"key",
"=",
"null",
",",
"$",
"separator",
"=",
"\".\"",
")",
"{",
"try",
"{",
"$",
"target",
"=",
"self",
"::",
"getFromPath",
"(",
"$",
"array",
",",
"$",
"path",
",",
"$",
"separator",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"target",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"target",
")",
")",
"throw",
"new",
"Exception",
"(",
"__METHOD__",
".",
"\" - element at path '$path' is no array\"",
")",
";",
"if",
"(",
"$",
"key",
"!==",
"null",
")",
"$",
"target",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"else",
"$",
"target",
"[",
"]",
"=",
"$",
"value",
";",
"self",
"::",
"setFromPath",
"(",
"$",
"array",
",",
"$",
"path",
",",
"$",
"target",
",",
"$",
"separator",
")",
";",
"}"
] | add a value (optionally with non-numeric key) to array at path
@param array $array array to search
@param string $path path to traverse to target array
@param mixed $value value to set. (if you set an array, it will be traversable via path too)
@param mixed $key (Optional) key to use instead of auto incremented numeric key. Default: null
@param string $separator (Optional) separator in path. Default: "."
@throws \Exception | [
"add",
"a",
"value",
"(",
"optionally",
"with",
"non",
"-",
"numeric",
"key",
")",
"to",
"array",
"at",
"path"
] | train | https://github.com/Topolis/FunctionLibrary/blob/bc57f465932fbf297927c2a32765255131b907eb/src/Collection.php#L71-L88 |
Topolis/FunctionLibrary | src/Collection.php | Collection.multisort | public static function multisort(){
$args = func_get_args();
$data = array_shift($args);
foreach ($args as $n => $field) {
if (is_string($field)) {
$tmp = array();
foreach ($data as $key => $row)
$tmp[$key] = $row[$field];
$args[$n] = $tmp;
}
}
$args[] = &$data;
call_user_func_array('array_multisort', $args);
return array_pop($args);
} | php | public static function multisort(){
$args = func_get_args();
$data = array_shift($args);
foreach ($args as $n => $field) {
if (is_string($field)) {
$tmp = array();
foreach ($data as $key => $row)
$tmp[$key] = $row[$field];
$args[$n] = $tmp;
}
}
$args[] = &$data;
call_user_func_array('array_multisort', $args);
return array_pop($args);
} | [
"public",
"static",
"function",
"multisort",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"data",
"=",
"array_shift",
"(",
"$",
"args",
")",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"n",
"=>",
"$",
"field",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"field",
")",
")",
"{",
"$",
"tmp",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"row",
")",
"$",
"tmp",
"[",
"$",
"key",
"]",
"=",
"$",
"row",
"[",
"$",
"field",
"]",
";",
"$",
"args",
"[",
"$",
"n",
"]",
"=",
"$",
"tmp",
";",
"}",
"}",
"$",
"args",
"[",
"]",
"=",
"&",
"$",
"data",
";",
"call_user_func_array",
"(",
"'array_multisort'",
",",
"$",
"args",
")",
";",
"return",
"array_pop",
"(",
"$",
"args",
")",
";",
"}"
] | sort an multidimensional array by any of it's fields and return sorted array
ex.: $sorted = Utility::multisort($data, 'volume', SORT_DESC, 'edition', SORT_ASC);
IMPORTANT: This function uses mutlisort and will reindex numeric keys !
@return array
@internal param array $data array to sort
@internal param string $field name of field to sort by
@internal param int $direction SORT_DESC or SORT_ASC constant | [
"sort",
"an",
"multidimensional",
"array",
"by",
"any",
"of",
"it",
"s",
"fields",
"and",
"return",
"sorted",
"array",
"ex",
".",
":",
"$sorted",
"=",
"Utility",
"::",
"multisort",
"(",
"$data",
"volume",
"SORT_DESC",
"edition",
"SORT_ASC",
")",
";",
"IMPORTANT",
":",
"This",
"function",
"uses",
"mutlisort",
"and",
"will",
"reindex",
"numeric",
"keys",
"!"
] | train | https://github.com/Topolis/FunctionLibrary/blob/bc57f465932fbf297927c2a32765255131b907eb/src/Collection.php#L121-L137 |
Topolis/FunctionLibrary | src/Collection.php | Collection.remove | public static function remove(&$array, $path, $separator = "."){
$nodes = explode($separator, $path);
$key = array_pop($nodes);
$parent = implode($separator, $nodes);
$siblings = self::getFromPath($array, $parent, $separator);
unset($siblings[$key]);
self::setFromPath($array, $parent, $siblings, $separator);
return $array;
} | php | public static function remove(&$array, $path, $separator = "."){
$nodes = explode($separator, $path);
$key = array_pop($nodes);
$parent = implode($separator, $nodes);
$siblings = self::getFromPath($array, $parent, $separator);
unset($siblings[$key]);
self::setFromPath($array, $parent, $siblings, $separator);
return $array;
} | [
"public",
"static",
"function",
"remove",
"(",
"&",
"$",
"array",
",",
"$",
"path",
",",
"$",
"separator",
"=",
"\".\"",
")",
"{",
"$",
"nodes",
"=",
"explode",
"(",
"$",
"separator",
",",
"$",
"path",
")",
";",
"$",
"key",
"=",
"array_pop",
"(",
"$",
"nodes",
")",
";",
"$",
"parent",
"=",
"implode",
"(",
"$",
"separator",
",",
"$",
"nodes",
")",
";",
"$",
"siblings",
"=",
"self",
"::",
"getFromPath",
"(",
"$",
"array",
",",
"$",
"parent",
",",
"$",
"separator",
")",
";",
"unset",
"(",
"$",
"siblings",
"[",
"$",
"key",
"]",
")",
";",
"self",
"::",
"setFromPath",
"(",
"$",
"array",
",",
"$",
"parent",
",",
"$",
"siblings",
",",
"$",
"separator",
")",
";",
"return",
"$",
"array",
";",
"}"
] | delete an element from the array (or path)
@param $array
@param string $path
@param string $separator (Optional)
@return mixed | [
"delete",
"an",
"element",
"from",
"the",
"array",
"(",
"or",
"path",
")"
] | train | https://github.com/Topolis/FunctionLibrary/blob/bc57f465932fbf297927c2a32765255131b907eb/src/Collection.php#L174-L184 |
Topolis/FunctionLibrary | src/Collection.php | Collection.find | public static function find($array, $path, $search, $field = false, $default = false){
$data = self::get($array, $path, array());
foreach($data as $item)
foreach($item as $key => $value)
if( ($field == false || $field = $key) && $value == $search)
return $item;
return $default;
} | php | public static function find($array, $path, $search, $field = false, $default = false){
$data = self::get($array, $path, array());
foreach($data as $item)
foreach($item as $key => $value)
if( ($field == false || $field = $key) && $value == $search)
return $item;
return $default;
} | [
"public",
"static",
"function",
"find",
"(",
"$",
"array",
",",
"$",
"path",
",",
"$",
"search",
",",
"$",
"field",
"=",
"false",
",",
"$",
"default",
"=",
"false",
")",
"{",
"$",
"data",
"=",
"self",
"::",
"get",
"(",
"$",
"array",
",",
"$",
"path",
",",
"array",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"item",
")",
"foreach",
"(",
"$",
"item",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"if",
"(",
"(",
"$",
"field",
"==",
"false",
"||",
"$",
"field",
"=",
"$",
"key",
")",
"&&",
"$",
"value",
"==",
"$",
"search",
")",
"return",
"$",
"item",
";",
"return",
"$",
"default",
";",
"}"
] | search for first sub array in $array that has a matching value either in any field or in a field named $field
eg: items:
munich:
country: germany
size: 1.3M
london:
country: great britain
size: 2.9M
find($items, "germany", "country") returns the array munich
@static
@param array $array array to search in
@param string $path path to start search in $array
@param mixed $search value to match
@param bool $field (Optional) match $value only in items named $field
@param mixed $default (Optional) return this value if nothing found
@return bool | [
"search",
"for",
"first",
"sub",
"array",
"in",
"$array",
"that",
"has",
"a",
"matching",
"value",
"either",
"in",
"any",
"field",
"or",
"in",
"a",
"field",
"named",
"$field",
"eg",
":",
"items",
":",
"munich",
":",
"country",
":",
"germany",
"size",
":",
"1",
".",
"3M",
"london",
":",
"country",
":",
"great",
"britain",
"size",
":",
"2",
".",
"9M",
"find",
"(",
"$items",
"germany",
"country",
")",
"returns",
"the",
"array",
"munich"
] | train | https://github.com/Topolis/FunctionLibrary/blob/bc57f465932fbf297927c2a32765255131b907eb/src/Collection.php#L233-L243 |
Topolis/FunctionLibrary | src/Collection.php | Collection.first | public static function first($array, $path, $default = false){
$data = self::get($array, $path, array());
if(count($data) > 0)
return reset($data);
return $default;
} | php | public static function first($array, $path, $default = false){
$data = self::get($array, $path, array());
if(count($data) > 0)
return reset($data);
return $default;
} | [
"public",
"static",
"function",
"first",
"(",
"$",
"array",
",",
"$",
"path",
",",
"$",
"default",
"=",
"false",
")",
"{",
"$",
"data",
"=",
"self",
"::",
"get",
"(",
"$",
"array",
",",
"$",
"path",
",",
"array",
"(",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"data",
")",
">",
"0",
")",
"return",
"reset",
"(",
"$",
"data",
")",
";",
"return",
"$",
"default",
";",
"}"
] | Return first element of an array at $path
@static
@param array $array
@param string $path
@param bool $default
@return bool|mixed | [
"Return",
"first",
"element",
"of",
"an",
"array",
"at",
"$path"
] | train | https://github.com/Topolis/FunctionLibrary/blob/bc57f465932fbf297927c2a32765255131b907eb/src/Collection.php#L253-L259 |
Topolis/FunctionLibrary | src/Collection.php | Collection.implodeMap | public static function implodeMap($array, $separatorAssign = ": ", $separatorElement = ", ", $encapsulation = ""){
$out = array();
foreach($array as $key => $value){
$out[] = $key.$separatorAssign.$encapsulation.$value.$encapsulation;
}
return implode($separatorElement, $out);
} | php | public static function implodeMap($array, $separatorAssign = ": ", $separatorElement = ", ", $encapsulation = ""){
$out = array();
foreach($array as $key => $value){
$out[] = $key.$separatorAssign.$encapsulation.$value.$encapsulation;
}
return implode($separatorElement, $out);
} | [
"public",
"static",
"function",
"implodeMap",
"(",
"$",
"array",
",",
"$",
"separatorAssign",
"=",
"\": \"",
",",
"$",
"separatorElement",
"=",
"\", \"",
",",
"$",
"encapsulation",
"=",
"\"\"",
")",
"{",
"$",
"out",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"out",
"[",
"]",
"=",
"$",
"key",
".",
"$",
"separatorAssign",
".",
"$",
"encapsulation",
".",
"$",
"value",
".",
"$",
"encapsulation",
";",
"}",
"return",
"implode",
"(",
"$",
"separatorElement",
",",
"$",
"out",
")",
";",
"}"
] | Implode array like implode() but also display keys.
@param array $array
@param string $separatorAssign (Optional) separator between key and value. Default: ": "
@param string $separatorElement (Optional) separator between elements. Default: ", "
@param string $encapsulation (Optional) Value encapsulation. Default: ""
@return string | [
"Implode",
"array",
"like",
"implode",
"()",
"but",
"also",
"display",
"keys",
"."
] | train | https://github.com/Topolis/FunctionLibrary/blob/bc57f465932fbf297927c2a32765255131b907eb/src/Collection.php#L269-L275 |
ezra-obiwale/dSCore | src/Stdlib/Util.php | Util.camelTo_ | public static function camelTo_($str) {
if (!is_string($str))
return '';
$str[0] = strtolower($str[0]);
$func = create_function('$c', 'return "_" . strtolower($c[1]);');
return preg_replace_callback('/([A-Z])/', $func, $str);
} | php | public static function camelTo_($str) {
if (!is_string($str))
return '';
$str[0] = strtolower($str[0]);
$func = create_function('$c', 'return "_" . strtolower($c[1]);');
return preg_replace_callback('/([A-Z])/', $func, $str);
} | [
"public",
"static",
"function",
"camelTo_",
"(",
"$",
"str",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"str",
")",
")",
"return",
"''",
";",
"$",
"str",
"[",
"0",
"]",
"=",
"strtolower",
"(",
"$",
"str",
"[",
"0",
"]",
")",
";",
"$",
"func",
"=",
"create_function",
"(",
"'$c'",
",",
"'return \"_\" . strtolower($c[1]);'",
")",
";",
"return",
"preg_replace_callback",
"(",
"'/([A-Z])/'",
",",
"$",
"func",
",",
"$",
"str",
")",
";",
"}"
] | Turns camelCasedString to under_scored_string
@param string $str
@return string | [
"Turns",
"camelCasedString",
"to",
"under_scored_string"
] | train | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Util.php#L24-L30 |
ezra-obiwale/dSCore | src/Stdlib/Util.php | Util.camelToHyphen | public static function camelToHyphen($str, $strtolower = true) {
if (!is_string($str))
return '';
$str[0] = strtolower($str[0]);
$func = create_function('$c', 'return "-" . $c[1];');
$str = preg_replace_callback('/([A-Z])/', $func, $str);
return ($strtolower) ? strtolower($str) : $str;
} | php | public static function camelToHyphen($str, $strtolower = true) {
if (!is_string($str))
return '';
$str[0] = strtolower($str[0]);
$func = create_function('$c', 'return "-" . $c[1];');
$str = preg_replace_callback('/([A-Z])/', $func, $str);
return ($strtolower) ? strtolower($str) : $str;
} | [
"public",
"static",
"function",
"camelToHyphen",
"(",
"$",
"str",
",",
"$",
"strtolower",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"str",
")",
")",
"return",
"''",
";",
"$",
"str",
"[",
"0",
"]",
"=",
"strtolower",
"(",
"$",
"str",
"[",
"0",
"]",
")",
";",
"$",
"func",
"=",
"create_function",
"(",
"'$c'",
",",
"'return \"-\" . $c[1];'",
")",
";",
"$",
"str",
"=",
"preg_replace_callback",
"(",
"'/([A-Z])/'",
",",
"$",
"func",
",",
"$",
"str",
")",
";",
"return",
"(",
"$",
"strtolower",
")",
"?",
"strtolower",
"(",
"$",
"str",
")",
":",
"$",
"str",
";",
"}"
] | Turns camelCasedString to hyphened-string
@param string $str
@param boolean $strtolower
@return string | [
"Turns",
"camelCasedString",
"to",
"hyphened",
"-",
"string"
] | train | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Util.php#L38-L45 |
ezra-obiwale/dSCore | src/Stdlib/Util.php | Util.camelToSpace | public static function camelToSpace($str) {
if (!is_string($str))
return '';
$str[0] = strtolower($str[0]);
$func = create_function('$c', 'return " " . $c[1];');
return preg_replace_callback('/([A-Z])/', $func, $str);
} | php | public static function camelToSpace($str) {
if (!is_string($str))
return '';
$str[0] = strtolower($str[0]);
$func = create_function('$c', 'return " " . $c[1];');
return preg_replace_callback('/([A-Z])/', $func, $str);
} | [
"public",
"static",
"function",
"camelToSpace",
"(",
"$",
"str",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"str",
")",
")",
"return",
"''",
";",
"$",
"str",
"[",
"0",
"]",
"=",
"strtolower",
"(",
"$",
"str",
"[",
"0",
"]",
")",
";",
"$",
"func",
"=",
"create_function",
"(",
"'$c'",
",",
"'return \" \" . $c[1];'",
")",
";",
"return",
"preg_replace_callback",
"(",
"'/([A-Z])/'",
",",
"$",
"func",
",",
"$",
"str",
")",
";",
"}"
] | Turns camelCasedString to spaced out string
@param string $str
@return string | [
"Turns",
"camelCasedString",
"to",
"spaced",
"out",
"string"
] | train | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Util.php#L63-L69 |
ezra-obiwale/dSCore | src/Stdlib/Util.php | Util.readDir | public static function readDir($dir, $return = Util::ALL, $recursive = false, $extension = NULL, $nameOnly = false, array $options = array()) {
if (!is_dir($dir))
return array(
'error' => 'Directory "' . $dir . '" does not exist',
);
if (!is_array($extension) && !empty($extension)) {
$extension = array($extension);
}
if (substr($dir, strlen($dir) - 1) !== DIRECTORY_SEPARATOR)
$dir .= DIRECTORY_SEPARATOR;
$toReturn = array('dirs' => array(), 'files' => array());
try {
foreach (scandir($dir) as $current) {
if (in_array($current, array('.', '..')))
continue;
if (is_dir($dir . $current)) {
if (in_array($return, array(self::DIRS_ONLY, self::ALL))) {
$toReturn['dirs'][] = ($nameOnly) ? $current : $dir . $current;
}
if ($recursive) {
$toReturn = array_merge_recursive($toReturn, self::readDir($dir . $current, self::ALL, true, $extension, $nameOnly, $options));
}
} else if (is_file($dir . $current) && in_array($return, array(self::FILES_ONLY, self::ALL))) {
if ($extension)
$info = pathinfo($current);
if (empty($extension) || (is_array($extension) && in_array($info['extension'], $extension))) {
$toReturn['files'][$dir][] = ($nameOnly) ? $current : $dir . $current;
}
}
}
if ($return == self::ALL)
return $toReturn;
elseif ($return == self::DIRS_ONLY)
return $toReturn['dirs'];
elseif ($return == self::FILES_ONLY)
return $toReturn['files'];
} catch (\Exception $ex) {
throw new \Exception($ex->getMessage());
}
} | php | public static function readDir($dir, $return = Util::ALL, $recursive = false, $extension = NULL, $nameOnly = false, array $options = array()) {
if (!is_dir($dir))
return array(
'error' => 'Directory "' . $dir . '" does not exist',
);
if (!is_array($extension) && !empty($extension)) {
$extension = array($extension);
}
if (substr($dir, strlen($dir) - 1) !== DIRECTORY_SEPARATOR)
$dir .= DIRECTORY_SEPARATOR;
$toReturn = array('dirs' => array(), 'files' => array());
try {
foreach (scandir($dir) as $current) {
if (in_array($current, array('.', '..')))
continue;
if (is_dir($dir . $current)) {
if (in_array($return, array(self::DIRS_ONLY, self::ALL))) {
$toReturn['dirs'][] = ($nameOnly) ? $current : $dir . $current;
}
if ($recursive) {
$toReturn = array_merge_recursive($toReturn, self::readDir($dir . $current, self::ALL, true, $extension, $nameOnly, $options));
}
} else if (is_file($dir . $current) && in_array($return, array(self::FILES_ONLY, self::ALL))) {
if ($extension)
$info = pathinfo($current);
if (empty($extension) || (is_array($extension) && in_array($info['extension'], $extension))) {
$toReturn['files'][$dir][] = ($nameOnly) ? $current : $dir . $current;
}
}
}
if ($return == self::ALL)
return $toReturn;
elseif ($return == self::DIRS_ONLY)
return $toReturn['dirs'];
elseif ($return == self::FILES_ONLY)
return $toReturn['files'];
} catch (\Exception $ex) {
throw new \Exception($ex->getMessage());
}
} | [
"public",
"static",
"function",
"readDir",
"(",
"$",
"dir",
",",
"$",
"return",
"=",
"Util",
"::",
"ALL",
",",
"$",
"recursive",
"=",
"false",
",",
"$",
"extension",
"=",
"NULL",
",",
"$",
"nameOnly",
"=",
"false",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"return",
"array",
"(",
"'error'",
"=>",
"'Directory \"'",
".",
"$",
"dir",
".",
"'\" does not exist'",
",",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"extension",
")",
"&&",
"!",
"empty",
"(",
"$",
"extension",
")",
")",
"{",
"$",
"extension",
"=",
"array",
"(",
"$",
"extension",
")",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"dir",
",",
"strlen",
"(",
"$",
"dir",
")",
"-",
"1",
")",
"!==",
"DIRECTORY_SEPARATOR",
")",
"$",
"dir",
".=",
"DIRECTORY_SEPARATOR",
";",
"$",
"toReturn",
"=",
"array",
"(",
"'dirs'",
"=>",
"array",
"(",
")",
",",
"'files'",
"=>",
"array",
"(",
")",
")",
";",
"try",
"{",
"foreach",
"(",
"scandir",
"(",
"$",
"dir",
")",
"as",
"$",
"current",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"current",
",",
"array",
"(",
"'.'",
",",
"'..'",
")",
")",
")",
"continue",
";",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
".",
"$",
"current",
")",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"return",
",",
"array",
"(",
"self",
"::",
"DIRS_ONLY",
",",
"self",
"::",
"ALL",
")",
")",
")",
"{",
"$",
"toReturn",
"[",
"'dirs'",
"]",
"[",
"]",
"=",
"(",
"$",
"nameOnly",
")",
"?",
"$",
"current",
":",
"$",
"dir",
".",
"$",
"current",
";",
"}",
"if",
"(",
"$",
"recursive",
")",
"{",
"$",
"toReturn",
"=",
"array_merge_recursive",
"(",
"$",
"toReturn",
",",
"self",
"::",
"readDir",
"(",
"$",
"dir",
".",
"$",
"current",
",",
"self",
"::",
"ALL",
",",
"true",
",",
"$",
"extension",
",",
"$",
"nameOnly",
",",
"$",
"options",
")",
")",
";",
"}",
"}",
"else",
"if",
"(",
"is_file",
"(",
"$",
"dir",
".",
"$",
"current",
")",
"&&",
"in_array",
"(",
"$",
"return",
",",
"array",
"(",
"self",
"::",
"FILES_ONLY",
",",
"self",
"::",
"ALL",
")",
")",
")",
"{",
"if",
"(",
"$",
"extension",
")",
"$",
"info",
"=",
"pathinfo",
"(",
"$",
"current",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"extension",
")",
"||",
"(",
"is_array",
"(",
"$",
"extension",
")",
"&&",
"in_array",
"(",
"$",
"info",
"[",
"'extension'",
"]",
",",
"$",
"extension",
")",
")",
")",
"{",
"$",
"toReturn",
"[",
"'files'",
"]",
"[",
"$",
"dir",
"]",
"[",
"]",
"=",
"(",
"$",
"nameOnly",
")",
"?",
"$",
"current",
":",
"$",
"dir",
".",
"$",
"current",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"return",
"==",
"self",
"::",
"ALL",
")",
"return",
"$",
"toReturn",
";",
"elseif",
"(",
"$",
"return",
"==",
"self",
"::",
"DIRS_ONLY",
")",
"return",
"$",
"toReturn",
"[",
"'dirs'",
"]",
";",
"elseif",
"(",
"$",
"return",
"==",
"self",
"::",
"FILES_ONLY",
")",
"return",
"$",
"toReturn",
"[",
"'files'",
"]",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"ex",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Reads the required source directory
@param string $dir
@param int $return
@param boolean $recursive
@param string|array\null $extension Extensions without the dot (.)
@param boolean $nameOnly Indicates whether to return full path of dirs/files or names only
@param array $options keys include:
@return array
@throws \Exception | [
"Reads",
"the",
"required",
"source",
"directory"
] | train | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Util.php#L107-L151 |
ezra-obiwale/dSCore | src/Stdlib/Util.php | Util.copyDir | public static function copyDir($source, $destination, $permission = 0777, $recursive = true) {
if (substr($source, strlen($destination) - 1) !== DIRECTORY_SEPARATOR)
$destination .= DIRECTORY_SEPARATOR;
try {
if (!is_dir($destination))
mkdir($destination, $permission);
$contents = self::readDir($source, self::ALL, $recursive, NULL);
if (isset($contents['dirs'])) {
foreach ($contents['dirs'] as $fullPath) {
@mkdir(str_replace(array($source, DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR), array($destination, DIRECTORY_SEPARATOR), $fullPath), $permission);
}
}
if (isset($contents['files'])) {
foreach ($contents['files'] as $fullPathsArray) {
foreach ($fullPathsArray as $fullPath) {
@copy($fullPath, str_replace(array($source, DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR), array($destination, DIRECTORY_SEPARATOR), $fullPath));
}
}
}
} catch (\Exception $ex) {
throw new \Exception($ex->getMessage());
}
} | php | public static function copyDir($source, $destination, $permission = 0777, $recursive = true) {
if (substr($source, strlen($destination) - 1) !== DIRECTORY_SEPARATOR)
$destination .= DIRECTORY_SEPARATOR;
try {
if (!is_dir($destination))
mkdir($destination, $permission);
$contents = self::readDir($source, self::ALL, $recursive, NULL);
if (isset($contents['dirs'])) {
foreach ($contents['dirs'] as $fullPath) {
@mkdir(str_replace(array($source, DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR), array($destination, DIRECTORY_SEPARATOR), $fullPath), $permission);
}
}
if (isset($contents['files'])) {
foreach ($contents['files'] as $fullPathsArray) {
foreach ($fullPathsArray as $fullPath) {
@copy($fullPath, str_replace(array($source, DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR), array($destination, DIRECTORY_SEPARATOR), $fullPath));
}
}
}
} catch (\Exception $ex) {
throw new \Exception($ex->getMessage());
}
} | [
"public",
"static",
"function",
"copyDir",
"(",
"$",
"source",
",",
"$",
"destination",
",",
"$",
"permission",
"=",
"0777",
",",
"$",
"recursive",
"=",
"true",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"source",
",",
"strlen",
"(",
"$",
"destination",
")",
"-",
"1",
")",
"!==",
"DIRECTORY_SEPARATOR",
")",
"$",
"destination",
".=",
"DIRECTORY_SEPARATOR",
";",
"try",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"destination",
")",
")",
"mkdir",
"(",
"$",
"destination",
",",
"$",
"permission",
")",
";",
"$",
"contents",
"=",
"self",
"::",
"readDir",
"(",
"$",
"source",
",",
"self",
"::",
"ALL",
",",
"$",
"recursive",
",",
"NULL",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"contents",
"[",
"'dirs'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"contents",
"[",
"'dirs'",
"]",
"as",
"$",
"fullPath",
")",
"{",
"@",
"mkdir",
"(",
"str_replace",
"(",
"array",
"(",
"$",
"source",
",",
"DIRECTORY_SEPARATOR",
".",
"DIRECTORY_SEPARATOR",
")",
",",
"array",
"(",
"$",
"destination",
",",
"DIRECTORY_SEPARATOR",
")",
",",
"$",
"fullPath",
")",
",",
"$",
"permission",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"contents",
"[",
"'files'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"contents",
"[",
"'files'",
"]",
"as",
"$",
"fullPathsArray",
")",
"{",
"foreach",
"(",
"$",
"fullPathsArray",
"as",
"$",
"fullPath",
")",
"{",
"@",
"copy",
"(",
"$",
"fullPath",
",",
"str_replace",
"(",
"array",
"(",
"$",
"source",
",",
"DIRECTORY_SEPARATOR",
".",
"DIRECTORY_SEPARATOR",
")",
",",
"array",
"(",
"$",
"destination",
",",
"DIRECTORY_SEPARATOR",
")",
",",
"$",
"fullPath",
")",
")",
";",
"}",
"}",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"ex",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Copies a directory to another location
@param string $source
@param string $destination
@param string $permission
@param boolean $recursive
@throws \Exception | [
"Copies",
"a",
"directory",
"to",
"another",
"location"
] | train | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Util.php#L161-L186 |
ezra-obiwale/dSCore | src/Stdlib/Util.php | Util.delDir | public static function delDir($dir) {
$all = self::readDir($dir, self::ALL, true, NULL);
if (isset($all['files'])) {
foreach ($all['files'] as $file) {
if (is_array($file)) {
foreach ($file as $fil) {
if (!unlink($fil)) {
return false;
}
}
} else {
if (!unlink($file)) {
return false;
}
}
}
}
if (isset($all['dirs'])) {
foreach (array_reverse($all['dirs']) as $_dir) {
if (is_array($_dir)) {
foreach ($_dir as $_dr) {
if (!rmdir($_dr)) {
return false;
}
}
} else {
if (!rmdir($_dir)) {
return false;
}
}
}
}
return rmdir($dir);
} | php | public static function delDir($dir) {
$all = self::readDir($dir, self::ALL, true, NULL);
if (isset($all['files'])) {
foreach ($all['files'] as $file) {
if (is_array($file)) {
foreach ($file as $fil) {
if (!unlink($fil)) {
return false;
}
}
} else {
if (!unlink($file)) {
return false;
}
}
}
}
if (isset($all['dirs'])) {
foreach (array_reverse($all['dirs']) as $_dir) {
if (is_array($_dir)) {
foreach ($_dir as $_dr) {
if (!rmdir($_dr)) {
return false;
}
}
} else {
if (!rmdir($_dir)) {
return false;
}
}
}
}
return rmdir($dir);
} | [
"public",
"static",
"function",
"delDir",
"(",
"$",
"dir",
")",
"{",
"$",
"all",
"=",
"self",
"::",
"readDir",
"(",
"$",
"dir",
",",
"self",
"::",
"ALL",
",",
"true",
",",
"NULL",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"all",
"[",
"'files'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"all",
"[",
"'files'",
"]",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"file",
")",
")",
"{",
"foreach",
"(",
"$",
"file",
"as",
"$",
"fil",
")",
"{",
"if",
"(",
"!",
"unlink",
"(",
"$",
"fil",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"unlink",
"(",
"$",
"file",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"all",
"[",
"'dirs'",
"]",
")",
")",
"{",
"foreach",
"(",
"array_reverse",
"(",
"$",
"all",
"[",
"'dirs'",
"]",
")",
"as",
"$",
"_dir",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"_dir",
")",
")",
"{",
"foreach",
"(",
"$",
"_dir",
"as",
"$",
"_dr",
")",
"{",
"if",
"(",
"!",
"rmdir",
"(",
"$",
"_dr",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"rmdir",
"(",
"$",
"_dir",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"}",
"return",
"rmdir",
"(",
"$",
"dir",
")",
";",
"}"
] | Deletes a directory and all contents including subdirectories and files
@param string $file
@return boolean | [
"Deletes",
"a",
"directory",
"and",
"all",
"contents",
"including",
"subdirectories",
"and",
"files"
] | train | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Util.php#L194-L229 |
ezra-obiwale/dSCore | src/Stdlib/Util.php | Util.resizeImage | public static function resizeImage($source, $desiredWidth = 200, $destination = null, $extension = null) {
if (!$destination)
$destination = $source;
$info = pathinfo($source);
$extension = !$extension ? $info['extension'] : $extension;
/* read the source image */
switch (strtolower($extension)) {
case 'jpeg':
case 'jpg':
$sourceImage = imagecreatefromjpeg($source);
break;
case 'gif':
$sourceImage = imagecreatefromgif($source);
break;
case 'png':
$sourceImage = imagecreatefrompng($source);
break;
}
$width = imagesx($sourceImage);
$height = imagesy($sourceImage);
/* find the "desired height" of this thumbnail, relative to the desired width */
$desiredHeight = floor($height * ($desiredWidth / $width));
/* create a new "virtual" image */
$virtualImage = imagecreatetruecolor($desiredWidth, $desiredHeight);
/* copy source image at a resized size */
imagecopyresampled($virtualImage, $sourceImage, 0, 0, 0, 0, $desiredWidth, $desiredHeight, $width, $height);
$return = false;
/* create the physical thumbnail image to its destination */
switch (strtolower($extension)) {
case 'jpeg':
case 'jpg':
$return = imagejpeg($virtualImage, $destination);
break;
case 'gif':
$return = imagegif($virtualImage, $destination);
break;
case 'png':
$return = imagepng($virtualImage, $destination);
break;
}
return $return;
} | php | public static function resizeImage($source, $desiredWidth = 200, $destination = null, $extension = null) {
if (!$destination)
$destination = $source;
$info = pathinfo($source);
$extension = !$extension ? $info['extension'] : $extension;
/* read the source image */
switch (strtolower($extension)) {
case 'jpeg':
case 'jpg':
$sourceImage = imagecreatefromjpeg($source);
break;
case 'gif':
$sourceImage = imagecreatefromgif($source);
break;
case 'png':
$sourceImage = imagecreatefrompng($source);
break;
}
$width = imagesx($sourceImage);
$height = imagesy($sourceImage);
/* find the "desired height" of this thumbnail, relative to the desired width */
$desiredHeight = floor($height * ($desiredWidth / $width));
/* create a new "virtual" image */
$virtualImage = imagecreatetruecolor($desiredWidth, $desiredHeight);
/* copy source image at a resized size */
imagecopyresampled($virtualImage, $sourceImage, 0, 0, 0, 0, $desiredWidth, $desiredHeight, $width, $height);
$return = false;
/* create the physical thumbnail image to its destination */
switch (strtolower($extension)) {
case 'jpeg':
case 'jpg':
$return = imagejpeg($virtualImage, $destination);
break;
case 'gif':
$return = imagegif($virtualImage, $destination);
break;
case 'png':
$return = imagepng($virtualImage, $destination);
break;
}
return $return;
} | [
"public",
"static",
"function",
"resizeImage",
"(",
"$",
"source",
",",
"$",
"desiredWidth",
"=",
"200",
",",
"$",
"destination",
"=",
"null",
",",
"$",
"extension",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"destination",
")",
"$",
"destination",
"=",
"$",
"source",
";",
"$",
"info",
"=",
"pathinfo",
"(",
"$",
"source",
")",
";",
"$",
"extension",
"=",
"!",
"$",
"extension",
"?",
"$",
"info",
"[",
"'extension'",
"]",
":",
"$",
"extension",
";",
"/* read the source image */",
"switch",
"(",
"strtolower",
"(",
"$",
"extension",
")",
")",
"{",
"case",
"'jpeg'",
":",
"case",
"'jpg'",
":",
"$",
"sourceImage",
"=",
"imagecreatefromjpeg",
"(",
"$",
"source",
")",
";",
"break",
";",
"case",
"'gif'",
":",
"$",
"sourceImage",
"=",
"imagecreatefromgif",
"(",
"$",
"source",
")",
";",
"break",
";",
"case",
"'png'",
":",
"$",
"sourceImage",
"=",
"imagecreatefrompng",
"(",
"$",
"source",
")",
";",
"break",
";",
"}",
"$",
"width",
"=",
"imagesx",
"(",
"$",
"sourceImage",
")",
";",
"$",
"height",
"=",
"imagesy",
"(",
"$",
"sourceImage",
")",
";",
"/* find the \"desired height\" of this thumbnail, relative to the desired width */",
"$",
"desiredHeight",
"=",
"floor",
"(",
"$",
"height",
"*",
"(",
"$",
"desiredWidth",
"/",
"$",
"width",
")",
")",
";",
"/* create a new \"virtual\" image */",
"$",
"virtualImage",
"=",
"imagecreatetruecolor",
"(",
"$",
"desiredWidth",
",",
"$",
"desiredHeight",
")",
";",
"/* copy source image at a resized size */",
"imagecopyresampled",
"(",
"$",
"virtualImage",
",",
"$",
"sourceImage",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"$",
"desiredWidth",
",",
"$",
"desiredHeight",
",",
"$",
"width",
",",
"$",
"height",
")",
";",
"$",
"return",
"=",
"false",
";",
"/* create the physical thumbnail image to its destination */",
"switch",
"(",
"strtolower",
"(",
"$",
"extension",
")",
")",
"{",
"case",
"'jpeg'",
":",
"case",
"'jpg'",
":",
"$",
"return",
"=",
"imagejpeg",
"(",
"$",
"virtualImage",
",",
"$",
"destination",
")",
";",
"break",
";",
"case",
"'gif'",
":",
"$",
"return",
"=",
"imagegif",
"(",
"$",
"virtualImage",
",",
"$",
"destination",
")",
";",
"break",
";",
"case",
"'png'",
":",
"$",
"return",
"=",
"imagepng",
"(",
"$",
"virtualImage",
",",
"$",
"destination",
")",
";",
"break",
";",
"}",
"return",
"$",
"return",
";",
"}"
] | Resizes an image
@param string $source Path to image file
@param int $desiredWidth The width of the new image
@param string $destination Path to save image to. If null, the source
will be overwritten
@param string $extension The extension of the source file, provided if
the source does not bear an explicit extension
@return boolean | [
"Resizes",
"an",
"image"
] | train | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Util.php#L241-L288 |
ezra-obiwale/dSCore | src/Stdlib/Util.php | Util.resizeImageDirectory | public static function resizeImageDirectory($dir, $desiredWidth = 200, $overwrite = false, $recursive = true, $subDir = 'resized') {
foreach (self::readDir($dir, self::FILES_ONLY, $recursive, null, true) as $path => $filesArray) {
foreach ($filesArray as $file) {
$destination = null;
if (!$overwrite) {
if (!is_dir($path . $subDir)) {
mkdir($path . $subDir);
}
$destination = $path . $subDir . DIRECTORY_SEPARATOR . $file;
}
self::resizeImage($path . $file, $desiredWidth, $destination);
}
}
} | php | public static function resizeImageDirectory($dir, $desiredWidth = 200, $overwrite = false, $recursive = true, $subDir = 'resized') {
foreach (self::readDir($dir, self::FILES_ONLY, $recursive, null, true) as $path => $filesArray) {
foreach ($filesArray as $file) {
$destination = null;
if (!$overwrite) {
if (!is_dir($path . $subDir)) {
mkdir($path . $subDir);
}
$destination = $path . $subDir . DIRECTORY_SEPARATOR . $file;
}
self::resizeImage($path . $file, $desiredWidth, $destination);
}
}
} | [
"public",
"static",
"function",
"resizeImageDirectory",
"(",
"$",
"dir",
",",
"$",
"desiredWidth",
"=",
"200",
",",
"$",
"overwrite",
"=",
"false",
",",
"$",
"recursive",
"=",
"true",
",",
"$",
"subDir",
"=",
"'resized'",
")",
"{",
"foreach",
"(",
"self",
"::",
"readDir",
"(",
"$",
"dir",
",",
"self",
"::",
"FILES_ONLY",
",",
"$",
"recursive",
",",
"null",
",",
"true",
")",
"as",
"$",
"path",
"=>",
"$",
"filesArray",
")",
"{",
"foreach",
"(",
"$",
"filesArray",
"as",
"$",
"file",
")",
"{",
"$",
"destination",
"=",
"null",
";",
"if",
"(",
"!",
"$",
"overwrite",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"path",
".",
"$",
"subDir",
")",
")",
"{",
"mkdir",
"(",
"$",
"path",
".",
"$",
"subDir",
")",
";",
"}",
"$",
"destination",
"=",
"$",
"path",
".",
"$",
"subDir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
";",
"}",
"self",
"::",
"resizeImage",
"(",
"$",
"path",
".",
"$",
"file",
",",
"$",
"desiredWidth",
",",
"$",
"destination",
")",
";",
"}",
"}",
"}"
] | Resize all images in a directory
@param string $dir Directory path of images
@param int $desiredWidth Desired width of new images
@param boolean $overwrite Overwrite old images?
@param boolean $recursive Indicates if subdirectories should be searched too
@param string $subDir If not overwrite, name of subfolder within the $dir
to resize into | [
"Resize",
"all",
"images",
"in",
"a",
"directory"
] | train | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Util.php#L300-L313 |
ezra-obiwale/dSCore | src/Stdlib/Util.php | Util.shortenString | public static function shortenString($str, $length = 75, $break = '...') {
if (strlen($str) < $length)
return $str;
$str = strip_tags($str);
return substr($str, 0, $length) . $break;
} | php | public static function shortenString($str, $length = 75, $break = '...') {
if (strlen($str) < $length)
return $str;
$str = strip_tags($str);
return substr($str, 0, $length) . $break;
} | [
"public",
"static",
"function",
"shortenString",
"(",
"$",
"str",
",",
"$",
"length",
"=",
"75",
",",
"$",
"break",
"=",
"'...'",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"str",
")",
"<",
"$",
"length",
")",
"return",
"$",
"str",
";",
"$",
"str",
"=",
"strip_tags",
"(",
"$",
"str",
")",
";",
"return",
"substr",
"(",
"$",
"str",
",",
"0",
",",
"$",
"length",
")",
".",
"$",
"break",
";",
"}"
] | Shortens a string to desired length
@param string $str String to shorten
@param integer $length Length of the string to return
@param string $break String to replace the truncated part with
@return string | [
"Shortens",
"a",
"string",
"to",
"desired",
"length"
] | train | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Util.php#L322-L329 |
ezra-obiwale/dSCore | src/Stdlib/Util.php | Util.uploadFiles | public static function uploadFiles(\Object $data, array $options = array()) {
$return = array('success' => array(), 'errors' => array());
foreach ($data->toArray(TRUE) as $ppt => $info) {
if (is_array($options['ignore']) && in_array($ppt, $options['ignore']))
continue;
self::makeValuesArray($info);
foreach ($info['name'] as $key => $name) {
if ($info['error'][$key] !== UPLOAD_ERR_OK) {
$return['errors'][$ppt][$name] = self::UPLOAD_ERROR_NO_FILE;
continue;
}
if (isset($options['maxSize'][$key]) && $info['size'] > $options['maxSize'][$key]) {
$return['errors'][$ppt][$name] = self::UPLOAD_ERROR_SIZE;
continue;
}
$tmpName = $info['tmp_name'][$key];
$pInfo = pathinfo($name);
if (isset($options['extensions']) && !in_array(strtolower($pInfo['extension']), $options['extensions'])) {
$return['errors'][$ppt][$name] = self::UPLOAD_ERROR_EXTENSION;
continue;
}
$dir = isset($options['path']) ? $options['path'] : DATA . 'uploads';
if (substr($dir, strlen($dir) - 1) !== DIRECTORY_SEPARATOR)
$dir .= DIRECTORY_SEPARATOR;
if (!is_dir($dir)) {
if (!mkdir($dir, 0777, true)) {
$return['errors'][$ppt][$name] = self::UPLOAD_ERROR_PATH;
continue;
}
}
$savePath = $dir . $options['prefix'] . preg_replace('/[^A-Z0-9._-]/i', '_', basename($pInfo['filename'])) . '.' . $pInfo['extension'];
if (move_uploaded_file($tmpName, $savePath)) {
$return['success'][$ppt][$name] = $savePath;
self::$uploadSuccess = $savePath;
} else {
$return['errors'][$ppt][$name] = self::UPLOAD_ERROR_FAILED;
}
}
}
return $return;
} | php | public static function uploadFiles(\Object $data, array $options = array()) {
$return = array('success' => array(), 'errors' => array());
foreach ($data->toArray(TRUE) as $ppt => $info) {
if (is_array($options['ignore']) && in_array($ppt, $options['ignore']))
continue;
self::makeValuesArray($info);
foreach ($info['name'] as $key => $name) {
if ($info['error'][$key] !== UPLOAD_ERR_OK) {
$return['errors'][$ppt][$name] = self::UPLOAD_ERROR_NO_FILE;
continue;
}
if (isset($options['maxSize'][$key]) && $info['size'] > $options['maxSize'][$key]) {
$return['errors'][$ppt][$name] = self::UPLOAD_ERROR_SIZE;
continue;
}
$tmpName = $info['tmp_name'][$key];
$pInfo = pathinfo($name);
if (isset($options['extensions']) && !in_array(strtolower($pInfo['extension']), $options['extensions'])) {
$return['errors'][$ppt][$name] = self::UPLOAD_ERROR_EXTENSION;
continue;
}
$dir = isset($options['path']) ? $options['path'] : DATA . 'uploads';
if (substr($dir, strlen($dir) - 1) !== DIRECTORY_SEPARATOR)
$dir .= DIRECTORY_SEPARATOR;
if (!is_dir($dir)) {
if (!mkdir($dir, 0777, true)) {
$return['errors'][$ppt][$name] = self::UPLOAD_ERROR_PATH;
continue;
}
}
$savePath = $dir . $options['prefix'] . preg_replace('/[^A-Z0-9._-]/i', '_', basename($pInfo['filename'])) . '.' . $pInfo['extension'];
if (move_uploaded_file($tmpName, $savePath)) {
$return['success'][$ppt][$name] = $savePath;
self::$uploadSuccess = $savePath;
} else {
$return['errors'][$ppt][$name] = self::UPLOAD_ERROR_FAILED;
}
}
}
return $return;
} | [
"public",
"static",
"function",
"uploadFiles",
"(",
"\\",
"Object",
"$",
"data",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"return",
"=",
"array",
"(",
"'success'",
"=>",
"array",
"(",
")",
",",
"'errors'",
"=>",
"array",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"data",
"->",
"toArray",
"(",
"TRUE",
")",
"as",
"$",
"ppt",
"=>",
"$",
"info",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"options",
"[",
"'ignore'",
"]",
")",
"&&",
"in_array",
"(",
"$",
"ppt",
",",
"$",
"options",
"[",
"'ignore'",
"]",
")",
")",
"continue",
";",
"self",
"::",
"makeValuesArray",
"(",
"$",
"info",
")",
";",
"foreach",
"(",
"$",
"info",
"[",
"'name'",
"]",
"as",
"$",
"key",
"=>",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"info",
"[",
"'error'",
"]",
"[",
"$",
"key",
"]",
"!==",
"UPLOAD_ERR_OK",
")",
"{",
"$",
"return",
"[",
"'errors'",
"]",
"[",
"$",
"ppt",
"]",
"[",
"$",
"name",
"]",
"=",
"self",
"::",
"UPLOAD_ERROR_NO_FILE",
";",
"continue",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'maxSize'",
"]",
"[",
"$",
"key",
"]",
")",
"&&",
"$",
"info",
"[",
"'size'",
"]",
">",
"$",
"options",
"[",
"'maxSize'",
"]",
"[",
"$",
"key",
"]",
")",
"{",
"$",
"return",
"[",
"'errors'",
"]",
"[",
"$",
"ppt",
"]",
"[",
"$",
"name",
"]",
"=",
"self",
"::",
"UPLOAD_ERROR_SIZE",
";",
"continue",
";",
"}",
"$",
"tmpName",
"=",
"$",
"info",
"[",
"'tmp_name'",
"]",
"[",
"$",
"key",
"]",
";",
"$",
"pInfo",
"=",
"pathinfo",
"(",
"$",
"name",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'extensions'",
"]",
")",
"&&",
"!",
"in_array",
"(",
"strtolower",
"(",
"$",
"pInfo",
"[",
"'extension'",
"]",
")",
",",
"$",
"options",
"[",
"'extensions'",
"]",
")",
")",
"{",
"$",
"return",
"[",
"'errors'",
"]",
"[",
"$",
"ppt",
"]",
"[",
"$",
"name",
"]",
"=",
"self",
"::",
"UPLOAD_ERROR_EXTENSION",
";",
"continue",
";",
"}",
"$",
"dir",
"=",
"isset",
"(",
"$",
"options",
"[",
"'path'",
"]",
")",
"?",
"$",
"options",
"[",
"'path'",
"]",
":",
"DATA",
".",
"'uploads'",
";",
"if",
"(",
"substr",
"(",
"$",
"dir",
",",
"strlen",
"(",
"$",
"dir",
")",
"-",
"1",
")",
"!==",
"DIRECTORY_SEPARATOR",
")",
"$",
"dir",
".=",
"DIRECTORY_SEPARATOR",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"if",
"(",
"!",
"mkdir",
"(",
"$",
"dir",
",",
"0777",
",",
"true",
")",
")",
"{",
"$",
"return",
"[",
"'errors'",
"]",
"[",
"$",
"ppt",
"]",
"[",
"$",
"name",
"]",
"=",
"self",
"::",
"UPLOAD_ERROR_PATH",
";",
"continue",
";",
"}",
"}",
"$",
"savePath",
"=",
"$",
"dir",
".",
"$",
"options",
"[",
"'prefix'",
"]",
".",
"preg_replace",
"(",
"'/[^A-Z0-9._-]/i'",
",",
"'_'",
",",
"basename",
"(",
"$",
"pInfo",
"[",
"'filename'",
"]",
")",
")",
".",
"'.'",
".",
"$",
"pInfo",
"[",
"'extension'",
"]",
";",
"if",
"(",
"move_uploaded_file",
"(",
"$",
"tmpName",
",",
"$",
"savePath",
")",
")",
"{",
"$",
"return",
"[",
"'success'",
"]",
"[",
"$",
"ppt",
"]",
"[",
"$",
"name",
"]",
"=",
"$",
"savePath",
";",
"self",
"::",
"$",
"uploadSuccess",
"=",
"$",
"savePath",
";",
"}",
"else",
"{",
"$",
"return",
"[",
"'errors'",
"]",
"[",
"$",
"ppt",
"]",
"[",
"$",
"name",
"]",
"=",
"self",
"::",
"UPLOAD_ERROR_FAILED",
";",
"}",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] | Uploads file(s) to the server
@param \Object $data Files to upload
@param array $options Keys include [(string) path, (int) maxSize,
(array) extensions - in lower case, (array) ignore, (string) prefix]
@return boolean|string | [
"Uploads",
"file",
"(",
"s",
")",
"to",
"the",
"server"
] | train | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Util.php#L351-L394 |
ezra-obiwale/dSCore | src/Stdlib/Util.php | Util.randomPassword | public static function randomPassword($length = 8, $string = null) {
if (!$string)
$string = 'bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ123456789&^%$#@!_-+=';
$chars = str_split(str_shuffle($string));
$password = '';
foreach (array_rand($chars, $length) as $key) {
$password .= $chars[$key];
}
return $password;
} | php | public static function randomPassword($length = 8, $string = null) {
if (!$string)
$string = 'bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ123456789&^%$#@!_-+=';
$chars = str_split(str_shuffle($string));
$password = '';
foreach (array_rand($chars, $length) as $key) {
$password .= $chars[$key];
}
return $password;
} | [
"public",
"static",
"function",
"randomPassword",
"(",
"$",
"length",
"=",
"8",
",",
"$",
"string",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"string",
")",
"$",
"string",
"=",
"'bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ123456789&^%$#@!_-+='",
";",
"$",
"chars",
"=",
"str_split",
"(",
"str_shuffle",
"(",
"$",
"string",
")",
")",
";",
"$",
"password",
"=",
"''",
";",
"foreach",
"(",
"array_rand",
"(",
"$",
"chars",
",",
"$",
"length",
")",
"as",
"$",
"key",
")",
"{",
"$",
"password",
".=",
"$",
"chars",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"password",
";",
"}"
] | Generates a random password
@param int $length Length of the password to generate. Default is 8
@return string | [
"Generates",
"a",
"random",
"password"
] | train | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Util.php#L401-L410 |
ezra-obiwale/dSCore | src/Stdlib/Util.php | Util.listTimezones | public static function listTimezones() {
if (self::$timezones === null) {
self::$timezones = array();
$offsets = array();
$now = new DateTime();
foreach (DateTimeZone::listIdentifiers() as $timezone) {
$now->setTimezone(new DateTimeZone($timezone));
$offsets[] = $offset = $now->getOffset();
self::$timezones[$timezone] = '(' . self::formatGmtOffset($offset) . ') ' . self::formatTimezoneName($timezone);
}
array_multisort($offsets, self::$timezones);
}
return self::$timezones;
} | php | public static function listTimezones() {
if (self::$timezones === null) {
self::$timezones = array();
$offsets = array();
$now = new DateTime();
foreach (DateTimeZone::listIdentifiers() as $timezone) {
$now->setTimezone(new DateTimeZone($timezone));
$offsets[] = $offset = $now->getOffset();
self::$timezones[$timezone] = '(' . self::formatGmtOffset($offset) . ') ' . self::formatTimezoneName($timezone);
}
array_multisort($offsets, self::$timezones);
}
return self::$timezones;
} | [
"public",
"static",
"function",
"listTimezones",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"timezones",
"===",
"null",
")",
"{",
"self",
"::",
"$",
"timezones",
"=",
"array",
"(",
")",
";",
"$",
"offsets",
"=",
"array",
"(",
")",
";",
"$",
"now",
"=",
"new",
"DateTime",
"(",
")",
";",
"foreach",
"(",
"DateTimeZone",
"::",
"listIdentifiers",
"(",
")",
"as",
"$",
"timezone",
")",
"{",
"$",
"now",
"->",
"setTimezone",
"(",
"new",
"DateTimeZone",
"(",
"$",
"timezone",
")",
")",
";",
"$",
"offsets",
"[",
"]",
"=",
"$",
"offset",
"=",
"$",
"now",
"->",
"getOffset",
"(",
")",
";",
"self",
"::",
"$",
"timezones",
"[",
"$",
"timezone",
"]",
"=",
"'('",
".",
"self",
"::",
"formatGmtOffset",
"(",
"$",
"offset",
")",
".",
"') '",
".",
"self",
"::",
"formatTimezoneName",
"(",
"$",
"timezone",
")",
";",
"}",
"array_multisort",
"(",
"$",
"offsets",
",",
"self",
"::",
"$",
"timezones",
")",
";",
"}",
"return",
"self",
"::",
"$",
"timezones",
";",
"}"
] | Create a list of time zones
@return array | [
"Create",
"a",
"list",
"of",
"time",
"zones"
] | train | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Util.php#L448-L464 |
ezra-obiwale/dSCore | src/Stdlib/Util.php | Util.formatGmtOffset | public static function formatGmtOffset($offset) {
$hours = intval($offset / 3600);
$minutes = abs(intval($offset % 3600 / 60));
return 'GMT' . ($offset ? sprintf('%+03d:%02d', $hours, $minutes) : '');
} | php | public static function formatGmtOffset($offset) {
$hours = intval($offset / 3600);
$minutes = abs(intval($offset % 3600 / 60));
return 'GMT' . ($offset ? sprintf('%+03d:%02d', $hours, $minutes) : '');
} | [
"public",
"static",
"function",
"formatGmtOffset",
"(",
"$",
"offset",
")",
"{",
"$",
"hours",
"=",
"intval",
"(",
"$",
"offset",
"/",
"3600",
")",
";",
"$",
"minutes",
"=",
"abs",
"(",
"intval",
"(",
"$",
"offset",
"%",
"3600",
"/",
"60",
")",
")",
";",
"return",
"'GMT'",
".",
"(",
"$",
"offset",
"?",
"sprintf",
"(",
"'%+03d:%02d'",
",",
"$",
"hours",
",",
"$",
"minutes",
")",
":",
"''",
")",
";",
"}"
] | Formats GMT offset to string
@param string $offset
@return string | [
"Formats",
"GMT",
"offset",
"to",
"string"
] | train | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Util.php#L471-L475 |
swaros/golib | src/Types/Props.php | Props.applyData | public function applyData ( $data = NULL ) {
if (NULL != $data && is_array( $data )) {
foreach ($data as $propName => $propValue) {
$this->assignValue( $propName, $propValue );
}
} else {
$this->buildVars();
}
} | php | public function applyData ( $data = NULL ) {
if (NULL != $data && is_array( $data )) {
foreach ($data as $propName => $propValue) {
$this->assignValue( $propName, $propValue );
}
} else {
$this->buildVars();
}
} | [
"public",
"function",
"applyData",
"(",
"$",
"data",
"=",
"NULL",
")",
"{",
"if",
"(",
"NULL",
"!=",
"$",
"data",
"&&",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"propName",
"=>",
"$",
"propValue",
")",
"{",
"$",
"this",
"->",
"assignValue",
"(",
"$",
"propName",
",",
"$",
"propValue",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"buildVars",
"(",
")",
";",
"}",
"}"
] | apply given data to properties
@param array $data | [
"apply",
"given",
"data",
"to",
"properties"
] | train | https://github.com/swaros/golib/blob/9e75c8fb36de7c09b01a6c1c0d27c45f02fed567/src/Types/Props.php#L36-L44 |
swaros/golib | src/Types/Props.php | Props.assignExisting | public function assignExisting ( $propName, $propValue ) {
if (is_bool( $this->$propName )) {
if (strtolower( $propValue ) == 'false') {
$propValue = false;
}
$this->$propName = (bool) $propValue;
} elseif (is_int( $this->$propName )) {
$this->$propName = (int) $propValue;
} elseif (is_bool( $this->$propName )) {
$this->$propName = (bool) $propValue;
} elseif ($this->$propName instanceof Timer || $this->$propName == MapConst::TIMER) {
$this->$propName = new Timer( $propValue );
} else {
$this->$propName = $propValue;
}
} | php | public function assignExisting ( $propName, $propValue ) {
if (is_bool( $this->$propName )) {
if (strtolower( $propValue ) == 'false') {
$propValue = false;
}
$this->$propName = (bool) $propValue;
} elseif (is_int( $this->$propName )) {
$this->$propName = (int) $propValue;
} elseif (is_bool( $this->$propName )) {
$this->$propName = (bool) $propValue;
} elseif ($this->$propName instanceof Timer || $this->$propName == MapConst::TIMER) {
$this->$propName = new Timer( $propValue );
} else {
$this->$propName = $propValue;
}
} | [
"public",
"function",
"assignExisting",
"(",
"$",
"propName",
",",
"$",
"propValue",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"this",
"->",
"$",
"propName",
")",
")",
"{",
"if",
"(",
"strtolower",
"(",
"$",
"propValue",
")",
"==",
"'false'",
")",
"{",
"$",
"propValue",
"=",
"false",
";",
"}",
"$",
"this",
"->",
"$",
"propName",
"=",
"(",
"bool",
")",
"$",
"propValue",
";",
"}",
"elseif",
"(",
"is_int",
"(",
"$",
"this",
"->",
"$",
"propName",
")",
")",
"{",
"$",
"this",
"->",
"$",
"propName",
"=",
"(",
"int",
")",
"$",
"propValue",
";",
"}",
"elseif",
"(",
"is_bool",
"(",
"$",
"this",
"->",
"$",
"propName",
")",
")",
"{",
"$",
"this",
"->",
"$",
"propName",
"=",
"(",
"bool",
")",
"$",
"propValue",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"$",
"propName",
"instanceof",
"Timer",
"||",
"$",
"this",
"->",
"$",
"propName",
"==",
"MapConst",
"::",
"TIMER",
")",
"{",
"$",
"this",
"->",
"$",
"propName",
"=",
"new",
"Timer",
"(",
"$",
"propValue",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"$",
"propName",
"=",
"$",
"propValue",
";",
"}",
"}"
] | assign value to a existing propertie and
cast depending on defined default value
@param string $propName
@param boolean $propValue | [
"assign",
"value",
"to",
"a",
"existing",
"propertie",
"and",
"cast",
"depending",
"on",
"defined",
"default",
"value"
] | train | https://github.com/swaros/golib/blob/9e75c8fb36de7c09b01a6c1c0d27c45f02fed567/src/Types/Props.php#L61-L76 |
swaros/golib | src/Types/Props.php | Props.assignValue | public function assignValue ( $propNameOrig, $propValue ) {
$propNameA = str_replace( self::$replaceChars, '_', $propNameOrig );
$propName = preg_replace( "/[^A-Za-z0-9_]/", "", $propNameA );
if (property_exists( $this, $propName ) && $this->$propName !== NULL) {
$this->assignExisting( $propName, $propValue );
} elseif ($propName !== '') {
$this->$propName = $propValue;
}
} | php | public function assignValue ( $propNameOrig, $propValue ) {
$propNameA = str_replace( self::$replaceChars, '_', $propNameOrig );
$propName = preg_replace( "/[^A-Za-z0-9_]/", "", $propNameA );
if (property_exists( $this, $propName ) && $this->$propName !== NULL) {
$this->assignExisting( $propName, $propValue );
} elseif ($propName !== '') {
$this->$propName = $propValue;
}
} | [
"public",
"function",
"assignValue",
"(",
"$",
"propNameOrig",
",",
"$",
"propValue",
")",
"{",
"$",
"propNameA",
"=",
"str_replace",
"(",
"self",
"::",
"$",
"replaceChars",
",",
"'_'",
",",
"$",
"propNameOrig",
")",
";",
"$",
"propName",
"=",
"preg_replace",
"(",
"\"/[^A-Za-z0-9_]/\"",
",",
"\"\"",
",",
"$",
"propNameA",
")",
";",
"if",
"(",
"property_exists",
"(",
"$",
"this",
",",
"$",
"propName",
")",
"&&",
"$",
"this",
"->",
"$",
"propName",
"!==",
"NULL",
")",
"{",
"$",
"this",
"->",
"assignExisting",
"(",
"$",
"propName",
",",
"$",
"propValue",
")",
";",
"}",
"elseif",
"(",
"$",
"propName",
"!==",
"''",
")",
"{",
"$",
"this",
"->",
"$",
"propName",
"=",
"$",
"propValue",
";",
"}",
"}"
] | main assign value method.
@param string $propNameOrig
@param mixed $propValue | [
"main",
"assign",
"value",
"method",
"."
] | train | https://github.com/swaros/golib/blob/9e75c8fb36de7c09b01a6c1c0d27c45f02fed567/src/Types/Props.php#L84-L92 |
libreworks/caridea-auth | src/Service.php | Service.getPrincipal | public function getPrincipal(): Principal
{
if ($this->principal === null && !$this->resume()) {
$this->principal = Principal::getAnonymous();
}
return $this->principal;
} | php | public function getPrincipal(): Principal
{
if ($this->principal === null && !$this->resume()) {
$this->principal = Principal::getAnonymous();
}
return $this->principal;
} | [
"public",
"function",
"getPrincipal",
"(",
")",
":",
"Principal",
"{",
"if",
"(",
"$",
"this",
"->",
"principal",
"===",
"null",
"&&",
"!",
"$",
"this",
"->",
"resume",
"(",
")",
")",
"{",
"$",
"this",
"->",
"principal",
"=",
"Principal",
"::",
"getAnonymous",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"principal",
";",
"}"
] | Gets the currently authenticated principal.
If no one is authenticated, this will return an anonymous Principal. If
The session is not started but can be resumed, it will be resumed and the
principal will be loaded.
@return Principal the authenticated principal | [
"Gets",
"the",
"currently",
"authenticated",
"principal",
"."
] | train | https://github.com/libreworks/caridea-auth/blob/1bf965c57716942b18ca3204629f6bda99cf876a/src/Service.php#L81-L87 |
libreworks/caridea-auth | src/Service.php | Service.login | public function login(ServerRequestInterface $request, ?Adapter $adapter = null): bool
{
$started = $this->session->resume() || $this->session->start();
if (!$started) {
return false;
}
$login = $adapter ?? $this->adapter;
if ($login === null) {
throw new \InvalidArgumentException('You must specify an adapter for authentication');
}
$this->principal = $principal = $login->login($request);
$this->session->clear();
$this->session->regenerateId();
$this->values->offsetSet('principal', $principal);
$now = microtime(true);
$this->values->offsetSet('firstActive', $now);
$this->values->offsetSet('lastActive', $now);
$this->logger->info(
"Authentication login: {user}",
['user' => $principal]
);
return $this->publishLogin($principal);
} | php | public function login(ServerRequestInterface $request, ?Adapter $adapter = null): bool
{
$started = $this->session->resume() || $this->session->start();
if (!$started) {
return false;
}
$login = $adapter ?? $this->adapter;
if ($login === null) {
throw new \InvalidArgumentException('You must specify an adapter for authentication');
}
$this->principal = $principal = $login->login($request);
$this->session->clear();
$this->session->regenerateId();
$this->values->offsetSet('principal', $principal);
$now = microtime(true);
$this->values->offsetSet('firstActive', $now);
$this->values->offsetSet('lastActive', $now);
$this->logger->info(
"Authentication login: {user}",
['user' => $principal]
);
return $this->publishLogin($principal);
} | [
"public",
"function",
"login",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"?",
"Adapter",
"$",
"adapter",
"=",
"null",
")",
":",
"bool",
"{",
"$",
"started",
"=",
"$",
"this",
"->",
"session",
"->",
"resume",
"(",
")",
"||",
"$",
"this",
"->",
"session",
"->",
"start",
"(",
")",
";",
"if",
"(",
"!",
"$",
"started",
")",
"{",
"return",
"false",
";",
"}",
"$",
"login",
"=",
"$",
"adapter",
"??",
"$",
"this",
"->",
"adapter",
";",
"if",
"(",
"$",
"login",
"===",
"null",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'You must specify an adapter for authentication'",
")",
";",
"}",
"$",
"this",
"->",
"principal",
"=",
"$",
"principal",
"=",
"$",
"login",
"->",
"login",
"(",
"$",
"request",
")",
";",
"$",
"this",
"->",
"session",
"->",
"clear",
"(",
")",
";",
"$",
"this",
"->",
"session",
"->",
"regenerateId",
"(",
")",
";",
"$",
"this",
"->",
"values",
"->",
"offsetSet",
"(",
"'principal'",
",",
"$",
"principal",
")",
";",
"$",
"now",
"=",
"microtime",
"(",
"true",
")",
";",
"$",
"this",
"->",
"values",
"->",
"offsetSet",
"(",
"'firstActive'",
",",
"$",
"now",
")",
";",
"$",
"this",
"->",
"values",
"->",
"offsetSet",
"(",
"'lastActive'",
",",
"$",
"now",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"\"Authentication login: {user}\"",
",",
"[",
"'user'",
"=>",
"$",
"principal",
"]",
")",
";",
"return",
"$",
"this",
"->",
"publishLogin",
"(",
"$",
"principal",
")",
";",
"}"
] | Authenticates a principal.
@param ServerRequestInterface $request The Server Request message containing credentials
@param Adapter|null $adapter An optional adapter to use.
Will use the default authentication adapter if none is specified.
@return bool Whether the session could be established
@throws \InvalidArgumentException If no adapter is provided and no default adapter is set
@throws Exception\UsernameNotFound if the provided username wasn't found
@throws Exception\UsernameAmbiguous if the provided username matches multiple accounts
@throws Exception\InvalidPassword if the provided password is invalid
@throws Exception\ConnectionFailed if the access to a remote data source failed
(e.g. missing flat file, unreachable LDAP server, database login denied) | [
"Authenticates",
"a",
"principal",
"."
] | train | https://github.com/libreworks/caridea-auth/blob/1bf965c57716942b18ca3204629f6bda99cf876a/src/Service.php#L103-L129 |
libreworks/caridea-auth | src/Service.php | Service.publishLogin | protected function publishLogin(Principal $principal): bool
{
$this->publisher->publish(new Event\Login($this, $principal));
return true;
} | php | protected function publishLogin(Principal $principal): bool
{
$this->publisher->publish(new Event\Login($this, $principal));
return true;
} | [
"protected",
"function",
"publishLogin",
"(",
"Principal",
"$",
"principal",
")",
":",
"bool",
"{",
"$",
"this",
"->",
"publisher",
"->",
"publish",
"(",
"new",
"Event",
"\\",
"Login",
"(",
"$",
"this",
",",
"$",
"principal",
")",
")",
";",
"return",
"true",
";",
"}"
] | Publishes the login event.
@param \Caridea\Auth\Principal $principal The authenticated principal
@return bool Always true | [
"Publishes",
"the",
"login",
"event",
"."
] | train | https://github.com/libreworks/caridea-auth/blob/1bf965c57716942b18ca3204629f6bda99cf876a/src/Service.php#L137-L141 |
libreworks/caridea-auth | src/Service.php | Service.resume | public function resume(): bool
{
if ($this->values->offsetExists('principal')) {
$this->principal = $this->values->get('principal');
$this->logger->info(
"Authentication resume: {user}",
['user' => $this->principal]
);
$this->publishResume($this->principal, $this->values);
$this->values->offsetSet('lastActive', microtime(true));
return true;
}
return false;
} | php | public function resume(): bool
{
if ($this->values->offsetExists('principal')) {
$this->principal = $this->values->get('principal');
$this->logger->info(
"Authentication resume: {user}",
['user' => $this->principal]
);
$this->publishResume($this->principal, $this->values);
$this->values->offsetSet('lastActive', microtime(true));
return true;
}
return false;
} | [
"public",
"function",
"resume",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"values",
"->",
"offsetExists",
"(",
"'principal'",
")",
")",
"{",
"$",
"this",
"->",
"principal",
"=",
"$",
"this",
"->",
"values",
"->",
"get",
"(",
"'principal'",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"\"Authentication resume: {user}\"",
",",
"[",
"'user'",
"=>",
"$",
"this",
"->",
"principal",
"]",
")",
";",
"$",
"this",
"->",
"publishResume",
"(",
"$",
"this",
"->",
"principal",
",",
"$",
"this",
"->",
"values",
")",
";",
"$",
"this",
"->",
"values",
"->",
"offsetSet",
"(",
"'lastActive'",
",",
"microtime",
"(",
"true",
")",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Resumes an existing authenticated session.
@return bool If an authentication session existed | [
"Resumes",
"an",
"existing",
"authenticated",
"session",
"."
] | train | https://github.com/libreworks/caridea-auth/blob/1bf965c57716942b18ca3204629f6bda99cf876a/src/Service.php#L148-L164 |
libreworks/caridea-auth | src/Service.php | Service.publishResume | protected function publishResume(Principal $principal, Map $values)
{
$this->publisher->publish(new Event\Resume(
$this,
$principal,
$values->get('firstActive') ?? 0.0,
$values->get('lastActive') ?? 0.0
));
} | php | protected function publishResume(Principal $principal, Map $values)
{
$this->publisher->publish(new Event\Resume(
$this,
$principal,
$values->get('firstActive') ?? 0.0,
$values->get('lastActive') ?? 0.0
));
} | [
"protected",
"function",
"publishResume",
"(",
"Principal",
"$",
"principal",
",",
"Map",
"$",
"values",
")",
"{",
"$",
"this",
"->",
"publisher",
"->",
"publish",
"(",
"new",
"Event",
"\\",
"Resume",
"(",
"$",
"this",
",",
"$",
"principal",
",",
"$",
"values",
"->",
"get",
"(",
"'firstActive'",
")",
"??",
"0.0",
",",
"$",
"values",
"->",
"get",
"(",
"'lastActive'",
")",
"??",
"0.0",
")",
")",
";",
"}"
] | Publishes the resume event.
@param \Caridea\Auth\Principal $principal The authenticated principal
@param \Caridea\Session\Map $values The session values | [
"Publishes",
"the",
"resume",
"event",
"."
] | train | https://github.com/libreworks/caridea-auth/blob/1bf965c57716942b18ca3204629f6bda99cf876a/src/Service.php#L172-L180 |
libreworks/caridea-auth | src/Service.php | Service.logout | public function logout(): bool
{
if ($this->values->offsetExists('principal')) {
$principal = $this->getPrincipal();
$this->principal = Principal::getAnonymous();
$this->session->destroy();
$this->logger->info(
"Authentication logout: {user}",
['user' => $principal]
);
return $this->publishLogout($principal);
}
return false;
} | php | public function logout(): bool
{
if ($this->values->offsetExists('principal')) {
$principal = $this->getPrincipal();
$this->principal = Principal::getAnonymous();
$this->session->destroy();
$this->logger->info(
"Authentication logout: {user}",
['user' => $principal]
);
return $this->publishLogout($principal);
}
return false;
} | [
"public",
"function",
"logout",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"values",
"->",
"offsetExists",
"(",
"'principal'",
")",
")",
"{",
"$",
"principal",
"=",
"$",
"this",
"->",
"getPrincipal",
"(",
")",
";",
"$",
"this",
"->",
"principal",
"=",
"Principal",
"::",
"getAnonymous",
"(",
")",
";",
"$",
"this",
"->",
"session",
"->",
"destroy",
"(",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"\"Authentication logout: {user}\"",
",",
"[",
"'user'",
"=>",
"$",
"principal",
"]",
")",
";",
"return",
"$",
"this",
"->",
"publishLogout",
"(",
"$",
"principal",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Logs out the currently authenticated principal.
@return bool If a principal existed in the session to log out | [
"Logs",
"out",
"the",
"currently",
"authenticated",
"principal",
"."
] | train | https://github.com/libreworks/caridea-auth/blob/1bf965c57716942b18ca3204629f6bda99cf876a/src/Service.php#L187-L202 |
libreworks/caridea-auth | src/Service.php | Service.publishLogout | protected function publishLogout(Principal $principal): bool
{
$this->publisher->publish(new Event\Logout($this, $principal));
return true;
} | php | protected function publishLogout(Principal $principal): bool
{
$this->publisher->publish(new Event\Logout($this, $principal));
return true;
} | [
"protected",
"function",
"publishLogout",
"(",
"Principal",
"$",
"principal",
")",
":",
"bool",
"{",
"$",
"this",
"->",
"publisher",
"->",
"publish",
"(",
"new",
"Event",
"\\",
"Logout",
"(",
"$",
"this",
",",
"$",
"principal",
")",
")",
";",
"return",
"true",
";",
"}"
] | Publishes the logout event.
@param \Caridea\Auth\Principal $principal The authenticated principal
@return bool Always true | [
"Publishes",
"the",
"logout",
"event",
"."
] | train | https://github.com/libreworks/caridea-auth/blob/1bf965c57716942b18ca3204629f6bda99cf876a/src/Service.php#L210-L214 |
CrunchPHP/fastcgi | src/Protocol/Role.php | Role.instance | public static function instance($role)
{
// @codeCoverageIgnoreStart
if (!self::$instances) {
self::$instances = [
self::RESPONDER => new self(self::RESPONDER),
self::AUTHORIZER => new self(self::AUTHORIZER),
self::FILTER => new self(self::FILTER),
];
}
// @codeCoverageIgnoreEnd
if (!array_key_exists($role, self::$instances)) {
throw new \InvalidArgumentException("Invalid Role $role");
}
return self::$instances[$role];
} | php | public static function instance($role)
{
// @codeCoverageIgnoreStart
if (!self::$instances) {
self::$instances = [
self::RESPONDER => new self(self::RESPONDER),
self::AUTHORIZER => new self(self::AUTHORIZER),
self::FILTER => new self(self::FILTER),
];
}
// @codeCoverageIgnoreEnd
if (!array_key_exists($role, self::$instances)) {
throw new \InvalidArgumentException("Invalid Role $role");
}
return self::$instances[$role];
} | [
"public",
"static",
"function",
"instance",
"(",
"$",
"role",
")",
"{",
"// @codeCoverageIgnoreStart",
"if",
"(",
"!",
"self",
"::",
"$",
"instances",
")",
"{",
"self",
"::",
"$",
"instances",
"=",
"[",
"self",
"::",
"RESPONDER",
"=>",
"new",
"self",
"(",
"self",
"::",
"RESPONDER",
")",
",",
"self",
"::",
"AUTHORIZER",
"=>",
"new",
"self",
"(",
"self",
"::",
"AUTHORIZER",
")",
",",
"self",
"::",
"FILTER",
"=>",
"new",
"self",
"(",
"self",
"::",
"FILTER",
")",
",",
"]",
";",
"}",
"// @codeCoverageIgnoreEnd",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"role",
",",
"self",
"::",
"$",
"instances",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid Role $role\"",
")",
";",
"}",
"return",
"self",
"::",
"$",
"instances",
"[",
"$",
"role",
"]",
";",
"}"
] | Returns an instance of the given role.
@param int $role
@throws \InvalidArgumentException
@return Role | [
"Returns",
"an",
"instance",
"of",
"the",
"given",
"role",
"."
] | train | https://github.com/CrunchPHP/fastcgi/blob/102437193e67e5a841ec5a897549ec345788d1bd/src/Protocol/Role.php#L46-L63 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.hasFields | protected function hasFields(/*variable arguments*/)
{
$missingFields = array();
$args = func_get_args();
foreach ($args as $field) {
if (!isset($this->config[$field])) {
$missingFields[] = $field;
}
}
if (count($missingFields) > 0) {
throw new Klarna_ConfigFieldMissingException(
implode(', ', $missingFields)
);
}
} | php | protected function hasFields(/*variable arguments*/)
{
$missingFields = array();
$args = func_get_args();
foreach ($args as $field) {
if (!isset($this->config[$field])) {
$missingFields[] = $field;
}
}
if (count($missingFields) > 0) {
throw new Klarna_ConfigFieldMissingException(
implode(', ', $missingFields)
);
}
} | [
"protected",
"function",
"hasFields",
"(",
"/*variable arguments*/",
")",
"{",
"$",
"missingFields",
"=",
"array",
"(",
")",
";",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"$",
"field",
"]",
")",
")",
"{",
"$",
"missingFields",
"[",
"]",
"=",
"$",
"field",
";",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"missingFields",
")",
">",
"0",
")",
"{",
"throw",
"new",
"Klarna_ConfigFieldMissingException",
"(",
"implode",
"(",
"', '",
",",
"$",
"missingFields",
")",
")",
";",
"}",
"}"
] | Checks if the config has fields described in argument.<br>
Missing field(s) is in the exception message.
To check that the config has eid and secret:<br>
<code>
try {
$this->hasFields('eid', 'secret');
}
catch(Exception $e) {
echo "Missing fields: " . $e->getMessage();
}
</code>
@throws Exception
@return void | [
"Checks",
"if",
"the",
"config",
"has",
"fields",
"described",
"in",
"argument",
".",
"<br",
">",
"Missing",
"field",
"(",
"s",
")",
"is",
"in",
"the",
"exception",
"message",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L412-L426 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.init | protected function init()
{
$this->hasFields('eid', 'secret', 'mode', 'pcStorage', 'pcURI');
if (!is_int($this->config['eid'])) {
$this->config['eid'] = intval($this->config['eid']);
}
if ($this->config['eid'] <= 0) {
throw new Klarna_ConfigFieldMissingException('eid');
}
if (!is_string($this->config['secret'])) {
$this->config['secret'] = strval($this->config['secret']);
}
if (strlen($this->config['secret']) == 0) {
throw new Klarna_ConfigFieldMissingException('secret');
}
//Set the shop id and secret.
$this->_eid = $this->config['eid'];
$this->_secret = $this->config['secret'];
//Set the country specific attributes.
try {
$this->hasFields('country', 'language', 'currency');
//If hasFields doesn't throw exception we can set them all.
$this->setCountry($this->config['country']);
$this->setLanguage($this->config['language']);
$this->setCurrency($this->config['currency']);
} catch(Exception $e) {
//fields missing for country, language or currency
$this->_country = $this->_language = $this->_currency = null;
}
//Set addr and port according to mode.
$this->mode = (int)$this->config['mode'];
$this->_url = array();
// If a custom url has been added to the config, use that as xmlrpc
// recipient.
if (isset($this->config['url'])) {
$this->_url = parse_url($this->config['url']);
if ($this->_url === false) {
$message = "Configuration value 'url' could not be parsed. " .
"(Was: '{$this->config['url']}')";
Klarna::printDebug(__METHOD__, $message);
throw new InvalidArgumentException($message);
}
} else {
$this->_url['scheme'] = 'https';
if ($this->mode === self::LIVE) {
$this->_url['host'] = self::$_live_addr;
} else {
$this->_url['host'] = self::$_beta_addr;
}
if (isset($this->config['ssl'])
&& (bool)$this->config['ssl'] === false
) {
$this->_url['scheme'] = 'http';
}
}
// If no port has been specified, deduce from url scheme
if (!array_key_exists('port', $this->_url)) {
if ($this->_url['scheme'] === 'https') {
$this->_url['port'] = 443;
} else {
$this->_url['port'] = 80;
}
}
try {
$this->hasFields('xmlrpcDebug');
Klarna::$xmlrpcDebug = $this->config['xmlrpcDebug'];
} catch(Exception $e) {
//No 'xmlrpcDebug' field ignore it...
}
try {
$this->hasFields('debug');
Klarna::$debug = $this->config['debug'];
} catch(Exception $e) {
//No 'debug' field ignore it...
}
$this->pcStorage = $this->config['pcStorage'];
$this->pcURI = $this->config['pcURI'];
// Default path to '/' if not set.
if (!array_key_exists('path', $this->_url)) {
$this->_url['path'] = '/';
}
$this->xmlrpc = new xmlrpc_client(
$this->_url['path'],
$this->_url['host'],
$this->_url['port'],
$this->_url['scheme']
);
$this->xmlrpc->setSSLVerifyHost(2);
$this->xmlrpc->request_charset_encoding = 'ISO-8859-1';
} | php | protected function init()
{
$this->hasFields('eid', 'secret', 'mode', 'pcStorage', 'pcURI');
if (!is_int($this->config['eid'])) {
$this->config['eid'] = intval($this->config['eid']);
}
if ($this->config['eid'] <= 0) {
throw new Klarna_ConfigFieldMissingException('eid');
}
if (!is_string($this->config['secret'])) {
$this->config['secret'] = strval($this->config['secret']);
}
if (strlen($this->config['secret']) == 0) {
throw new Klarna_ConfigFieldMissingException('secret');
}
//Set the shop id and secret.
$this->_eid = $this->config['eid'];
$this->_secret = $this->config['secret'];
//Set the country specific attributes.
try {
$this->hasFields('country', 'language', 'currency');
//If hasFields doesn't throw exception we can set them all.
$this->setCountry($this->config['country']);
$this->setLanguage($this->config['language']);
$this->setCurrency($this->config['currency']);
} catch(Exception $e) {
//fields missing for country, language or currency
$this->_country = $this->_language = $this->_currency = null;
}
//Set addr and port according to mode.
$this->mode = (int)$this->config['mode'];
$this->_url = array();
// If a custom url has been added to the config, use that as xmlrpc
// recipient.
if (isset($this->config['url'])) {
$this->_url = parse_url($this->config['url']);
if ($this->_url === false) {
$message = "Configuration value 'url' could not be parsed. " .
"(Was: '{$this->config['url']}')";
Klarna::printDebug(__METHOD__, $message);
throw new InvalidArgumentException($message);
}
} else {
$this->_url['scheme'] = 'https';
if ($this->mode === self::LIVE) {
$this->_url['host'] = self::$_live_addr;
} else {
$this->_url['host'] = self::$_beta_addr;
}
if (isset($this->config['ssl'])
&& (bool)$this->config['ssl'] === false
) {
$this->_url['scheme'] = 'http';
}
}
// If no port has been specified, deduce from url scheme
if (!array_key_exists('port', $this->_url)) {
if ($this->_url['scheme'] === 'https') {
$this->_url['port'] = 443;
} else {
$this->_url['port'] = 80;
}
}
try {
$this->hasFields('xmlrpcDebug');
Klarna::$xmlrpcDebug = $this->config['xmlrpcDebug'];
} catch(Exception $e) {
//No 'xmlrpcDebug' field ignore it...
}
try {
$this->hasFields('debug');
Klarna::$debug = $this->config['debug'];
} catch(Exception $e) {
//No 'debug' field ignore it...
}
$this->pcStorage = $this->config['pcStorage'];
$this->pcURI = $this->config['pcURI'];
// Default path to '/' if not set.
if (!array_key_exists('path', $this->_url)) {
$this->_url['path'] = '/';
}
$this->xmlrpc = new xmlrpc_client(
$this->_url['path'],
$this->_url['host'],
$this->_url['port'],
$this->_url['scheme']
);
$this->xmlrpc->setSSLVerifyHost(2);
$this->xmlrpc->request_charset_encoding = 'ISO-8859-1';
} | [
"protected",
"function",
"init",
"(",
")",
"{",
"$",
"this",
"->",
"hasFields",
"(",
"'eid'",
",",
"'secret'",
",",
"'mode'",
",",
"'pcStorage'",
",",
"'pcURI'",
")",
";",
"if",
"(",
"!",
"is_int",
"(",
"$",
"this",
"->",
"config",
"[",
"'eid'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"config",
"[",
"'eid'",
"]",
"=",
"intval",
"(",
"$",
"this",
"->",
"config",
"[",
"'eid'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"config",
"[",
"'eid'",
"]",
"<=",
"0",
")",
"{",
"throw",
"new",
"Klarna_ConfigFieldMissingException",
"(",
"'eid'",
")",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"this",
"->",
"config",
"[",
"'secret'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"config",
"[",
"'secret'",
"]",
"=",
"strval",
"(",
"$",
"this",
"->",
"config",
"[",
"'secret'",
"]",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"this",
"->",
"config",
"[",
"'secret'",
"]",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"Klarna_ConfigFieldMissingException",
"(",
"'secret'",
")",
";",
"}",
"//Set the shop id and secret.",
"$",
"this",
"->",
"_eid",
"=",
"$",
"this",
"->",
"config",
"[",
"'eid'",
"]",
";",
"$",
"this",
"->",
"_secret",
"=",
"$",
"this",
"->",
"config",
"[",
"'secret'",
"]",
";",
"//Set the country specific attributes.",
"try",
"{",
"$",
"this",
"->",
"hasFields",
"(",
"'country'",
",",
"'language'",
",",
"'currency'",
")",
";",
"//If hasFields doesn't throw exception we can set them all.",
"$",
"this",
"->",
"setCountry",
"(",
"$",
"this",
"->",
"config",
"[",
"'country'",
"]",
")",
";",
"$",
"this",
"->",
"setLanguage",
"(",
"$",
"this",
"->",
"config",
"[",
"'language'",
"]",
")",
";",
"$",
"this",
"->",
"setCurrency",
"(",
"$",
"this",
"->",
"config",
"[",
"'currency'",
"]",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"//fields missing for country, language or currency",
"$",
"this",
"->",
"_country",
"=",
"$",
"this",
"->",
"_language",
"=",
"$",
"this",
"->",
"_currency",
"=",
"null",
";",
"}",
"//Set addr and port according to mode.",
"$",
"this",
"->",
"mode",
"=",
"(",
"int",
")",
"$",
"this",
"->",
"config",
"[",
"'mode'",
"]",
";",
"$",
"this",
"->",
"_url",
"=",
"array",
"(",
")",
";",
"// If a custom url has been added to the config, use that as xmlrpc",
"// recipient.",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'url'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_url",
"=",
"parse_url",
"(",
"$",
"this",
"->",
"config",
"[",
"'url'",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_url",
"===",
"false",
")",
"{",
"$",
"message",
"=",
"\"Configuration value 'url' could not be parsed. \"",
".",
"\"(Was: '{$this->config['url']}')\"",
";",
"Klarna",
"::",
"printDebug",
"(",
"__METHOD__",
",",
"$",
"message",
")",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"message",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"_url",
"[",
"'scheme'",
"]",
"=",
"'https'",
";",
"if",
"(",
"$",
"this",
"->",
"mode",
"===",
"self",
"::",
"LIVE",
")",
"{",
"$",
"this",
"->",
"_url",
"[",
"'host'",
"]",
"=",
"self",
"::",
"$",
"_live_addr",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_url",
"[",
"'host'",
"]",
"=",
"self",
"::",
"$",
"_beta_addr",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'ssl'",
"]",
")",
"&&",
"(",
"bool",
")",
"$",
"this",
"->",
"config",
"[",
"'ssl'",
"]",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"_url",
"[",
"'scheme'",
"]",
"=",
"'http'",
";",
"}",
"}",
"// If no port has been specified, deduce from url scheme",
"if",
"(",
"!",
"array_key_exists",
"(",
"'port'",
",",
"$",
"this",
"->",
"_url",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_url",
"[",
"'scheme'",
"]",
"===",
"'https'",
")",
"{",
"$",
"this",
"->",
"_url",
"[",
"'port'",
"]",
"=",
"443",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_url",
"[",
"'port'",
"]",
"=",
"80",
";",
"}",
"}",
"try",
"{",
"$",
"this",
"->",
"hasFields",
"(",
"'xmlrpcDebug'",
")",
";",
"Klarna",
"::",
"$",
"xmlrpcDebug",
"=",
"$",
"this",
"->",
"config",
"[",
"'xmlrpcDebug'",
"]",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"//No 'xmlrpcDebug' field ignore it...",
"}",
"try",
"{",
"$",
"this",
"->",
"hasFields",
"(",
"'debug'",
")",
";",
"Klarna",
"::",
"$",
"debug",
"=",
"$",
"this",
"->",
"config",
"[",
"'debug'",
"]",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"//No 'debug' field ignore it...",
"}",
"$",
"this",
"->",
"pcStorage",
"=",
"$",
"this",
"->",
"config",
"[",
"'pcStorage'",
"]",
";",
"$",
"this",
"->",
"pcURI",
"=",
"$",
"this",
"->",
"config",
"[",
"'pcURI'",
"]",
";",
"// Default path to '/' if not set.",
"if",
"(",
"!",
"array_key_exists",
"(",
"'path'",
",",
"$",
"this",
"->",
"_url",
")",
")",
"{",
"$",
"this",
"->",
"_url",
"[",
"'path'",
"]",
"=",
"'/'",
";",
"}",
"$",
"this",
"->",
"xmlrpc",
"=",
"new",
"xmlrpc_client",
"(",
"$",
"this",
"->",
"_url",
"[",
"'path'",
"]",
",",
"$",
"this",
"->",
"_url",
"[",
"'host'",
"]",
",",
"$",
"this",
"->",
"_url",
"[",
"'port'",
"]",
",",
"$",
"this",
"->",
"_url",
"[",
"'scheme'",
"]",
")",
";",
"$",
"this",
"->",
"xmlrpc",
"->",
"setSSLVerifyHost",
"(",
"2",
")",
";",
"$",
"this",
"->",
"xmlrpc",
"->",
"request_charset_encoding",
"=",
"'ISO-8859-1'",
";",
"}"
] | Initializes the Klarna object accordingly to the set config object.
@throws KlarnaException
@return void | [
"Initializes",
"the",
"Klarna",
"object",
"accordingly",
"to",
"the",
"set",
"config",
"object",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L434-L544 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.config | public function config(
$eid, $secret, $country, $language, $currency,
$mode = Klarna::LIVE, $pcStorage = 'json', $pcURI = 'pclasses.json',
$ssl = true
) {
try {
KlarnaConfig::$store = false;
$this->config = new KlarnaConfig(null);
$this->config['eid'] = $eid;
$this->config['secret'] = $secret;
$this->config['country'] = $country;
$this->config['language'] = $language;
$this->config['currency'] = $currency;
$this->config['mode'] = $mode;
$this->config['ssl'] = $ssl;
$this->config['pcStorage'] = $pcStorage;
$this->config['pcURI'] = $pcURI;
$this->init();
} catch(Exception $e) {
$this->config = null;
throw new KlarnaException(
$e->getMessage(),
$e->getCode()
);
}
} | php | public function config(
$eid, $secret, $country, $language, $currency,
$mode = Klarna::LIVE, $pcStorage = 'json', $pcURI = 'pclasses.json',
$ssl = true
) {
try {
KlarnaConfig::$store = false;
$this->config = new KlarnaConfig(null);
$this->config['eid'] = $eid;
$this->config['secret'] = $secret;
$this->config['country'] = $country;
$this->config['language'] = $language;
$this->config['currency'] = $currency;
$this->config['mode'] = $mode;
$this->config['ssl'] = $ssl;
$this->config['pcStorage'] = $pcStorage;
$this->config['pcURI'] = $pcURI;
$this->init();
} catch(Exception $e) {
$this->config = null;
throw new KlarnaException(
$e->getMessage(),
$e->getCode()
);
}
} | [
"public",
"function",
"config",
"(",
"$",
"eid",
",",
"$",
"secret",
",",
"$",
"country",
",",
"$",
"language",
",",
"$",
"currency",
",",
"$",
"mode",
"=",
"Klarna",
"::",
"LIVE",
",",
"$",
"pcStorage",
"=",
"'json'",
",",
"$",
"pcURI",
"=",
"'pclasses.json'",
",",
"$",
"ssl",
"=",
"true",
")",
"{",
"try",
"{",
"KlarnaConfig",
"::",
"$",
"store",
"=",
"false",
";",
"$",
"this",
"->",
"config",
"=",
"new",
"KlarnaConfig",
"(",
"null",
")",
";",
"$",
"this",
"->",
"config",
"[",
"'eid'",
"]",
"=",
"$",
"eid",
";",
"$",
"this",
"->",
"config",
"[",
"'secret'",
"]",
"=",
"$",
"secret",
";",
"$",
"this",
"->",
"config",
"[",
"'country'",
"]",
"=",
"$",
"country",
";",
"$",
"this",
"->",
"config",
"[",
"'language'",
"]",
"=",
"$",
"language",
";",
"$",
"this",
"->",
"config",
"[",
"'currency'",
"]",
"=",
"$",
"currency",
";",
"$",
"this",
"->",
"config",
"[",
"'mode'",
"]",
"=",
"$",
"mode",
";",
"$",
"this",
"->",
"config",
"[",
"'ssl'",
"]",
"=",
"$",
"ssl",
";",
"$",
"this",
"->",
"config",
"[",
"'pcStorage'",
"]",
"=",
"$",
"pcStorage",
";",
"$",
"this",
"->",
"config",
"[",
"'pcURI'",
"]",
"=",
"$",
"pcURI",
";",
"$",
"this",
"->",
"init",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"config",
"=",
"null",
";",
"throw",
"new",
"KlarnaException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
")",
";",
"}",
"}"
] | Method of ease for setting common config fields.
The storage module for PClasses:<br>
Use 'xml' for xmlstorage.class.php.<br>
Use 'mysql' for mysqlstorage.class.php.<br>
Use 'json' for jsonstorage.class.php.<br>
The storage URI for PClasses:<br>
Use the absolute or relative URI to a file if {@link Klarna::$pcStorage}
is set as 'xml' or 'json'.<br>
Use a HTTP-auth similar URL if {@link Klarna::$pcStorage} is set as
mysql', e.g. user:passwd@addr:port/dbName.dbTable.
Or an associative array (recommended) {@see MySQLStorage}
<b>Note</b>:<br>
This disables the config file storage.<br>
@param int $eid Merchant ID/EID
@param string $secret Secret key/Shared key
@param int $country {@link KlarnaCountry}
@param int $language {@link KlarnaLanguage}
@param int $currency {@link KlarnaCurrency}
@param int $mode {@link Klarna::LIVE} or {@link Klarna::BETA}
@param string $pcStorage PClass storage module.
@param string $pcURI PClass URI.
@param bool $ssl Whether HTTPS (HTTP over SSL) or HTTP is used.
@see Klarna::setConfig()
@see KlarnaConfig
@throws KlarnaException
@return void | [
"Method",
"of",
"ease",
"for",
"setting",
"common",
"config",
"fields",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L580-L607 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.setConfig | public function setConfig(&$config)
{
$this->_checkConfig($config);
$this->config = $config;
$this->init();
} | php | public function setConfig(&$config)
{
$this->_checkConfig($config);
$this->config = $config;
$this->init();
} | [
"public",
"function",
"setConfig",
"(",
"&",
"$",
"config",
")",
"{",
"$",
"this",
"->",
"_checkConfig",
"(",
"$",
"config",
")",
";",
"$",
"this",
"->",
"config",
"=",
"$",
"config",
";",
"$",
"this",
"->",
"init",
"(",
")",
";",
"}"
] | Sets and initializes this Klarna object using the supplied config object.
@param KlarnaConfig &$config Config object.
@see KlarnaConfig
@throws KlarnaException
@return void | [
"Sets",
"and",
"initializes",
"this",
"Klarna",
"object",
"using",
"the",
"supplied",
"config",
"object",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L618-L624 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.getLocale | public function getLocale(
$country = null, $language = null, $currency = null
) {
$locale = array(
'country' => null,
'language' => null,
'currency' => null
);
if ($country === null) {
// Use the configured country / language / currency
$locale['country'] = $this->_country;
if ($this->_language !== null) {
$locale['language'] = $this->_language;
}
if ($this->_currency !== null) {
$locale['currency'] = $this->_currency;
}
} else {
// Use the given country / language / currency
if (!is_numeric($country)) {
$country = KlarnaCountry::fromCode($country);
}
$locale['country'] = intval($country);
if ($language !== null) {
if (!is_numeric($language)) {
$language = KlarnaLanguage::fromCode($language);
}
$locale['language'] = intval($language);
}
if ($currency !== null) {
if (!is_numeric($currency)) {
$currency = KlarnaCurrency::fromCode($currency);
}
$locale['currency'] = intval($currency);
}
}
// Complete partial structure with defaults
if ($locale['currency'] === null) {
$locale['currency'] = $this->getCurrencyForCountry(
$locale['country']
);
}
if ($locale['language'] === null) {
$locale['language'] = $this->getLanguageForCountry(
$locale['country']
);
}
$this->_checkCountry($locale['country']);
$this->_checkCurrency($locale['currency']);
$this->_checkLanguage($locale['language']);
return $locale;
} | php | public function getLocale(
$country = null, $language = null, $currency = null
) {
$locale = array(
'country' => null,
'language' => null,
'currency' => null
);
if ($country === null) {
// Use the configured country / language / currency
$locale['country'] = $this->_country;
if ($this->_language !== null) {
$locale['language'] = $this->_language;
}
if ($this->_currency !== null) {
$locale['currency'] = $this->_currency;
}
} else {
// Use the given country / language / currency
if (!is_numeric($country)) {
$country = KlarnaCountry::fromCode($country);
}
$locale['country'] = intval($country);
if ($language !== null) {
if (!is_numeric($language)) {
$language = KlarnaLanguage::fromCode($language);
}
$locale['language'] = intval($language);
}
if ($currency !== null) {
if (!is_numeric($currency)) {
$currency = KlarnaCurrency::fromCode($currency);
}
$locale['currency'] = intval($currency);
}
}
// Complete partial structure with defaults
if ($locale['currency'] === null) {
$locale['currency'] = $this->getCurrencyForCountry(
$locale['country']
);
}
if ($locale['language'] === null) {
$locale['language'] = $this->getLanguageForCountry(
$locale['country']
);
}
$this->_checkCountry($locale['country']);
$this->_checkCurrency($locale['currency']);
$this->_checkLanguage($locale['language']);
return $locale;
} | [
"public",
"function",
"getLocale",
"(",
"$",
"country",
"=",
"null",
",",
"$",
"language",
"=",
"null",
",",
"$",
"currency",
"=",
"null",
")",
"{",
"$",
"locale",
"=",
"array",
"(",
"'country'",
"=>",
"null",
",",
"'language'",
"=>",
"null",
",",
"'currency'",
"=>",
"null",
")",
";",
"if",
"(",
"$",
"country",
"===",
"null",
")",
"{",
"// Use the configured country / language / currency",
"$",
"locale",
"[",
"'country'",
"]",
"=",
"$",
"this",
"->",
"_country",
";",
"if",
"(",
"$",
"this",
"->",
"_language",
"!==",
"null",
")",
"{",
"$",
"locale",
"[",
"'language'",
"]",
"=",
"$",
"this",
"->",
"_language",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_currency",
"!==",
"null",
")",
"{",
"$",
"locale",
"[",
"'currency'",
"]",
"=",
"$",
"this",
"->",
"_currency",
";",
"}",
"}",
"else",
"{",
"// Use the given country / language / currency",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"country",
")",
")",
"{",
"$",
"country",
"=",
"KlarnaCountry",
"::",
"fromCode",
"(",
"$",
"country",
")",
";",
"}",
"$",
"locale",
"[",
"'country'",
"]",
"=",
"intval",
"(",
"$",
"country",
")",
";",
"if",
"(",
"$",
"language",
"!==",
"null",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"language",
")",
")",
"{",
"$",
"language",
"=",
"KlarnaLanguage",
"::",
"fromCode",
"(",
"$",
"language",
")",
";",
"}",
"$",
"locale",
"[",
"'language'",
"]",
"=",
"intval",
"(",
"$",
"language",
")",
";",
"}",
"if",
"(",
"$",
"currency",
"!==",
"null",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"currency",
")",
")",
"{",
"$",
"currency",
"=",
"KlarnaCurrency",
"::",
"fromCode",
"(",
"$",
"currency",
")",
";",
"}",
"$",
"locale",
"[",
"'currency'",
"]",
"=",
"intval",
"(",
"$",
"currency",
")",
";",
"}",
"}",
"// Complete partial structure with defaults",
"if",
"(",
"$",
"locale",
"[",
"'currency'",
"]",
"===",
"null",
")",
"{",
"$",
"locale",
"[",
"'currency'",
"]",
"=",
"$",
"this",
"->",
"getCurrencyForCountry",
"(",
"$",
"locale",
"[",
"'country'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"locale",
"[",
"'language'",
"]",
"===",
"null",
")",
"{",
"$",
"locale",
"[",
"'language'",
"]",
"=",
"$",
"this",
"->",
"getLanguageForCountry",
"(",
"$",
"locale",
"[",
"'country'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"_checkCountry",
"(",
"$",
"locale",
"[",
"'country'",
"]",
")",
";",
"$",
"this",
"->",
"_checkCurrency",
"(",
"$",
"locale",
"[",
"'currency'",
"]",
")",
";",
"$",
"this",
"->",
"_checkLanguage",
"(",
"$",
"locale",
"[",
"'language'",
"]",
")",
";",
"return",
"$",
"locale",
";",
"}"
] | Get the complete locale (country, language, currency) to use for the
values passed, or the configured value if passing null.
@param mixed $country country constant or code
@param mixed $language language constant or code
@param mixed $currency currency constant or code
@throws KlarnaException
@return array | [
"Get",
"the",
"complete",
"locale",
"(",
"country",
"language",
"currency",
")",
"to",
"use",
"for",
"the",
"values",
"passed",
"or",
"the",
"configured",
"value",
"if",
"passing",
"null",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L637-L696 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.setCountry | public function setCountry($country)
{
if (!is_numeric($country)
&& (strlen($country) == 2 || strlen($country) == 3)
) {
$country = KlarnaCountry::fromCode($country);
}
$this->_checkCountry($country);
$this->_country = $country;
} | php | public function setCountry($country)
{
if (!is_numeric($country)
&& (strlen($country) == 2 || strlen($country) == 3)
) {
$country = KlarnaCountry::fromCode($country);
}
$this->_checkCountry($country);
$this->_country = $country;
} | [
"public",
"function",
"setCountry",
"(",
"$",
"country",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"country",
")",
"&&",
"(",
"strlen",
"(",
"$",
"country",
")",
"==",
"2",
"||",
"strlen",
"(",
"$",
"country",
")",
"==",
"3",
")",
")",
"{",
"$",
"country",
"=",
"KlarnaCountry",
"::",
"fromCode",
"(",
"$",
"country",
")",
";",
"}",
"$",
"this",
"->",
"_checkCountry",
"(",
"$",
"country",
")",
";",
"$",
"this",
"->",
"_country",
"=",
"$",
"country",
";",
"}"
] | Sets the country used.
<b>Note</b>:<br>
If you input 'dk', 'fi', 'de', 'nl', 'no' or 'se', <br>
then currency and language will be set to mirror that country.<br>
@param string|int $country {@link KlarnaCountry}
@see KlarnaCountry
@throws KlarnaException
@return void | [
"Sets",
"the",
"country",
"used",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L712-L721 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.getCountryCode | public function getCountryCode($country = null)
{
if ($country === null) {
$country = $this->_country;
}
$code = KlarnaCountry::getCode($country);
return (string) $code;
} | php | public function getCountryCode($country = null)
{
if ($country === null) {
$country = $this->_country;
}
$code = KlarnaCountry::getCode($country);
return (string) $code;
} | [
"public",
"function",
"getCountryCode",
"(",
"$",
"country",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"country",
"===",
"null",
")",
"{",
"$",
"country",
"=",
"$",
"this",
"->",
"_country",
";",
"}",
"$",
"code",
"=",
"KlarnaCountry",
"::",
"getCode",
"(",
"$",
"country",
")",
";",
"return",
"(",
"string",
")",
"$",
"code",
";",
"}"
] | Returns the country code for the set country constant.
@param int $country {@link KlarnaCountry Country} constant.
@return string Two letter code, e.g. "se", "no", etc. | [
"Returns",
"the",
"country",
"code",
"for",
"the",
"set",
"country",
"constant",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L730-L738 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.getCountryForCode | public static function getCountryForCode($code)
{
$country = KlarnaCountry::fromCode($code);
if ($country === null) {
throw new Klarna_UnknownCountryException($code);
}
return $country;
} | php | public static function getCountryForCode($code)
{
$country = KlarnaCountry::fromCode($code);
if ($country === null) {
throw new Klarna_UnknownCountryException($code);
}
return $country;
} | [
"public",
"static",
"function",
"getCountryForCode",
"(",
"$",
"code",
")",
"{",
"$",
"country",
"=",
"KlarnaCountry",
"::",
"fromCode",
"(",
"$",
"code",
")",
";",
"if",
"(",
"$",
"country",
"===",
"null",
")",
"{",
"throw",
"new",
"Klarna_UnknownCountryException",
"(",
"$",
"code",
")",
";",
"}",
"return",
"$",
"country",
";",
"}"
] | Returns the {@link KlarnaCountry country} constant from the country code.
@param string $code Two letter code, e.g. "se", "no", etc.
@throws KlarnaException
@return int {@link KlarnaCountry Country} constant. | [
"Returns",
"the",
"{",
"@link",
"KlarnaCountry",
"country",
"}",
"constant",
"from",
"the",
"country",
"code",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L748-L755 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.setLanguage | public function setLanguage($language)
{
if (!is_numeric($language) && strlen($language) == 2) {
$this->setLanguage(self::getLanguageForCode($language));
} else {
$this->_checkLanguage($language);
$this->_language = $language;
}
} | php | public function setLanguage($language)
{
if (!is_numeric($language) && strlen($language) == 2) {
$this->setLanguage(self::getLanguageForCode($language));
} else {
$this->_checkLanguage($language);
$this->_language = $language;
}
} | [
"public",
"function",
"setLanguage",
"(",
"$",
"language",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"language",
")",
"&&",
"strlen",
"(",
"$",
"language",
")",
"==",
"2",
")",
"{",
"$",
"this",
"->",
"setLanguage",
"(",
"self",
"::",
"getLanguageForCode",
"(",
"$",
"language",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_checkLanguage",
"(",
"$",
"language",
")",
";",
"$",
"this",
"->",
"_language",
"=",
"$",
"language",
";",
"}",
"}"
] | Sets the language used.
<b>Note</b>:<br>
You can use the two letter language code instead of the constant.<br>
E.g. 'da' instead of using {@link KlarnaLanguage::DA}.<br>
@param string|int $language {@link KlarnaLanguage}
@see KlarnaLanguage
@throws KlarnaException
@return void | [
"Sets",
"the",
"language",
"used",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L781-L789 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.getLanguageCode | public function getLanguageCode($language = null)
{
if ($language === null) {
$language = $this->_language;
}
$code = KlarnaLanguage::getCode($language);
return (string) $code;
} | php | public function getLanguageCode($language = null)
{
if ($language === null) {
$language = $this->_language;
}
$code = KlarnaLanguage::getCode($language);
return (string) $code;
} | [
"public",
"function",
"getLanguageCode",
"(",
"$",
"language",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"language",
"===",
"null",
")",
"{",
"$",
"language",
"=",
"$",
"this",
"->",
"_language",
";",
"}",
"$",
"code",
"=",
"KlarnaLanguage",
"::",
"getCode",
"(",
"$",
"language",
")",
";",
"return",
"(",
"string",
")",
"$",
"code",
";",
"}"
] | Returns the language code for the set language constant.
@param int $language {@link KlarnaLanguage Language} constant.
@return string Two letter code, e.g. "da", "de", etc. | [
"Returns",
"the",
"language",
"code",
"for",
"the",
"set",
"language",
"constant",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L798-L806 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.getLanguageForCode | public static function getLanguageForCode($code)
{
$language = KlarnaLanguage::fromCode($code);
if ($language === null) {
throw new Klarna_UnknownLanguageException($code);
}
return $language;
} | php | public static function getLanguageForCode($code)
{
$language = KlarnaLanguage::fromCode($code);
if ($language === null) {
throw new Klarna_UnknownLanguageException($code);
}
return $language;
} | [
"public",
"static",
"function",
"getLanguageForCode",
"(",
"$",
"code",
")",
"{",
"$",
"language",
"=",
"KlarnaLanguage",
"::",
"fromCode",
"(",
"$",
"code",
")",
";",
"if",
"(",
"$",
"language",
"===",
"null",
")",
"{",
"throw",
"new",
"Klarna_UnknownLanguageException",
"(",
"$",
"code",
")",
";",
"}",
"return",
"$",
"language",
";",
"}"
] | Returns the {@link KlarnaLanguage language} constant from the language code.
@param string $code Two letter code, e.g. "da", "de", etc.
@throws KlarnaException
@return int {@link KlarnaLanguage Language} constant. | [
"Returns",
"the",
"{",
"@link",
"KlarnaLanguage",
"language",
"}",
"constant",
"from",
"the",
"language",
"code",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L816-L824 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.setCurrency | public function setCurrency($currency)
{
if (!is_numeric($currency) && strlen($currency) == 3) {
$this->setCurrency(self::getCurrencyForCode($currency));
} else {
$this->_checkCurrency($currency);
$this->_currency = $currency;
}
} | php | public function setCurrency($currency)
{
if (!is_numeric($currency) && strlen($currency) == 3) {
$this->setCurrency(self::getCurrencyForCode($currency));
} else {
$this->_checkCurrency($currency);
$this->_currency = $currency;
}
} | [
"public",
"function",
"setCurrency",
"(",
"$",
"currency",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"currency",
")",
"&&",
"strlen",
"(",
"$",
"currency",
")",
"==",
"3",
")",
"{",
"$",
"this",
"->",
"setCurrency",
"(",
"self",
"::",
"getCurrencyForCode",
"(",
"$",
"currency",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_checkCurrency",
"(",
"$",
"currency",
")",
";",
"$",
"this",
"->",
"_currency",
"=",
"$",
"currency",
";",
"}",
"}"
] | Sets the currency used.
<b>Note</b>:<br>
You can use the three letter shortening of the currency.<br>
E.g. "dkk", "eur", "nok" or "sek" instead of the constant.<br>
@param string|int $currency {@link KlarnaCurrency}
@see KlarnaCurrency
@throws KlarnaException
@return void | [
"Sets",
"the",
"currency",
"used",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L850-L858 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.getCurrencyForCode | public static function getCurrencyForCode($code)
{
$currency = KlarnaCurrency::fromCode($code);
if ($currency === null) {
throw new Klarna_UnknownCurrencyException($code);
}
return $currency;
} | php | public static function getCurrencyForCode($code)
{
$currency = KlarnaCurrency::fromCode($code);
if ($currency === null) {
throw new Klarna_UnknownCurrencyException($code);
}
return $currency;
} | [
"public",
"static",
"function",
"getCurrencyForCode",
"(",
"$",
"code",
")",
"{",
"$",
"currency",
"=",
"KlarnaCurrency",
"::",
"fromCode",
"(",
"$",
"code",
")",
";",
"if",
"(",
"$",
"currency",
"===",
"null",
")",
"{",
"throw",
"new",
"Klarna_UnknownCurrencyException",
"(",
"$",
"code",
")",
";",
"}",
"return",
"$",
"currency",
";",
"}"
] | Returns the {@link KlarnaCurrency currency} constant from the currency
code.
@param string $code Two letter code, e.g. "dkk", "eur", etc.
@throws KlarnaException
@return int {@link KlarnaCurrency Currency} constant. | [
"Returns",
"the",
"{",
"@link",
"KlarnaCurrency",
"currency",
"}",
"constant",
"from",
"the",
"currency",
"code",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L869-L876 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.getCurrencyCode | public function getCurrencyCode($currency = null)
{
if ($currency === null) {
$currency = $this->_currency;
}
$code = KlarnaCurrency::getCode($currency);
return (string) $code;
} | php | public function getCurrencyCode($currency = null)
{
if ($currency === null) {
$currency = $this->_currency;
}
$code = KlarnaCurrency::getCode($currency);
return (string) $code;
} | [
"public",
"function",
"getCurrencyCode",
"(",
"$",
"currency",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"currency",
"===",
"null",
")",
"{",
"$",
"currency",
"=",
"$",
"this",
"->",
"_currency",
";",
"}",
"$",
"code",
"=",
"KlarnaCurrency",
"::",
"getCode",
"(",
"$",
"currency",
")",
";",
"return",
"(",
"string",
")",
"$",
"code",
";",
"}"
] | Returns the the currency code for the set currency constant.
@param int $currency {@link KlarnaCurrency Currency} constant.
@return string Three letter currency code. | [
"Returns",
"the",
"the",
"currency",
"code",
"for",
"the",
"set",
"currency",
"constant",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L885-L893 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.getLanguageForCountry | public function getLanguageForCountry($country = null)
{
if ($country === null) {
$country = $this->_country;
}
// Since getLanguage defaults to EN, check so we actually have a match
$language = KlarnaCountry::getLanguage($country);
if (KlarnaCountry::checkLanguage($country, $language)) {
return $language;
}
return false;
} | php | public function getLanguageForCountry($country = null)
{
if ($country === null) {
$country = $this->_country;
}
// Since getLanguage defaults to EN, check so we actually have a match
$language = KlarnaCountry::getLanguage($country);
if (KlarnaCountry::checkLanguage($country, $language)) {
return $language;
}
return false;
} | [
"public",
"function",
"getLanguageForCountry",
"(",
"$",
"country",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"country",
"===",
"null",
")",
"{",
"$",
"country",
"=",
"$",
"this",
"->",
"_country",
";",
"}",
"// Since getLanguage defaults to EN, check so we actually have a match",
"$",
"language",
"=",
"KlarnaCountry",
"::",
"getLanguage",
"(",
"$",
"country",
")",
";",
"if",
"(",
"KlarnaCountry",
"::",
"checkLanguage",
"(",
"$",
"country",
",",
"$",
"language",
")",
")",
"{",
"return",
"$",
"language",
";",
"}",
"return",
"false",
";",
"}"
] | Returns the {@link KlarnaLanguage language} constant for the specified
or set country.
@param int $country {@link KlarnaCountry Country} constant.
@deprecated Do not use.
@return int|false if no match otherwise KlarnaLanguage constant. | [
"Returns",
"the",
"{",
"@link",
"KlarnaLanguage",
"language",
"}",
"constant",
"for",
"the",
"specified",
"or",
"set",
"country",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L915-L926 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.getCurrencyForCountry | public function getCurrencyForCountry($country = null)
{
if ($country === null) {
$country = $this->_country;
}
return KlarnaCountry::getCurrency($country);
} | php | public function getCurrencyForCountry($country = null)
{
if ($country === null) {
$country = $this->_country;
}
return KlarnaCountry::getCurrency($country);
} | [
"public",
"function",
"getCurrencyForCountry",
"(",
"$",
"country",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"country",
"===",
"null",
")",
"{",
"$",
"country",
"=",
"$",
"this",
"->",
"_country",
";",
"}",
"return",
"KlarnaCountry",
"::",
"getCurrency",
"(",
"$",
"country",
")",
";",
"}"
] | Returns the {@link KlarnaCurrency currency} constant for the specified
or set country.
@param int $country {@link KlarnaCountry country} constant.
@deprecated Do not use.
@return int|false {@link KlarnaCurrency currency} constant. | [
"Returns",
"the",
"{",
"@link",
"KlarnaCurrency",
"currency",
"}",
"constant",
"for",
"the",
"specified",
"or",
"set",
"country",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L938-L944 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.setSessionID | public function setSessionID($name, $sid)
{
$this->_checkArgument($name, "name");
$this->_checkArgument($sid, "sid");
$this->sid[$name] = $sid;
} | php | public function setSessionID($name, $sid)
{
$this->_checkArgument($name, "name");
$this->_checkArgument($sid, "sid");
$this->sid[$name] = $sid;
} | [
"public",
"function",
"setSessionID",
"(",
"$",
"name",
",",
"$",
"sid",
")",
"{",
"$",
"this",
"->",
"_checkArgument",
"(",
"$",
"name",
",",
"\"name\"",
")",
";",
"$",
"this",
"->",
"_checkArgument",
"(",
"$",
"sid",
",",
"\"sid\"",
")",
";",
"$",
"this",
"->",
"sid",
"[",
"$",
"name",
"]",
"=",
"$",
"sid",
";",
"}"
] | Sets the session id's for various device identification,
behaviour identification software.
<b>Available named session id's</b>:<br>
string - dev_id_1<br>
string - dev_id_2<br>
string - dev_id_3<br>
string - beh_id_1<br>
string - beh_id_2<br>
string - beh_id_3<br>
@param string $name Session ID identifier, e.g. 'dev_id_1'.
@param string $sid Session ID.
@throws KlarnaException
@return void | [
"Sets",
"the",
"session",
"id",
"s",
"for",
"various",
"device",
"identification",
"behaviour",
"identification",
"software",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L964-L970 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.setShipmentInfo | public function setShipmentInfo($name, $value)
{
$this->_checkArgument($name, "name");
$this->shipInfo[$name] = $value;
} | php | public function setShipmentInfo($name, $value)
{
$this->_checkArgument($name, "name");
$this->shipInfo[$name] = $value;
} | [
"public",
"function",
"setShipmentInfo",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"_checkArgument",
"(",
"$",
"name",
",",
"\"name\"",
")",
";",
"$",
"this",
"->",
"shipInfo",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}"
] | Sets the shipment information for the upcoming transaction.<br>
Using this method is optional.
<b>Available named values are</b>:<br>
int - delay_adjust<br>
string - shipping_company<br>
string - shipping_product<br>
string - tracking_no<br>
array - warehouse_addr<br>
"warehouse_addr" is sent using {@link KlarnaAddr::toArray()}.
Make sure you send in the values as the right data type.<br>
Use strval, intval or similar methods to ensure the right type is sent.
@param string $name key
@param mixed $value value
@throws KlarnaException
@return void | [
"Sets",
"the",
"shipment",
"information",
"for",
"the",
"upcoming",
"transaction",
".",
"<br",
">"
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L995-L1000 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.setExtraInfo | public function setExtraInfo($name, $value)
{
$this->_checkArgument($name, "name");
$this->extraInfo[$name] = $value;
} | php | public function setExtraInfo($name, $value)
{
$this->_checkArgument($name, "name");
$this->extraInfo[$name] = $value;
} | [
"public",
"function",
"setExtraInfo",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"_checkArgument",
"(",
"$",
"name",
",",
"\"name\"",
")",
";",
"$",
"this",
"->",
"extraInfo",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}"
] | Sets the extra information for the upcoming transaction.<br>
Using this method is optional.
<b>Available named values are</b>:<br>
string - cust_no<br>
string - estore_user<br>
string - ready_date<br>
string - rand_string<br>
int - bclass<br>
string - pin<br>
Make sure you send in the values as the right data type.<br>
Use strval, intval or similar methods to ensure the right type is sent.
@param string $name key
@param mixed $value value
@throws KlarnaException
@return void | [
"Sets",
"the",
"extra",
"information",
"for",
"the",
"upcoming",
"transaction",
".",
"<br",
">"
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L1054-L1059 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.setIncomeInfo | public function setIncomeInfo($name, $value)
{
$this->_checkArgument($name, "name");
$this->incomeInfo[$name] = $value;
} | php | public function setIncomeInfo($name, $value)
{
$this->_checkArgument($name, "name");
$this->incomeInfo[$name] = $value;
} | [
"public",
"function",
"setIncomeInfo",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"_checkArgument",
"(",
"$",
"name",
",",
"\"name\"",
")",
";",
"$",
"this",
"->",
"incomeInfo",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}"
] | Sets the income expense information for the upcoming transaction.<br>
Using this method is optional.
Make sure you send in the values as the right data type.<br>
Use strval, intval or similar methods to ensure the right type is sent.
@param string $name key
@param mixed $value value
@throws KlarnaException
@return void | [
"Sets",
"the",
"income",
"expense",
"information",
"for",
"the",
"upcoming",
"transaction",
".",
"<br",
">"
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L1075-L1080 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.setBankInfo | public function setBankInfo($name, $value)
{
$this->_checkArgument($name, "name");
$this->bankInfo[$name] = $value;
} | php | public function setBankInfo($name, $value)
{
$this->_checkArgument($name, "name");
$this->bankInfo[$name] = $value;
} | [
"public",
"function",
"setBankInfo",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"_checkArgument",
"(",
"$",
"name",
",",
"\"name\"",
")",
";",
"$",
"this",
"->",
"bankInfo",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}"
] | Sets the bank information for the upcoming transaction.<br>
Using this method is optional.
Make sure you send in the values as the right data type.<br>
Use strval, intval or similar methods to ensure the right type is sent.
@param string $name key
@param mixed $value value
@throws KlarnaException
@return void | [
"Sets",
"the",
"bank",
"information",
"for",
"the",
"upcoming",
"transaction",
".",
"<br",
">"
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L1096-L1101 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.setTravelInfo | public function setTravelInfo($name, $value)
{
$this->_checkArgument($name, "name");
$this->travelInfo[$name] = $value;
} | php | public function setTravelInfo($name, $value)
{
$this->_checkArgument($name, "name");
$this->travelInfo[$name] = $value;
} | [
"public",
"function",
"setTravelInfo",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"_checkArgument",
"(",
"$",
"name",
",",
"\"name\"",
")",
";",
"$",
"this",
"->",
"travelInfo",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}"
] | Sets the travel information for the upcoming transaction.<br>
Using this method is optional.
Make sure you send in the values as the right data type.<br>
Use strval, intval or similar methods to ensure the right type is sent.
@param string $name key
@param mixed $value value
@throws KlarnaException
@return void | [
"Sets",
"the",
"travel",
"information",
"for",
"the",
"upcoming",
"transaction",
".",
"<br",
">"
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L1117-L1122 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.getClientIP | public function getClientIP()
{
if (isset($this->clientIP)) {
return $this->clientIP;
}
$tmp_ip = '';
$x_fwd = null;
//Proxy handling.
if (array_key_exists('REMOTE_ADDR', $_SERVER)) {
$tmp_ip = $_SERVER['REMOTE_ADDR'];
}
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
$x_fwd = $_SERVER["HTTP_X_FORWARDED_FOR"];
}
if (self::$x_forwarded_for && ($x_fwd !== null)) {
$forwarded = explode(",", $x_fwd);
return trim($forwarded[0]);
}
return $tmp_ip;
} | php | public function getClientIP()
{
if (isset($this->clientIP)) {
return $this->clientIP;
}
$tmp_ip = '';
$x_fwd = null;
//Proxy handling.
if (array_key_exists('REMOTE_ADDR', $_SERVER)) {
$tmp_ip = $_SERVER['REMOTE_ADDR'];
}
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
$x_fwd = $_SERVER["HTTP_X_FORWARDED_FOR"];
}
if (self::$x_forwarded_for && ($x_fwd !== null)) {
$forwarded = explode(",", $x_fwd);
return trim($forwarded[0]);
}
return $tmp_ip;
} | [
"public",
"function",
"getClientIP",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"clientIP",
")",
")",
"{",
"return",
"$",
"this",
"->",
"clientIP",
";",
"}",
"$",
"tmp_ip",
"=",
"''",
";",
"$",
"x_fwd",
"=",
"null",
";",
"//Proxy handling.",
"if",
"(",
"array_key_exists",
"(",
"'REMOTE_ADDR'",
",",
"$",
"_SERVER",
")",
")",
"{",
"$",
"tmp_ip",
"=",
"$",
"_SERVER",
"[",
"'REMOTE_ADDR'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"\"HTTP_X_FORWARDED_FOR\"",
"]",
")",
")",
"{",
"$",
"x_fwd",
"=",
"$",
"_SERVER",
"[",
"\"HTTP_X_FORWARDED_FOR\"",
"]",
";",
"}",
"if",
"(",
"self",
"::",
"$",
"x_forwarded_for",
"&&",
"(",
"$",
"x_fwd",
"!==",
"null",
")",
")",
"{",
"$",
"forwarded",
"=",
"explode",
"(",
"\",\"",
",",
"$",
"x_fwd",
")",
";",
"return",
"trim",
"(",
"$",
"forwarded",
"[",
"0",
"]",
")",
";",
"}",
"return",
"$",
"tmp_ip",
";",
"}"
] | Returns the clients IP address.
@return string | [
"Returns",
"the",
"clients",
"IP",
"address",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L1141-L1165 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.setAddress | public function setAddress($type, $addr)
{
if (!($addr instanceof KlarnaAddr)) {
throw new Klarna_InvalidKlarnaAddrException;
}
if ($addr->isCompany === null) {
$addr->isCompany = false;
}
if ($type === KlarnaFlags::IS_SHIPPING) {
$this->shipping = $addr;
self::printDebug("shipping address array", $this->shipping);
return;
}
if ($type === KlarnaFlags::IS_BILLING) {
$this->billing = $addr;
self::printDebug("billing address array", $this->billing);
return;
}
throw new Klarna_UnknownAddressTypeException($type);
} | php | public function setAddress($type, $addr)
{
if (!($addr instanceof KlarnaAddr)) {
throw new Klarna_InvalidKlarnaAddrException;
}
if ($addr->isCompany === null) {
$addr->isCompany = false;
}
if ($type === KlarnaFlags::IS_SHIPPING) {
$this->shipping = $addr;
self::printDebug("shipping address array", $this->shipping);
return;
}
if ($type === KlarnaFlags::IS_BILLING) {
$this->billing = $addr;
self::printDebug("billing address array", $this->billing);
return;
}
throw new Klarna_UnknownAddressTypeException($type);
} | [
"public",
"function",
"setAddress",
"(",
"$",
"type",
",",
"$",
"addr",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"addr",
"instanceof",
"KlarnaAddr",
")",
")",
"{",
"throw",
"new",
"Klarna_InvalidKlarnaAddrException",
";",
"}",
"if",
"(",
"$",
"addr",
"->",
"isCompany",
"===",
"null",
")",
"{",
"$",
"addr",
"->",
"isCompany",
"=",
"false",
";",
"}",
"if",
"(",
"$",
"type",
"===",
"KlarnaFlags",
"::",
"IS_SHIPPING",
")",
"{",
"$",
"this",
"->",
"shipping",
"=",
"$",
"addr",
";",
"self",
"::",
"printDebug",
"(",
"\"shipping address array\"",
",",
"$",
"this",
"->",
"shipping",
")",
";",
"return",
";",
"}",
"if",
"(",
"$",
"type",
"===",
"KlarnaFlags",
"::",
"IS_BILLING",
")",
"{",
"$",
"this",
"->",
"billing",
"=",
"$",
"addr",
";",
"self",
"::",
"printDebug",
"(",
"\"billing address array\"",
",",
"$",
"this",
"->",
"billing",
")",
";",
"return",
";",
"}",
"throw",
"new",
"Klarna_UnknownAddressTypeException",
"(",
"$",
"type",
")",
";",
"}"
] | Sets the specified address for the current order.
<b>Address type can be</b>:<br>
{@link KlarnaFlags::IS_SHIPPING}<br>
{@link KlarnaFlags::IS_BILLING}<br>
@param int $type Address type.
@param KlarnaAddr $addr Specified address.
@throws KlarnaException
@return void | [
"Sets",
"the",
"specified",
"address",
"for",
"the",
"current",
"order",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L1180-L1202 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.setEstoreInfo | public function setEstoreInfo($orderid1 = "", $orderid2 = "", $user = "")
{
if (!is_string($orderid1)) {
$orderid1 = strval($orderid1);
}
if (!is_string($orderid2)) {
$orderid2 = strval($orderid2);
}
if (!is_string($user)) {
$user = strval($user);
}
if (strlen($user) > 0 ) {
$this->setExtraInfo('estore_user', $user);
}
$this->orderid[0] = $orderid1;
$this->orderid[1] = $orderid2;
} | php | public function setEstoreInfo($orderid1 = "", $orderid2 = "", $user = "")
{
if (!is_string($orderid1)) {
$orderid1 = strval($orderid1);
}
if (!is_string($orderid2)) {
$orderid2 = strval($orderid2);
}
if (!is_string($user)) {
$user = strval($user);
}
if (strlen($user) > 0 ) {
$this->setExtraInfo('estore_user', $user);
}
$this->orderid[0] = $orderid1;
$this->orderid[1] = $orderid2;
} | [
"public",
"function",
"setEstoreInfo",
"(",
"$",
"orderid1",
"=",
"\"\"",
",",
"$",
"orderid2",
"=",
"\"\"",
",",
"$",
"user",
"=",
"\"\"",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"orderid1",
")",
")",
"{",
"$",
"orderid1",
"=",
"strval",
"(",
"$",
"orderid1",
")",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"orderid2",
")",
")",
"{",
"$",
"orderid2",
"=",
"strval",
"(",
"$",
"orderid2",
")",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"user",
")",
")",
"{",
"$",
"user",
"=",
"strval",
"(",
"$",
"user",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"user",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"setExtraInfo",
"(",
"'estore_user'",
",",
"$",
"user",
")",
";",
"}",
"$",
"this",
"->",
"orderid",
"[",
"0",
"]",
"=",
"$",
"orderid1",
";",
"$",
"this",
"->",
"orderid",
"[",
"1",
"]",
"=",
"$",
"orderid2",
";",
"}"
] | Sets order id's from other systems for the upcoming transaction.<br>
User is only sent with {@link Klarna::addTransaction()}.<br>
@param string $orderid1 order id 1
@param string $orderid2 order id 2
@param string $user username
@see Klarna::setExtraInfo()
@throws KlarnaException
@return void | [
"Sets",
"order",
"id",
"s",
"from",
"other",
"systems",
"for",
"the",
"upcoming",
"transaction",
".",
"<br",
">",
"User",
"is",
"only",
"sent",
"with",
"{",
"@link",
"Klarna",
"::",
"addTransaction",
"()",
"}",
".",
"<br",
">"
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L1217-L1237 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.setReference | public function setReference($ref, $code)
{
$this->_checkRef($ref, $code);
$this->reference = $ref;
$this->reference_code = $code;
} | php | public function setReference($ref, $code)
{
$this->_checkRef($ref, $code);
$this->reference = $ref;
$this->reference_code = $code;
} | [
"public",
"function",
"setReference",
"(",
"$",
"ref",
",",
"$",
"code",
")",
"{",
"$",
"this",
"->",
"_checkRef",
"(",
"$",
"ref",
",",
"$",
"code",
")",
";",
"$",
"this",
"->",
"reference",
"=",
"$",
"ref",
";",
"$",
"this",
"->",
"reference_code",
"=",
"$",
"code",
";",
"}"
] | Sets the reference (person) and reference code, for the upcoming
transaction.
If this is omitted, it can grab first name, last name from the address
and use that as a reference person.
@param string $ref Reference person / message to customer on invoice.
@param string $code Reference code / message to customer on invoice.
@return void | [
"Sets",
"the",
"reference",
"(",
"person",
")",
"and",
"reference",
"code",
"for",
"the",
"upcoming",
"transaction",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L1251-L1256 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.getPNOEncoding | public function getPNOEncoding()
{
$this->_checkLocale();
$country = KlarnaCountry::getCode($this->_country);
return KlarnaEncoding::get($country);
} | php | public function getPNOEncoding()
{
$this->_checkLocale();
$country = KlarnaCountry::getCode($this->_country);
return KlarnaEncoding::get($country);
} | [
"public",
"function",
"getPNOEncoding",
"(",
")",
"{",
"$",
"this",
"->",
"_checkLocale",
"(",
")",
";",
"$",
"country",
"=",
"KlarnaCountry",
"::",
"getCode",
"(",
"$",
"this",
"->",
"_country",
")",
";",
"return",
"KlarnaEncoding",
"::",
"get",
"(",
"$",
"country",
")",
";",
"}"
] | Returns the PNO/SSN encoding constant for currently set country.
<b>Note</b>:<br>
Country, language and currency needs to match!
@throws KlarnaException
@return int {@link KlarnaEncoding} constant. | [
"Returns",
"the",
"PNO",
"/",
"SSN",
"encoding",
"constant",
"for",
"currently",
"set",
"country",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L1321-L1328 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.getAddresses | public function getAddresses(
$pno, $encoding = null, $type = KlarnaFlags::GA_GIVEN
) {
if ($this->_country !== KlarnaCountry::SE) {
throw new Klarna_UnsupportedMarketException("Sweden");
}
//Get the PNO/SSN encoding constant.
if ($encoding === null) {
$encoding = $this->getPNOEncoding();
}
$this->_checkPNO($pno, $encoding);
$digestSecret = self::digest(
$this->colon(
$this->_eid, $pno, $this->_secret
)
);
$paramList = array(
$pno,
$this->_eid,
$digestSecret,
$encoding,
$type,
$this->getClientIP()
);
self::printDebug("get_addresses array", $paramList);
$result = $this->xmlrpc_call('get_addresses', $paramList);
self::printDebug("get_addresses result array", $result);
$addrs = array();
foreach ($result as $tmpAddr) {
try {
$addr = new KlarnaAddr();
if ($type === KlarnaFlags::GA_GIVEN) {
$addr->isCompany = (count($tmpAddr) == 5) ? true : false;
if ($addr->isCompany) {
$addr->setCompanyName($tmpAddr[0]);
$addr->setStreet($tmpAddr[1]);
$addr->setZipCode($tmpAddr[2]);
$addr->setCity($tmpAddr[3]);
$addr->setCountry($tmpAddr[4]);
} else {
$addr->setFirstName($tmpAddr[0]);
$addr->setLastName($tmpAddr[1]);
$addr->setStreet($tmpAddr[2]);
$addr->setZipCode($tmpAddr[3]);
$addr->setCity($tmpAddr[4]);
$addr->setCountry($tmpAddr[5]);
}
} else if ($type === KlarnaFlags::GA_LAST) {
// Here we cannot decide if it is a company or not?
// Assume private person.
$addr->setLastName($tmpAddr[0]);
$addr->setStreet($tmpAddr[1]);
$addr->setZipCode($tmpAddr[2]);
$addr->setCity($tmpAddr[3]);
$addr->setCountry($tmpAddr[4]);
} else if ($type === KlarnaFlags::GA_ALL) {
if (strlen($tmpAddr[0]) > 0) {
$addr->setFirstName($tmpAddr[0]);
$addr->setLastName($tmpAddr[1]);
} else {
$addr->isCompany = true;
$addr->setCompanyName($tmpAddr[1]);
}
$addr->setStreet($tmpAddr[2]);
$addr->setZipCode($tmpAddr[3]);
$addr->setCity($tmpAddr[4]);
$addr->setCountry($tmpAddr[5]);
} else {
continue;
}
$addrs[] = $addr;
} catch(Exception $e) {
//Silently fail
}
}
return $addrs;
} | php | public function getAddresses(
$pno, $encoding = null, $type = KlarnaFlags::GA_GIVEN
) {
if ($this->_country !== KlarnaCountry::SE) {
throw new Klarna_UnsupportedMarketException("Sweden");
}
//Get the PNO/SSN encoding constant.
if ($encoding === null) {
$encoding = $this->getPNOEncoding();
}
$this->_checkPNO($pno, $encoding);
$digestSecret = self::digest(
$this->colon(
$this->_eid, $pno, $this->_secret
)
);
$paramList = array(
$pno,
$this->_eid,
$digestSecret,
$encoding,
$type,
$this->getClientIP()
);
self::printDebug("get_addresses array", $paramList);
$result = $this->xmlrpc_call('get_addresses', $paramList);
self::printDebug("get_addresses result array", $result);
$addrs = array();
foreach ($result as $tmpAddr) {
try {
$addr = new KlarnaAddr();
if ($type === KlarnaFlags::GA_GIVEN) {
$addr->isCompany = (count($tmpAddr) == 5) ? true : false;
if ($addr->isCompany) {
$addr->setCompanyName($tmpAddr[0]);
$addr->setStreet($tmpAddr[1]);
$addr->setZipCode($tmpAddr[2]);
$addr->setCity($tmpAddr[3]);
$addr->setCountry($tmpAddr[4]);
} else {
$addr->setFirstName($tmpAddr[0]);
$addr->setLastName($tmpAddr[1]);
$addr->setStreet($tmpAddr[2]);
$addr->setZipCode($tmpAddr[3]);
$addr->setCity($tmpAddr[4]);
$addr->setCountry($tmpAddr[5]);
}
} else if ($type === KlarnaFlags::GA_LAST) {
// Here we cannot decide if it is a company or not?
// Assume private person.
$addr->setLastName($tmpAddr[0]);
$addr->setStreet($tmpAddr[1]);
$addr->setZipCode($tmpAddr[2]);
$addr->setCity($tmpAddr[3]);
$addr->setCountry($tmpAddr[4]);
} else if ($type === KlarnaFlags::GA_ALL) {
if (strlen($tmpAddr[0]) > 0) {
$addr->setFirstName($tmpAddr[0]);
$addr->setLastName($tmpAddr[1]);
} else {
$addr->isCompany = true;
$addr->setCompanyName($tmpAddr[1]);
}
$addr->setStreet($tmpAddr[2]);
$addr->setZipCode($tmpAddr[3]);
$addr->setCity($tmpAddr[4]);
$addr->setCountry($tmpAddr[5]);
} else {
continue;
}
$addrs[] = $addr;
} catch(Exception $e) {
//Silently fail
}
}
return $addrs;
} | [
"public",
"function",
"getAddresses",
"(",
"$",
"pno",
",",
"$",
"encoding",
"=",
"null",
",",
"$",
"type",
"=",
"KlarnaFlags",
"::",
"GA_GIVEN",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_country",
"!==",
"KlarnaCountry",
"::",
"SE",
")",
"{",
"throw",
"new",
"Klarna_UnsupportedMarketException",
"(",
"\"Sweden\"",
")",
";",
"}",
"//Get the PNO/SSN encoding constant.",
"if",
"(",
"$",
"encoding",
"===",
"null",
")",
"{",
"$",
"encoding",
"=",
"$",
"this",
"->",
"getPNOEncoding",
"(",
")",
";",
"}",
"$",
"this",
"->",
"_checkPNO",
"(",
"$",
"pno",
",",
"$",
"encoding",
")",
";",
"$",
"digestSecret",
"=",
"self",
"::",
"digest",
"(",
"$",
"this",
"->",
"colon",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"pno",
",",
"$",
"this",
"->",
"_secret",
")",
")",
";",
"$",
"paramList",
"=",
"array",
"(",
"$",
"pno",
",",
"$",
"this",
"->",
"_eid",
",",
"$",
"digestSecret",
",",
"$",
"encoding",
",",
"$",
"type",
",",
"$",
"this",
"->",
"getClientIP",
"(",
")",
")",
";",
"self",
"::",
"printDebug",
"(",
"\"get_addresses array\"",
",",
"$",
"paramList",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'get_addresses'",
",",
"$",
"paramList",
")",
";",
"self",
"::",
"printDebug",
"(",
"\"get_addresses result array\"",
",",
"$",
"result",
")",
";",
"$",
"addrs",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"tmpAddr",
")",
"{",
"try",
"{",
"$",
"addr",
"=",
"new",
"KlarnaAddr",
"(",
")",
";",
"if",
"(",
"$",
"type",
"===",
"KlarnaFlags",
"::",
"GA_GIVEN",
")",
"{",
"$",
"addr",
"->",
"isCompany",
"=",
"(",
"count",
"(",
"$",
"tmpAddr",
")",
"==",
"5",
")",
"?",
"true",
":",
"false",
";",
"if",
"(",
"$",
"addr",
"->",
"isCompany",
")",
"{",
"$",
"addr",
"->",
"setCompanyName",
"(",
"$",
"tmpAddr",
"[",
"0",
"]",
")",
";",
"$",
"addr",
"->",
"setStreet",
"(",
"$",
"tmpAddr",
"[",
"1",
"]",
")",
";",
"$",
"addr",
"->",
"setZipCode",
"(",
"$",
"tmpAddr",
"[",
"2",
"]",
")",
";",
"$",
"addr",
"->",
"setCity",
"(",
"$",
"tmpAddr",
"[",
"3",
"]",
")",
";",
"$",
"addr",
"->",
"setCountry",
"(",
"$",
"tmpAddr",
"[",
"4",
"]",
")",
";",
"}",
"else",
"{",
"$",
"addr",
"->",
"setFirstName",
"(",
"$",
"tmpAddr",
"[",
"0",
"]",
")",
";",
"$",
"addr",
"->",
"setLastName",
"(",
"$",
"tmpAddr",
"[",
"1",
"]",
")",
";",
"$",
"addr",
"->",
"setStreet",
"(",
"$",
"tmpAddr",
"[",
"2",
"]",
")",
";",
"$",
"addr",
"->",
"setZipCode",
"(",
"$",
"tmpAddr",
"[",
"3",
"]",
")",
";",
"$",
"addr",
"->",
"setCity",
"(",
"$",
"tmpAddr",
"[",
"4",
"]",
")",
";",
"$",
"addr",
"->",
"setCountry",
"(",
"$",
"tmpAddr",
"[",
"5",
"]",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"type",
"===",
"KlarnaFlags",
"::",
"GA_LAST",
")",
"{",
"// Here we cannot decide if it is a company or not?",
"// Assume private person.",
"$",
"addr",
"->",
"setLastName",
"(",
"$",
"tmpAddr",
"[",
"0",
"]",
")",
";",
"$",
"addr",
"->",
"setStreet",
"(",
"$",
"tmpAddr",
"[",
"1",
"]",
")",
";",
"$",
"addr",
"->",
"setZipCode",
"(",
"$",
"tmpAddr",
"[",
"2",
"]",
")",
";",
"$",
"addr",
"->",
"setCity",
"(",
"$",
"tmpAddr",
"[",
"3",
"]",
")",
";",
"$",
"addr",
"->",
"setCountry",
"(",
"$",
"tmpAddr",
"[",
"4",
"]",
")",
";",
"}",
"else",
"if",
"(",
"$",
"type",
"===",
"KlarnaFlags",
"::",
"GA_ALL",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"tmpAddr",
"[",
"0",
"]",
")",
">",
"0",
")",
"{",
"$",
"addr",
"->",
"setFirstName",
"(",
"$",
"tmpAddr",
"[",
"0",
"]",
")",
";",
"$",
"addr",
"->",
"setLastName",
"(",
"$",
"tmpAddr",
"[",
"1",
"]",
")",
";",
"}",
"else",
"{",
"$",
"addr",
"->",
"isCompany",
"=",
"true",
";",
"$",
"addr",
"->",
"setCompanyName",
"(",
"$",
"tmpAddr",
"[",
"1",
"]",
")",
";",
"}",
"$",
"addr",
"->",
"setStreet",
"(",
"$",
"tmpAddr",
"[",
"2",
"]",
")",
";",
"$",
"addr",
"->",
"setZipCode",
"(",
"$",
"tmpAddr",
"[",
"3",
"]",
")",
";",
"$",
"addr",
"->",
"setCity",
"(",
"$",
"tmpAddr",
"[",
"4",
"]",
")",
";",
"$",
"addr",
"->",
"setCountry",
"(",
"$",
"tmpAddr",
"[",
"5",
"]",
")",
";",
"}",
"else",
"{",
"continue",
";",
"}",
"$",
"addrs",
"[",
"]",
"=",
"$",
"addr",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"//Silently fail",
"}",
"}",
"return",
"$",
"addrs",
";",
"}"
] | Purpose: The get_addresses function is used to retrieve a customer's
address(es). Using this, the customer is not required to enter any
information, only confirm the one presented to him/her.<br>
The get_addresses function can also be used for companies.<br>
If the customer enters a company number, it will return all the
addresses where the company is registered at.<br>
The get_addresses function is ONLY allowed to be used for Swedish
persons with the following conditions:
<ul>
<li>
It can be only used if invoice or part payment is
the default payment method
</li>
<li>
It has to disappear if the customer chooses another
payment method
</li>
<li>
The button is not allowed to be called "get address", but
"continue" or<br>
it can be picked up automatically when all the numbers have
been typed.
</li>
</ul>
<b>Type can be one of these</b>:<br>
{@link KlarnaFlags::GA_ALL},<br>
{@link KlarnaFlags::GA_LAST},<br>
{@link KlarnaFlags::GA_GIVEN}.<br>
@param string $pno Social security number, personal number, ...
@param int $encoding {@link KlarnaEncoding PNO Encoding} constant.
@param int $type Specifies returned information.
@throws KlarnaException
@return array An array of {@link KlarnaAddr} objects. | [
"Purpose",
":",
"The",
"get_addresses",
"function",
"is",
"used",
"to",
"retrieve",
"a",
"customer",
"s",
"address",
"(",
"es",
")",
".",
"Using",
"this",
"the",
"customer",
"is",
"not",
"required",
"to",
"enter",
"any",
"information",
"only",
"confirm",
"the",
"one",
"presented",
"to",
"him",
"/",
"her",
".",
"<br",
">"
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L1370-L1455 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.addArticle | public function addArticle(
$qty, $artNo, $title, $price, $vat, $discount = 0,
$flags = KlarnaFlags::INC_VAT
) {
$this->_checkQty($qty);
// Either artno or title has to be set
if ((($artNo === null ) || ($artNo == ""))
&& (($title === null ) || ($title == ""))
) {
throw new Klarna_ArgumentNotSetException('Title and ArtNo', 50026);
}
$this->_checkPrice($price);
$this->_checkVAT($vat);
$this->_checkDiscount($discount);
$this->_checkInt($flags, 'flags');
//Create goodsList array if not set.
if (!$this->goodsList || !is_array($this->goodsList)) {
$this->goodsList = array();
}
//Populate a temp array with the article details.
$tmpArr = array(
"artno" => $artNo,
"title" => $title,
"price" => $price,
"vat" => $vat,
"discount" => $discount,
"flags" => $flags
);
//Add the temp array and quantity field to the internal goods list.
$this->goodsList[] = array(
"goods" => $tmpArr,
"qty" => $qty
);
if (count($this->goodsList) > 0) {
self::printDebug(
"article added",
$this->goodsList[count($this->goodsList)-1]
);
}
} | php | public function addArticle(
$qty, $artNo, $title, $price, $vat, $discount = 0,
$flags = KlarnaFlags::INC_VAT
) {
$this->_checkQty($qty);
// Either artno or title has to be set
if ((($artNo === null ) || ($artNo == ""))
&& (($title === null ) || ($title == ""))
) {
throw new Klarna_ArgumentNotSetException('Title and ArtNo', 50026);
}
$this->_checkPrice($price);
$this->_checkVAT($vat);
$this->_checkDiscount($discount);
$this->_checkInt($flags, 'flags');
//Create goodsList array if not set.
if (!$this->goodsList || !is_array($this->goodsList)) {
$this->goodsList = array();
}
//Populate a temp array with the article details.
$tmpArr = array(
"artno" => $artNo,
"title" => $title,
"price" => $price,
"vat" => $vat,
"discount" => $discount,
"flags" => $flags
);
//Add the temp array and quantity field to the internal goods list.
$this->goodsList[] = array(
"goods" => $tmpArr,
"qty" => $qty
);
if (count($this->goodsList) > 0) {
self::printDebug(
"article added",
$this->goodsList[count($this->goodsList)-1]
);
}
} | [
"public",
"function",
"addArticle",
"(",
"$",
"qty",
",",
"$",
"artNo",
",",
"$",
"title",
",",
"$",
"price",
",",
"$",
"vat",
",",
"$",
"discount",
"=",
"0",
",",
"$",
"flags",
"=",
"KlarnaFlags",
"::",
"INC_VAT",
")",
"{",
"$",
"this",
"->",
"_checkQty",
"(",
"$",
"qty",
")",
";",
"// Either artno or title has to be set",
"if",
"(",
"(",
"(",
"$",
"artNo",
"===",
"null",
")",
"||",
"(",
"$",
"artNo",
"==",
"\"\"",
")",
")",
"&&",
"(",
"(",
"$",
"title",
"===",
"null",
")",
"||",
"(",
"$",
"title",
"==",
"\"\"",
")",
")",
")",
"{",
"throw",
"new",
"Klarna_ArgumentNotSetException",
"(",
"'Title and ArtNo'",
",",
"50026",
")",
";",
"}",
"$",
"this",
"->",
"_checkPrice",
"(",
"$",
"price",
")",
";",
"$",
"this",
"->",
"_checkVAT",
"(",
"$",
"vat",
")",
";",
"$",
"this",
"->",
"_checkDiscount",
"(",
"$",
"discount",
")",
";",
"$",
"this",
"->",
"_checkInt",
"(",
"$",
"flags",
",",
"'flags'",
")",
";",
"//Create goodsList array if not set.",
"if",
"(",
"!",
"$",
"this",
"->",
"goodsList",
"||",
"!",
"is_array",
"(",
"$",
"this",
"->",
"goodsList",
")",
")",
"{",
"$",
"this",
"->",
"goodsList",
"=",
"array",
"(",
")",
";",
"}",
"//Populate a temp array with the article details.",
"$",
"tmpArr",
"=",
"array",
"(",
"\"artno\"",
"=>",
"$",
"artNo",
",",
"\"title\"",
"=>",
"$",
"title",
",",
"\"price\"",
"=>",
"$",
"price",
",",
"\"vat\"",
"=>",
"$",
"vat",
",",
"\"discount\"",
"=>",
"$",
"discount",
",",
"\"flags\"",
"=>",
"$",
"flags",
")",
";",
"//Add the temp array and quantity field to the internal goods list.",
"$",
"this",
"->",
"goodsList",
"[",
"]",
"=",
"array",
"(",
"\"goods\"",
"=>",
"$",
"tmpArr",
",",
"\"qty\"",
"=>",
"$",
"qty",
")",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"goodsList",
")",
">",
"0",
")",
"{",
"self",
"::",
"printDebug",
"(",
"\"article added\"",
",",
"$",
"this",
"->",
"goodsList",
"[",
"count",
"(",
"$",
"this",
"->",
"goodsList",
")",
"-",
"1",
"]",
")",
";",
"}",
"}"
] | Adds an article to the current goods list for the current order.
<b>Note</b>:<br>
It is recommended that you use {@link KlarnaFlags::INC_VAT}.<br>
<b>Flags can be</b>:<br>
{@link KlarnaFlags::INC_VAT}<br>
{@link KlarnaFlags::IS_SHIPMENT}<br>
{@link KlarnaFlags::IS_HANDLING}<br>
{@link KlarnaFlags::PRINT_1000}<br>
{@link KlarnaFlags::PRINT_100}<br>
{@link KlarnaFlags::PRINT_10}<br>
{@link KlarnaFlags::NO_FLAG}<br>
Some flags can be added to each other for multiple options.
@param int $qty Quantity.
@param string $artNo Article number.
@param string $title Article title.
@param int $price Article price.
@param float $vat VAT in percent, e.g. 25% is inputted as 25.
@param float $discount Possible discount on article.
@param int $flags Options which specify the article
({@link KlarnaFlags::IS_HANDLING}) and it's price
({@link KlarnaFlags::INC_VAT})
@see Klarna::addTransaction()
@see Klarna::reserveAmount()
@see Klarna::activateReservation()
@throws KlarnaException
@return void | [
"Adds",
"an",
"article",
"to",
"the",
"current",
"goods",
"list",
"for",
"the",
"current",
"order",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L1491-L1536 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.addTransaction | public function addTransaction(
$pno, $gender, $flags = KlarnaFlags::NO_FLAG,
$pclass = KlarnaPClass::INVOICE, $encoding = null, $clear = true
) {
$this->_checkLocale(50023);
//Get the PNO/SSN encoding constant.
if ($encoding === null) {
$encoding = $this->getPNOEncoding();
}
if (!($flags & KlarnaFlags::PRE_PAY)) {
$this->_checkPNO($pno, $encoding);
}
if ($gender === 'm') {
$gender = KlarnaFlags::MALE;
} else if ($gender === 'f') {
$gender = KlarnaFlags::FEMALE;
}
if ($gender !== null && strlen($gender) > 0) {
$this->_checkInt($gender, 'gender');
}
$this->_checkInt($flags, 'flags');
$this->_checkInt($pclass, 'pclass');
//Check so required information is set.
$this->_checkGoodslist();
//We need at least one address set
if (!($this->billing instanceof KlarnaAddr)
&& !($this->shipping instanceof KlarnaAddr)
) {
throw new Klarna_MissingAddressException;
}
//If only one address is set, copy to the other address.
if (!($this->shipping instanceof KlarnaAddr)
&& ($this->billing instanceof KlarnaAddr)
) {
$this->shipping = $this->billing;
} else if (!($this->billing instanceof KlarnaAddr)
&& ($this->shipping instanceof KlarnaAddr)
) {
$this->billing = $this->shipping;
}
//Assume normal shipment unless otherwise specified.
if (!isset($this->shipInfo['delay_adjust'])) {
$this->setShipmentInfo('delay_adjust', KlarnaFlags::NORMAL_SHIPMENT);
}
//Make sure we get any session ID's or similar
$this->initCheckout();
//function add_transaction_digest
$string = "";
foreach ($this->goodsList as $goods) {
$string .= $goods['goods']['title'] .':';
}
$digestSecret = self::digest($string . $this->_secret);
//end function add_transaction_digest
$billing = $this->assembleAddr($this->billing);
$shipping = $this->assembleAddr($this->shipping);
//Shipping country must match specified country!
if (strlen($shipping['country']) > 0
&& ($shipping['country'] !== $this->_country)
) {
throw new Klarna_ShippingCountryException;
}
$paramList = array(
$pno,
$gender,
$this->reference,
$this->reference_code,
$this->orderid[0],
$this->orderid[1],
$shipping,
$billing,
$this->getClientIP(),
$flags,
$this->_currency,
$this->_country,
$this->_language,
$this->_eid,
$digestSecret,
$encoding,
$pclass,
$this->goodsList,
$this->comment,
$this->shipInfo,
$this->travelInfo,
$this->incomeInfo,
$this->bankInfo,
$this->sid,
$this->extraInfo
);
self::printDebug('add_invoice', $paramList);
$result = $this->xmlrpc_call('add_invoice', $paramList);
if ($clear === true) {
//Make sure any stored values that need to be unique between
//purchases are cleared.
foreach ($this->coObjects as $co) {
$co->clear();
}
$this->clear();
}
self::printDebug('add_invoice result', $result);
return $result;
} | php | public function addTransaction(
$pno, $gender, $flags = KlarnaFlags::NO_FLAG,
$pclass = KlarnaPClass::INVOICE, $encoding = null, $clear = true
) {
$this->_checkLocale(50023);
//Get the PNO/SSN encoding constant.
if ($encoding === null) {
$encoding = $this->getPNOEncoding();
}
if (!($flags & KlarnaFlags::PRE_PAY)) {
$this->_checkPNO($pno, $encoding);
}
if ($gender === 'm') {
$gender = KlarnaFlags::MALE;
} else if ($gender === 'f') {
$gender = KlarnaFlags::FEMALE;
}
if ($gender !== null && strlen($gender) > 0) {
$this->_checkInt($gender, 'gender');
}
$this->_checkInt($flags, 'flags');
$this->_checkInt($pclass, 'pclass');
//Check so required information is set.
$this->_checkGoodslist();
//We need at least one address set
if (!($this->billing instanceof KlarnaAddr)
&& !($this->shipping instanceof KlarnaAddr)
) {
throw new Klarna_MissingAddressException;
}
//If only one address is set, copy to the other address.
if (!($this->shipping instanceof KlarnaAddr)
&& ($this->billing instanceof KlarnaAddr)
) {
$this->shipping = $this->billing;
} else if (!($this->billing instanceof KlarnaAddr)
&& ($this->shipping instanceof KlarnaAddr)
) {
$this->billing = $this->shipping;
}
//Assume normal shipment unless otherwise specified.
if (!isset($this->shipInfo['delay_adjust'])) {
$this->setShipmentInfo('delay_adjust', KlarnaFlags::NORMAL_SHIPMENT);
}
//Make sure we get any session ID's or similar
$this->initCheckout();
//function add_transaction_digest
$string = "";
foreach ($this->goodsList as $goods) {
$string .= $goods['goods']['title'] .':';
}
$digestSecret = self::digest($string . $this->_secret);
//end function add_transaction_digest
$billing = $this->assembleAddr($this->billing);
$shipping = $this->assembleAddr($this->shipping);
//Shipping country must match specified country!
if (strlen($shipping['country']) > 0
&& ($shipping['country'] !== $this->_country)
) {
throw new Klarna_ShippingCountryException;
}
$paramList = array(
$pno,
$gender,
$this->reference,
$this->reference_code,
$this->orderid[0],
$this->orderid[1],
$shipping,
$billing,
$this->getClientIP(),
$flags,
$this->_currency,
$this->_country,
$this->_language,
$this->_eid,
$digestSecret,
$encoding,
$pclass,
$this->goodsList,
$this->comment,
$this->shipInfo,
$this->travelInfo,
$this->incomeInfo,
$this->bankInfo,
$this->sid,
$this->extraInfo
);
self::printDebug('add_invoice', $paramList);
$result = $this->xmlrpc_call('add_invoice', $paramList);
if ($clear === true) {
//Make sure any stored values that need to be unique between
//purchases are cleared.
foreach ($this->coObjects as $co) {
$co->clear();
}
$this->clear();
}
self::printDebug('add_invoice result', $result);
return $result;
} | [
"public",
"function",
"addTransaction",
"(",
"$",
"pno",
",",
"$",
"gender",
",",
"$",
"flags",
"=",
"KlarnaFlags",
"::",
"NO_FLAG",
",",
"$",
"pclass",
"=",
"KlarnaPClass",
"::",
"INVOICE",
",",
"$",
"encoding",
"=",
"null",
",",
"$",
"clear",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"_checkLocale",
"(",
"50023",
")",
";",
"//Get the PNO/SSN encoding constant.",
"if",
"(",
"$",
"encoding",
"===",
"null",
")",
"{",
"$",
"encoding",
"=",
"$",
"this",
"->",
"getPNOEncoding",
"(",
")",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"flags",
"&",
"KlarnaFlags",
"::",
"PRE_PAY",
")",
")",
"{",
"$",
"this",
"->",
"_checkPNO",
"(",
"$",
"pno",
",",
"$",
"encoding",
")",
";",
"}",
"if",
"(",
"$",
"gender",
"===",
"'m'",
")",
"{",
"$",
"gender",
"=",
"KlarnaFlags",
"::",
"MALE",
";",
"}",
"else",
"if",
"(",
"$",
"gender",
"===",
"'f'",
")",
"{",
"$",
"gender",
"=",
"KlarnaFlags",
"::",
"FEMALE",
";",
"}",
"if",
"(",
"$",
"gender",
"!==",
"null",
"&&",
"strlen",
"(",
"$",
"gender",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"_checkInt",
"(",
"$",
"gender",
",",
"'gender'",
")",
";",
"}",
"$",
"this",
"->",
"_checkInt",
"(",
"$",
"flags",
",",
"'flags'",
")",
";",
"$",
"this",
"->",
"_checkInt",
"(",
"$",
"pclass",
",",
"'pclass'",
")",
";",
"//Check so required information is set.",
"$",
"this",
"->",
"_checkGoodslist",
"(",
")",
";",
"//We need at least one address set",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"billing",
"instanceof",
"KlarnaAddr",
")",
"&&",
"!",
"(",
"$",
"this",
"->",
"shipping",
"instanceof",
"KlarnaAddr",
")",
")",
"{",
"throw",
"new",
"Klarna_MissingAddressException",
";",
"}",
"//If only one address is set, copy to the other address.",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"shipping",
"instanceof",
"KlarnaAddr",
")",
"&&",
"(",
"$",
"this",
"->",
"billing",
"instanceof",
"KlarnaAddr",
")",
")",
"{",
"$",
"this",
"->",
"shipping",
"=",
"$",
"this",
"->",
"billing",
";",
"}",
"else",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"billing",
"instanceof",
"KlarnaAddr",
")",
"&&",
"(",
"$",
"this",
"->",
"shipping",
"instanceof",
"KlarnaAddr",
")",
")",
"{",
"$",
"this",
"->",
"billing",
"=",
"$",
"this",
"->",
"shipping",
";",
"}",
"//Assume normal shipment unless otherwise specified.",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"shipInfo",
"[",
"'delay_adjust'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setShipmentInfo",
"(",
"'delay_adjust'",
",",
"KlarnaFlags",
"::",
"NORMAL_SHIPMENT",
")",
";",
"}",
"//Make sure we get any session ID's or similar",
"$",
"this",
"->",
"initCheckout",
"(",
")",
";",
"//function add_transaction_digest",
"$",
"string",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
"this",
"->",
"goodsList",
"as",
"$",
"goods",
")",
"{",
"$",
"string",
".=",
"$",
"goods",
"[",
"'goods'",
"]",
"[",
"'title'",
"]",
".",
"':'",
";",
"}",
"$",
"digestSecret",
"=",
"self",
"::",
"digest",
"(",
"$",
"string",
".",
"$",
"this",
"->",
"_secret",
")",
";",
"//end function add_transaction_digest",
"$",
"billing",
"=",
"$",
"this",
"->",
"assembleAddr",
"(",
"$",
"this",
"->",
"billing",
")",
";",
"$",
"shipping",
"=",
"$",
"this",
"->",
"assembleAddr",
"(",
"$",
"this",
"->",
"shipping",
")",
";",
"//Shipping country must match specified country!",
"if",
"(",
"strlen",
"(",
"$",
"shipping",
"[",
"'country'",
"]",
")",
">",
"0",
"&&",
"(",
"$",
"shipping",
"[",
"'country'",
"]",
"!==",
"$",
"this",
"->",
"_country",
")",
")",
"{",
"throw",
"new",
"Klarna_ShippingCountryException",
";",
"}",
"$",
"paramList",
"=",
"array",
"(",
"$",
"pno",
",",
"$",
"gender",
",",
"$",
"this",
"->",
"reference",
",",
"$",
"this",
"->",
"reference_code",
",",
"$",
"this",
"->",
"orderid",
"[",
"0",
"]",
",",
"$",
"this",
"->",
"orderid",
"[",
"1",
"]",
",",
"$",
"shipping",
",",
"$",
"billing",
",",
"$",
"this",
"->",
"getClientIP",
"(",
")",
",",
"$",
"flags",
",",
"$",
"this",
"->",
"_currency",
",",
"$",
"this",
"->",
"_country",
",",
"$",
"this",
"->",
"_language",
",",
"$",
"this",
"->",
"_eid",
",",
"$",
"digestSecret",
",",
"$",
"encoding",
",",
"$",
"pclass",
",",
"$",
"this",
"->",
"goodsList",
",",
"$",
"this",
"->",
"comment",
",",
"$",
"this",
"->",
"shipInfo",
",",
"$",
"this",
"->",
"travelInfo",
",",
"$",
"this",
"->",
"incomeInfo",
",",
"$",
"this",
"->",
"bankInfo",
",",
"$",
"this",
"->",
"sid",
",",
"$",
"this",
"->",
"extraInfo",
")",
";",
"self",
"::",
"printDebug",
"(",
"'add_invoice'",
",",
"$",
"paramList",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'add_invoice'",
",",
"$",
"paramList",
")",
";",
"if",
"(",
"$",
"clear",
"===",
"true",
")",
"{",
"//Make sure any stored values that need to be unique between",
"//purchases are cleared.",
"foreach",
"(",
"$",
"this",
"->",
"coObjects",
"as",
"$",
"co",
")",
"{",
"$",
"co",
"->",
"clear",
"(",
")",
";",
"}",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"}",
"self",
"::",
"printDebug",
"(",
"'add_invoice result'",
",",
"$",
"result",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Assembles and sends the current order to Klarna.<br>
This clears all relevant data if $clear is set to true.<br>
<b>This method returns an array with</b>:<br>
Invoice number<br>
Order status flag<br>
If the flag {@link KlarnaFlags::RETURN_OCR} is used:<br>
Invoice number<br>
OCR number <br>
Order status flag<br>
<b>Order status can be</b>:<br>
{@link KlarnaFlags::ACCEPTED}<br>
{@link KlarnaFlags::PENDING}<br>
{@link KlarnaFlags::DENIED}<br>
Gender is only required for Germany and Netherlands.<br>
<b>Flags can be</b>:<br>
{@link KlarnaFlags::NO_FLAG}<br>
{@link KlarnaFlags::TEST_MODE}<br>
{@link KlarnaFlags::AUTO_ACTIVATE}<br>
{@link KlarnaFlags::SENSITIVE_ORDER}<br>
{@link KlarnaFlags::RETURN_OCR}<br>
{@link KlarnaFlags::M_PHONE_TRANSACTION}<br>
{@link KlarnaFlags::M_SEND_PHONE_PIN}<br>
Some flags can be added to each other for multiple options.
<b>Note</b>:<br>
Normal shipment type is assumed unless otherwise specified,
ou can do this by calling:<br>
{@link Klarna::setShipmentInfo() setShipmentInfo('delay_adjust', ...)}
with either:<br>
{@link KlarnaFlags::NORMAL_SHIPMENT NORMAL_SHIPMENT} or
{@link KlarnaFlags::EXPRESS_SHIPMENT EXPRESS_SHIPMENT}<br>
@param string $pno Personal number, SSN, date of birth, etc.
@param int $gender {@link KlarnaFlags::FEMALE} or
{@link KlarnaFlags::MALE},
null or "" for unspecified.
@param int $flags Options which affect the behaviour.
@param int $pclass PClass id used for this invoice.
@param int $encoding {@link KlarnaEncoding Encoding} constant for the
PNO parameter.
@param bool $clear Whether customer info should be cleared after
this call or not.
@throws KlarnaException
@return array An array with invoice number and order status. [string, int] | [
"Assembles",
"and",
"sends",
"the",
"current",
"order",
"to",
"Klarna",
".",
"<br",
">",
"This",
"clears",
"all",
"relevant",
"data",
"if",
"$clear",
"is",
"set",
"to",
"true",
".",
"<br",
">"
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L1591-L1710 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.activateInvoice | public function activateInvoice(
$invNo, $pclass = KlarnaPClass::INVOICE, $clear = true
) {
$this->_checkInvNo($invNo);
$digestSecret = self::digest(
$this->colon($this->_eid, $invNo, $this->_secret)
);
$paramList = array(
$this->_eid,
$invNo,
$digestSecret,
$pclass,
$this->shipInfo
);
self::printDebug('activate_invoice', $paramList);
$result = $this->xmlrpc_call('activate_invoice', $paramList);
if ($clear === true) {
$this->clear();
}
self::printDebug('activate_invoice result', $result);
return $result;
} | php | public function activateInvoice(
$invNo, $pclass = KlarnaPClass::INVOICE, $clear = true
) {
$this->_checkInvNo($invNo);
$digestSecret = self::digest(
$this->colon($this->_eid, $invNo, $this->_secret)
);
$paramList = array(
$this->_eid,
$invNo,
$digestSecret,
$pclass,
$this->shipInfo
);
self::printDebug('activate_invoice', $paramList);
$result = $this->xmlrpc_call('activate_invoice', $paramList);
if ($clear === true) {
$this->clear();
}
self::printDebug('activate_invoice result', $result);
return $result;
} | [
"public",
"function",
"activateInvoice",
"(",
"$",
"invNo",
",",
"$",
"pclass",
"=",
"KlarnaPClass",
"::",
"INVOICE",
",",
"$",
"clear",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"_checkInvNo",
"(",
"$",
"invNo",
")",
";",
"$",
"digestSecret",
"=",
"self",
"::",
"digest",
"(",
"$",
"this",
"->",
"colon",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"invNo",
",",
"$",
"this",
"->",
"_secret",
")",
")",
";",
"$",
"paramList",
"=",
"array",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"invNo",
",",
"$",
"digestSecret",
",",
"$",
"pclass",
",",
"$",
"this",
"->",
"shipInfo",
")",
";",
"self",
"::",
"printDebug",
"(",
"'activate_invoice'",
",",
"$",
"paramList",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'activate_invoice'",
",",
"$",
"paramList",
")",
";",
"if",
"(",
"$",
"clear",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"}",
"self",
"::",
"printDebug",
"(",
"'activate_invoice result'",
",",
"$",
"result",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Activates previously created invoice
(from {@link Klarna::addTransaction()}).
<b>Note</b>:<br>
If you want to change the shipment type, you can specify it using:
{@link Klarna::setShipmentInfo() setShipmentInfo('delay_adjust', ...)}
with either: {@link KlarnaFlags::NORMAL_SHIPMENT NORMAL_SHIPMENT} or
{@link KlarnaFlags::EXPRESS_SHIPMENT EXPRESS_SHIPMENT}
@param string $invNo Invoice number.
@param int $pclass PClass id used for this invoice.
@param bool $clear Whether customer info should be cleared after this
call.
@see Klarna::setShipmentInfo()
@throws KlarnaException
@return string An URL to the PDF invoice. | [
"Activates",
"previously",
"created",
"invoice",
"(",
"from",
"{",
"@link",
"Klarna",
"::",
"addTransaction",
"()",
"}",
")",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L1733-L1761 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.deleteInvoice | public function deleteInvoice($invNo)
{
$this->_checkInvNo($invNo);
$digestSecret = self::digest(
$this->colon($this->_eid, $invNo, $this->_secret)
);
$paramList = array(
$this->_eid,
$invNo,
$digestSecret
);
self::printDebug('delete_invoice', $paramList);
$result = $this->xmlrpc_call('delete_invoice', $paramList);
return ($result == 'ok') ? true : false;
} | php | public function deleteInvoice($invNo)
{
$this->_checkInvNo($invNo);
$digestSecret = self::digest(
$this->colon($this->_eid, $invNo, $this->_secret)
);
$paramList = array(
$this->_eid,
$invNo,
$digestSecret
);
self::printDebug('delete_invoice', $paramList);
$result = $this->xmlrpc_call('delete_invoice', $paramList);
return ($result == 'ok') ? true : false;
} | [
"public",
"function",
"deleteInvoice",
"(",
"$",
"invNo",
")",
"{",
"$",
"this",
"->",
"_checkInvNo",
"(",
"$",
"invNo",
")",
";",
"$",
"digestSecret",
"=",
"self",
"::",
"digest",
"(",
"$",
"this",
"->",
"colon",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"invNo",
",",
"$",
"this",
"->",
"_secret",
")",
")",
";",
"$",
"paramList",
"=",
"array",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"invNo",
",",
"$",
"digestSecret",
")",
";",
"self",
"::",
"printDebug",
"(",
"'delete_invoice'",
",",
"$",
"paramList",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'delete_invoice'",
",",
"$",
"paramList",
")",
";",
"return",
"(",
"$",
"result",
"==",
"'ok'",
")",
"?",
"true",
":",
"false",
";",
"}"
] | Removes a passive invoices which has previously been created with
{@link Klarna::addTransaction()}.
True is returned if the invoice was successfully removed, otherwise an
exception is thrown.<br>
@param string $invNo Invoice number.
@throws KlarnaException
@return bool | [
"Removes",
"a",
"passive",
"invoices",
"which",
"has",
"previously",
"been",
"created",
"with",
"{",
"@link",
"Klarna",
"::",
"addTransaction",
"()",
"}",
".",
"True",
"is",
"returned",
"if",
"the",
"invoice",
"was",
"successfully",
"removed",
"otherwise",
"an",
"exception",
"is",
"thrown",
".",
"<br",
">"
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L1774-L1793 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.summarizeGoodsList | public function summarizeGoodsList()
{
$amount = 0;
if (!is_array($this->goodsList)) {
return $amount;
}
foreach ($this->goodsList as $goods) {
$price = $goods['goods']['price'];
// Add VAT if price is Excluding VAT
if (($goods['goods']['flags'] & KlarnaFlags::INC_VAT) === 0) {
$vat = $goods['goods']['vat'] / 100.0;
$price *= (1.0 + $vat);
}
// Reduce discounts
if ($goods['goods']['discount'] > 0) {
$discount = $goods['goods']['discount'] / 100.0;
$price *= (1.0 - $discount);
}
$amount += $price * (int)$goods['qty'];
}
return $amount;
} | php | public function summarizeGoodsList()
{
$amount = 0;
if (!is_array($this->goodsList)) {
return $amount;
}
foreach ($this->goodsList as $goods) {
$price = $goods['goods']['price'];
// Add VAT if price is Excluding VAT
if (($goods['goods']['flags'] & KlarnaFlags::INC_VAT) === 0) {
$vat = $goods['goods']['vat'] / 100.0;
$price *= (1.0 + $vat);
}
// Reduce discounts
if ($goods['goods']['discount'] > 0) {
$discount = $goods['goods']['discount'] / 100.0;
$price *= (1.0 - $discount);
}
$amount += $price * (int)$goods['qty'];
}
return $amount;
} | [
"public",
"function",
"summarizeGoodsList",
"(",
")",
"{",
"$",
"amount",
"=",
"0",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"goodsList",
")",
")",
"{",
"return",
"$",
"amount",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"goodsList",
"as",
"$",
"goods",
")",
"{",
"$",
"price",
"=",
"$",
"goods",
"[",
"'goods'",
"]",
"[",
"'price'",
"]",
";",
"// Add VAT if price is Excluding VAT",
"if",
"(",
"(",
"$",
"goods",
"[",
"'goods'",
"]",
"[",
"'flags'",
"]",
"&",
"KlarnaFlags",
"::",
"INC_VAT",
")",
"===",
"0",
")",
"{",
"$",
"vat",
"=",
"$",
"goods",
"[",
"'goods'",
"]",
"[",
"'vat'",
"]",
"/",
"100.0",
";",
"$",
"price",
"*=",
"(",
"1.0",
"+",
"$",
"vat",
")",
";",
"}",
"// Reduce discounts",
"if",
"(",
"$",
"goods",
"[",
"'goods'",
"]",
"[",
"'discount'",
"]",
">",
"0",
")",
"{",
"$",
"discount",
"=",
"$",
"goods",
"[",
"'goods'",
"]",
"[",
"'discount'",
"]",
"/",
"100.0",
";",
"$",
"price",
"*=",
"(",
"1.0",
"-",
"$",
"discount",
")",
";",
"}",
"$",
"amount",
"+=",
"$",
"price",
"*",
"(",
"int",
")",
"$",
"goods",
"[",
"'qty'",
"]",
";",
"}",
"return",
"$",
"amount",
";",
"}"
] | Summarizes the prices of the held goods list
@return int total amount | [
"Summarizes",
"the",
"prices",
"of",
"the",
"held",
"goods",
"list"
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L1800-L1824 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.reserveAmount | public function reserveAmount(
$pno, $gender, $amount, $flags = 0, $pclass = KlarnaPClass::INVOICE,
$encoding = null, $clear = true
) {
$this->_checkLocale();
//Get the PNO/SSN encoding constant.
if ($encoding === null) {
$encoding = $this->getPNOEncoding();
}
$this->_checkPNO($pno, $encoding);
if ($gender === 'm') {
$gender = KlarnaFlags::MALE;
} else if ($gender === 'f') {
$gender = KlarnaFlags::FEMALE;
}
if ($gender !== null && strlen($gender) > 0) {
$this->_checkInt($gender, 'gender');
}
$this->_checkInt($flags, 'flags');
$this->_checkInt($pclass, 'pclass');
//Check so required information is set.
$this->_checkGoodslist();
//Calculate automatically the amount from goodsList.
if ($amount === -1) {
$amount = (int)round($this->summarizeGoodsList());
} else {
$this->_checkAmount($amount);
}
if ($amount < 0) {
throw new Klarna_InvalidPriceException($amount);
}
//No addresses used for phone transactions
if ($flags & KlarnaFlags::RSRV_PHONE_TRANSACTION) {
$billing = $shipping = '';
} else {
$billing = $this->assembleAddr($this->billing);
$shipping = $this->assembleAddr($this->shipping);
if (strlen($shipping['country']) > 0
&& ($shipping['country'] !== $this->_country)
) {
throw new Klarna_ShippingCountryException;
}
}
//Assume normal shipment unless otherwise specified.
if (!isset($this->shipInfo['delay_adjust'])) {
$this->setShipmentInfo('delay_adjust', KlarnaFlags::NORMAL_SHIPMENT);
}
//Make sure we get any session ID's or similar
$this->initCheckout($this, $this->_eid);
$digestSecret = self::digest(
"{$this->_eid}:{$pno}:{$amount}:{$this->_secret}"
);
$paramList = array(
$pno,
$gender,
$amount,
$this->reference,
$this->reference_code,
$this->orderid[0],
$this->orderid[1],
$shipping,
$billing,
$this->getClientIP(),
$flags,
$this->_currency,
$this->_country,
$this->_language,
$this->_eid,
$digestSecret,
$encoding, $pclass,
$this->goodsList,
$this->comment,
$this->shipInfo,
$this->travelInfo,
$this->incomeInfo,
$this->bankInfo,
$this->sid,
$this->extraInfo
);
self::printDebug('reserve_amount', $paramList);
$result = $this->xmlrpc_call('reserve_amount', $paramList);
if ($clear === true) {
//Make sure any stored values that need to be unique between
//purchases are cleared.
foreach ($this->coObjects as $co) {
$co->clear();
}
$this->clear();
}
self::printDebug('reserve_amount result', $result);
return $result;
} | php | public function reserveAmount(
$pno, $gender, $amount, $flags = 0, $pclass = KlarnaPClass::INVOICE,
$encoding = null, $clear = true
) {
$this->_checkLocale();
//Get the PNO/SSN encoding constant.
if ($encoding === null) {
$encoding = $this->getPNOEncoding();
}
$this->_checkPNO($pno, $encoding);
if ($gender === 'm') {
$gender = KlarnaFlags::MALE;
} else if ($gender === 'f') {
$gender = KlarnaFlags::FEMALE;
}
if ($gender !== null && strlen($gender) > 0) {
$this->_checkInt($gender, 'gender');
}
$this->_checkInt($flags, 'flags');
$this->_checkInt($pclass, 'pclass');
//Check so required information is set.
$this->_checkGoodslist();
//Calculate automatically the amount from goodsList.
if ($amount === -1) {
$amount = (int)round($this->summarizeGoodsList());
} else {
$this->_checkAmount($amount);
}
if ($amount < 0) {
throw new Klarna_InvalidPriceException($amount);
}
//No addresses used for phone transactions
if ($flags & KlarnaFlags::RSRV_PHONE_TRANSACTION) {
$billing = $shipping = '';
} else {
$billing = $this->assembleAddr($this->billing);
$shipping = $this->assembleAddr($this->shipping);
if (strlen($shipping['country']) > 0
&& ($shipping['country'] !== $this->_country)
) {
throw new Klarna_ShippingCountryException;
}
}
//Assume normal shipment unless otherwise specified.
if (!isset($this->shipInfo['delay_adjust'])) {
$this->setShipmentInfo('delay_adjust', KlarnaFlags::NORMAL_SHIPMENT);
}
//Make sure we get any session ID's or similar
$this->initCheckout($this, $this->_eid);
$digestSecret = self::digest(
"{$this->_eid}:{$pno}:{$amount}:{$this->_secret}"
);
$paramList = array(
$pno,
$gender,
$amount,
$this->reference,
$this->reference_code,
$this->orderid[0],
$this->orderid[1],
$shipping,
$billing,
$this->getClientIP(),
$flags,
$this->_currency,
$this->_country,
$this->_language,
$this->_eid,
$digestSecret,
$encoding, $pclass,
$this->goodsList,
$this->comment,
$this->shipInfo,
$this->travelInfo,
$this->incomeInfo,
$this->bankInfo,
$this->sid,
$this->extraInfo
);
self::printDebug('reserve_amount', $paramList);
$result = $this->xmlrpc_call('reserve_amount', $paramList);
if ($clear === true) {
//Make sure any stored values that need to be unique between
//purchases are cleared.
foreach ($this->coObjects as $co) {
$co->clear();
}
$this->clear();
}
self::printDebug('reserve_amount result', $result);
return $result;
} | [
"public",
"function",
"reserveAmount",
"(",
"$",
"pno",
",",
"$",
"gender",
",",
"$",
"amount",
",",
"$",
"flags",
"=",
"0",
",",
"$",
"pclass",
"=",
"KlarnaPClass",
"::",
"INVOICE",
",",
"$",
"encoding",
"=",
"null",
",",
"$",
"clear",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"_checkLocale",
"(",
")",
";",
"//Get the PNO/SSN encoding constant.",
"if",
"(",
"$",
"encoding",
"===",
"null",
")",
"{",
"$",
"encoding",
"=",
"$",
"this",
"->",
"getPNOEncoding",
"(",
")",
";",
"}",
"$",
"this",
"->",
"_checkPNO",
"(",
"$",
"pno",
",",
"$",
"encoding",
")",
";",
"if",
"(",
"$",
"gender",
"===",
"'m'",
")",
"{",
"$",
"gender",
"=",
"KlarnaFlags",
"::",
"MALE",
";",
"}",
"else",
"if",
"(",
"$",
"gender",
"===",
"'f'",
")",
"{",
"$",
"gender",
"=",
"KlarnaFlags",
"::",
"FEMALE",
";",
"}",
"if",
"(",
"$",
"gender",
"!==",
"null",
"&&",
"strlen",
"(",
"$",
"gender",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"_checkInt",
"(",
"$",
"gender",
",",
"'gender'",
")",
";",
"}",
"$",
"this",
"->",
"_checkInt",
"(",
"$",
"flags",
",",
"'flags'",
")",
";",
"$",
"this",
"->",
"_checkInt",
"(",
"$",
"pclass",
",",
"'pclass'",
")",
";",
"//Check so required information is set.",
"$",
"this",
"->",
"_checkGoodslist",
"(",
")",
";",
"//Calculate automatically the amount from goodsList.",
"if",
"(",
"$",
"amount",
"===",
"-",
"1",
")",
"{",
"$",
"amount",
"=",
"(",
"int",
")",
"round",
"(",
"$",
"this",
"->",
"summarizeGoodsList",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_checkAmount",
"(",
"$",
"amount",
")",
";",
"}",
"if",
"(",
"$",
"amount",
"<",
"0",
")",
"{",
"throw",
"new",
"Klarna_InvalidPriceException",
"(",
"$",
"amount",
")",
";",
"}",
"//No addresses used for phone transactions",
"if",
"(",
"$",
"flags",
"&",
"KlarnaFlags",
"::",
"RSRV_PHONE_TRANSACTION",
")",
"{",
"$",
"billing",
"=",
"$",
"shipping",
"=",
"''",
";",
"}",
"else",
"{",
"$",
"billing",
"=",
"$",
"this",
"->",
"assembleAddr",
"(",
"$",
"this",
"->",
"billing",
")",
";",
"$",
"shipping",
"=",
"$",
"this",
"->",
"assembleAddr",
"(",
"$",
"this",
"->",
"shipping",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"shipping",
"[",
"'country'",
"]",
")",
">",
"0",
"&&",
"(",
"$",
"shipping",
"[",
"'country'",
"]",
"!==",
"$",
"this",
"->",
"_country",
")",
")",
"{",
"throw",
"new",
"Klarna_ShippingCountryException",
";",
"}",
"}",
"//Assume normal shipment unless otherwise specified.",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"shipInfo",
"[",
"'delay_adjust'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setShipmentInfo",
"(",
"'delay_adjust'",
",",
"KlarnaFlags",
"::",
"NORMAL_SHIPMENT",
")",
";",
"}",
"//Make sure we get any session ID's or similar",
"$",
"this",
"->",
"initCheckout",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"_eid",
")",
";",
"$",
"digestSecret",
"=",
"self",
"::",
"digest",
"(",
"\"{$this->_eid}:{$pno}:{$amount}:{$this->_secret}\"",
")",
";",
"$",
"paramList",
"=",
"array",
"(",
"$",
"pno",
",",
"$",
"gender",
",",
"$",
"amount",
",",
"$",
"this",
"->",
"reference",
",",
"$",
"this",
"->",
"reference_code",
",",
"$",
"this",
"->",
"orderid",
"[",
"0",
"]",
",",
"$",
"this",
"->",
"orderid",
"[",
"1",
"]",
",",
"$",
"shipping",
",",
"$",
"billing",
",",
"$",
"this",
"->",
"getClientIP",
"(",
")",
",",
"$",
"flags",
",",
"$",
"this",
"->",
"_currency",
",",
"$",
"this",
"->",
"_country",
",",
"$",
"this",
"->",
"_language",
",",
"$",
"this",
"->",
"_eid",
",",
"$",
"digestSecret",
",",
"$",
"encoding",
",",
"$",
"pclass",
",",
"$",
"this",
"->",
"goodsList",
",",
"$",
"this",
"->",
"comment",
",",
"$",
"this",
"->",
"shipInfo",
",",
"$",
"this",
"->",
"travelInfo",
",",
"$",
"this",
"->",
"incomeInfo",
",",
"$",
"this",
"->",
"bankInfo",
",",
"$",
"this",
"->",
"sid",
",",
"$",
"this",
"->",
"extraInfo",
")",
";",
"self",
"::",
"printDebug",
"(",
"'reserve_amount'",
",",
"$",
"paramList",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'reserve_amount'",
",",
"$",
"paramList",
")",
";",
"if",
"(",
"$",
"clear",
"===",
"true",
")",
"{",
"//Make sure any stored values that need to be unique between",
"//purchases are cleared.",
"foreach",
"(",
"$",
"this",
"->",
"coObjects",
"as",
"$",
"co",
")",
"{",
"$",
"co",
"->",
"clear",
"(",
")",
";",
"}",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"}",
"self",
"::",
"printDebug",
"(",
"'reserve_amount result'",
",",
"$",
"result",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Reserves a purchase amount for a specific customer. <br>
The reservation is valid, by default, for 7 days.<br>
<b>This method returns an array with</b>:<br>
A reservation number (rno)<br>
Order status flag<br>
<b>Order status can be</b>:<br>
{@link KlarnaFlags::ACCEPTED}<br>
{@link KlarnaFlags::PENDING}<br>
{@link KlarnaFlags::DENIED}<br>
<b>Please note</b>:<br>
Activation must be done with activate_reservation, i.e. you cannot
activate through Klarna Online.
Gender is only required for Germany and Netherlands.<br>
<b>Flags can be set to</b>:<br>
{@link KlarnaFlags::NO_FLAG}<br>
{@link KlarnaFlags::TEST_MODE}<br>
{@link KlarnaFlags::RSRV_SENSITIVE_ORDER}<br>
{@link KlarnaFlags::RSRV_PHONE_TRANSACTION}<br>
{@link KlarnaFlags::RSRV_SEND_PHONE_PIN}<br>
Some flags can be added to each other for multiple options.
<b>Note</b>:<br>
Normal shipment type is assumed unless otherwise specified, you can do
this by calling:<br>
{@link Klarna::setShipmentInfo() setShipmentInfo('delay_adjust', ...)}
with either: {@link KlarnaFlags::NORMAL_SHIPMENT NORMAL_SHIPMENT} or
{@link KlarnaFlags::EXPRESS_SHIPMENT EXPRESS_SHIPMENT}<br>
@param string $pno Personal number, SSN, date of birth, etc.
@param int $gender {@link KlarnaFlags::FEMALE} or
{@link KlarnaFlags::MALE}, null for unspecified.
@param int $amount Amount to be reserved, including VAT.
@param int $flags Options which affect the behaviour.
@param int $pclass {@link KlarnaPClass::getId() PClass ID}.
@param int $encoding {@link KlarnaEncoding PNO Encoding} constant.
@param bool $clear Whether customer info should be cleared after
this call.
@throws KlarnaException
@return array An array with reservation number and order
status. [string, int] | [
"Reserves",
"a",
"purchase",
"amount",
"for",
"a",
"specific",
"customer",
".",
"<br",
">",
"The",
"reservation",
"is",
"valid",
"by",
"default",
"for",
"7",
"days",
".",
"<br",
">"
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L1875-L1985 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.cancelReservation | public function cancelReservation($rno)
{
$this->_checkRNO($rno);
$digestSecret = self::digest(
$this->colon($this->_eid, $rno, $this->_secret)
);
$paramList = array(
$rno,
$this->_eid,
$digestSecret
);
self::printDebug('cancel_reservation', $paramList);
$result = $this->xmlrpc_call('cancel_reservation', $paramList);
return ($result == 'ok');
} | php | public function cancelReservation($rno)
{
$this->_checkRNO($rno);
$digestSecret = self::digest(
$this->colon($this->_eid, $rno, $this->_secret)
);
$paramList = array(
$rno,
$this->_eid,
$digestSecret
);
self::printDebug('cancel_reservation', $paramList);
$result = $this->xmlrpc_call('cancel_reservation', $paramList);
return ($result == 'ok');
} | [
"public",
"function",
"cancelReservation",
"(",
"$",
"rno",
")",
"{",
"$",
"this",
"->",
"_checkRNO",
"(",
"$",
"rno",
")",
";",
"$",
"digestSecret",
"=",
"self",
"::",
"digest",
"(",
"$",
"this",
"->",
"colon",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"rno",
",",
"$",
"this",
"->",
"_secret",
")",
")",
";",
"$",
"paramList",
"=",
"array",
"(",
"$",
"rno",
",",
"$",
"this",
"->",
"_eid",
",",
"$",
"digestSecret",
")",
";",
"self",
"::",
"printDebug",
"(",
"'cancel_reservation'",
",",
"$",
"paramList",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'cancel_reservation'",
",",
"$",
"paramList",
")",
";",
"return",
"(",
"$",
"result",
"==",
"'ok'",
")",
";",
"}"
] | Cancels a reservation.
@param string $rno Reservation number.
@throws KlarnaException
@return bool True, if the cancellation was successful. | [
"Cancels",
"a",
"reservation",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L1996-L2014 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.changeReservation | public function changeReservation(
$rno, $amount, $flags = KlarnaFlags::NEW_AMOUNT
) {
$this->_checkRNO($rno);
$this->_checkAmount($amount);
$this->_checkInt($flags, 'flags');
$digestSecret = self::digest(
$this->colon($this->_eid, $rno, $amount, $this->_secret)
);
$paramList = array(
$rno,
$amount,
$this->_eid,
$digestSecret,
$flags
);
self::printDebug('change_reservation', $paramList);
$result = $this->xmlrpc_call('change_reservation', $paramList);
return ($result == 'ok') ? true : false;
} | php | public function changeReservation(
$rno, $amount, $flags = KlarnaFlags::NEW_AMOUNT
) {
$this->_checkRNO($rno);
$this->_checkAmount($amount);
$this->_checkInt($flags, 'flags');
$digestSecret = self::digest(
$this->colon($this->_eid, $rno, $amount, $this->_secret)
);
$paramList = array(
$rno,
$amount,
$this->_eid,
$digestSecret,
$flags
);
self::printDebug('change_reservation', $paramList);
$result = $this->xmlrpc_call('change_reservation', $paramList);
return ($result == 'ok') ? true : false;
} | [
"public",
"function",
"changeReservation",
"(",
"$",
"rno",
",",
"$",
"amount",
",",
"$",
"flags",
"=",
"KlarnaFlags",
"::",
"NEW_AMOUNT",
")",
"{",
"$",
"this",
"->",
"_checkRNO",
"(",
"$",
"rno",
")",
";",
"$",
"this",
"->",
"_checkAmount",
"(",
"$",
"amount",
")",
";",
"$",
"this",
"->",
"_checkInt",
"(",
"$",
"flags",
",",
"'flags'",
")",
";",
"$",
"digestSecret",
"=",
"self",
"::",
"digest",
"(",
"$",
"this",
"->",
"colon",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"rno",
",",
"$",
"amount",
",",
"$",
"this",
"->",
"_secret",
")",
")",
";",
"$",
"paramList",
"=",
"array",
"(",
"$",
"rno",
",",
"$",
"amount",
",",
"$",
"this",
"->",
"_eid",
",",
"$",
"digestSecret",
",",
"$",
"flags",
")",
";",
"self",
"::",
"printDebug",
"(",
"'change_reservation'",
",",
"$",
"paramList",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'change_reservation'",
",",
"$",
"paramList",
")",
";",
"return",
"(",
"$",
"result",
"==",
"'ok'",
")",
"?",
"true",
":",
"false",
";",
"}"
] | Changes specified reservation to a new amount.
<b>Flags can be either of these</b>:<br>
{@link KlarnaFlags::NEW_AMOUNT}<br>
{@link KlarnaFlags::ADD_AMOUNT}<br>
@param string $rno Reservation number.
@param int $amount Amount including VAT.
@param int $flags Options which affect the behaviour.
@throws KlarnaException
@return bool True, if the change was successful. | [
"Changes",
"specified",
"reservation",
"to",
"a",
"new",
"amount",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L2031-L2054 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.update | public function update($rno, $clear = true)
{
$rno = strval($rno);
// All info that is sent in is part of the digest secret, in this order:
// [
// proto_vsn, client_vsn, eid, rno, careof, street, zip, city,
// country, fname, lname, careof, street, zip, city, country,
// fname, lname, artno, qty, orderid1, orderid2
// ].
// The address part appears twice, that is one per address that
// changes. If no value is sent in for an optional field, there
// is no entry for this field in the digest secret. Shared secret
// is added at the end of the digest secret.
$digestArray = array(
str_replace('.', ':', $this->PROTO),
$this->VERSION,
$this->_eid,
$rno
);
$digestArray = array_merge(
$digestArray, $this->_addressDigestPart($this->shipping)
);
$digestArray = array_merge(
$digestArray, $this->_addressDigestPart($this->billing)
);
if (is_array($this->goodsList) && $this->goodsList !== array()) {
foreach ($this->goodsList as $goods) {
if (strlen($goods["goods"]["artno"]) > 0) {
$digestArray[] = $goods["goods"]["artno"];
} else {
$digestArray[] = $goods["goods"]["title"];
}
$digestArray[] = $goods["qty"];
}
}
foreach ($this->orderid as $orderid) {
$digestArray[] = $orderid;
}
$digestArray[] = $this->_secret;
$digestSecret = $this->digest(
call_user_func_array(
array('self', 'colon'), $digestArray
)
);
$shipping = array();
$billing = array();
if ($this->shipping !== null && $this->shipping instanceof KlarnaAddr) {
$shipping = $this->shipping->toArray();
}
if ($this->billing !== null && $this->billing instanceof KlarnaAddr) {
$billing = $this->billing->toArray();
}
$paramList = array(
$this->_eid,
$digestSecret,
$rno,
array(
'goods_list' => $this->goodsList,
'dlv_addr' => $shipping,
'bill_addr' => $billing,
'orderid1' => $this->orderid[0],
'orderid2' => $this->orderid[1]
)
);
self::printDebug('update array', $paramList);
$result = $this->xmlrpc_call('update', $paramList);
self::printDebug('update result', $result);
return ($result === 'ok');
} | php | public function update($rno, $clear = true)
{
$rno = strval($rno);
// All info that is sent in is part of the digest secret, in this order:
// [
// proto_vsn, client_vsn, eid, rno, careof, street, zip, city,
// country, fname, lname, careof, street, zip, city, country,
// fname, lname, artno, qty, orderid1, orderid2
// ].
// The address part appears twice, that is one per address that
// changes. If no value is sent in for an optional field, there
// is no entry for this field in the digest secret. Shared secret
// is added at the end of the digest secret.
$digestArray = array(
str_replace('.', ':', $this->PROTO),
$this->VERSION,
$this->_eid,
$rno
);
$digestArray = array_merge(
$digestArray, $this->_addressDigestPart($this->shipping)
);
$digestArray = array_merge(
$digestArray, $this->_addressDigestPart($this->billing)
);
if (is_array($this->goodsList) && $this->goodsList !== array()) {
foreach ($this->goodsList as $goods) {
if (strlen($goods["goods"]["artno"]) > 0) {
$digestArray[] = $goods["goods"]["artno"];
} else {
$digestArray[] = $goods["goods"]["title"];
}
$digestArray[] = $goods["qty"];
}
}
foreach ($this->orderid as $orderid) {
$digestArray[] = $orderid;
}
$digestArray[] = $this->_secret;
$digestSecret = $this->digest(
call_user_func_array(
array('self', 'colon'), $digestArray
)
);
$shipping = array();
$billing = array();
if ($this->shipping !== null && $this->shipping instanceof KlarnaAddr) {
$shipping = $this->shipping->toArray();
}
if ($this->billing !== null && $this->billing instanceof KlarnaAddr) {
$billing = $this->billing->toArray();
}
$paramList = array(
$this->_eid,
$digestSecret,
$rno,
array(
'goods_list' => $this->goodsList,
'dlv_addr' => $shipping,
'bill_addr' => $billing,
'orderid1' => $this->orderid[0],
'orderid2' => $this->orderid[1]
)
);
self::printDebug('update array', $paramList);
$result = $this->xmlrpc_call('update', $paramList);
self::printDebug('update result', $result);
return ($result === 'ok');
} | [
"public",
"function",
"update",
"(",
"$",
"rno",
",",
"$",
"clear",
"=",
"true",
")",
"{",
"$",
"rno",
"=",
"strval",
"(",
"$",
"rno",
")",
";",
"// All info that is sent in is part of the digest secret, in this order:",
"// [",
"// proto_vsn, client_vsn, eid, rno, careof, street, zip, city,",
"// country, fname, lname, careof, street, zip, city, country,",
"// fname, lname, artno, qty, orderid1, orderid2",
"// ].",
"// The address part appears twice, that is one per address that",
"// changes. If no value is sent in for an optional field, there",
"// is no entry for this field in the digest secret. Shared secret",
"// is added at the end of the digest secret.",
"$",
"digestArray",
"=",
"array",
"(",
"str_replace",
"(",
"'.'",
",",
"':'",
",",
"$",
"this",
"->",
"PROTO",
")",
",",
"$",
"this",
"->",
"VERSION",
",",
"$",
"this",
"->",
"_eid",
",",
"$",
"rno",
")",
";",
"$",
"digestArray",
"=",
"array_merge",
"(",
"$",
"digestArray",
",",
"$",
"this",
"->",
"_addressDigestPart",
"(",
"$",
"this",
"->",
"shipping",
")",
")",
";",
"$",
"digestArray",
"=",
"array_merge",
"(",
"$",
"digestArray",
",",
"$",
"this",
"->",
"_addressDigestPart",
"(",
"$",
"this",
"->",
"billing",
")",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"goodsList",
")",
"&&",
"$",
"this",
"->",
"goodsList",
"!==",
"array",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"goodsList",
"as",
"$",
"goods",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"goods",
"[",
"\"goods\"",
"]",
"[",
"\"artno\"",
"]",
")",
">",
"0",
")",
"{",
"$",
"digestArray",
"[",
"]",
"=",
"$",
"goods",
"[",
"\"goods\"",
"]",
"[",
"\"artno\"",
"]",
";",
"}",
"else",
"{",
"$",
"digestArray",
"[",
"]",
"=",
"$",
"goods",
"[",
"\"goods\"",
"]",
"[",
"\"title\"",
"]",
";",
"}",
"$",
"digestArray",
"[",
"]",
"=",
"$",
"goods",
"[",
"\"qty\"",
"]",
";",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"orderid",
"as",
"$",
"orderid",
")",
"{",
"$",
"digestArray",
"[",
"]",
"=",
"$",
"orderid",
";",
"}",
"$",
"digestArray",
"[",
"]",
"=",
"$",
"this",
"->",
"_secret",
";",
"$",
"digestSecret",
"=",
"$",
"this",
"->",
"digest",
"(",
"call_user_func_array",
"(",
"array",
"(",
"'self'",
",",
"'colon'",
")",
",",
"$",
"digestArray",
")",
")",
";",
"$",
"shipping",
"=",
"array",
"(",
")",
";",
"$",
"billing",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"shipping",
"!==",
"null",
"&&",
"$",
"this",
"->",
"shipping",
"instanceof",
"KlarnaAddr",
")",
"{",
"$",
"shipping",
"=",
"$",
"this",
"->",
"shipping",
"->",
"toArray",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"billing",
"!==",
"null",
"&&",
"$",
"this",
"->",
"billing",
"instanceof",
"KlarnaAddr",
")",
"{",
"$",
"billing",
"=",
"$",
"this",
"->",
"billing",
"->",
"toArray",
"(",
")",
";",
"}",
"$",
"paramList",
"=",
"array",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"digestSecret",
",",
"$",
"rno",
",",
"array",
"(",
"'goods_list'",
"=>",
"$",
"this",
"->",
"goodsList",
",",
"'dlv_addr'",
"=>",
"$",
"shipping",
",",
"'bill_addr'",
"=>",
"$",
"billing",
",",
"'orderid1'",
"=>",
"$",
"this",
"->",
"orderid",
"[",
"0",
"]",
",",
"'orderid2'",
"=>",
"$",
"this",
"->",
"orderid",
"[",
"1",
"]",
")",
")",
";",
"self",
"::",
"printDebug",
"(",
"'update array'",
",",
"$",
"paramList",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'update'",
",",
"$",
"paramList",
")",
";",
"self",
"::",
"printDebug",
"(",
"'update result'",
",",
"$",
"result",
")",
";",
"return",
"(",
"$",
"result",
"===",
"'ok'",
")",
";",
"}"
] | Update the reservation matching the given reservation number.
@param string $rno Reservation number
@param boolean $clear clear set data aftre updating. Defaulted to true.
@throws KlarnaException if no RNO is given, or if an error is recieved
from Klarna Online.
@return true if the update was successful | [
"Update",
"the",
"reservation",
"matching",
"the",
"given",
"reservation",
"number",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L2067-L2142 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna._addressDigestPart | private function _addressDigestPart(KlarnaAddr $address = null)
{
if ($address === null) {
return array();
}
$keyOrder = array(
'careof', 'street', 'zip', 'city', 'country', 'fname', 'lname'
);
$holder = $address->toArray();
$digest = array();
foreach ($keyOrder as $key) {
if ($holder[$key] != "") {
$digest[] = $holder[$key];
}
}
return $digest;
} | php | private function _addressDigestPart(KlarnaAddr $address = null)
{
if ($address === null) {
return array();
}
$keyOrder = array(
'careof', 'street', 'zip', 'city', 'country', 'fname', 'lname'
);
$holder = $address->toArray();
$digest = array();
foreach ($keyOrder as $key) {
if ($holder[$key] != "") {
$digest[] = $holder[$key];
}
}
return $digest;
} | [
"private",
"function",
"_addressDigestPart",
"(",
"KlarnaAddr",
"$",
"address",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"address",
"===",
"null",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"keyOrder",
"=",
"array",
"(",
"'careof'",
",",
"'street'",
",",
"'zip'",
",",
"'city'",
",",
"'country'",
",",
"'fname'",
",",
"'lname'",
")",
";",
"$",
"holder",
"=",
"$",
"address",
"->",
"toArray",
"(",
")",
";",
"$",
"digest",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"keyOrder",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"holder",
"[",
"$",
"key",
"]",
"!=",
"\"\"",
")",
"{",
"$",
"digest",
"[",
"]",
"=",
"$",
"holder",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"return",
"$",
"digest",
";",
"}"
] | Help function to sort the address for update digest.
@param KlarnaAddr|null $address KlarnaAddr object or null
@return array | [
"Help",
"function",
"to",
"sort",
"the",
"address",
"for",
"update",
"digest",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L2151-L2171 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.activate | public function activate(
$rno, $ocr = null, $flags = null, $clear = true
) {
$this->_checkRNO($rno);
// Overwrite any OCR set on activateInfo if supplied here since this
// method call is more specific.
if ($ocr !== null) {
$this->setActivateInfo('ocr', $ocr);
}
// If flags is specified set the flag supplied here to activateInfo.
if ($flags !== null) {
$this->setActivateInfo('flags', $flags);
}
//Assume normal shipment unless otherwise specified.
if (!array_key_exists('delay_adjust', $this->shipInfo)) {
$this->setShipmentInfo('delay_adjust', KlarnaFlags::NORMAL_SHIPMENT);
}
// Append shipment info to activateInfo
$this->activateInfo['shipment_info'] = $this->shipInfo;
// Unlike other calls, if NO_FLAG is specified it should not be sent in
// at all.
if (array_key_exists('flags', $this->activateInfo)
&& $this->activateInfo['flags'] === KlarnaFlags::NO_FLAG
) {
unset($this->activateInfo['flags']);
}
// Build digest. Any field in activateInfo that is set is included in
// the digest.
$digestArray = array(
str_replace('.', ':', $this->PROTO),
$this->VERSION,
$this->_eid,
$rno
);
$optionalDigestKeys = array(
'bclass',
'cust_no',
'flags',
'ocr',
'orderid1',
'orderid2',
'reference',
'reference_code'
);
foreach ($optionalDigestKeys as $key) {
if (array_key_exists($key, $this->activateInfo)) {
$digestArray[] = $this->activateInfo[$key];
}
}
if (array_key_exists('delay_adjust', $this->activateInfo['shipment_info'])) {
$digestArray[] = $this->activateInfo['shipment_info']['delay_adjust'];
}
// If there are any artnos added with addArtNo, add them to the digest
// and to the activateInfo
if (is_array($this->artNos)) {
foreach ($this->artNos as $artNo) {
$digestArray[] = $artNo['artno'];
$digestArray[] = $artNo['qty'];
}
$this->setActivateInfo('artnos', $this->artNos);
}
$digestArray[] = $this->_secret;
$digestSecret = self::digest(
call_user_func_array(
array('self', 'colon'), $digestArray
)
);
// Create the parameter list.
$paramList = array(
$this->_eid,
$digestSecret,
$rno,
$this->activateInfo
);
self::printDebug('activate array', $paramList);
$result = $this->xmlrpc_call('activate', $paramList);
self::printDebug('activate result', $result);
// Clear the state if specified.
if ($clear) {
$this->clear();
}
return $result;
} | php | public function activate(
$rno, $ocr = null, $flags = null, $clear = true
) {
$this->_checkRNO($rno);
// Overwrite any OCR set on activateInfo if supplied here since this
// method call is more specific.
if ($ocr !== null) {
$this->setActivateInfo('ocr', $ocr);
}
// If flags is specified set the flag supplied here to activateInfo.
if ($flags !== null) {
$this->setActivateInfo('flags', $flags);
}
//Assume normal shipment unless otherwise specified.
if (!array_key_exists('delay_adjust', $this->shipInfo)) {
$this->setShipmentInfo('delay_adjust', KlarnaFlags::NORMAL_SHIPMENT);
}
// Append shipment info to activateInfo
$this->activateInfo['shipment_info'] = $this->shipInfo;
// Unlike other calls, if NO_FLAG is specified it should not be sent in
// at all.
if (array_key_exists('flags', $this->activateInfo)
&& $this->activateInfo['flags'] === KlarnaFlags::NO_FLAG
) {
unset($this->activateInfo['flags']);
}
// Build digest. Any field in activateInfo that is set is included in
// the digest.
$digestArray = array(
str_replace('.', ':', $this->PROTO),
$this->VERSION,
$this->_eid,
$rno
);
$optionalDigestKeys = array(
'bclass',
'cust_no',
'flags',
'ocr',
'orderid1',
'orderid2',
'reference',
'reference_code'
);
foreach ($optionalDigestKeys as $key) {
if (array_key_exists($key, $this->activateInfo)) {
$digestArray[] = $this->activateInfo[$key];
}
}
if (array_key_exists('delay_adjust', $this->activateInfo['shipment_info'])) {
$digestArray[] = $this->activateInfo['shipment_info']['delay_adjust'];
}
// If there are any artnos added with addArtNo, add them to the digest
// and to the activateInfo
if (is_array($this->artNos)) {
foreach ($this->artNos as $artNo) {
$digestArray[] = $artNo['artno'];
$digestArray[] = $artNo['qty'];
}
$this->setActivateInfo('artnos', $this->artNos);
}
$digestArray[] = $this->_secret;
$digestSecret = self::digest(
call_user_func_array(
array('self', 'colon'), $digestArray
)
);
// Create the parameter list.
$paramList = array(
$this->_eid,
$digestSecret,
$rno,
$this->activateInfo
);
self::printDebug('activate array', $paramList);
$result = $this->xmlrpc_call('activate', $paramList);
self::printDebug('activate result', $result);
// Clear the state if specified.
if ($clear) {
$this->clear();
}
return $result;
} | [
"public",
"function",
"activate",
"(",
"$",
"rno",
",",
"$",
"ocr",
"=",
"null",
",",
"$",
"flags",
"=",
"null",
",",
"$",
"clear",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"_checkRNO",
"(",
"$",
"rno",
")",
";",
"// Overwrite any OCR set on activateInfo if supplied here since this",
"// method call is more specific.",
"if",
"(",
"$",
"ocr",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"setActivateInfo",
"(",
"'ocr'",
",",
"$",
"ocr",
")",
";",
"}",
"// If flags is specified set the flag supplied here to activateInfo.",
"if",
"(",
"$",
"flags",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"setActivateInfo",
"(",
"'flags'",
",",
"$",
"flags",
")",
";",
"}",
"//Assume normal shipment unless otherwise specified.",
"if",
"(",
"!",
"array_key_exists",
"(",
"'delay_adjust'",
",",
"$",
"this",
"->",
"shipInfo",
")",
")",
"{",
"$",
"this",
"->",
"setShipmentInfo",
"(",
"'delay_adjust'",
",",
"KlarnaFlags",
"::",
"NORMAL_SHIPMENT",
")",
";",
"}",
"// Append shipment info to activateInfo",
"$",
"this",
"->",
"activateInfo",
"[",
"'shipment_info'",
"]",
"=",
"$",
"this",
"->",
"shipInfo",
";",
"// Unlike other calls, if NO_FLAG is specified it should not be sent in",
"// at all.",
"if",
"(",
"array_key_exists",
"(",
"'flags'",
",",
"$",
"this",
"->",
"activateInfo",
")",
"&&",
"$",
"this",
"->",
"activateInfo",
"[",
"'flags'",
"]",
"===",
"KlarnaFlags",
"::",
"NO_FLAG",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"activateInfo",
"[",
"'flags'",
"]",
")",
";",
"}",
"// Build digest. Any field in activateInfo that is set is included in",
"// the digest.",
"$",
"digestArray",
"=",
"array",
"(",
"str_replace",
"(",
"'.'",
",",
"':'",
",",
"$",
"this",
"->",
"PROTO",
")",
",",
"$",
"this",
"->",
"VERSION",
",",
"$",
"this",
"->",
"_eid",
",",
"$",
"rno",
")",
";",
"$",
"optionalDigestKeys",
"=",
"array",
"(",
"'bclass'",
",",
"'cust_no'",
",",
"'flags'",
",",
"'ocr'",
",",
"'orderid1'",
",",
"'orderid2'",
",",
"'reference'",
",",
"'reference_code'",
")",
";",
"foreach",
"(",
"$",
"optionalDigestKeys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"activateInfo",
")",
")",
"{",
"$",
"digestArray",
"[",
"]",
"=",
"$",
"this",
"->",
"activateInfo",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"if",
"(",
"array_key_exists",
"(",
"'delay_adjust'",
",",
"$",
"this",
"->",
"activateInfo",
"[",
"'shipment_info'",
"]",
")",
")",
"{",
"$",
"digestArray",
"[",
"]",
"=",
"$",
"this",
"->",
"activateInfo",
"[",
"'shipment_info'",
"]",
"[",
"'delay_adjust'",
"]",
";",
"}",
"// If there are any artnos added with addArtNo, add them to the digest",
"// and to the activateInfo",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"artNos",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"artNos",
"as",
"$",
"artNo",
")",
"{",
"$",
"digestArray",
"[",
"]",
"=",
"$",
"artNo",
"[",
"'artno'",
"]",
";",
"$",
"digestArray",
"[",
"]",
"=",
"$",
"artNo",
"[",
"'qty'",
"]",
";",
"}",
"$",
"this",
"->",
"setActivateInfo",
"(",
"'artnos'",
",",
"$",
"this",
"->",
"artNos",
")",
";",
"}",
"$",
"digestArray",
"[",
"]",
"=",
"$",
"this",
"->",
"_secret",
";",
"$",
"digestSecret",
"=",
"self",
"::",
"digest",
"(",
"call_user_func_array",
"(",
"array",
"(",
"'self'",
",",
"'colon'",
")",
",",
"$",
"digestArray",
")",
")",
";",
"// Create the parameter list.",
"$",
"paramList",
"=",
"array",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"digestSecret",
",",
"$",
"rno",
",",
"$",
"this",
"->",
"activateInfo",
")",
";",
"self",
"::",
"printDebug",
"(",
"'activate array'",
",",
"$",
"paramList",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'activate'",
",",
"$",
"paramList",
")",
";",
"self",
"::",
"printDebug",
"(",
"'activate result'",
",",
"$",
"result",
")",
";",
"// Clear the state if specified.",
"if",
"(",
"$",
"clear",
")",
"{",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Activate the reservation matching the given reservation number.
Optional information should be set in ActivateInfo.
To perform a partial activation, use the addArtNo function to specify
which items in the reservation to include in the activation.
@param string $rno Reservation number
@param string $ocr optional OCR number to attach to the reservation when
activating. Overrides OCR specified in activateInfo.
@param string $flags optional flags to affect behavior. If specified it
will overwrite any flag set in activateInfo.
@param boolean $clear clear set data after activating. Defaulted to true.
@throws KlarnaException when the RNO is not specified, or if an error
is recieved from Klarna Online.
@return A string array with risk status and reservation number. | [
"Activate",
"the",
"reservation",
"matching",
"the",
"given",
"reservation",
"number",
".",
"Optional",
"information",
"should",
"be",
"set",
"in",
"ActivateInfo",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L2191-L2290 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.activateReservation | public function activateReservation(
$pno, $rno, $gender, $ocr = "", $flags = KlarnaFlags::NO_FLAG,
$pclass = KlarnaPClass::INVOICE, $encoding = null, $clear = true
) {
$this->_checkLocale();
//Get the PNO/SSN encoding constant.
if ($encoding === null) {
$encoding = $this->getPNOEncoding();
}
// Only check PNO if it is not explicitly null.
if ($pno !== null) {
$this->_checkPNO($pno, $encoding);
}
$this->_checkRNO($rno);
if ($gender !== null && strlen($gender) > 0) {
$this->_checkInt($gender, 'gender');
}
$this->_checkOCR($ocr);
$this->_checkRef($this->reference, $this->reference_code);
$this->_checkGoodslist();
//No addresses used for phone transactions
$billing = $shipping = '';
if ( !($flags & KlarnaFlags::RSRV_PHONE_TRANSACTION) ) {
$billing = $this->assembleAddr($this->billing);
$shipping = $this->assembleAddr($this->shipping);
if (strlen($shipping['country']) > 0
&& ($shipping['country'] !== $this->_country)
) {
throw new Klarna_ShippingCountryException;
}
}
//activate digest
$string = $this->_eid . ":" . $pno . ":";
foreach ($this->goodsList as $goods) {
$string .= $goods["goods"]["artno"] . ":" . $goods["qty"] . ":";
}
$digestSecret = self::digest($string . $this->_secret);
//end digest
//Assume normal shipment unless otherwise specified.
if (!isset($this->shipInfo['delay_adjust'])) {
$this->setShipmentInfo('delay_adjust', KlarnaFlags::NORMAL_SHIPMENT);
}
$paramList = array(
$rno,
$ocr,
$pno,
$gender,
$this->reference,
$this->reference_code,
$this->orderid[0],
$this->orderid[1],
$shipping,
$billing,
"0.0.0.0",
$flags,
$this->_currency,
$this->_country,
$this->_language,
$this->_eid,
$digestSecret,
$encoding,
$pclass,
$this->goodsList,
$this->comment,
$this->shipInfo,
$this->travelInfo,
$this->incomeInfo,
$this->bankInfo,
$this->extraInfo
);
self::printDebug('activate_reservation', $paramList);
$result = $this->xmlrpc_call('activate_reservation', $paramList);
if ($clear === true) {
$this->clear();
}
self::printDebug('activate_reservation result', $result);
return $result;
} | php | public function activateReservation(
$pno, $rno, $gender, $ocr = "", $flags = KlarnaFlags::NO_FLAG,
$pclass = KlarnaPClass::INVOICE, $encoding = null, $clear = true
) {
$this->_checkLocale();
//Get the PNO/SSN encoding constant.
if ($encoding === null) {
$encoding = $this->getPNOEncoding();
}
// Only check PNO if it is not explicitly null.
if ($pno !== null) {
$this->_checkPNO($pno, $encoding);
}
$this->_checkRNO($rno);
if ($gender !== null && strlen($gender) > 0) {
$this->_checkInt($gender, 'gender');
}
$this->_checkOCR($ocr);
$this->_checkRef($this->reference, $this->reference_code);
$this->_checkGoodslist();
//No addresses used for phone transactions
$billing = $shipping = '';
if ( !($flags & KlarnaFlags::RSRV_PHONE_TRANSACTION) ) {
$billing = $this->assembleAddr($this->billing);
$shipping = $this->assembleAddr($this->shipping);
if (strlen($shipping['country']) > 0
&& ($shipping['country'] !== $this->_country)
) {
throw new Klarna_ShippingCountryException;
}
}
//activate digest
$string = $this->_eid . ":" . $pno . ":";
foreach ($this->goodsList as $goods) {
$string .= $goods["goods"]["artno"] . ":" . $goods["qty"] . ":";
}
$digestSecret = self::digest($string . $this->_secret);
//end digest
//Assume normal shipment unless otherwise specified.
if (!isset($this->shipInfo['delay_adjust'])) {
$this->setShipmentInfo('delay_adjust', KlarnaFlags::NORMAL_SHIPMENT);
}
$paramList = array(
$rno,
$ocr,
$pno,
$gender,
$this->reference,
$this->reference_code,
$this->orderid[0],
$this->orderid[1],
$shipping,
$billing,
"0.0.0.0",
$flags,
$this->_currency,
$this->_country,
$this->_language,
$this->_eid,
$digestSecret,
$encoding,
$pclass,
$this->goodsList,
$this->comment,
$this->shipInfo,
$this->travelInfo,
$this->incomeInfo,
$this->bankInfo,
$this->extraInfo
);
self::printDebug('activate_reservation', $paramList);
$result = $this->xmlrpc_call('activate_reservation', $paramList);
if ($clear === true) {
$this->clear();
}
self::printDebug('activate_reservation result', $result);
return $result;
} | [
"public",
"function",
"activateReservation",
"(",
"$",
"pno",
",",
"$",
"rno",
",",
"$",
"gender",
",",
"$",
"ocr",
"=",
"\"\"",
",",
"$",
"flags",
"=",
"KlarnaFlags",
"::",
"NO_FLAG",
",",
"$",
"pclass",
"=",
"KlarnaPClass",
"::",
"INVOICE",
",",
"$",
"encoding",
"=",
"null",
",",
"$",
"clear",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"_checkLocale",
"(",
")",
";",
"//Get the PNO/SSN encoding constant.",
"if",
"(",
"$",
"encoding",
"===",
"null",
")",
"{",
"$",
"encoding",
"=",
"$",
"this",
"->",
"getPNOEncoding",
"(",
")",
";",
"}",
"// Only check PNO if it is not explicitly null.",
"if",
"(",
"$",
"pno",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"_checkPNO",
"(",
"$",
"pno",
",",
"$",
"encoding",
")",
";",
"}",
"$",
"this",
"->",
"_checkRNO",
"(",
"$",
"rno",
")",
";",
"if",
"(",
"$",
"gender",
"!==",
"null",
"&&",
"strlen",
"(",
"$",
"gender",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"_checkInt",
"(",
"$",
"gender",
",",
"'gender'",
")",
";",
"}",
"$",
"this",
"->",
"_checkOCR",
"(",
"$",
"ocr",
")",
";",
"$",
"this",
"->",
"_checkRef",
"(",
"$",
"this",
"->",
"reference",
",",
"$",
"this",
"->",
"reference_code",
")",
";",
"$",
"this",
"->",
"_checkGoodslist",
"(",
")",
";",
"//No addresses used for phone transactions",
"$",
"billing",
"=",
"$",
"shipping",
"=",
"''",
";",
"if",
"(",
"!",
"(",
"$",
"flags",
"&",
"KlarnaFlags",
"::",
"RSRV_PHONE_TRANSACTION",
")",
")",
"{",
"$",
"billing",
"=",
"$",
"this",
"->",
"assembleAddr",
"(",
"$",
"this",
"->",
"billing",
")",
";",
"$",
"shipping",
"=",
"$",
"this",
"->",
"assembleAddr",
"(",
"$",
"this",
"->",
"shipping",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"shipping",
"[",
"'country'",
"]",
")",
">",
"0",
"&&",
"(",
"$",
"shipping",
"[",
"'country'",
"]",
"!==",
"$",
"this",
"->",
"_country",
")",
")",
"{",
"throw",
"new",
"Klarna_ShippingCountryException",
";",
"}",
"}",
"//activate digest",
"$",
"string",
"=",
"$",
"this",
"->",
"_eid",
".",
"\":\"",
".",
"$",
"pno",
".",
"\":\"",
";",
"foreach",
"(",
"$",
"this",
"->",
"goodsList",
"as",
"$",
"goods",
")",
"{",
"$",
"string",
".=",
"$",
"goods",
"[",
"\"goods\"",
"]",
"[",
"\"artno\"",
"]",
".",
"\":\"",
".",
"$",
"goods",
"[",
"\"qty\"",
"]",
".",
"\":\"",
";",
"}",
"$",
"digestSecret",
"=",
"self",
"::",
"digest",
"(",
"$",
"string",
".",
"$",
"this",
"->",
"_secret",
")",
";",
"//end digest",
"//Assume normal shipment unless otherwise specified.",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"shipInfo",
"[",
"'delay_adjust'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setShipmentInfo",
"(",
"'delay_adjust'",
",",
"KlarnaFlags",
"::",
"NORMAL_SHIPMENT",
")",
";",
"}",
"$",
"paramList",
"=",
"array",
"(",
"$",
"rno",
",",
"$",
"ocr",
",",
"$",
"pno",
",",
"$",
"gender",
",",
"$",
"this",
"->",
"reference",
",",
"$",
"this",
"->",
"reference_code",
",",
"$",
"this",
"->",
"orderid",
"[",
"0",
"]",
",",
"$",
"this",
"->",
"orderid",
"[",
"1",
"]",
",",
"$",
"shipping",
",",
"$",
"billing",
",",
"\"0.0.0.0\"",
",",
"$",
"flags",
",",
"$",
"this",
"->",
"_currency",
",",
"$",
"this",
"->",
"_country",
",",
"$",
"this",
"->",
"_language",
",",
"$",
"this",
"->",
"_eid",
",",
"$",
"digestSecret",
",",
"$",
"encoding",
",",
"$",
"pclass",
",",
"$",
"this",
"->",
"goodsList",
",",
"$",
"this",
"->",
"comment",
",",
"$",
"this",
"->",
"shipInfo",
",",
"$",
"this",
"->",
"travelInfo",
",",
"$",
"this",
"->",
"incomeInfo",
",",
"$",
"this",
"->",
"bankInfo",
",",
"$",
"this",
"->",
"extraInfo",
")",
";",
"self",
"::",
"printDebug",
"(",
"'activate_reservation'",
",",
"$",
"paramList",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'activate_reservation'",
",",
"$",
"paramList",
")",
";",
"if",
"(",
"$",
"clear",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"}",
"self",
"::",
"printDebug",
"(",
"'activate_reservation result'",
",",
"$",
"result",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Activates a previously created reservation.
<b>This method returns an array with</b>:<br>
Risk status ("no_risk", "ok")<br>
Invoice number<br>
Gender is only required for Germany and Netherlands.<br>
Use of the OCR parameter is optional.
An OCR number can be retrieved by using: {@link Klarna::reserveOCR()}.
<b>Flags can be set to</b>:<br>
{@link KlarnaFlags::NO_FLAG}<br>
{@link KlarnaFlags::TEST_MODE}<br>
{@link KlarnaFlags::RSRV_SEND_BY_MAIL}<br>
{@link KlarnaFlags::RSRV_SEND_BY_EMAIL}<br>
{@link KlarnaFlags::RSRV_PRESERVE_RESERVATION}<br>
{@link KlarnaFlags::RSRV_SENSITIVE_ORDER}<br>
Some flags can be added to each other for multiple options.
<b>Note</b>:<br>
Normal shipment type is assumed unless otherwise specified, you can
do this by calling:
{@link Klarna::setShipmentInfo() setShipmentInfo('delay_adjust', ...)}
with either: {@link KlarnaFlags::NORMAL_SHIPMENT NORMAL_SHIPMENT} or
{@link KlarnaFlags::EXPRESS_SHIPMENT EXPRESS_SHIPMENT}<br>
@param string $pno Personal number, SSN, date of birth, etc.
@param string $rno Reservation number.
@param int $gender {@link KlarnaFlags::FEMALE} or
{@link KlarnaFlags::MALE}, null for unspecified.
@param string $ocr A OCR number.
@param int $flags Options which affect the behaviour.
@param int $pclass {@link KlarnaPClass::getId() PClass ID}.
@param int $encoding {@link KlarnaEncoding PNO Encoding} constant.
@param bool $clear Whether customer info should be cleared after
this call.
@see Klarna::reserveAmount()
@throws KlarnaException
@return array An array with risk status and invoice number [string, string]. | [
"Activates",
"a",
"previously",
"created",
"reservation",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L2337-L2430 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.splitReservation | public function splitReservation(
$rno, $amount, $flags = KlarnaFlags::NO_FLAG
) {
//Check so required information is set.
$this->_checkRNO($rno);
$this->_checkAmount($amount);
if ($amount <= 0) {
throw new Klarna_InvalidPriceException($amount);
}
$digestSecret = self::digest(
$this->colon($this->_eid, $rno, $amount, $this->_secret)
);
$paramList = array(
$rno,
$amount,
$this->orderid[0],
$this->orderid[1],
$flags,
$this->_eid,
$digestSecret
);
self::printDebug('split_reservation array', $paramList);
$result = $this->xmlrpc_call('split_reservation', $paramList);
self::printDebug('split_reservation result', $result);
return $result;
} | php | public function splitReservation(
$rno, $amount, $flags = KlarnaFlags::NO_FLAG
) {
//Check so required information is set.
$this->_checkRNO($rno);
$this->_checkAmount($amount);
if ($amount <= 0) {
throw new Klarna_InvalidPriceException($amount);
}
$digestSecret = self::digest(
$this->colon($this->_eid, $rno, $amount, $this->_secret)
);
$paramList = array(
$rno,
$amount,
$this->orderid[0],
$this->orderid[1],
$flags,
$this->_eid,
$digestSecret
);
self::printDebug('split_reservation array', $paramList);
$result = $this->xmlrpc_call('split_reservation', $paramList);
self::printDebug('split_reservation result', $result);
return $result;
} | [
"public",
"function",
"splitReservation",
"(",
"$",
"rno",
",",
"$",
"amount",
",",
"$",
"flags",
"=",
"KlarnaFlags",
"::",
"NO_FLAG",
")",
"{",
"//Check so required information is set.",
"$",
"this",
"->",
"_checkRNO",
"(",
"$",
"rno",
")",
";",
"$",
"this",
"->",
"_checkAmount",
"(",
"$",
"amount",
")",
";",
"if",
"(",
"$",
"amount",
"<=",
"0",
")",
"{",
"throw",
"new",
"Klarna_InvalidPriceException",
"(",
"$",
"amount",
")",
";",
"}",
"$",
"digestSecret",
"=",
"self",
"::",
"digest",
"(",
"$",
"this",
"->",
"colon",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"rno",
",",
"$",
"amount",
",",
"$",
"this",
"->",
"_secret",
")",
")",
";",
"$",
"paramList",
"=",
"array",
"(",
"$",
"rno",
",",
"$",
"amount",
",",
"$",
"this",
"->",
"orderid",
"[",
"0",
"]",
",",
"$",
"this",
"->",
"orderid",
"[",
"1",
"]",
",",
"$",
"flags",
",",
"$",
"this",
"->",
"_eid",
",",
"$",
"digestSecret",
")",
";",
"self",
"::",
"printDebug",
"(",
"'split_reservation array'",
",",
"$",
"paramList",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'split_reservation'",
",",
"$",
"paramList",
")",
";",
"self",
"::",
"printDebug",
"(",
"'split_reservation result'",
",",
"$",
"result",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Splits a reservation due to for example outstanding articles.
<b>For flags usage see</b>:<br>
{@link Klarna::reserveAmount()}<br>
@param string $rno Reservation number.
@param int $amount The amount to be subtracted from the reservation.
@param int $flags Options which affect the behaviour.
@throws KlarnaException
@return string A new reservation number. | [
"Splits",
"a",
"reservation",
"due",
"to",
"for",
"example",
"outstanding",
"articles",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L2447-L2478 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.reserveOCR | public function reserveOCR($no, $country = null)
{
$this->_checkNo($no);
if ($country === null) {
if (!$this->_country) {
throw new Klarna_MissingCountryException;
}
$country = $this->_country;
} else {
$this->_checkCountry($country);
}
$digestSecret = self::digest(
$this->colon($this->_eid, $no, $this->_secret)
);
$paramList = array(
$no,
$this->_eid,
$digestSecret,
$country
);
self::printDebug('reserve_ocr_nums array', $paramList);
return $this->xmlrpc_call('reserve_ocr_nums', $paramList);
} | php | public function reserveOCR($no, $country = null)
{
$this->_checkNo($no);
if ($country === null) {
if (!$this->_country) {
throw new Klarna_MissingCountryException;
}
$country = $this->_country;
} else {
$this->_checkCountry($country);
}
$digestSecret = self::digest(
$this->colon($this->_eid, $no, $this->_secret)
);
$paramList = array(
$no,
$this->_eid,
$digestSecret,
$country
);
self::printDebug('reserve_ocr_nums array', $paramList);
return $this->xmlrpc_call('reserve_ocr_nums', $paramList);
} | [
"public",
"function",
"reserveOCR",
"(",
"$",
"no",
",",
"$",
"country",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"_checkNo",
"(",
"$",
"no",
")",
";",
"if",
"(",
"$",
"country",
"===",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_country",
")",
"{",
"throw",
"new",
"Klarna_MissingCountryException",
";",
"}",
"$",
"country",
"=",
"$",
"this",
"->",
"_country",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_checkCountry",
"(",
"$",
"country",
")",
";",
"}",
"$",
"digestSecret",
"=",
"self",
"::",
"digest",
"(",
"$",
"this",
"->",
"colon",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"no",
",",
"$",
"this",
"->",
"_secret",
")",
")",
";",
"$",
"paramList",
"=",
"array",
"(",
"$",
"no",
",",
"$",
"this",
"->",
"_eid",
",",
"$",
"digestSecret",
",",
"$",
"country",
")",
";",
"self",
"::",
"printDebug",
"(",
"'reserve_ocr_nums array'",
",",
"$",
"paramList",
")",
";",
"return",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'reserve_ocr_nums'",
",",
"$",
"paramList",
")",
";",
"}"
] | Reserves a specified number of OCR numbers.<br>
For the specified country or the {@link Klarna::setCountry() set country}.<br>
@param int $no The number of OCR numbers to reserve.
@param int $country {@link KlarnaCountry} constant.
@throws KlarnaException
@return array An array of OCR numbers. | [
"Reserves",
"a",
"specified",
"number",
"of",
"OCR",
"numbers",
".",
"<br",
">",
"For",
"the",
"specified",
"country",
"or",
"the",
"{",
"@link",
"Klarna",
"::",
"setCountry",
"()",
"set",
"country",
"}",
".",
"<br",
">"
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L2491-L2516 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.hasAccount | public function hasAccount($pno, $encoding = null)
{
//Get the PNO/SSN encoding constant.
if ($encoding === null) {
$encoding = $this->getPNOEncoding();
}
$this->_checkPNO($pno, $encoding);
$digest = self::digest(
$this->colon($this->_eid, $pno, $this->_secret)
);
$paramList = array(
$this->_eid,
$pno,
$digest,
$encoding
);
self::printDebug('has_account', $paramList);
$result = $this->xmlrpc_call('has_account', $paramList);
return ($result === 'true');
} | php | public function hasAccount($pno, $encoding = null)
{
//Get the PNO/SSN encoding constant.
if ($encoding === null) {
$encoding = $this->getPNOEncoding();
}
$this->_checkPNO($pno, $encoding);
$digest = self::digest(
$this->colon($this->_eid, $pno, $this->_secret)
);
$paramList = array(
$this->_eid,
$pno,
$digest,
$encoding
);
self::printDebug('has_account', $paramList);
$result = $this->xmlrpc_call('has_account', $paramList);
return ($result === 'true');
} | [
"public",
"function",
"hasAccount",
"(",
"$",
"pno",
",",
"$",
"encoding",
"=",
"null",
")",
"{",
"//Get the PNO/SSN encoding constant.",
"if",
"(",
"$",
"encoding",
"===",
"null",
")",
"{",
"$",
"encoding",
"=",
"$",
"this",
"->",
"getPNOEncoding",
"(",
")",
";",
"}",
"$",
"this",
"->",
"_checkPNO",
"(",
"$",
"pno",
",",
"$",
"encoding",
")",
";",
"$",
"digest",
"=",
"self",
"::",
"digest",
"(",
"$",
"this",
"->",
"colon",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"pno",
",",
"$",
"this",
"->",
"_secret",
")",
")",
";",
"$",
"paramList",
"=",
"array",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"pno",
",",
"$",
"digest",
",",
"$",
"encoding",
")",
";",
"self",
"::",
"printDebug",
"(",
"'has_account'",
",",
"$",
"paramList",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'has_account'",
",",
"$",
"paramList",
")",
";",
"return",
"(",
"$",
"result",
"===",
"'true'",
")",
";",
"}"
] | Checks if the specified SSN/PNO has an part payment account with Klarna.
@param string $pno Social security number, Personal number, ...
@param int $encoding {@link KlarnaEncoding PNO Encoding} constant.
@throws KlarnaException
@return bool True, if customer has an account. | [
"Checks",
"if",
"the",
"specified",
"SSN",
"/",
"PNO",
"has",
"an",
"part",
"payment",
"account",
"with",
"Klarna",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L2528-L2553 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.addArtNo | public function addArtNo($qty, $artNo)
{
$this->_checkQty($qty);
$this->_checkArtNo($artNo);
if (!is_array($this->artNos)) {
$this->artNos = array();
}
$this->artNos[] = array('artno' => $artNo, 'qty' => $qty);
} | php | public function addArtNo($qty, $artNo)
{
$this->_checkQty($qty);
$this->_checkArtNo($artNo);
if (!is_array($this->artNos)) {
$this->artNos = array();
}
$this->artNos[] = array('artno' => $artNo, 'qty' => $qty);
} | [
"public",
"function",
"addArtNo",
"(",
"$",
"qty",
",",
"$",
"artNo",
")",
"{",
"$",
"this",
"->",
"_checkQty",
"(",
"$",
"qty",
")",
";",
"$",
"this",
"->",
"_checkArtNo",
"(",
"$",
"artNo",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"artNos",
")",
")",
"{",
"$",
"this",
"->",
"artNos",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"artNos",
"[",
"]",
"=",
"array",
"(",
"'artno'",
"=>",
"$",
"artNo",
",",
"'qty'",
"=>",
"$",
"qty",
")",
";",
"}"
] | Adds an article number and quantity to be used in
{@link Klarna::activatePart()}, {@link Klarna::creditPart()}
and {@link Klarna::invoicePartAmount()}.
@param int $qty Quantity of specified article.
@param string $artNo Article number.
@throws KlarnaException
@return void | [
"Adds",
"an",
"article",
"number",
"and",
"quantity",
"to",
"be",
"used",
"in",
"{",
"@link",
"Klarna",
"::",
"activatePart",
"()",
"}",
"{",
"@link",
"Klarna",
"::",
"creditPart",
"()",
"}",
"and",
"{",
"@link",
"Klarna",
"::",
"invoicePartAmount",
"()",
"}",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L2566-L2576 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.activatePart | public function activatePart(
$invNo, $pclass = KlarnaPClass::INVOICE, $clear = true
) {
$this->_checkInvNo($invNo);
$this->_checkArtNos($this->artNos);
self::printDebug('activate_part artNos array', $this->artNos);
//function activate_part_digest
$string = $this->_eid . ":" . $invNo . ":";
foreach ($this->artNos as $artNo) {
$string .= $artNo["artno"] . ":". $artNo["qty"] . ":";
}
$digestSecret = self::digest($string . $this->_secret);
//end activate_part_digest
$paramList = array(
$this->_eid,
$invNo,
$this->artNos,
$digestSecret,
$pclass,
$this->shipInfo
);
self::printDebug('activate_part array', $paramList);
$result = $this->xmlrpc_call('activate_part', $paramList);
if ($clear === true) {
$this->clear();
}
self::printDebug('activate_part result', $result);
return $result;
} | php | public function activatePart(
$invNo, $pclass = KlarnaPClass::INVOICE, $clear = true
) {
$this->_checkInvNo($invNo);
$this->_checkArtNos($this->artNos);
self::printDebug('activate_part artNos array', $this->artNos);
//function activate_part_digest
$string = $this->_eid . ":" . $invNo . ":";
foreach ($this->artNos as $artNo) {
$string .= $artNo["artno"] . ":". $artNo["qty"] . ":";
}
$digestSecret = self::digest($string . $this->_secret);
//end activate_part_digest
$paramList = array(
$this->_eid,
$invNo,
$this->artNos,
$digestSecret,
$pclass,
$this->shipInfo
);
self::printDebug('activate_part array', $paramList);
$result = $this->xmlrpc_call('activate_part', $paramList);
if ($clear === true) {
$this->clear();
}
self::printDebug('activate_part result', $result);
return $result;
} | [
"public",
"function",
"activatePart",
"(",
"$",
"invNo",
",",
"$",
"pclass",
"=",
"KlarnaPClass",
"::",
"INVOICE",
",",
"$",
"clear",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"_checkInvNo",
"(",
"$",
"invNo",
")",
";",
"$",
"this",
"->",
"_checkArtNos",
"(",
"$",
"this",
"->",
"artNos",
")",
";",
"self",
"::",
"printDebug",
"(",
"'activate_part artNos array'",
",",
"$",
"this",
"->",
"artNos",
")",
";",
"//function activate_part_digest",
"$",
"string",
"=",
"$",
"this",
"->",
"_eid",
".",
"\":\"",
".",
"$",
"invNo",
".",
"\":\"",
";",
"foreach",
"(",
"$",
"this",
"->",
"artNos",
"as",
"$",
"artNo",
")",
"{",
"$",
"string",
".=",
"$",
"artNo",
"[",
"\"artno\"",
"]",
".",
"\":\"",
".",
"$",
"artNo",
"[",
"\"qty\"",
"]",
".",
"\":\"",
";",
"}",
"$",
"digestSecret",
"=",
"self",
"::",
"digest",
"(",
"$",
"string",
".",
"$",
"this",
"->",
"_secret",
")",
";",
"//end activate_part_digest",
"$",
"paramList",
"=",
"array",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"invNo",
",",
"$",
"this",
"->",
"artNos",
",",
"$",
"digestSecret",
",",
"$",
"pclass",
",",
"$",
"this",
"->",
"shipInfo",
")",
";",
"self",
"::",
"printDebug",
"(",
"'activate_part array'",
",",
"$",
"paramList",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'activate_part'",
",",
"$",
"paramList",
")",
";",
"if",
"(",
"$",
"clear",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"}",
"self",
"::",
"printDebug",
"(",
"'activate_part result'",
",",
"$",
"result",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Partially activates a passive invoice.
Returned array contains index "url" and "invno".<br>
The value of "url" is a URL pointing to a temporary PDF-version of the
activated invoice.<br>
The value of "invno" is either 0 if the entire invoice was activated or
the number on the new passive invoice.<br>
<b>Note</b>:<br>
You need to call {@link Klarna::addArtNo()} first, to specify which
articles and how many you want to partially activate.<br>
If you want to change the shipment type, you can specify it using:
{@link Klarna::setShipmentInfo() setShipmentInfo('delay_adjust', ...)}
with either: {@link KlarnaFlags::NORMAL_SHIPMENT NORMAL_SHIPMENT}
or {@link KlarnaFlags::EXPRESS_SHIPMENT EXPRESS_SHIPMENT}
@param string $invNo Invoice numbers.
@param int $pclass PClass id used for this invoice.
@param bool $clear Whether customer info should be cleared after
this call.
@see Klarna::addArtNo()
@see Klarna::activateInvoice()
@throws KlarnaException
@return array An array with invoice URL and invoice number.
['url' => val, 'invno' => val] | [
"Partially",
"activates",
"a",
"passive",
"invoice",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L2607-L2643 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.invoiceAmount | public function invoiceAmount($invNo)
{
$this->_checkInvNo($invNo);
$digestSecret = self::digest(
$this->colon($this->_eid, $invNo, $this->_secret)
);
$paramList = array(
$this->_eid,
$invNo,
$digestSecret
);
self::printDebug('invoice_amount array', $paramList);
$result = $this->xmlrpc_call('invoice_amount', $paramList);
//Result is in cents, fix it.
return ($result / 100);
} | php | public function invoiceAmount($invNo)
{
$this->_checkInvNo($invNo);
$digestSecret = self::digest(
$this->colon($this->_eid, $invNo, $this->_secret)
);
$paramList = array(
$this->_eid,
$invNo,
$digestSecret
);
self::printDebug('invoice_amount array', $paramList);
$result = $this->xmlrpc_call('invoice_amount', $paramList);
//Result is in cents, fix it.
return ($result / 100);
} | [
"public",
"function",
"invoiceAmount",
"(",
"$",
"invNo",
")",
"{",
"$",
"this",
"->",
"_checkInvNo",
"(",
"$",
"invNo",
")",
";",
"$",
"digestSecret",
"=",
"self",
"::",
"digest",
"(",
"$",
"this",
"->",
"colon",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"invNo",
",",
"$",
"this",
"->",
"_secret",
")",
")",
";",
"$",
"paramList",
"=",
"array",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"invNo",
",",
"$",
"digestSecret",
")",
";",
"self",
"::",
"printDebug",
"(",
"'invoice_amount array'",
",",
"$",
"paramList",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'invoice_amount'",
",",
"$",
"paramList",
")",
";",
"//Result is in cents, fix it.",
"return",
"(",
"$",
"result",
"/",
"100",
")",
";",
"}"
] | Retrieves the total amount for an active invoice.
@param string $invNo Invoice number.
@throws KlarnaException
@return float The total amount. | [
"Retrieves",
"the",
"total",
"amount",
"for",
"an",
"active",
"invoice",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L2654-L2674 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.updateOrderNo | public function updateOrderNo($invNo, $orderid)
{
$this->_checkInvNo($invNo);
$this->_checkEstoreOrderNo($orderid);
$digestSecret = self::digest(
$this->colon($invNo, $orderid, $this->_secret)
);
$paramList = array(
$this->_eid,
$digestSecret,
$invNo,
$orderid
);
self::printDebug('update_orderno array', $paramList);
$result = $this->xmlrpc_call('update_orderno', $paramList);
return $result;
} | php | public function updateOrderNo($invNo, $orderid)
{
$this->_checkInvNo($invNo);
$this->_checkEstoreOrderNo($orderid);
$digestSecret = self::digest(
$this->colon($invNo, $orderid, $this->_secret)
);
$paramList = array(
$this->_eid,
$digestSecret,
$invNo,
$orderid
);
self::printDebug('update_orderno array', $paramList);
$result = $this->xmlrpc_call('update_orderno', $paramList);
return $result;
} | [
"public",
"function",
"updateOrderNo",
"(",
"$",
"invNo",
",",
"$",
"orderid",
")",
"{",
"$",
"this",
"->",
"_checkInvNo",
"(",
"$",
"invNo",
")",
";",
"$",
"this",
"->",
"_checkEstoreOrderNo",
"(",
"$",
"orderid",
")",
";",
"$",
"digestSecret",
"=",
"self",
"::",
"digest",
"(",
"$",
"this",
"->",
"colon",
"(",
"$",
"invNo",
",",
"$",
"orderid",
",",
"$",
"this",
"->",
"_secret",
")",
")",
";",
"$",
"paramList",
"=",
"array",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"digestSecret",
",",
"$",
"invNo",
",",
"$",
"orderid",
")",
";",
"self",
"::",
"printDebug",
"(",
"'update_orderno array'",
",",
"$",
"paramList",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'update_orderno'",
",",
"$",
"paramList",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Changes the order number of a purchase that was set when the order was
made online.
@param string $invNo Invoice number.
@param string $orderid Estores order number.
@throws KlarnaException
@return string Invoice number. | [
"Changes",
"the",
"order",
"number",
"of",
"a",
"purchase",
"that",
"was",
"set",
"when",
"the",
"order",
"was",
"made",
"online",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L2687-L2708 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.returnAmount | public function returnAmount(
$invNo, $amount, $vat, $flags = KlarnaFlags::INC_VAT, $description = ""
) {
$this->_checkInvNo($invNo);
$this->_checkAmount($amount);
$this->_checkVAT($vat);
$this->_checkInt($flags, 'flags');
if ($description == null) {
$description = "";
}
$digestSecret = self::digest(
$this->colon($this->_eid, $invNo, $this->_secret)
);
$paramList = array(
$this->_eid,
$invNo,
$amount,
$vat,
$digestSecret,
$flags,
$description
);
self::printDebug('return_amount', $paramList);
return $this->xmlrpc_call('return_amount', $paramList);
} | php | public function returnAmount(
$invNo, $amount, $vat, $flags = KlarnaFlags::INC_VAT, $description = ""
) {
$this->_checkInvNo($invNo);
$this->_checkAmount($amount);
$this->_checkVAT($vat);
$this->_checkInt($flags, 'flags');
if ($description == null) {
$description = "";
}
$digestSecret = self::digest(
$this->colon($this->_eid, $invNo, $this->_secret)
);
$paramList = array(
$this->_eid,
$invNo,
$amount,
$vat,
$digestSecret,
$flags,
$description
);
self::printDebug('return_amount', $paramList);
return $this->xmlrpc_call('return_amount', $paramList);
} | [
"public",
"function",
"returnAmount",
"(",
"$",
"invNo",
",",
"$",
"amount",
",",
"$",
"vat",
",",
"$",
"flags",
"=",
"KlarnaFlags",
"::",
"INC_VAT",
",",
"$",
"description",
"=",
"\"\"",
")",
"{",
"$",
"this",
"->",
"_checkInvNo",
"(",
"$",
"invNo",
")",
";",
"$",
"this",
"->",
"_checkAmount",
"(",
"$",
"amount",
")",
";",
"$",
"this",
"->",
"_checkVAT",
"(",
"$",
"vat",
")",
";",
"$",
"this",
"->",
"_checkInt",
"(",
"$",
"flags",
",",
"'flags'",
")",
";",
"if",
"(",
"$",
"description",
"==",
"null",
")",
"{",
"$",
"description",
"=",
"\"\"",
";",
"}",
"$",
"digestSecret",
"=",
"self",
"::",
"digest",
"(",
"$",
"this",
"->",
"colon",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"invNo",
",",
"$",
"this",
"->",
"_secret",
")",
")",
";",
"$",
"paramList",
"=",
"array",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"invNo",
",",
"$",
"amount",
",",
"$",
"vat",
",",
"$",
"digestSecret",
",",
"$",
"flags",
",",
"$",
"description",
")",
";",
"self",
"::",
"printDebug",
"(",
"'return_amount'",
",",
"$",
"paramList",
")",
";",
"return",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'return_amount'",
",",
"$",
"paramList",
")",
";",
"}"
] | Gives discounts on invoices.<br>
If you are using standard integration and the purchase is not yet
activated (you have not yet delivered the goods), <br>
just change the article list in our online interface Klarna Online.<br>
<b>Flags can be</b>:<br>
{@link KlarnaFlags::INC_VAT}<br>
{@link KlarnaFlags::NO_FLAG}, <b>NOT RECOMMENDED!</b><br>
@param string $invNo Invoice number.
@param int $amount The amount given as a discount.
@param float $vat VAT in percent, e.g. 22.2 for 22.2%.
@param int $flags If amount is
{@link KlarnaFlags::INC_VAT including} or
{@link KlarnaFlags::NO_FLAG excluding} VAT.
@param string $description Optional custom text to present as discount
in the invoice.
@throws KlarnaException
@return string Invoice number. | [
"Gives",
"discounts",
"on",
"invoices",
".",
"<br",
">",
"If",
"you",
"are",
"using",
"standard",
"integration",
"and",
"the",
"purchase",
"is",
"not",
"yet",
"activated",
"(",
"you",
"have",
"not",
"yet",
"delivered",
"the",
"goods",
")",
"<br",
">",
"just",
"change",
"the",
"article",
"list",
"in",
"our",
"online",
"interface",
"Klarna",
"Online",
".",
"<br",
">"
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L2791-L2819 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.creditInvoice | public function creditInvoice($invNo, $credNo = "")
{
$this->_checkInvNo($invNo);
$this->_checkCredNo($credNo);
$digestSecret = self::digest(
$this->colon($this->_eid, $invNo, $this->_secret)
);
$paramList = array(
$this->_eid,
$invNo,
$credNo,
$digestSecret
);
self::printDebug('credit_invoice', $paramList);
return $this->xmlrpc_call('credit_invoice', $paramList);
} | php | public function creditInvoice($invNo, $credNo = "")
{
$this->_checkInvNo($invNo);
$this->_checkCredNo($credNo);
$digestSecret = self::digest(
$this->colon($this->_eid, $invNo, $this->_secret)
);
$paramList = array(
$this->_eid,
$invNo,
$credNo,
$digestSecret
);
self::printDebug('credit_invoice', $paramList);
return $this->xmlrpc_call('credit_invoice', $paramList);
} | [
"public",
"function",
"creditInvoice",
"(",
"$",
"invNo",
",",
"$",
"credNo",
"=",
"\"\"",
")",
"{",
"$",
"this",
"->",
"_checkInvNo",
"(",
"$",
"invNo",
")",
";",
"$",
"this",
"->",
"_checkCredNo",
"(",
"$",
"credNo",
")",
";",
"$",
"digestSecret",
"=",
"self",
"::",
"digest",
"(",
"$",
"this",
"->",
"colon",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"invNo",
",",
"$",
"this",
"->",
"_secret",
")",
")",
";",
"$",
"paramList",
"=",
"array",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"invNo",
",",
"$",
"credNo",
",",
"$",
"digestSecret",
")",
";",
"self",
"::",
"printDebug",
"(",
"'credit_invoice'",
",",
"$",
"paramList",
")",
";",
"return",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'credit_invoice'",
",",
"$",
"paramList",
")",
";",
"}"
] | Performs a complete refund on an invoice, part payment and mobile
purchase.
@param string $invNo Invoice number.
@param string $credNo Credit number.
@throws KlarnaException
@return string Invoice number. | [
"Performs",
"a",
"complete",
"refund",
"on",
"an",
"invoice",
"part",
"payment",
"and",
"mobile",
"purchase",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L2831-L2849 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.creditPart | public function creditPart($invNo, $credNo = "")
{
$this->_checkInvNo($invNo);
$this->_checkCredNo($credNo);
if ($this->goodsList === null || empty($this->goodsList)) {
$this->_checkArtNos($this->artNos);
}
//function activate_part_digest
$string = $this->_eid . ":" . $invNo . ":";
if ($this->artNos !== null && !empty($this->artNos)) {
foreach ($this->artNos as $artNo) {
$string .= $artNo["artno"] . ":". $artNo["qty"] . ":";
}
}
$digestSecret = self::digest($string . $this->_secret);
//end activate_part_digest
$paramList = array(
$this->_eid,
$invNo,
$this->artNos,
$credNo,
$digestSecret
);
if ($this->goodsList !== null && !empty($this->goodsList)) {
$paramList[] = 0;
$paramList[] = $this->goodsList;
}
$this->artNos = array();
self::printDebug('credit_part', $paramList);
return $this->xmlrpc_call('credit_part', $paramList);
} | php | public function creditPart($invNo, $credNo = "")
{
$this->_checkInvNo($invNo);
$this->_checkCredNo($credNo);
if ($this->goodsList === null || empty($this->goodsList)) {
$this->_checkArtNos($this->artNos);
}
//function activate_part_digest
$string = $this->_eid . ":" . $invNo . ":";
if ($this->artNos !== null && !empty($this->artNos)) {
foreach ($this->artNos as $artNo) {
$string .= $artNo["artno"] . ":". $artNo["qty"] . ":";
}
}
$digestSecret = self::digest($string . $this->_secret);
//end activate_part_digest
$paramList = array(
$this->_eid,
$invNo,
$this->artNos,
$credNo,
$digestSecret
);
if ($this->goodsList !== null && !empty($this->goodsList)) {
$paramList[] = 0;
$paramList[] = $this->goodsList;
}
$this->artNos = array();
self::printDebug('credit_part', $paramList);
return $this->xmlrpc_call('credit_part', $paramList);
} | [
"public",
"function",
"creditPart",
"(",
"$",
"invNo",
",",
"$",
"credNo",
"=",
"\"\"",
")",
"{",
"$",
"this",
"->",
"_checkInvNo",
"(",
"$",
"invNo",
")",
";",
"$",
"this",
"->",
"_checkCredNo",
"(",
"$",
"credNo",
")",
";",
"if",
"(",
"$",
"this",
"->",
"goodsList",
"===",
"null",
"||",
"empty",
"(",
"$",
"this",
"->",
"goodsList",
")",
")",
"{",
"$",
"this",
"->",
"_checkArtNos",
"(",
"$",
"this",
"->",
"artNos",
")",
";",
"}",
"//function activate_part_digest",
"$",
"string",
"=",
"$",
"this",
"->",
"_eid",
".",
"\":\"",
".",
"$",
"invNo",
".",
"\":\"",
";",
"if",
"(",
"$",
"this",
"->",
"artNos",
"!==",
"null",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"artNos",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"artNos",
"as",
"$",
"artNo",
")",
"{",
"$",
"string",
".=",
"$",
"artNo",
"[",
"\"artno\"",
"]",
".",
"\":\"",
".",
"$",
"artNo",
"[",
"\"qty\"",
"]",
".",
"\":\"",
";",
"}",
"}",
"$",
"digestSecret",
"=",
"self",
"::",
"digest",
"(",
"$",
"string",
".",
"$",
"this",
"->",
"_secret",
")",
";",
"//end activate_part_digest",
"$",
"paramList",
"=",
"array",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"invNo",
",",
"$",
"this",
"->",
"artNos",
",",
"$",
"credNo",
",",
"$",
"digestSecret",
")",
";",
"if",
"(",
"$",
"this",
"->",
"goodsList",
"!==",
"null",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"goodsList",
")",
")",
"{",
"$",
"paramList",
"[",
"]",
"=",
"0",
";",
"$",
"paramList",
"[",
"]",
"=",
"$",
"this",
"->",
"goodsList",
";",
"}",
"$",
"this",
"->",
"artNos",
"=",
"array",
"(",
")",
";",
"self",
"::",
"printDebug",
"(",
"'credit_part'",
",",
"$",
"paramList",
")",
";",
"return",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'credit_part'",
",",
"$",
"paramList",
")",
";",
"}"
] | Performs a partial refund on an invoice, part payment or mobile purchase.
<b>Note</b>:<br>
You need to call {@link Klarna::addArtNo()} first.<br>
@param string $invNo Invoice number.
@param string $credNo Credit number.
@see Klarna::addArtNo()
@throws KlarnaException
@return string Invoice number. | [
"Performs",
"a",
"partial",
"refund",
"on",
"an",
"invoice",
"part",
"payment",
"or",
"mobile",
"purchase",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L2865-L2904 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.updateGoodsQty | public function updateGoodsQty($invNo, $artNo, $qty)
{
$this->_checkInvNo($invNo);
$this->_checkQty($qty);
$this->_checkArtNo($artNo);
$digestSecret = self::digest(
$this->colon($invNo, $artNo, $qty, $this->_secret)
);
$paramList = array(
$this->_eid,
$digestSecret,
$invNo,
$artNo,
$qty
);
self::printDebug('update_goods_qty', $paramList);
return $this->xmlrpc_call('update_goods_qty', $paramList);
} | php | public function updateGoodsQty($invNo, $artNo, $qty)
{
$this->_checkInvNo($invNo);
$this->_checkQty($qty);
$this->_checkArtNo($artNo);
$digestSecret = self::digest(
$this->colon($invNo, $artNo, $qty, $this->_secret)
);
$paramList = array(
$this->_eid,
$digestSecret,
$invNo,
$artNo,
$qty
);
self::printDebug('update_goods_qty', $paramList);
return $this->xmlrpc_call('update_goods_qty', $paramList);
} | [
"public",
"function",
"updateGoodsQty",
"(",
"$",
"invNo",
",",
"$",
"artNo",
",",
"$",
"qty",
")",
"{",
"$",
"this",
"->",
"_checkInvNo",
"(",
"$",
"invNo",
")",
";",
"$",
"this",
"->",
"_checkQty",
"(",
"$",
"qty",
")",
";",
"$",
"this",
"->",
"_checkArtNo",
"(",
"$",
"artNo",
")",
";",
"$",
"digestSecret",
"=",
"self",
"::",
"digest",
"(",
"$",
"this",
"->",
"colon",
"(",
"$",
"invNo",
",",
"$",
"artNo",
",",
"$",
"qty",
",",
"$",
"this",
"->",
"_secret",
")",
")",
";",
"$",
"paramList",
"=",
"array",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"digestSecret",
",",
"$",
"invNo",
",",
"$",
"artNo",
",",
"$",
"qty",
")",
";",
"self",
"::",
"printDebug",
"(",
"'update_goods_qty'",
",",
"$",
"paramList",
")",
";",
"return",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'update_goods_qty'",
",",
"$",
"paramList",
")",
";",
"}"
] | Changes the quantity of a specific item in a passive invoice.
@param string $invNo Invoice number.
@param string $artNo Article number.
@param int $qty Quantity of specified article.
@throws KlarnaException
@return string Invoice number. | [
"Changes",
"the",
"quantity",
"of",
"a",
"specific",
"item",
"in",
"a",
"passive",
"invoice",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L2917-L2938 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.updateChargeAmount | public function updateChargeAmount($invNo, $type, $newAmount)
{
$this->_checkInvNo($invNo);
$this->_checkInt($type, 'type');
$this->_checkAmount($newAmount);
if ($type === KlarnaFlags::IS_SHIPMENT) {
$type = 1;
} else if ($type === KlarnaFlags::IS_HANDLING) {
$type = 2;
}
$digestSecret = self::digest(
$this->colon($invNo, $type, $newAmount, $this->_secret)
);
$paramList = array(
$this->_eid,
$digestSecret,
$invNo,
$type,
$newAmount
);
self::printDebug('update_charge_amount', $paramList);
return $this->xmlrpc_call('update_charge_amount', $paramList);
} | php | public function updateChargeAmount($invNo, $type, $newAmount)
{
$this->_checkInvNo($invNo);
$this->_checkInt($type, 'type');
$this->_checkAmount($newAmount);
if ($type === KlarnaFlags::IS_SHIPMENT) {
$type = 1;
} else if ($type === KlarnaFlags::IS_HANDLING) {
$type = 2;
}
$digestSecret = self::digest(
$this->colon($invNo, $type, $newAmount, $this->_secret)
);
$paramList = array(
$this->_eid,
$digestSecret,
$invNo,
$type,
$newAmount
);
self::printDebug('update_charge_amount', $paramList);
return $this->xmlrpc_call('update_charge_amount', $paramList);
} | [
"public",
"function",
"updateChargeAmount",
"(",
"$",
"invNo",
",",
"$",
"type",
",",
"$",
"newAmount",
")",
"{",
"$",
"this",
"->",
"_checkInvNo",
"(",
"$",
"invNo",
")",
";",
"$",
"this",
"->",
"_checkInt",
"(",
"$",
"type",
",",
"'type'",
")",
";",
"$",
"this",
"->",
"_checkAmount",
"(",
"$",
"newAmount",
")",
";",
"if",
"(",
"$",
"type",
"===",
"KlarnaFlags",
"::",
"IS_SHIPMENT",
")",
"{",
"$",
"type",
"=",
"1",
";",
"}",
"else",
"if",
"(",
"$",
"type",
"===",
"KlarnaFlags",
"::",
"IS_HANDLING",
")",
"{",
"$",
"type",
"=",
"2",
";",
"}",
"$",
"digestSecret",
"=",
"self",
"::",
"digest",
"(",
"$",
"this",
"->",
"colon",
"(",
"$",
"invNo",
",",
"$",
"type",
",",
"$",
"newAmount",
",",
"$",
"this",
"->",
"_secret",
")",
")",
";",
"$",
"paramList",
"=",
"array",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"digestSecret",
",",
"$",
"invNo",
",",
"$",
"type",
",",
"$",
"newAmount",
")",
";",
"self",
"::",
"printDebug",
"(",
"'update_charge_amount'",
",",
"$",
"paramList",
")",
";",
"return",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'update_charge_amount'",
",",
"$",
"paramList",
")",
";",
"}"
] | Changes the amount of a fee (e.g. the invoice fee) in a passive invoice.
<b>Type can be</b>:<br>
{@link KlarnaFlags::IS_SHIPMENT}<br>
{@link KlarnaFlags::IS_HANDLING}<br>
@param string $invNo Invoice number.
@param int $type Charge type.
@param int $newAmount The new amount for the charge.
@throws KlarnaException
@return string Invoice number. | [
"Changes",
"the",
"amount",
"of",
"a",
"fee",
"(",
"e",
".",
"g",
".",
"the",
"invoice",
"fee",
")",
"in",
"a",
"passive",
"invoice",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L2955-L2982 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.invoiceAddress | public function invoiceAddress($invNo)
{
$this->_checkInvNo($invNo);
$digestSecret = self::digest(
$this->colon($this->_eid, $invNo, $this->_secret)
);
$paramList = array(
$this->_eid,
$invNo,
$digestSecret
);
self::printDebug('invoice_address', $paramList);
$result = $this->xmlrpc_call('invoice_address', $paramList);
$addr = new KlarnaAddr();
if (strlen($result[0]) > 0) {
$addr->isCompany = false;
$addr->setFirstName($result[0]);
$addr->setLastName($result[1]);
} else {
$addr->isCompany = true;
$addr->setCompanyName($result[1]);
}
$addr->setStreet($result[2]);
$addr->setZipCode($result[3]);
$addr->setCity($result[4]);
$addr->setCountry($result[5]);
return $addr;
} | php | public function invoiceAddress($invNo)
{
$this->_checkInvNo($invNo);
$digestSecret = self::digest(
$this->colon($this->_eid, $invNo, $this->_secret)
);
$paramList = array(
$this->_eid,
$invNo,
$digestSecret
);
self::printDebug('invoice_address', $paramList);
$result = $this->xmlrpc_call('invoice_address', $paramList);
$addr = new KlarnaAddr();
if (strlen($result[0]) > 0) {
$addr->isCompany = false;
$addr->setFirstName($result[0]);
$addr->setLastName($result[1]);
} else {
$addr->isCompany = true;
$addr->setCompanyName($result[1]);
}
$addr->setStreet($result[2]);
$addr->setZipCode($result[3]);
$addr->setCity($result[4]);
$addr->setCountry($result[5]);
return $addr;
} | [
"public",
"function",
"invoiceAddress",
"(",
"$",
"invNo",
")",
"{",
"$",
"this",
"->",
"_checkInvNo",
"(",
"$",
"invNo",
")",
";",
"$",
"digestSecret",
"=",
"self",
"::",
"digest",
"(",
"$",
"this",
"->",
"colon",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"invNo",
",",
"$",
"this",
"->",
"_secret",
")",
")",
";",
"$",
"paramList",
"=",
"array",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"invNo",
",",
"$",
"digestSecret",
")",
";",
"self",
"::",
"printDebug",
"(",
"'invoice_address'",
",",
"$",
"paramList",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'invoice_address'",
",",
"$",
"paramList",
")",
";",
"$",
"addr",
"=",
"new",
"KlarnaAddr",
"(",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"result",
"[",
"0",
"]",
")",
">",
"0",
")",
"{",
"$",
"addr",
"->",
"isCompany",
"=",
"false",
";",
"$",
"addr",
"->",
"setFirstName",
"(",
"$",
"result",
"[",
"0",
"]",
")",
";",
"$",
"addr",
"->",
"setLastName",
"(",
"$",
"result",
"[",
"1",
"]",
")",
";",
"}",
"else",
"{",
"$",
"addr",
"->",
"isCompany",
"=",
"true",
";",
"$",
"addr",
"->",
"setCompanyName",
"(",
"$",
"result",
"[",
"1",
"]",
")",
";",
"}",
"$",
"addr",
"->",
"setStreet",
"(",
"$",
"result",
"[",
"2",
"]",
")",
";",
"$",
"addr",
"->",
"setZipCode",
"(",
"$",
"result",
"[",
"3",
"]",
")",
";",
"$",
"addr",
"->",
"setCity",
"(",
"$",
"result",
"[",
"4",
"]",
")",
";",
"$",
"addr",
"->",
"setCountry",
"(",
"$",
"result",
"[",
"5",
"]",
")",
";",
"return",
"$",
"addr",
";",
"}"
] | The invoice_address function is used to retrieve the address of a
purchase.
@param string $invNo Invoice number.
@throws KlarnaException
@return KlarnaAddr | [
"The",
"invoice_address",
"function",
"is",
"used",
"to",
"retrieve",
"the",
"address",
"of",
"a",
"purchase",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L2993-L3025 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.invoicePartAmount | public function invoicePartAmount($invNo)
{
$this->_checkInvNo($invNo);
$this->_checkArtNos($this->artNos);
//function activate_part_digest
$string = $this->_eid . ":" . $invNo . ":";
foreach ($this->artNos as $artNo) {
$string .= $artNo["artno"] . ":". $artNo["qty"] . ":";
}
$digestSecret = self::digest($string . $this->_secret);
//end activate_part_digest
$paramList = array(
$this->_eid,
$invNo,
$this->artNos,
$digestSecret
);
$this->artNos = array();
self::printDebug('invoice_part_amount', $paramList);
$result = $this->xmlrpc_call('invoice_part_amount', $paramList);
return ($result / 100);
} | php | public function invoicePartAmount($invNo)
{
$this->_checkInvNo($invNo);
$this->_checkArtNos($this->artNos);
//function activate_part_digest
$string = $this->_eid . ":" . $invNo . ":";
foreach ($this->artNos as $artNo) {
$string .= $artNo["artno"] . ":". $artNo["qty"] . ":";
}
$digestSecret = self::digest($string . $this->_secret);
//end activate_part_digest
$paramList = array(
$this->_eid,
$invNo,
$this->artNos,
$digestSecret
);
$this->artNos = array();
self::printDebug('invoice_part_amount', $paramList);
$result = $this->xmlrpc_call('invoice_part_amount', $paramList);
return ($result / 100);
} | [
"public",
"function",
"invoicePartAmount",
"(",
"$",
"invNo",
")",
"{",
"$",
"this",
"->",
"_checkInvNo",
"(",
"$",
"invNo",
")",
";",
"$",
"this",
"->",
"_checkArtNos",
"(",
"$",
"this",
"->",
"artNos",
")",
";",
"//function activate_part_digest",
"$",
"string",
"=",
"$",
"this",
"->",
"_eid",
".",
"\":\"",
".",
"$",
"invNo",
".",
"\":\"",
";",
"foreach",
"(",
"$",
"this",
"->",
"artNos",
"as",
"$",
"artNo",
")",
"{",
"$",
"string",
".=",
"$",
"artNo",
"[",
"\"artno\"",
"]",
".",
"\":\"",
".",
"$",
"artNo",
"[",
"\"qty\"",
"]",
".",
"\":\"",
";",
"}",
"$",
"digestSecret",
"=",
"self",
"::",
"digest",
"(",
"$",
"string",
".",
"$",
"this",
"->",
"_secret",
")",
";",
"//end activate_part_digest",
"$",
"paramList",
"=",
"array",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"invNo",
",",
"$",
"this",
"->",
"artNos",
",",
"$",
"digestSecret",
")",
";",
"$",
"this",
"->",
"artNos",
"=",
"array",
"(",
")",
";",
"self",
"::",
"printDebug",
"(",
"'invoice_part_amount'",
",",
"$",
"paramList",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'invoice_part_amount'",
",",
"$",
"paramList",
")",
";",
"return",
"(",
"$",
"result",
"/",
"100",
")",
";",
"}"
] | Retrieves the amount of a specific goods from a purchase.
<b>Note</b>:<br>
You need to call {@link Klarna::addArtNo()} first.<br>
@param string $invNo Invoice number.
@see Klarna::addArtNo()
@throws KlarnaException
@return float The amount of the goods. | [
"Retrieves",
"the",
"amount",
"of",
"a",
"specific",
"goods",
"from",
"a",
"purchase",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L3040-L3066 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.checkOrderStatus | public function checkOrderStatus($id, $type = 0)
{
$this->_checkArgument($id, "id");
$this->_checkInt($type, 'type');
if ($type !== 0 && $type !== 1) {
throw new Klarna_InvalidTypeException(
'type', "0 or 1"
);
}
$digestSecret = self::digest(
$this->colon($this->_eid, $id, $this->_secret)
);
$paramList = array(
$this->_eid,
$digestSecret,
$id,
$type
);
self::printDebug('check_order_status', $paramList);
return $this->xmlrpc_call('check_order_status', $paramList);
} | php | public function checkOrderStatus($id, $type = 0)
{
$this->_checkArgument($id, "id");
$this->_checkInt($type, 'type');
if ($type !== 0 && $type !== 1) {
throw new Klarna_InvalidTypeException(
'type', "0 or 1"
);
}
$digestSecret = self::digest(
$this->colon($this->_eid, $id, $this->_secret)
);
$paramList = array(
$this->_eid,
$digestSecret,
$id,
$type
);
self::printDebug('check_order_status', $paramList);
return $this->xmlrpc_call('check_order_status', $paramList);
} | [
"public",
"function",
"checkOrderStatus",
"(",
"$",
"id",
",",
"$",
"type",
"=",
"0",
")",
"{",
"$",
"this",
"->",
"_checkArgument",
"(",
"$",
"id",
",",
"\"id\"",
")",
";",
"$",
"this",
"->",
"_checkInt",
"(",
"$",
"type",
",",
"'type'",
")",
";",
"if",
"(",
"$",
"type",
"!==",
"0",
"&&",
"$",
"type",
"!==",
"1",
")",
"{",
"throw",
"new",
"Klarna_InvalidTypeException",
"(",
"'type'",
",",
"\"0 or 1\"",
")",
";",
"}",
"$",
"digestSecret",
"=",
"self",
"::",
"digest",
"(",
"$",
"this",
"->",
"colon",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"id",
",",
"$",
"this",
"->",
"_secret",
")",
")",
";",
"$",
"paramList",
"=",
"array",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"digestSecret",
",",
"$",
"id",
",",
"$",
"type",
")",
";",
"self",
"::",
"printDebug",
"(",
"'check_order_status'",
",",
"$",
"paramList",
")",
";",
"return",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'check_order_status'",
",",
"$",
"paramList",
")",
";",
"}"
] | Returns the current order status for a specific reservation or invoice.
Use this when {@link Klarna::addTransaction()} or
{@link Klarna::reserveAmount()} returns a {@link KlarnaFlags::PENDING}
status.
<b>Order status can be</b>:<br>
{@link KlarnaFlags::ACCEPTED}<br>
{@link KlarnaFlags::PENDING}<br>
{@link KlarnaFlags::DENIED}<br>
@param string $id Reservation number or invoice number.
@param int $type 0 if $id is an invoice or reservation, 1 for order id
@throws KlarnaException
@return string The order status. | [
"Returns",
"the",
"current",
"order",
"status",
"for",
"a",
"specific",
"reservation",
"or",
"invoice",
".",
"Use",
"this",
"when",
"{",
"@link",
"Klarna",
"::",
"addTransaction",
"()",
"}",
"or",
"{",
"@link",
"Klarna",
"::",
"reserveAmount",
"()",
"}",
"returns",
"a",
"{",
"@link",
"KlarnaFlags",
"::",
"PENDING",
"}",
"status",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L3086-L3110 |
Subscribo/klarna-invoice-sdk-wrapped | src/Klarna.php | Klarna.getCustomerNo | public function getCustomerNo($pno, $encoding = null)
{
//Get the PNO/SSN encoding constant.
if ($encoding === null) {
$encoding = $this->getPNOEncoding();
}
$this->_checkPNO($pno, $encoding);
$digestSecret = self::digest(
$this->colon($this->_eid, $pno, $this->_secret)
);
$paramList = array(
$pno,
$this->_eid,
$digestSecret,
$encoding
);
self::printDebug('get_customer_no', $paramList);
return $this->xmlrpc_call('get_customer_no', $paramList);
} | php | public function getCustomerNo($pno, $encoding = null)
{
//Get the PNO/SSN encoding constant.
if ($encoding === null) {
$encoding = $this->getPNOEncoding();
}
$this->_checkPNO($pno, $encoding);
$digestSecret = self::digest(
$this->colon($this->_eid, $pno, $this->_secret)
);
$paramList = array(
$pno,
$this->_eid,
$digestSecret,
$encoding
);
self::printDebug('get_customer_no', $paramList);
return $this->xmlrpc_call('get_customer_no', $paramList);
} | [
"public",
"function",
"getCustomerNo",
"(",
"$",
"pno",
",",
"$",
"encoding",
"=",
"null",
")",
"{",
"//Get the PNO/SSN encoding constant.",
"if",
"(",
"$",
"encoding",
"===",
"null",
")",
"{",
"$",
"encoding",
"=",
"$",
"this",
"->",
"getPNOEncoding",
"(",
")",
";",
"}",
"$",
"this",
"->",
"_checkPNO",
"(",
"$",
"pno",
",",
"$",
"encoding",
")",
";",
"$",
"digestSecret",
"=",
"self",
"::",
"digest",
"(",
"$",
"this",
"->",
"colon",
"(",
"$",
"this",
"->",
"_eid",
",",
"$",
"pno",
",",
"$",
"this",
"->",
"_secret",
")",
")",
";",
"$",
"paramList",
"=",
"array",
"(",
"$",
"pno",
",",
"$",
"this",
"->",
"_eid",
",",
"$",
"digestSecret",
",",
"$",
"encoding",
")",
";",
"self",
"::",
"printDebug",
"(",
"'get_customer_no'",
",",
"$",
"paramList",
")",
";",
"return",
"$",
"this",
"->",
"xmlrpc_call",
"(",
"'get_customer_no'",
",",
"$",
"paramList",
")",
";",
"}"
] | Retrieves a list of all the customer numbers associated with the
specified pno.
@param string $pno Social security number, Personal number, ...
@param int $encoding {@link KlarnaEncoding PNO Encoding} constant.
@throws KlarnaException
@return array An array containing all customer numbers associated
with that pno. | [
"Retrieves",
"a",
"list",
"of",
"all",
"the",
"customer",
"numbers",
"associated",
"with",
"the",
"specified",
"pno",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Klarna.php#L3123-L3144 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.