idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
50,500 | public function loadTranslations ( $ sFilePath , $ sLanguage ) { if ( ! file_exists ( $ sFilePath ) ) { return ; } $ aTranslations = require ( $ sFilePath ) ; if ( ! is_array ( $ aTranslations ) ) { return ; } if ( ! array_key_exists ( $ sLanguage , $ this -> aTranslations ) ) { $ this -> aTranslations [ $ sLanguage ] = [ ] ; } $ this -> _loadTranslations ( $ sLanguage , '' , $ aTranslations ) ; } | Load translated strings from a file |
50,501 | public function attributes ( array $ value = [ ] ) { $ this -> attributes [ 'attributes' ] = $ this -> decorate ( $ value , $ this -> attributes [ 'attributes' ] ) ; return $ this ; } | Setup attributes via decorate . |
50,502 | protected function getUploadDir ( $ sFieldId ) { $ sDefaultUploadDir = $ this -> getOption ( 'upload.default.dir' ) ; $ sUploadDir = $ this -> getOption ( 'upload.files.' . $ sFieldId . '.dir' , $ sDefaultUploadDir ) ; $ sUploadDir = rtrim ( trim ( $ sUploadDir ) , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR ; if ( ! is_writable ( $ sUploadDir ) ) { throw new \ Jaxon \ Exception \ Error ( $ this -> trans ( 'errors.upload.access' ) ) ; } $ sUploadDir .= $ this -> sUploadSubdir ; if ( ! @ mkdir ( $ sUploadDir ) ) { throw new \ Jaxon \ Exception \ Error ( $ this -> trans ( 'errors.upload.access' ) ) ; } return $ sUploadDir ; } | Get the path to the upload dir |
50,503 | protected function getUploadTempDir ( ) { $ sUploadDir = $ this -> getOption ( 'upload.default.dir' ) ; $ sUploadDir = rtrim ( trim ( $ sUploadDir ) , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR ; if ( ! is_writable ( $ sUploadDir ) ) { throw new \ Jaxon \ Exception \ Error ( $ this -> trans ( 'errors.upload.access' ) ) ; } $ sUploadDir .= 'tmp' . DIRECTORY_SEPARATOR ; if ( ! @ mkdir ( $ sUploadDir ) ) { throw new \ Jaxon \ Exception \ Error ( $ this -> trans ( 'errors.upload.access' ) ) ; } return $ sUploadDir ; } | Get the path to the upload temp dir |
50,504 | protected function getUploadTempFile ( ) { $ sUploadDir = $ this -> getOption ( 'upload.default.dir' ) ; $ sUploadDir = rtrim ( trim ( $ sUploadDir ) , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR ; $ sUploadDir .= 'tmp' . DIRECTORY_SEPARATOR ; $ sUploadTempFile = $ sUploadDir . $ this -> sTempFile . '.json' ; if ( ! is_readable ( $ sUploadTempFile ) ) { throw new \ Jaxon \ Exception \ Error ( $ this -> trans ( 'errors.upload.access' ) ) ; } return $ sUploadTempFile ; } | Get the path to the upload temp file |
50,505 | protected function saveToTempFile ( ) { $ aFiles = [ ] ; foreach ( $ this -> aUserFiles as $ sVarName => $ aUserFiles ) { $ aFiles [ $ sVarName ] = [ ] ; foreach ( $ aUserFiles as $ aUserFile ) { $ aFiles [ $ sVarName ] [ ] = $ aUserFile -> toTempData ( ) ; } } $ sUploadDir = $ this -> getUploadTempDir ( ) ; $ this -> sTempFile = uniqid ( ) ; file_put_contents ( $ sUploadDir . $ this -> sTempFile . '.json' , json_encode ( $ aFiles ) ) ; } | Save uploaded files info to a temp file |
50,506 | protected function readFromTempFile ( ) { $ sUploadTempFile = $ this -> getUploadTempFile ( ) ; $ aFiles = json_decode ( file_get_contents ( $ sUploadTempFile ) , true ) ; foreach ( $ aFiles as $ sVarName => $ aUserFiles ) { $ this -> aUserFiles [ $ sVarName ] = [ ] ; foreach ( $ aUserFiles as $ aUserFile ) { $ this -> aUserFiles [ $ sVarName ] [ ] = UploadedFile :: fromTempData ( $ aUserFile ) ; } } unlink ( $ sUploadTempFile ) ; } | Read uploaded files info from a temp file |
50,507 | public function processRequest ( ) { if ( ! $ this -> canProcessRequest ( ) ) { return false ; } if ( count ( $ _FILES ) > 0 ) { $ this -> readFromHttpData ( ) ; } elseif ( ( $ this -> sTempFile ) ) { $ this -> readFromTempFile ( ) ; } return true ; } | Process the uploaded files into the HTTP request |
50,508 | public function ifeq ( $ sValue1 , $ sValue2 ) { $ this -> sCondition = '(' . Parameter :: make ( $ sValue1 ) . '==' . Parameter :: make ( $ sValue2 ) . ')' ; return $ this ; } | Check if a value is equal to another before sending the request |
50,509 | public function ifne ( $ sValue1 , $ sValue2 ) { $ this -> sCondition = '(' . Parameter :: make ( $ sValue1 ) . '!=' . Parameter :: make ( $ sValue2 ) . ')' ; return $ this ; } | Check if a value is not equal to another before sending the request |
50,510 | public function ifgt ( $ sValue1 , $ sValue2 ) { $ this -> sCondition = '(' . Parameter :: make ( $ sValue1 ) . '>' . Parameter :: make ( $ sValue2 ) . ')' ; return $ this ; } | Check if a value is greater than another before sending the request |
50,511 | public function ifge ( $ sValue1 , $ sValue2 ) { $ this -> sCondition = '(' . Parameter :: make ( $ sValue1 ) . '>=' . Parameter :: make ( $ sValue2 ) . ')' ; return $ this ; } | Check if a value is greater or equal to another before sending the request |
50,512 | public function iflt ( $ sValue1 , $ sValue2 ) { $ this -> sCondition = '(' . Parameter :: make ( $ sValue1 ) . '<' . Parameter :: make ( $ sValue2 ) . ')' ; return $ this ; } | Check if a value is lower than another before sending the request |
50,513 | public function ifle ( $ sValue1 , $ sValue2 ) { $ this -> sCondition = '(' . Parameter :: make ( $ sValue1 ) . '<=' . Parameter :: make ( $ sValue2 ) . ')' ; return $ this ; } | Check if a value is lower or equal to another before sending the request |
50,514 | public static function read ( $ sConfigFile ) { $ sConfigFile = realpath ( $ sConfigFile ) ; if ( ! is_readable ( $ sConfigFile ) ) { throw new \ Jaxon \ Config \ Exception \ File ( jaxon_trans ( 'config.errors.file.access' , array ( 'path' => $ sConfigFile ) ) ) ; } $ aConfigOptions = include ( $ sConfigFile ) ; if ( ! is_array ( $ aConfigOptions ) ) { throw new \ Jaxon \ Config \ Exception \ File ( jaxon_trans ( 'config.errors.file.content' , array ( 'path' => $ sConfigFile ) ) ) ; } return $ aConfigOptions ; } | Read options from a PHP config file |
50,515 | public static function read ( $ sConfigFile ) { $ sConfigFile = realpath ( $ sConfigFile ) ; if ( ! extension_loaded ( 'yaml' ) ) { throw new \ Jaxon \ Config \ Exception \ Yaml ( jaxon_trans ( 'config.errors.yaml.install' ) ) ; } if ( ! is_readable ( $ sConfigFile ) ) { throw new \ Jaxon \ Config \ Exception \ File ( jaxon_trans ( 'config.errors.file.access' , array ( 'path' => $ sConfigFile ) ) ) ; } $ aConfigOptions = yaml_parse_file ( $ sConfigFile ) ; if ( ! is_array ( $ aConfigOptions ) ) { throw new \ Jaxon \ Config \ Exception \ File ( jaxon_trans ( 'config.errors.file.content' , array ( 'path' => $ sConfigFile ) ) ) ; } return $ aConfigOptions ; } | Read options from a YAML formatted config file |
50,516 | public function checkbox ( FieldContract $ field ) : Htmlable { return $ this -> form -> checkbox ( $ field -> get ( 'name' ) , $ field -> get ( 'value' ) , $ field -> get ( 'checked' ) , $ field -> get ( 'attributes' ) ) ; } | Checkbox template . |
50,517 | public function radio ( FieldContract $ field ) : Htmlable { return $ this -> form -> radio ( $ field -> get ( 'name' ) , $ field -> get ( 'value' ) , $ field -> get ( 'checked' ) ) ; } | Radio template . |
50,518 | public function register ( $ sType , $ sUserFunction , $ aOptions ) { if ( $ sType != $ this -> getName ( ) ) { return false ; } if ( ! is_string ( $ sUserFunction ) ) { throw new \ Jaxon \ Exception \ Error ( $ this -> trans ( 'errors.functions.invalid-declaration' ) ) ; } if ( is_string ( $ aOptions ) ) { $ aOptions = [ 'include' => $ aOptions ] ; } if ( ! is_array ( $ aOptions ) ) { throw new \ Jaxon \ Exception \ Error ( $ this -> trans ( 'errors.functions.invalid-declaration' ) ) ; } $ sFunctionName = $ sUserFunction ; foreach ( $ aOptions as $ sName => $ sValue ) { if ( $ sName == 'alias' ) { $ sFunctionName = $ sValue ; break ; } } $ this -> aFunctions [ $ sFunctionName ] = $ aOptions ; jaxon ( ) -> di ( ) -> set ( $ sFunctionName , function ( ) use ( $ sFunctionName , $ sUserFunction ) { $ xUserFunction = new \ Jaxon \ Request \ Support \ UserFunction ( $ sUserFunction ) ; $ aOptions = $ this -> aFunctions [ $ sFunctionName ] ; foreach ( $ aOptions as $ sName => $ sValue ) { $ xUserFunction -> configure ( $ sName , $ sValue ) ; } return $ xUserFunction ; } ) ; return true ; } | Register a user defined function |
50,519 | public function getScript ( ) { $ di = jaxon ( ) -> di ( ) ; $ code = '' ; foreach ( array_keys ( $ this -> aFunctions ) as $ sName ) { $ xFunction = $ di -> get ( $ sName ) ; $ code .= $ xFunction -> getScript ( ) ; } return $ code ; } | Generate client side javascript code for the registered user functions |
50,520 | public function validateUploadedFile ( $ sName , array $ aUploadedFile ) { $ this -> sErrorMessage = '' ; $ xDefault = $ this -> xConfig -> getOption ( 'upload.default.types' ) ; $ aAllowed = $ this -> xConfig -> getOption ( 'upload.files.' . $ sName . '.types' , $ xDefault ) ; if ( is_array ( $ aAllowed ) && ! in_array ( $ aUploadedFile [ 'type' ] , $ aAllowed ) ) { $ this -> sErrorMessage = $ this -> xTranslator -> trans ( 'errors.upload.type' , $ aUploadedFile ) ; return false ; } $ xDefault = $ this -> xConfig -> getOption ( 'upload.default.extensions' ) ; $ aAllowed = $ this -> xConfig -> getOption ( 'upload.files.' . $ sName . '.extensions' , $ xDefault ) ; if ( is_array ( $ aAllowed ) && ! in_array ( $ aUploadedFile [ 'extension' ] , $ aAllowed ) ) { $ this -> sErrorMessage = $ this -> xTranslator -> trans ( 'errors.upload.extension' , $ aUploadedFile ) ; return false ; } $ xDefault = $ this -> xConfig -> getOption ( 'upload.default.max-size' , 0 ) ; $ iSize = $ this -> xConfig -> getOption ( 'upload.files.' . $ sName . '.max-size' , $ xDefault ) ; if ( $ iSize > 0 && $ aUploadedFile [ 'size' ] > $ iSize ) { $ this -> sErrorMessage = $ this -> xTranslator -> trans ( 'errors.upload.max-size' , $ aUploadedFile ) ; return false ; } $ xDefault = $ this -> xConfig -> getOption ( 'upload.default.min-size' , 0 ) ; $ iSize = $ this -> xConfig -> getOption ( 'upload.files.' . $ sName . '.min-size' , $ xDefault ) ; if ( $ iSize > 0 && $ aUploadedFile [ 'size' ] < $ iSize ) { $ this -> sErrorMessage = $ this -> xTranslator -> trans ( 'errors.upload.min-size' , $ aUploadedFile ) ; return false ; } return true ; } | Validate an uploaded file |
50,521 | public function hasUploadedFiles ( ) { if ( ( $ xUploadPlugin = $ this -> getPluginManager ( ) -> getRequestPlugin ( self :: FILE_UPLOAD ) ) == null ) { return false ; } return $ xUploadPlugin -> canProcessRequest ( ) ; } | Check if uploaded files are available |
50,522 | public function saveUploadedFiles ( ) { try { if ( ( $ xUploadPlugin = $ this -> getPluginManager ( ) -> getRequestPlugin ( self :: FILE_UPLOAD ) ) == null ) { throw new Exception ( $ this -> trans ( 'errors.upload.plugin' ) ) ; } elseif ( ! $ xUploadPlugin -> canProcessRequest ( ) ) { throw new Exception ( $ this -> trans ( 'errors.upload.request' ) ) ; } $ sKey = $ xUploadPlugin -> saveUploadedFiles ( ) ; $ sResponse = '{"code": "success", "upl": "' . $ sKey . '"}' ; $ return = true ; } catch ( Exception $ e ) { $ sResponse = '{"code": "error", "msg": "' . addslashes ( $ e -> getMessage ( ) ) . '"}' ; $ return = false ; } echo '<script>var res = ' , $ sResponse , '; </script>' ; if ( ( $ this -> getOption ( 'core.process.exit' ) ) ) { exit ( ) ; } return $ return ; } | Check uploaded files validity and move them to the user dir |
50,523 | public function getUploadedFiles ( ) { if ( ( $ xUploadPlugin = $ this -> getPluginManager ( ) -> getRequestPlugin ( self :: FILE_UPLOAD ) ) == null ) { return [ ] ; } return $ xUploadPlugin -> getUploadedFiles ( ) ; } | Get the uploaded files |
50,524 | public function buildFluentData ( string $ type , $ row , Fluent $ control ) : FieldContract { $ name = $ control -> get ( 'name' ) ; $ value = $ this -> resolveFieldValue ( $ name , $ row , $ control ) ; $ data = new Field ( [ 'method' => '' , 'type' => '' , 'options' => [ ] , 'checked' => false , 'attributes' => [ ] , 'name' => $ name , 'value' => $ value , ] ) ; return $ this -> resolveFieldType ( $ type , $ data ) ; } | Build data . |
50,525 | protected function getOptionList ( $ row , Fluent $ control ) { $ options = $ control -> get ( 'options' ) ; if ( $ options instanceof Closure ) { $ options = $ options ( $ row , $ control ) ; } return $ options ; } | Get options from control . |
50,526 | public function getMethods ( ) { $ aMethods = [ ] ; foreach ( $ this -> reflectionClass -> getMethods ( \ ReflectionMethod :: IS_PUBLIC ) as $ xMethod ) { $ sMethodName = $ xMethod -> getShortName ( ) ; if ( strlen ( $ sMethodName ) > 2 && substr ( $ sMethodName , 0 , 2 ) == '__' ) { continue ; } if ( in_array ( $ sMethodName , $ this -> aProtectedMethods ) ) { continue ; } $ aMethods [ ] = $ sMethodName ; } return $ aMethods ; } | Return a list of methods of the callable object to export to javascript |
50,527 | public function getRegisteredObject ( ) { if ( $ this -> registeredObject == null ) { $ di = jaxon ( ) -> di ( ) ; if ( ( $ constructor = $ this -> reflectionClass -> getConstructor ( ) ) != null ) { $ parameters = $ constructor -> getParameters ( ) ; $ parameterInstances = [ ] ; foreach ( $ parameters as $ parameter ) { $ parameterInstances [ ] = $ di -> get ( $ parameter -> getClass ( ) -> getName ( ) ) ; } $ this -> registeredObject = $ this -> reflectionClass -> newInstanceArgs ( $ parameterInstances ) ; } else { $ this -> registeredObject = $ this -> reflectionClass -> newInstance ( ) ; } } return $ this -> registeredObject ; } | Return the registered callable object |
50,528 | public function call ( $ sMethod , $ aArgs ) { if ( ! $ this -> hasMethod ( $ sMethod ) ) { return ; } $ reflectionMethod = $ this -> reflectionClass -> getMethod ( $ sMethod ) ; $ registeredObject = $ this -> getRegisteredObject ( ) ; return $ reflectionMethod -> invokeArgs ( $ registeredObject , $ aArgs ) ; } | Call the specified method of the registered callable object using the specified array of arguments |
50,529 | public function confirm ( $ question , $ yesScript , $ noScript ) { return $ this -> getConfirm ( ) -> confirm ( $ question , $ yesScript , $ noScript ) ; } | Get the script which makes a call only if the user answers yes to the given question |
50,530 | public function minify ( $ sJsFile , $ sMinFile ) { $ xJsMinifier = new JsMinifier ( ) ; $ xJsMinifier -> add ( $ sJsFile ) ; $ xJsMinifier -> minify ( $ sMinFile ) ; return is_file ( $ sMinFile ) ; } | Minify javascript code |
50,531 | private function setMessageArgs ( array $ aArgs ) { array_walk ( $ aArgs , function ( & $ xParameter ) { $ xParameter = Parameter :: make ( $ xParameter ) ; } ) ; $ this -> aMessageArgs = $ aArgs ; } | Create parameters for message arguments |
50,532 | public function listPayments ( Payplug \ Payplug $ payplug = null ) { if ( $ payplug === null ) { $ payplug = Payplug \ Payplug :: getDefaultConfiguration ( ) ; } if ( ! array_key_exists ( 'id' , $ this -> getAttributes ( ) ) ) { throw new Payplug \ Exception \ UndefinedAttributeException ( "This installment plan object has no id. You can't list payments on it." ) ; } $ httpClient = new Payplug \ Core \ HttpClient ( $ payplug ) ; $ response = $ httpClient -> get ( Payplug \ Core \ APIRoutes :: getRoute ( Payplug \ Core \ APIRoutes :: INSTALLMENT_PLAN_RESOURCE , $ this -> id ) ) ; $ payments = array ( ) ; foreach ( $ response [ 'httpResponse' ] [ 'schedule' ] as $ schedule ) { foreach ( $ schedule [ 'payment_ids' ] as $ payment_id ) { $ payments [ $ payment_id ] = Payment :: retrieve ( $ payment_id , $ payplug ) ; } } return $ payments ; } | List the payments of this installment plan . |
50,533 | public static function treat ( $ requestBody , $ authentication = null ) { $ postArray = json_decode ( $ requestBody , true ) ; if ( $ postArray === null ) { throw new Exception \ UnknownAPIResourceException ( 'Request body is not valid JSON.' ) ; } $ unsafeAPIResource = Resource \ APIResource :: factory ( $ postArray ) ; return $ unsafeAPIResource -> getConsistentResource ( $ authentication ) ; } | This function treats a notification and verifies its authenticity . |
50,534 | public function post ( $ resource , $ data = null , $ authenticated = true ) { return $ this -> request ( 'POST' , $ resource , $ data , $ authenticated ) ; } | Sends a POST request to the API . |
50,535 | public static function addDefaultUserAgentProduct ( $ product , $ version = null , $ comment = null ) { self :: $ defaultUserAgentProducts [ ] = array ( $ product , $ version , $ comment ) ; } | Adds a default product for the User - Agent HTTP header sent for each HTTP request . |
50,536 | private static function formatUserAgentProduct ( $ product , $ version = null , $ comment = null ) { $ productString = $ product ; if ( $ version ) { $ productString .= '/' . $ version ; } if ( $ comment ) { $ productString .= ' (' . $ comment . ')' ; } return $ productString ; } | Formats a product for a User - Agent HTTP header . |
50,537 | public static function getUserAgent ( ) { $ curlVersion = curl_version ( ) ; $ userAgent = self :: formatUserAgentProduct ( 'PayPlug-PHP' , Payplug \ Core \ Config :: LIBRARY_VERSION , sprintf ( 'PHP/%s; curl/%s' , phpversion ( ) , $ curlVersion [ 'version' ] ) ) ; foreach ( self :: $ defaultUserAgentProducts as $ product ) { $ userAgent .= ' ' . self :: formatUserAgentProduct ( $ product [ 0 ] , $ product [ 1 ] , $ product [ 2 ] ) ; } return $ userAgent ; } | Gets the User - Agent HTTP header sent for each HTTP request . |
50,538 | private function request ( $ httpVerb , $ resource , array $ data = null , $ authenticated = true ) { if ( self :: $ REQUEST_HANDLER === null ) { $ request = new CurlRequest ( ) ; } else { $ request = self :: $ REQUEST_HANDLER ; } $ userAgent = self :: getUserAgent ( ) ; $ headers = array ( 'Accept: application/json' , 'Content-Type: application/json' , 'User-Agent: ' . $ userAgent ) ; if ( $ authenticated ) { $ headers [ ] = 'Authorization: Bearer ' . $ this -> _configuration -> getToken ( ) ; } $ request -> setopt ( CURLOPT_FAILONERROR , false ) ; $ request -> setopt ( CURLOPT_RETURNTRANSFER , true ) ; $ request -> setopt ( CURLOPT_CUSTOMREQUEST , $ httpVerb ) ; $ request -> setopt ( CURLOPT_URL , $ resource ) ; $ request -> setopt ( CURLOPT_HTTPHEADER , $ headers ) ; $ request -> setopt ( CURLOPT_SSL_VERIFYPEER , true ) ; $ request -> setopt ( CURLOPT_SSL_VERIFYHOST , 2 ) ; $ request -> setopt ( CURLOPT_CAINFO , self :: $ CACERT_PATH ) ; if ( ! empty ( $ data ) ) { $ request -> setopt ( CURLOPT_POSTFIELDS , json_encode ( $ data ) ) ; } $ result = array ( 'httpResponse' => $ request -> exec ( ) , 'httpStatus' => $ request -> getInfo ( CURLINFO_HTTP_CODE ) ) ; $ errorCode = $ request -> errno ( ) ; $ errorMessage = $ request -> error ( ) ; $ request -> close ( ) ; $ curlStatusNotManage = array ( 0 , 22 ) ; if ( in_array ( $ errorCode , $ curlStatusNotManage ) && substr ( $ result [ 'httpStatus' ] , 0 , 1 ) !== '2' ) { $ this -> throwRequestException ( $ result [ 'httpResponse' ] , $ result [ 'httpStatus' ] ) ; } elseif ( $ result [ 'httpResponse' ] === false || $ errorCode ) { $ this -> throwConnectionException ( $ result [ 'httpStatus' ] , $ errorMessage ) ; } $ result [ 'httpResponse' ] = json_decode ( $ result [ 'httpResponse' ] , true ) ; if ( $ result [ 'httpResponse' ] === null ) { throw new Payplug \ Exception \ UnexpectedAPIResponseException ( 'API response is not valid JSON.' , $ result [ 'httpResponse' ] ) ; } return $ result ; } | Performs a request . |
50,539 | private function throwRequestException ( $ httpResponse , $ httpStatus ) { $ exception = null ; if ( substr ( $ httpStatus , 0 , 1 ) === '5' ) { throw new Payplug \ Exception \ PayplugServerException ( 'Unexpected server error during the request.' , $ httpResponse , $ httpStatus ) ; } switch ( $ httpStatus ) { case 400 : throw new Payplug \ Exception \ BadRequestException ( 'Bad request.' , $ httpResponse , $ httpStatus ) ; break ; case 401 : throw new Payplug \ Exception \ UnauthorizedException ( 'Unauthorized. Please check your credentials.' , $ httpResponse , $ httpStatus ) ; break ; case 403 : throw new Payplug \ Exception \ ForbiddenException ( 'Forbidden error. You are not allowed to access this resource.' , $ httpResponse , $ httpStatus ) ; break ; case 404 : throw new Payplug \ Exception \ NotFoundException ( 'The resource you requested could not be found.' , $ httpResponse , $ httpStatus ) ; break ; case 405 : throw new Payplug \ Exception \ NotAllowedException ( 'The requested method is not supported by this resource.' , $ httpResponse , $ httpStatus ) ; break ; } throw new Payplug \ Exception \ HttpException ( 'Unhandled HTTP error.' , $ httpResponse , $ httpStatus ) ; } | Throws an exception from a given HTTP response and status . |
50,540 | public function refund ( array $ data = null , Payplug \ Payplug $ payplug = null ) { if ( ! array_key_exists ( 'id' , $ this -> getAttributes ( ) ) ) { throw new Payplug \ Exception \ InvalidPaymentException ( "This payment object has no id. It can't be refunded." ) ; } return Refund :: create ( $ this -> id , $ data , $ payplug ) ; } | Open a refund on the payment . |
50,541 | public function listRefunds ( Payplug \ Payplug $ payplug = null ) { if ( ! array_key_exists ( 'id' , $ this -> getAttributes ( ) ) ) { throw new Payplug \ Exception \ InvalidPaymentException ( "This payment object has no id. You can't list refunds on it." ) ; } return Refund :: listRefunds ( $ this -> id , $ payplug ) ; } | List the refunds of this payment . |
50,542 | public function capture ( Payplug \ Payplug $ payplug = null ) { if ( $ payplug === null ) { $ payplug = Payplug \ Payplug :: getDefaultConfiguration ( ) ; } $ httpClient = new Payplug \ Core \ HttpClient ( $ payplug ) ; $ response = $ httpClient -> patch ( Payplug \ Core \ APIRoutes :: getRoute ( Payplug \ Core \ APIRoutes :: PAYMENT_RESOURCE , $ this -> id ) , array ( 'captured' => true ) ) ; return Payment :: fromAttributes ( $ response [ 'httpResponse' ] ) ; } | Captures a Payment . |
50,543 | public static function getRoute ( $ route , $ resourceId = null , array $ parameters = array ( ) , array $ pagination = array ( ) ) { foreach ( $ parameters as $ parameter => $ value ) { $ route = str_replace ( '{' . $ parameter . '}' , $ value , $ route ) ; } $ resourceIdUrl = $ resourceId ? '/' . $ resourceId : '' ; $ query_pagination = '' ; if ( ! empty ( $ pagination ) ) $ query_pagination = '?' . http_build_query ( $ pagination ) ; return self :: $ API_BASE_URL . '/v' . self :: API_VERSION . $ route . $ resourceIdUrl . $ query_pagination ; } | Get the route to a specified resource . |
50,544 | public static function delete ( $ card , Payplug $ payplug = null ) { return Resource \ Card :: deleteCard ( $ card , $ payplug ) ; } | Delete a card . |
50,545 | public static function factory ( array $ attributes ) { if ( ! array_key_exists ( 'object' , $ attributes ) ) { throw new Payplug \ Exception \ UnknownAPIResourceException ( 'Missing "object" property.' ) ; } switch ( $ attributes [ 'object' ] ) { case 'payment' : return Payplug \ Resource \ Payment :: fromAttributes ( $ attributes ) ; case 'refund' : return Payplug \ Resource \ Refund :: fromAttributes ( $ attributes ) ; case 'installment_plan' : return Payplug \ Resource \ InstallmentPlan :: fromAttributes ( $ attributes ) ; } throw new Payplug \ Exception \ UnknownAPIResourceException ( 'Unknown "object" property "' . $ attributes [ 'object' ] . '".' ) ; } | Tries to recompose an API Resource from its attributes . For example when you got it from a notification . The API Resource must have a known object property . |
50,546 | public static function abort ( $ paymentId , Payplug $ payplug = null ) { $ payment = Resource \ Payment :: fromAttributes ( array ( 'id' => $ paymentId ) ) ; return $ payment -> abort ( $ payplug ) ; } | Aborts a Payment . |
50,547 | public function getAll ( array $ access = [ ] , array $ tags = [ ] ) { $ response = $ this -> request ( self :: REQUEST_GET , 'templates' , [ 'access' => implode ( ',' , $ access ) , 'tags' => implode ( ',' , $ tags ) ] ) ; return $ response -> response ; } | Returns list of templates available in active workspace |
50,548 | public function get ( $ template ) { $ response = $ this -> request ( self :: REQUEST_GET , 'templates/' . $ template ) ; return $ response -> response ; } | Returns template configuration |
50,549 | public function copy ( $ template , $ newName = null ) { $ response = $ this -> request ( self :: REQUEST_POST , 'templates/' . $ template . '/copy' , [ 'name' => $ newName ] ) ; return $ response -> response ; } | Creates copy of given template to active workspace |
50,550 | public function output ( $ template , $ data , $ format = self :: FORMAT_PDF , $ name = null , array $ params = [ ] ) { return $ this -> request ( self :: REQUEST_POST , 'templates/' . $ template . '/output' , array_merge ( [ 'data' => $ data , 'format' => $ format , 'name' => $ name ] , $ params ) ) ; } | Returns document as base64 encoded string for given template and data |
50,551 | public function editor ( $ template , $ data = null , array $ params = [ ] ) { $ resource = 'templates/' . $ template . '/editor' ; $ params = array_merge ( [ 'key' => $ this -> key , 'workspace' => $ this -> workspace , 'signature' => $ this -> createSignature ( $ resource ) ] , $ params ) ; if ( $ data ) { $ params [ 'data' ] = self :: dataToString ( $ data ) ; } return $ this -> baseUrl . $ resource . '?' . http_build_query ( $ params ) ; } | Creates editor url |
50,552 | protected static function dataToString ( $ data ) { if ( ! is_string ( $ data ) ) { try { $ data = \ GuzzleHttp \ json_encode ( $ data ) ; } catch ( \ InvalidArgumentException $ e ) { } } return $ data ; } | Turns data into string |
50,553 | public static function abort ( $ installmentPlanId , Payplug $ payplug = null ) { $ installmentPlan = Resource \ InstallmentPlan :: fromAttributes ( array ( 'id' => $ installmentPlanId ) ) ; return $ installmentPlan -> abort ( $ payplug ) ; } | Aborts an InstallmentPlan . |
50,554 | public static function setSecretKey ( $ token ) { if ( ! is_string ( $ token ) ) { throw new Exception \ ConfigurationException ( 'Expected string values for the token.' ) ; } $ clientConfiguration = new Payplug ( $ token ) ; self :: setDefaultConfiguration ( $ clientConfiguration ) ; return $ clientConfiguration ; } | Initializes a Authentication and sets it as the new default global authentication . It also performs some checks before saving the authentication . |
50,555 | function getPaymentProcessUrl ( $ payment ) { $ payId = $ this -> getPayId ( $ payment ) ; $ payload = array ( "merchantId" => $ this -> config -> merchantId , "payId" => $ payId , "dttm" => $ this -> getDTTM ( ) ) ; $ payload [ "signature" ] = $ this -> signRequest ( $ payload ) ; $ url = $ this -> sendRequest ( "payment/process" , $ payload , "GET" , array ( ) , array ( "merchantId" , "payId" , "dttm" , "signature" ) , true ) ; $ this -> writeToLog ( "URL for processing payment " . $ payId . ": $url" ) ; return $ url ; } | Generates URL to send customer s browser to after initiating the payment . |
50,556 | function getPaymentCheckoutUrl ( $ payment , $ oneClickPaymentCheckbox , $ displayOmnibox = null , $ returnCheckoutUrl = null ) { $ payId = $ this -> getPayId ( $ payment ) ; $ payload = array ( "merchantId" => $ this -> config -> merchantId , "payId" => $ payId , "dttm" => $ this -> getDTTM ( ) , "oneclickPaymentCheckbox" => $ oneClickPaymentCheckbox , ) ; if ( $ displayOmnibox !== null ) { $ payload [ "displayOmnibox" ] = $ displayOmnibox ? "true" : "false" ; } if ( $ returnCheckoutUrl !== null ) { $ payload [ "returnCheckoutUrl" ] = $ returnCheckoutUrl ; } $ payload [ "signature" ] = $ this -> signRequest ( $ payload ) ; $ url = $ this -> sendRequest ( "payment/checkout" , $ payload , "GET" , array ( ) , array ( "merchantId" , "payId" , "dttm" , "oneclickPaymentCheckbox" , "displayOmnibox" , "returnCheckoutUrl" , "signature" ) , true ) ; $ this -> writeToLog ( "URL for processing payment " . $ payId . ": $url" ) ; return $ url ; } | Generates checkout URL to send customer s browser to after initiating the payment . |
50,557 | function redirectToGateway ( $ payment ) { if ( headers_sent ( $ file , $ line ) ) { $ this -> writeToLog ( "Can't redirect, headers sent at $file, line $line" ) ; throw new Exception ( "Can't redirect the browser, headers were already sent at $file line $line" ) ; } $ url = $ this -> getPaymentProcessUrl ( $ payment ) ; $ this -> writeToLog ( "Redirecting to payment gate..." ) ; header ( "HTTP/1.1 302 Moved" ) ; header ( "Location: $url" ) ; header ( "Connection: close" ) ; } | Redirect customer s browser to payment gateway . |
50,558 | function customRequest ( $ methodUrl , $ inputPayload , $ expectedOutputFields = array ( ) , $ extensions = array ( ) , $ method = "POST" , $ logOutput = false , $ ignoreInvalidReturnSignature = false ) { if ( array_key_exists ( 'dttm' , $ inputPayload ) and ! $ inputPayload [ 'dttm' ] ) { $ inputPayload [ 'dttm' ] = $ this -> getDTTM ( ) ; } if ( array_key_exists ( 'merchantId' , $ inputPayload ) and ! $ inputPayload [ 'merchantId' ] ) { $ inputPayload [ 'merchantId' ] = $ this -> config -> merchantId ; } $ signature = $ this -> signRequest ( $ inputPayload ) ; $ inputPayload [ 'signature' ] = $ signature ; $ this -> writeToLog ( "custom request to $methodUrl - start" ) ; try { $ ret = $ this -> sendRequest ( $ methodUrl , $ inputPayload , $ method , $ expectedOutputFields , array_keys ( $ inputPayload ) , false , $ ignoreInvalidReturnSignature , $ extensions ) ; } catch ( Exception $ e ) { $ this -> writeToLog ( "Fail, got exception: " . $ e -> getCode ( ) . ", " . $ e -> getMessage ( ) ) ; throw $ e ; } $ this -> writeToLog ( "custom request to $methodUrl - OK" ) ; if ( $ logOutput ) { $ this -> writeToTraceLog ( print_r ( $ ret , true ) ) ; } return $ ret ; } | Sends an arbitrary request to bank s API with any parameters . |
50,559 | function receiveReturningCustomer ( $ input = null ) { $ returnDataNames = array ( "payId" , "dttm" , "resultCode" , "resultMessage" , "paymentStatus" , "?authCode" , "merchantData" , ) ; if ( ! $ input ) { if ( isset ( $ _GET [ "payId" ] ) ) $ input = $ _GET ; elseif ( isset ( $ _POST [ "payId" ] ) ) $ input = $ _POST ; } if ( ! $ input ) { return null ; } $ this -> writeToTraceLog ( "Received data from returning customer: " . str_replace ( "\n" , " " , print_r ( $ input , true ) ) ) ; $ nullFields = array_fill_keys ( $ returnDataNames , null ) ; $ input += $ nullFields ; $ signatureOk = $ this -> verifyResponseSignature ( $ input , $ input [ "signature" ] , $ returnDataNames ) ; if ( ! $ signatureOk ) { $ this -> writeToTraceLog ( "Signature is invalid." ) ; $ this -> writeToLog ( "Returning customer: payId $input[payId], has invalid signature." ) ; throw new Exception ( "Signature is invalid." ) ; } $ merch = @ base64_decode ( $ input [ "merchantData" ] ) ; if ( $ merch ) { $ input [ "merchantData" ] = $ merch ; } $ mess = "Returning customer: payId " . $ input [ "payId" ] . ", authCode " . ( isset ( $ input [ "authCode" ] ) ? $ input [ "authCode" ] : '(not set)' ) . ", payment status " . $ input [ "paymentStatus" ] ; if ( $ input [ "merchantData" ] ) { $ mess .= ", merchantData " . $ input [ "merchantData" ] ; } $ this -> writeToLog ( $ mess ) ; return $ input ; } | Processes the data that are sent together with customer when he returns back from payment gateway . |
50,560 | function setLog ( $ log ) { if ( ! $ log ) { $ this -> logFile = null ; $ this -> logCallback = null ; } elseif ( is_callable ( $ log ) ) { $ this -> logFile = null ; $ this -> logCallback = $ log ; } else { Files :: create ( $ log ) ; $ this -> logFile = $ log ; $ this -> logCallback = null ; } return $ this ; } | Sets logging for bussiness - logic level messages . |
50,561 | function setTraceLog ( $ log ) { if ( ! $ log ) { $ this -> traceLogFile = null ; $ this -> traceLogCallback = null ; } elseif ( is_callable ( $ log ) ) { $ this -> traceLogFile = null ; $ this -> traceLogCallback = $ log ; } else { Files :: create ( $ log ) ; $ this -> traceLogFile = $ log ; $ this -> traceLogCallback = null ; } return $ this ; } | Sets logging for exact contents of communication |
50,562 | protected function getPayId ( $ payment ) { if ( ! is_string ( $ payment ) and $ payment instanceof Payment ) { $ payment = $ payment -> getPayId ( ) ; if ( ! $ payment ) { throw new Exception ( "Given Payment object does not have payId. Please call paymentInit() first." ) ; } } if ( is_array ( $ payment ) and isset ( $ payment [ "payId" ] ) ) { $ payment = $ payment [ "payId" ] ; } if ( ! is_string ( $ payment ) or strlen ( $ payment ) != 15 ) { throw new Exception ( "Given Payment ID is not valid - it should be a string with length 15 characters." ) ; } return $ payment ; } | Get payId as string and validate it . |
50,563 | protected function getCustomerId ( $ payment ) { if ( ! is_string ( $ payment ) and $ payment instanceof Payment ) { $ payment = $ payment -> customerId ; } if ( is_array ( $ payment ) and isset ( $ payment [ "customerId" ] ) ) { $ payment = $ payment [ "customerId" ] ; } if ( ! is_string ( $ payment ) ) { throw new Exception ( "Given Customer ID is not valid." ) ; } return $ payment ; } | Get customerId as string and validate it . |
50,564 | protected function signRequest ( $ arrayToSign ) { $ stringToSign = Crypto :: createSignatureBaseFromArray ( $ arrayToSign ) ; $ keyFile = $ this -> config -> privateKeyFile ; $ signature = Crypto :: signString ( $ stringToSign , $ keyFile , $ this -> config -> privateKeyPassword ) ; $ this -> writeToTraceLog ( "Signing string \"$stringToSign\" using key $keyFile, result: " . $ signature ) ; return $ signature ; } | Signs array payload |
50,565 | public function asArray ( ) { $ a = array ( ) ; $ a [ 'premiseId' ] = + $ this -> premiseId ; $ a [ 'cashRegisterId' ] = $ this -> cashRegisterId ; $ a [ 'totalPrice' ] = self :: formatPriceValue ( $ this -> totalPrice ) ; if ( $ this -> delegatedVatId ) { $ a [ 'delegatedVatId' ] = $ this -> delegatedVatId ; } if ( $ this -> priceZeroVat ) { $ a [ 'priceZeroVat' ] = self :: formatPriceValue ( $ this -> priceZeroVat ) ; } if ( $ this -> priceStandardVat ) { $ a [ 'priceStandardVat' ] = self :: formatPriceValue ( $ this -> priceStandardVat ) ; } if ( $ this -> vatStandard ) { $ a [ 'vatStandard' ] = self :: formatPriceValue ( $ this -> vatStandard ) ; } if ( $ this -> priceFirstReducedVat ) { $ a [ 'priceFirstReducedVat' ] = self :: formatPriceValue ( $ this -> priceFirstReducedVat ) ; } if ( $ this -> vatFirstReduced ) { $ a [ 'vatFirstReduced' ] = self :: formatPriceValue ( $ this -> vatFirstReduced ) ; } if ( $ this -> priceSecondReducedVat ) { $ a [ 'priceSecondReducedVat' ] = self :: formatPriceValue ( $ this -> priceSecondReducedVat ) ; } if ( $ this -> vatSecondReduced ) { $ a [ 'vatSecondReduced' ] = self :: formatPriceValue ( $ this -> vatSecondReduced ) ; } if ( $ this -> priceTravelService ) { $ a [ 'priceTravelService' ] = self :: formatPriceValue ( $ this -> priceTravelService ) ; } if ( $ this -> priceUsedGoodsStandardVat ) { $ a [ 'priceUsedGoodsStandardVat' ] = self :: formatPriceValue ( $ this -> priceUsedGoodsStandardVat ) ; } if ( $ this -> priceUsedGoodsFirstReduced ) { $ a [ 'priceUsedGoodsFirstReduced' ] = self :: formatPriceValue ( $ this -> priceUsedGoodsFirstReduced ) ; } if ( $ this -> priceUsedGoodsSecondReduced ) { $ a [ 'priceUsedGoodsSecondReduced' ] = self :: formatPriceValue ( $ this -> priceUsedGoodsSecondReduced ) ; } if ( $ this -> priceSubsequentSettlement ) { $ a [ 'priceSubsequentSettlement' ] = self :: formatPriceValue ( $ this -> priceSubsequentSettlement ) ; } if ( $ this -> priceUsedSubsequentSettlement ) { $ a [ 'priceUsedSubsequentSettlement' ] = self :: formatPriceValue ( $ this -> priceUsedSubsequentSettlement ) ; } return $ a ; } | Export as array |
50,566 | static function fromArray ( $ array ) { $ data = new EETData ( ) ; foreach ( self :: $ keyNames as $ key ) { if ( array_key_exists ( $ key , $ array ) ) { $ data -> $ key = $ array [ $ key ] ; } } $ data -> rawData = $ array ; return $ data ; } | Creates EETData object from array received from API |
50,567 | public function createRequestArray ( Client $ client ) { $ sourceArray = $ this -> getInputData ( ) ; if ( ! $ sourceArray ) { return null ; } $ config = $ client -> getConfig ( ) ; if ( array_key_exists ( 'dttm' , $ sourceArray ) and ! $ sourceArray [ 'dttm' ] ) { $ sourceArray [ 'dttm' ] = $ client -> getDTTM ( ) ; } if ( array_key_exists ( 'extension' , $ sourceArray ) and ! $ sourceArray [ 'extension' ] ) { $ sourceArray [ 'extension' ] = $ this -> getExtensionId ( ) ; } $ baseString = $ this -> getRequestSignatureBase ( $ sourceArray ) ; $ client -> writeToTraceLog ( 'Signing request of extension ' . $ this -> extensionId . ', base string is:' . "\n" . $ baseString ) ; $ signature = Crypto :: signString ( $ baseString , $ config -> privateKeyFile , $ config -> privateKeyPassword ) ; $ sourceArray [ 'signature' ] = $ signature ; return $ sourceArray ; } | Creates array for request . |
50,568 | public function verifySignature ( $ receivedData , Client $ client ) { $ signature = isset ( $ receivedData [ 'signature' ] ) ? $ receivedData [ 'signature' ] : '' ; if ( ! $ signature ) { return false ; } $ responseWithoutSignature = $ receivedData ; unset ( $ responseWithoutSignature [ "signature" ] ) ; $ baseString = $ this -> getResponseSignatureBase ( $ responseWithoutSignature ) ; $ config = $ client -> getConfig ( ) ; $ client -> writeToTraceLog ( 'Verifying signature of response of extension ' . $ this -> extensionId . ', base string is:' . "\n" . $ baseString ) ; return Crypto :: verifySignature ( $ baseString , $ signature , $ config -> bankPublicKeyFile ) ; } | Verifies signature . |
50,569 | public function getResponseSignatureBase ( $ responseWithoutSignature ) { $ keys = $ this -> getExpectedResponseKeysOrder ( ) ; if ( $ keys ) { $ baseString = Crypto :: createSignatureBaseWithOrder ( $ responseWithoutSignature , $ keys , false ) ; } else { $ baseString = Crypto :: createSignatureBaseFromArray ( $ responseWithoutSignature , false ) ; } return $ baseString ; } | Returns base string for verifying signature of response . |
50,570 | static public function fromArray ( $ array ) { $ status = new EETReport ( ) ; $ status -> rawData = $ array ; if ( array_key_exists ( 'eetStatus' , $ array ) ) { $ status -> eetStatus = $ array [ 'eetStatus' ] ; } if ( array_key_exists ( 'data' , $ array ) ) { $ status -> data = EETData :: fromArray ( $ array [ 'data' ] ) ; } if ( array_key_exists ( 'verificationMode' , $ array ) ) { $ status -> verificationMode = $ array [ 'verificationMode' ] ? true : false ; } if ( array_key_exists ( 'vatId' , $ array ) ) { $ status -> vatId = $ array [ 'vatId' ] ; } if ( array_key_exists ( 'receiptNumber' , $ array ) ) { $ status -> receiptNumber = $ array [ 'receiptNumber' ] ; } if ( array_key_exists ( 'receiptTime' , $ array ) ) { $ status -> receiptTime = new DateTime ( $ array [ 'receiptTime' ] ) ; } if ( array_key_exists ( 'evidenceMode' , $ array ) ) { $ status -> evidenceMode = $ array [ 'evidenceMode' ] ; } if ( array_key_exists ( 'uuid' , $ array ) ) { $ status -> uuid = $ array [ 'uuid' ] ; } if ( array_key_exists ( 'sendTime' , $ array ) ) { $ status -> sendTime = new DateTime ( $ array [ 'sendTime' ] ) ; } if ( array_key_exists ( 'acceptTime' , $ array ) ) { $ status -> acceptTime = new DateTime ( $ array [ 'acceptTime' ] ) ; } if ( array_key_exists ( 'bkp' , $ array ) ) { $ status -> bkp = $ array [ 'bkp' ] ; } if ( array_key_exists ( 'pkp' , $ array ) ) { $ status -> pkp = $ array [ 'pkp' ] ; } if ( array_key_exists ( 'fik' , $ array ) ) { $ status -> fik = $ array [ 'fik' ] ; } if ( array_key_exists ( 'rejectTime' , $ array ) ) { $ status -> rejectTime = new DateTime ( $ array [ 'rejectTime' ] ) ; } if ( array_key_exists ( 'error' , $ array ) and $ array [ 'error' ] ) { $ status -> error = new EETError ( $ array [ 'error' ] [ 'code' ] , $ array [ 'error' ] [ 'desc' ] ) ; } if ( array_key_exists ( 'warning' , $ array ) and is_array ( $ array [ 'warning' ] ) ) { foreach ( $ array [ 'warning' ] as $ warningData ) { $ status -> warning [ ] = new EETWarning ( $ warningData [ 'code' ] , $ warningData [ 'desc' ] ) ; } } return $ status ; } | Creates an EETStatus object from received data array |
50,571 | function addCartItem ( $ name , $ quantity , $ totalAmount , $ description = "" ) { if ( count ( $ this -> cart ) >= 2 ) { throw new Exception ( "This version of banks's API supports only up to 2 cart items in single payment, you can't add any more items." ) ; } if ( ! is_numeric ( $ quantity ) or $ quantity < 1 ) { throw new Exception ( "Invalid quantity: $quantity. It must be numeric and >= 1" ) ; } $ name = trim ( Strings :: shorten ( $ name , 20 , "" , true , true ) ) ; $ description = trim ( Strings :: shorten ( $ description , 40 , "" , true , true ) ) ; $ this -> cart [ ] = array ( "name" => $ name , "quantity" => $ quantity , "amount" => intval ( round ( $ totalAmount ) ) , "description" => $ description ) ; return $ this ; } | Add one cart item . |
50,572 | public function setMerchantData ( $ data , $ alreadyEncoded = false ) { if ( ! $ alreadyEncoded ) { $ data = base64_encode ( $ data ) ; } if ( strlen ( $ data ) > 255 ) { throw new Exception ( "Merchant data can not be longer than 255 characters after base64 encoding." ) ; } $ this -> merchantData = $ data ; return $ this ; } | Set some arbitrary data you will receive back when customer returns |
50,573 | function setRecurrentPayment ( $ recurrent = true ) { $ this -> payOperation = $ recurrent ? self :: OPERATION_RECURRENT : self :: OPERATION_PAYMENT ; trigger_error ( 'setRecurrentPayment() is deprecated, use setOneClickPayment() instead.' , E_USER_DEPRECATED ) ; return $ this ; } | Mark this payment as a template for recurrent payments . |
50,574 | function setOneClickPayment ( $ oneClick = true ) { $ this -> payOperation = $ oneClick ? self :: OPERATION_ONE_CLICK : self :: OPERATION_PAYMENT ; return $ this ; } | Mark this payment as one - click payment template |
50,575 | function checkAndPrepare ( Config $ config ) { $ this -> merchantId = $ config -> merchantId ; $ this -> dttm = date ( Client :: DATE_FORMAT ) ; if ( ! $ this -> payOperation ) { $ this -> payOperation = self :: OPERATION_PAYMENT ; } if ( ! $ this -> payMethod ) { $ this -> payMethod = "card" ; } if ( ! $ this -> currency ) { $ this -> currency = "CZK" ; } if ( ! $ this -> language ) { $ this -> language = "CZ" ; } if ( ! $ this -> ttlSec or ! is_numeric ( $ this -> ttlSec ) ) { $ this -> ttlSec = 1800 ; } if ( $ this -> closePayment === null ) { $ this -> closePayment = $ config -> closePayment ? true : false ; } if ( ! $ this -> returnUrl ) { $ this -> returnUrl = $ config -> returnUrl ; } if ( ! $ this -> returnUrl ) { throw new Exception ( "A ReturnUrl must be set - either by setting \$returnUrl property, or by specifying it in Config." ) ; } if ( ! $ this -> returnMethod ) { $ this -> returnMethod = $ config -> returnMethod ; } if ( ! $ this -> description ) { $ this -> description = $ config -> shopName . ", " . $ this -> orderNo ; } $ this -> description = Strings :: shorten ( $ this -> description , 240 , "..." ) ; $ this -> customerId = Strings :: shorten ( $ this -> customerId , 50 , "" , true , true ) ; if ( ! $ this -> cart ) { throw new Exception ( "Cart is empty. Please add one or two items into cart using addCartItem() method." ) ; } if ( ! $ this -> orderNo or ! preg_match ( '~^[0-9]{1,10}$~' , $ this -> orderNo ) ) { throw new Exception ( "Invalid orderNo - it must be a non-empty numeric value, 10 characters max." ) ; } $ sumOfItems = array_sum ( Arrays :: transform ( $ this -> cart , true , "amount" ) ) ; $ this -> totalAmount = $ sumOfItems ; return $ this ; } | Validate and initialise properties . This method is called automatically in proper time you never have to call it on your own . |
50,576 | function signAndExport ( Client $ client ) { $ arr = array ( ) ; $ config = $ client -> getConfig ( ) ; foreach ( $ this -> fieldsInOrder as $ f ) { $ val = $ this -> $ f ; if ( $ val === null ) { $ val = "" ; } $ arr [ $ f ] = $ val ; } foreach ( $ this -> auxFieldsInOrder as $ f ) { $ val = $ this -> $ f ; if ( $ val !== null ) { $ arr [ $ f ] = $ val ; } } $ stringToSign = $ this -> getSignatureString ( ) ; $ client -> writeToTraceLog ( 'Signing payment request, base for the signature:' . "\n" . $ stringToSign ) ; $ signed = Crypto :: signString ( $ stringToSign , $ config -> privateKeyFile , $ config -> privateKeyPassword ) ; $ arr [ "signature" ] = $ signed ; return $ arr ; } | Add signature and export to array . This method is called automatically and you don t need to call is on your own . |
50,577 | function getSignatureString ( ) { $ parts = array ( ) ; foreach ( $ this -> fieldsInOrder as $ f ) { $ val = $ this -> $ f ; if ( $ val === null ) { $ val = "" ; } elseif ( is_bool ( $ val ) ) { if ( $ val ) { $ val = "true" ; } else { $ val = "false" ; } } elseif ( is_array ( $ val ) ) { $ valParts = array ( ) ; foreach ( $ val as $ v ) { if ( is_scalar ( $ v ) ) { $ valParts [ ] = $ v ; } else { $ valParts [ ] = implode ( "|" , $ v ) ; } } $ val = implode ( "|" , $ valParts ) ; } $ parts [ ] = $ val ; } foreach ( $ this -> auxFieldsInOrder as $ f ) { $ val = $ this -> $ f ; if ( $ val !== null ) { $ parts [ ] = $ val ; } } return implode ( "|" , $ parts ) ; } | Convert to string that serves as base for signing . |
50,578 | static function signString ( $ string , $ privateKeyFile , $ privateKeyPassword = "" ) { if ( ! function_exists ( "openssl_get_privatekey" ) ) { throw new CryptoException ( "OpenSSL extension in PHP is required. Please install or enable it." ) ; } if ( ! file_exists ( $ privateKeyFile ) or ! is_readable ( $ privateKeyFile ) ) { throw new CryptoException ( "Private key file \"$privateKeyFile\" not found or not readable." ) ; } $ keyAsString = file_get_contents ( $ privateKeyFile ) ; $ privateKeyId = openssl_get_privatekey ( $ keyAsString , $ privateKeyPassword ) ; if ( ! $ privateKeyId ) { throw new CryptoException ( "Private key could not be loaded from file \"$privateKeyFile\". Please make sure that the file contains valid private key in PEM format." ) ; } $ ok = openssl_sign ( $ string , $ signature , $ privateKeyId , self :: HASH_METHOD ) ; if ( ! $ ok ) { throw new CryptoException ( "Signing failed." ) ; } $ signature = base64_encode ( $ signature ) ; openssl_free_key ( $ privateKeyId ) ; return $ signature ; } | Signs a string |
50,579 | static function verifySignature ( $ textToVerify , $ signatureInBase64 , $ publicKeyFile ) { if ( ! function_exists ( "openssl_get_privatekey" ) ) { throw new CryptoException ( "OpenSSL extension in PHP is required. Please install or enable it." ) ; } if ( ! file_exists ( $ publicKeyFile ) or ! is_readable ( $ publicKeyFile ) ) { throw new CryptoException ( "Public key file \"$publicKeyFile\" not found or not readable." ) ; } $ keyAsString = file_get_contents ( $ publicKeyFile ) ; $ publicKeyId = openssl_get_publickey ( $ keyAsString ) ; $ signature = base64_decode ( $ signatureInBase64 ) ; $ res = openssl_verify ( $ textToVerify , $ signature , $ publicKeyId , self :: HASH_METHOD ) ; openssl_free_key ( $ publicKeyId ) ; if ( $ res == - 1 ) { throw new CryptoException ( "Verification of signature failed: " . openssl_error_string ( ) ) ; } return $ res ? true : false ; } | Verifies signature of a string |
50,580 | protected function registerClientScript ( ) { $ js = [ ] ; $ view = $ this -> getView ( ) ; TinyMceAsset :: register ( $ view ) ; if ( $ tinyAssetBundle = TinyMceAsset :: register ( $ view ) ) { $ xCopy = new xCopy ( ) ; $ assetPath = $ tinyAssetBundle -> basePath ; $ languagesPack = Yii :: getAlias ( '@dominus77/tinymce/assets/languages_pack' ) ; $ xCopy -> copyFolder ( $ languagesPack , $ assetPath , true , true ) ; $ pluginsPack = Yii :: getAlias ( '@dominus77/tinymce/assets/plugins_pack' ) ; $ xCopy -> copyFolder ( $ pluginsPack , $ assetPath , true , true ) ; $ skinsPack = Yii :: getAlias ( '@dominus77/tinymce/assets/skins_pack' ) ; $ xCopy -> copyFolder ( $ skinsPack , $ assetPath , true , true ) ; } $ id = $ this -> options [ 'id' ] ? $ this -> options [ 'id' ] : $ this -> getId ( ) ; $ this -> clientOptions [ 'selector' ] = "#{$id}" ; $ this -> clientOptions [ 'language' ] = isset ( $ this -> clientOptions [ 'language' ] ) ? $ this -> clientOptions [ 'language' ] : $ this -> language ; if ( $ this -> fileManager !== false ) { $ fm = Yii :: createObject ( array_merge ( $ this -> fileManager , [ 'tinyMceSettings' => $ this -> clientOptions , 'parentView' => $ view ] ) ) ; $ fm -> init ( ) ; $ fm -> registerAsset ( ) ; $ this -> clientOptions [ 'file_picker_callback' ] = $ fm -> getFilePickerCallback ( ) ; } $ options = Json :: encode ( $ this -> clientOptions ) ; $ js [ ] = "tinymce.init({$options});" ; if ( $ this -> triggerSaveOnBeforeValidateForm ) { $ js [ ] = "$('#{$id}').parents('form').on('beforeValidate', function() { tinymce.triggerSave(); });" ; } $ view -> registerJs ( implode ( "\n" , $ js ) ) ; } | Registers tinyMCE js plugin |
50,581 | protected function getResponseData ( $ path , $ default = null ) { $ array = $ this -> response ; if ( ! empty ( $ path ) ) { $ keys = explode ( '.' , $ path ) ; foreach ( $ keys as $ key ) { if ( isset ( $ array [ $ key ] ) ) { $ array = $ array [ $ key ] ; } else { return $ default ; } } } return $ array ; } | Attempts to pull value from array using dot notation . |
50,582 | private function traverse ( $ pointer ) { $ parsedPointer = $ this -> parse ( $ pointer ) ; $ json = $ this -> json ; foreach ( $ parsedPointer as $ segment ) { if ( $ json instanceof Reference ) { if ( ! $ json -> has ( $ segment ) ) { return new NonExistentValue ( $ segment , $ pointer ) ; } $ json = $ json -> get ( $ segment ) ; } elseif ( is_object ( $ json ) ) { if ( $ segment === '' && property_exists ( $ json , '_empty_' ) ) { $ segment = '_empty_' ; } if ( ! property_exists ( $ json , $ segment ) ) { return new NonExistentValue ( $ segment , $ pointer ) ; } $ json = $ json -> $ segment ; } elseif ( is_array ( $ json ) ) { if ( ! array_key_exists ( $ segment , $ json ) ) { return new NonExistentValue ( $ segment , $ pointer ) ; } $ json = $ json [ $ segment ] ; } else { return new NonExistentValue ( $ segment , $ pointer ) ; } } return $ json ; } | Returns the value referenced by the pointer or a NonExistentValue if the value does not exist . |
50,583 | private function loadExternalRef ( $ reference ) { list ( $ prefix , $ path ) = parse_external_ref ( $ reference ) ; return $ this -> loaderManager -> getLoader ( $ prefix ) -> load ( $ path ) ; } | Load an external ref and return the JSON object . |
50,584 | public function getLoader ( $ prefix ) { if ( ! $ this -> hasLoader ( $ prefix ) ) { throw new \ InvalidArgumentException ( sprintf ( 'A loader is not registered for the prefix "%s"' , $ prefix ) ) ; } return $ this -> loaders [ $ prefix ] ; } | Get the loader for the given prefix . |
50,585 | private function registerDefaultWebLoaders ( ) { if ( function_exists ( 'curl_init' ) ) { $ this -> loaders [ 'https' ] = new CurlWebLoader ( 'https://' ) ; $ this -> loaders [ 'http' ] = new CurlWebLoader ( 'http://' ) ; } else { $ this -> loaders [ 'https' ] = new FileGetContentsWebLoader ( 'https://' ) ; $ this -> loaders [ 'http' ] = new FileGetContentsWebLoader ( 'http://' ) ; } } | Register the default web loaders . If the curl extension is loaded the CurlWebLoader will be used . Otherwise the FileGetContentsWebLoader will be used . You can override this by registering your own loader for the http and https protocols . |
50,586 | public function resolve ( ) { if ( isset ( $ this -> resolved ) ) { return $ this -> resolved ; } $ pointer = new Pointer ( $ this -> schema ) ; if ( is_internal_ref ( $ this -> ref ) && $ pointer -> has ( $ this -> ref ) ) { return $ this -> resolved = $ pointer -> get ( $ this -> ref ) ; } return $ this -> dereferencer ( ) -> dereference ( resolve_uri ( $ this -> ref , $ this -> scope ) ) ; } | Resolve the reference and return the data . |
50,587 | public function setDomain ( $ domain ) { try { $ this -> domain = ( string ) $ domain ; } catch ( Exception $ e ) { throw new InvalidArgumentException ( 'Value provided as domain is not a string' ) ; } return $ this ; } | Updates the provider domain with a given value . |
50,588 | public function process ( ) { if ( Yii :: $ app -> db -> getTableSchema ( $ this -> table ) == null ) { throw new \ yii \ base \ InvalidConfigException ( '"' . $ this -> table . '" not found in database. Make sure the db migration is properly done and the table is created.' ) ; } $ success = true ; $ items = Queue :: find ( ) -> where ( [ 'and' , [ 'sent_time' => NULL ] , [ '<' , 'attempts' , $ this -> maxAttempts ] , [ '<=' , 'time_to_send' , date ( 'Y-m-d H:i:s' ) ] ] ) -> orderBy ( [ 'created_at' => SORT_ASC ] ) -> limit ( $ this -> mailsPerRound ) ; foreach ( $ items -> each ( ) as $ item ) { if ( $ message = $ item -> toMessage ( ) ) { $ attributes = [ 'attempts' , 'last_attempt_time' ] ; if ( $ this -> send ( $ message ) ) { $ item -> sent_time = new \ yii \ db \ Expression ( 'NOW()' ) ; $ attributes [ ] = 'sent_time' ; } else { $ success = false ; } $ item -> attempts ++ ; $ item -> last_attempt_time = new \ yii \ db \ Expression ( 'NOW()' ) ; $ item -> updateAttributes ( $ attributes ) ; } } if ( $ this -> autoPurge ) { $ this -> purge ( ) ; } return $ success ; } | Sends out the messages in email queue and update the database . |
50,589 | public function queue ( $ time_to_send = 'now' ) { if ( $ time_to_send == 'now' ) { $ time_to_send = time ( ) ; } $ item = new Queue ( ) ; $ item -> subject = $ this -> getSubject ( ) ; $ item -> attempts = 0 ; $ item -> swift_message = base64_encode ( serialize ( $ this ) ) ; $ item -> time_to_send = date ( 'Y-m-d H:i:s' , $ time_to_send ) ; return $ item -> save ( ) ; } | Enqueue the message storing it in database . |
50,590 | public function setup ( PlayerCollection $ players ) : self { $ collection = $ players -> map ( function ( Player $ player , $ seatNumber ) { return [ 'seat' => $ seatNumber , 'player' => $ player -> name ( ) , 'action' => self :: STILL_TO_ACT , ] ; } ) ; return self :: make ( $ collection -> toArray ( ) ) ; } | Sets all players actions to STILL_TO_ACT . |
50,591 | public function setupWithoutDealer ( PlayerCollection $ players ) : self { $ collection = $ this -> setup ( $ players ) ; $ collection = $ collection -> movePlayerToLastInQueue ( ) ; return self :: make ( $ collection -> values ( ) -> toArray ( ) ) ; } | Resets all players and move dealer to the bottom of queue . |
50,592 | public function checkCommunityCards ( ) { if ( $ this -> communityCards ( ) -> count ( ) === 5 ) { return ; } if ( $ this -> communityCards ( ) -> count ( ) === 0 ) { $ this -> dealCommunityCards ( 3 ) ; } if ( $ this -> communityCards ( ) -> count ( ) === 3 ) { $ this -> dealCommunityCards ( 1 ) ; } if ( $ this -> communityCards ( ) -> count ( ) === 4 ) { $ this -> dealCommunityCards ( 1 ) ; } } | Deals the remainder of the community cards whilst taking burn cards into account . |
50,593 | public static function start ( Uuid $ id , Table $ table , GameParameters $ gameRules ) : Round { return new static ( $ id , $ table , $ gameRules ) ; } | Start a Round of poker . |
50,594 | public function end ( ) { $ this -> dealer ( ) -> checkCommunityCards ( ) ; $ this -> collectChipTotal ( ) ; $ this -> distributeWinnings ( ) ; $ this -> table ( ) -> moveButton ( ) ; } | Run the cleanup procedure for an end of Round . |
50,595 | private function distributeWinnings ( ) { $ this -> chipPots ( ) -> reverse ( ) -> each ( function ( ChipPot $ chipPot ) { if ( $ chipPot -> players ( ) -> count ( ) === 1 ) { $ potTotal = $ chipPot -> chips ( ) -> total ( ) ; $ chipPot -> players ( ) -> first ( ) -> chipStack ( ) -> add ( $ potTotal ) ; $ this -> chipPots ( ) -> remove ( $ chipPot ) ; return ; } $ activePlayers = $ chipPot -> players ( ) -> diff ( $ this -> foldedPlayers ( ) ) ; $ playerHands = $ this -> dealer ( ) -> hands ( ) -> findByPlayers ( $ activePlayers ) ; $ evaluate = $ this -> dealer ( ) -> evaluateHands ( $ this -> dealer ( ) -> communityCards ( ) , $ playerHands ) ; if ( $ evaluate -> count ( ) === 1 ) { $ player = $ evaluate -> first ( ) -> hand ( ) -> player ( ) ; $ potTotal = $ chipPot -> chips ( ) -> total ( ) ; $ player -> chipStack ( ) -> add ( $ potTotal ) ; $ this -> chipPots ( ) -> remove ( $ chipPot ) ; } else { $ potTotal = $ chipPot -> chips ( ) -> total ( ) ; $ splitTotal = Chips :: fromAmount ( ( $ potTotal -> amount ( ) / $ evaluate -> count ( ) ) ) ; $ evaluate -> each ( function ( CardResults $ result ) use ( $ splitTotal ) { $ result -> hand ( ) -> player ( ) -> chipStack ( ) -> add ( $ splitTotal ) ; } ) ; $ this -> chipPots ( ) -> remove ( $ chipPot ) ; } } ) ; } | Runs over each chipPot and assigns the chips to the winning player . |
50,596 | public function dealFlop ( ) { if ( $ this -> dealer ( ) -> communityCards ( ) -> count ( ) !== 0 ) { throw RoundException :: flopHasBeenDealt ( ) ; } if ( $ player = $ this -> whosTurnIsIt ( ) ) { throw RoundException :: playerStillNeedsToAct ( $ player ) ; } $ this -> collectChipTotal ( ) ; $ seat = $ this -> table ( ) -> findSeat ( $ this -> playerWithSmallBlind ( ) ) ; $ this -> resetPlayerList ( $ seat ) ; $ this -> dealer ( ) -> dealCommunityCards ( 3 ) ; $ this -> actions ( ) -> push ( new Action ( $ this -> dealer ( ) , Action :: DEALT_FLOP , [ 'communityCards' => $ this -> dealer ( ) -> communityCards ( ) -> only ( range ( 0 , 2 ) ) , ] ) ) ; } | Deal the Flop . |
50,597 | public function dealTurn ( ) { if ( $ this -> dealer ( ) -> communityCards ( ) -> count ( ) !== 3 ) { throw RoundException :: turnHasBeenDealt ( ) ; } if ( ( $ player = $ this -> whosTurnIsIt ( ) ) !== false ) { throw RoundException :: playerStillNeedsToAct ( $ player ) ; } $ this -> collectChipTotal ( ) ; $ seat = $ this -> table ( ) -> findSeat ( $ this -> playerWithSmallBlind ( ) ) ; $ this -> resetPlayerList ( $ seat ) ; $ this -> dealer ( ) -> dealCommunityCards ( 1 ) ; $ this -> actions ( ) -> push ( new Action ( $ this -> dealer ( ) , Action :: DEALT_TURN , [ 'communityCards' => $ this -> dealer ( ) -> communityCards ( ) -> only ( 3 ) , ] ) ) ; } | Deal the turn card . |
50,598 | public function dealRiver ( ) { if ( $ this -> dealer ( ) -> communityCards ( ) -> count ( ) !== 4 ) { throw RoundException :: riverHasBeenDealt ( ) ; } if ( ( $ player = $ this -> whosTurnIsIt ( ) ) !== false ) { throw RoundException :: playerStillNeedsToAct ( $ player ) ; } $ this -> collectChipTotal ( ) ; $ seat = $ this -> table ( ) -> findSeat ( $ this -> playerWithSmallBlind ( ) ) ; $ this -> resetPlayerList ( $ seat ) ; $ this -> dealer ( ) -> dealCommunityCards ( 1 ) ; $ this -> actions ( ) -> push ( new Action ( $ this -> dealer ( ) , Action :: DEALT_RIVER , [ 'communityCards' => $ this -> dealer ( ) -> communityCards ( ) -> only ( 4 ) , ] ) ) ; } | Deal the river card . |
50,599 | private function resetBetStacks ( ) { $ this -> players ( ) -> each ( function ( PlayerContract $ player ) { $ this -> betStacks -> put ( $ player -> name ( ) , Chips :: zero ( ) ) ; } ) ; } | Reset the chip stack for all players . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.