idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
39,100
private function getSmtpPassword ( $ storeId = null ) { $ value = $ this -> scopeConfig -> getValue ( self :: XML_PATH_DDG_TRANSACTIONAL_PASSWORD , \ Magento \ Store \ Model \ ScopeInterface :: SCOPE_STORE , $ storeId ) ; return $ this -> encryptor -> decrypt ( $ value ) ; }
Get smtp password .
39,101
private function getSmtpPort ( $ storeId ) { return $ this -> scopeConfig -> getValue ( self :: XML_PATH_DDG_TRANSACTIONAL_PORT , \ Magento \ Store \ Model \ ScopeInterface :: SCOPE_STORE , $ storeId ) ; }
Get smtp port .
39,102
private function isDebugEnabled ( $ storeId ) { return $ this -> scopeConfig -> isSetFlag ( self :: XML_PATH_DDG_TRANSACTIONAL_DEBUG , \ Magento \ Store \ Model \ ScopeInterface :: SCOPE_STORE , $ storeId ) ; }
Get transactional log enabled .
39,103
public function getTransportConfig ( $ storeId ) { $ config = [ 'port' => $ this -> getSmtpPort ( $ storeId ) , 'auth' => 'login' , 'username' => $ this -> getSmtpUsername ( $ storeId ) , 'password' => $ this -> getSmtpPassword ( $ storeId ) , 'ssl' => 'tls' , ] ; if ( $ this -> isDebugEnabled ( $ storeId ) ) { $ this -> _logger -> debug ( 'Mail transport config : ' . implode ( ',' , $ config ) ) ; } return $ config ; }
Get config values for transport .
39,104
private function checkRuleExistAndLoad ( $ id , $ emailRules ) { if ( $ id ) { $ this -> rulesResource -> load ( $ emailRules , $ id ) ; if ( ! $ emailRules -> getId ( ) ) { $ this -> messageManager -> addErrorMessage ( __ ( 'This rule no longer exists.' ) ) ; $ this -> _redirect ( '*/*' ) ; } } $ this -> _view -> getPage ( ) -> getConfig ( ) -> getTitle ( ) -> prepend ( $ emailRules -> getId ( ) ? $ emailRules -> getName ( ) : __ ( 'New Rule' ) ) ; $ data = $ this -> _session -> getPageData ( true ) ; if ( ! empty ( $ data ) ) { $ this -> rules -> addData ( $ data ) ; } }
Check rule exist
39,105
public function isLocked ( ) { if ( $ this -> getFailuresNum ( ) == \ Dotdigitalgroup \ Email \ Model \ FailedAuth :: NUMBER_MAX_FAILS_LIMIT && strtotime ( $ this -> getLastAttemptDate ( ) . '+5 min' ) > time ( ) ) { return true ; } return false ; }
Check if the store is in the locked state .
39,106
public function updateStatus ( $ contactIds , $ status , $ message , $ updatedAt , $ type ) { $ bind = [ 'enrolment_status' => $ status , 'message' => $ message , 'updated_at' => $ updatedAt , ] ; $ where = [ 'id IN(?)' => $ contactIds ] ; $ num = $ this -> getConnection ( ) -> update ( $ this -> getTable ( Schema :: EMAIL_AUTOMATION_TABLE ) , $ bind , $ where ) ; if ( $ num ) { $ this -> helper -> log ( 'Automation type : ' . $ type . ', updated : ' . $ num ) ; } }
update status for automation entries
39,107
public function getActiveRuleByWebsiteAndType ( $ type , $ websiteId ) { $ collection = $ this -> addFieldToFilter ( 'type' , [ 'eq' => $ type ] ) -> addFieldToFilter ( 'status' , [ 'eq' => 1 ] ) -> addFieldToFilter ( 'website_ids' , [ 'finset' => $ websiteId ] ) -> setPageSize ( 1 ) ; if ( $ collection -> getSize ( ) ) { return $ collection -> getFirstItem ( ) ; } return [ ] ; }
Get rule for website .
39,108
public function getStoreIdForSubscriber ( $ email , $ subscribers ) { $ defaultStore = 1 ; foreach ( $ subscribers as $ subscriber ) { if ( $ subscriber [ 'subscriber_email' ] == $ email ) { return $ subscriber [ 'store_id' ] ; } } return $ defaultStore ; }
Get the store id from newsletter_subscriber return default if not found .
39,109
public function createAbandonedCartTable ( $ installer , $ tableName ) { $ abandonedCartTable = $ installer -> getConnection ( ) -> newTable ( $ installer -> getTable ( $ tableName ) ) ; $ abandonedCartTable = $ this -> addColumnForAbandonedCartTable ( $ abandonedCartTable ) ; $ abandonedCartTable = $ this -> addIndexKeyForAbandonedCarts ( $ installer , $ abandonedCartTable ) ; $ abandonedCartTable -> setComment ( 'Abandoned Carts Table' ) ; $ installer -> getConnection ( ) -> createTable ( $ abandonedCartTable ) ; }
Create abandoned cart table
39,110
public function createConsentTable ( $ installer , $ tableName ) { $ emailContactConsentTable = $ installer -> getConnection ( ) -> newTable ( $ installer -> getTable ( $ tableName ) ) ; $ emailContactConsentTable = $ this -> addColumnForConsentTable ( $ emailContactConsentTable ) ; $ emailContactConsentTable = $ this -> addIndexToConsentTable ( $ installer , $ emailContactConsentTable ) ; $ emailContactConsentTable = $ this -> addKeyForConsentTable ( $ installer , $ emailContactConsentTable ) ; $ emailContactConsentTable -> setComment ( 'Email contact consent table.' ) ; $ installer -> getConnection ( ) -> createTable ( $ emailContactConsentTable ) ; }
Create consent table
39,111
public function createFailedAuthTable ( $ installer , $ tableName ) { $ emailAuthEdc = $ installer -> getConnection ( ) -> newTable ( $ installer -> getTable ( $ tableName ) ) ; $ emailAuthEdc = $ this -> addColumnForFailedAuthTable ( $ emailAuthEdc ) ; $ emailAuthEdc = $ this -> addIndexToFailedAuthTable ( $ installer , $ emailAuthEdc ) ; $ emailAuthEdc -> setComment ( 'Email Failed Auth Table.' ) ; $ installer -> getConnection ( ) -> createTable ( $ emailAuthEdc ) ; }
Create failed auth table
39,112
public function getDisplayType ( ) { $ mode = $ this -> context -> getRequest ( ) -> getActionName ( ) ; $ type = '' ; switch ( $ mode ) { case 'related' : $ type = $ this -> getRelatedProductsType ( ) ; break ; case 'upsell' : $ type = $ this -> getUpsellProductsType ( ) ; break ; case 'crosssell' : $ type = $ this -> getCrosssellProductsType ( ) ; break ; case 'bestsellers' : $ type = $ this -> getBestSellerProductsType ( ) ; break ; case 'mostviewed' : $ type = $ this -> getMostViewedProductsType ( ) ; break ; case 'recentlyviewed' : $ type = $ this -> getRecentlyviewedProductsType ( ) ; break ; case 'push' : $ type = $ this -> getProductpushProductsType ( ) ; } return $ type ; }
Dispay type .
39,113
public function getDisplayLimitByMode ( $ mode ) { $ result = 0 ; switch ( $ mode ) { case 'related' : $ result = $ this -> scopeConfig -> getValue ( self :: XML_PATH_RELATED_PRODUCTS_ITEMS ) ; break ; case 'upsell' : $ result = $ this -> scopeConfig -> getValue ( self :: XML_PATH_UPSELL_PRODUCTS_ITEMS ) ; break ; case 'crosssell' : $ result = $ this -> scopeConfig -> getValue ( self :: XML_PATH_CROSSSELL_PRODUCTS_ITEMS ) ; break ; case 'bestsellers' : $ result = $ this -> scopeConfig -> getValue ( self :: XML_PATH_BESTSELLER_PRODUCT_ITEMS ) ; break ; case 'mostviewed' : $ result = $ this -> scopeConfig -> getValue ( self :: XML_PATH_MOSTVIEWED_PRODUCT_ITEMS ) ; break ; case 'recentlyviewed' : $ result = $ this -> scopeConfig -> getValue ( self :: XML_PATH_RECENTLYVIEWED_PRODUCT_ITEMS ) ; break ; case 'push' : $ result = $ this -> scopeConfig -> getValue ( self :: XML_PATH_PRODUCTPUSH_DISPLAY_ITEMS ) ; } return $ result ; }
Limit of products displayed .
39,114
public function getFallbackIds ( ) { $ fallbackIds = $ this -> scopeConfig -> getValue ( self :: XML_PATH_FALLBACK_PRODUCTS_ITEMS ) ; if ( $ fallbackIds ) { return explode ( ',' , $ this -> scopeConfig -> getValue ( self :: XML_PATH_FALLBACK_PRODUCTS_ITEMS ) ) ; } return [ ] ; }
Fallback product ids .
39,115
public function getTimeFromConfig ( $ config ) { $ now = $ this -> date ; $ period = $ this -> processConfig ( $ config ) ; $ sub = $ this -> processPeriod ( $ period ) ; if ( isset ( $ sub ) ) { $ period = $ now -> sub ( 1 , $ sub ) ; } return $ period -> toString ( \ Zend_Date :: ISO_8601 ) ; }
Get time period from config .
39,116
public function getProductsToDisplay ( $ items , $ mode , & $ productsToDisplayCounter , $ limit , $ maxPerChild ) { $ productsToDisplay = [ ] ; foreach ( $ items as $ item ) { $ productModel = $ item -> getProduct ( ) ; if ( $ productModel -> getId ( ) ) { $ recommendedProductIds = $ this -> getRecommendedProduct ( $ productModel , $ mode ) ; $ recommendedProducts = $ this -> catalog -> getProductCollectionFromIds ( $ recommendedProductIds ) ; $ this -> addRecommendedProducts ( $ productsToDisplayCounter , $ limit , $ maxPerChild , $ recommendedProducts , $ productsToDisplay ) ; } if ( $ productsToDisplayCounter == $ limit ) { break ; } } return $ productsToDisplay ; }
Get products to display
39,117
private function registerWithImporter ( $ emailContactIds , $ subscribersFile , $ websiteId ) { $ subscriberNum = count ( $ emailContactIds ) ; if ( is_file ( $ this -> file -> getFilePath ( $ subscribersFile ) ) ) { if ( $ subscriberNum > 0 ) { $ check = $ this -> importerFactory -> create ( ) -> registerQueue ( \ Dotdigitalgroup \ Email \ Model \ Importer :: IMPORT_TYPE_SUBSCRIBERS , '' , \ Dotdigitalgroup \ Email \ Model \ Importer :: MODE_BULK , $ websiteId , $ subscribersFile ) ; if ( $ check ) { $ this -> emailContactResource -> updateSubscribers ( $ emailContactIds ) ; } } } }
Register data with importer
39,118
private function getProcessedTemplateBeforeSave ( $ result ) { if ( empty ( $ args ) ) { $ this -> getResultIfArgsEmptyForBeforeSave ( $ result ) ; } else { $ field = $ args [ 0 ] ; if ( $ field == 'template_text' && ! $ this -> isStringCompressed ( $ result ) && $ this -> transactionalHelper -> isDotmailerTemplate ( $ this -> templateCode ) ) { $ result = $ this -> compressString ( $ result ) ; } if ( $ field == 'template_id' ) { $ this -> saveTemplateIdInRegistry ( $ result ) ; } } return $ result ; }
Get data before saving
39,119
public function postAddressBookContactResubscribe ( $ addressBookId , $ email ) { $ contact = [ 'unsubscribedContact' => [ 'email' => $ email ] ] ; $ url = $ this -> getApiEndpoint ( ) . Client :: REST_ADDRESS_BOOKS . $ addressBookId . '/contacts/resubscribe' ; $ this -> setUrl ( $ url ) -> setVerb ( 'POST' ) -> buildPostBody ( $ contact ) ; $ response = $ this -> execute ( ) ; if ( isset ( $ response -> message ) ) { $ message = 'POST ADDRESS BOOK CONTACT RESUBSCRIBE ' . $ url . ', ' . $ response -> message ; $ this -> helper -> debug ( 'postAddressBookContactResubscribe' , [ $ message ] ) ; } return $ response ; }
Resubscribes a previously unsubscribed contact to a given address book
39,120
public function getItemsWithImportingStatus ( $ limit ) { $ collection = $ this -> addFieldToFilter ( 'import_status' , [ 'eq' => \ Dotdigitalgroup \ Email \ Model \ Importer :: IMPORTING ] ) -> addFieldToFilter ( 'import_id' , [ 'neq' => '' ] ) -> setPageSize ( $ limit ) -> setCurPage ( 1 ) ; if ( $ collection -> getSize ( ) ) { return $ collection ; } return false ; }
Get imports marked as importing .
39,121
public function getQueueByTypeAndMode ( $ importType , $ importMode , $ limit ) { if ( is_array ( $ importType ) ) { $ condition = [ ] ; foreach ( $ importType as $ type ) { if ( $ type == 'Catalog' ) { $ condition [ ] = [ 'like' => $ type . '%' ] ; } else { $ condition [ ] = [ 'eq' => $ type ] ; } } $ this -> addFieldToFilter ( 'import_type' , $ condition ) ; } else { $ this -> addFieldToFilter ( 'import_type' , [ 'eq' => $ importType ] ) ; } $ this -> addFieldToFilter ( 'import_mode' , [ 'eq' => $ importMode ] ) -> addFieldToFilter ( 'import_status' , [ 'eq' => \ Dotdigitalgroup \ Email \ Model \ Importer :: NOT_IMPORTED ] ) -> setPageSize ( $ limit ) -> setCurPage ( 1 ) ; return $ this ; }
Get the imports by type and mode .
39,122
public function aroundGetExcludes ( \ Magento \ Framework \ View \ Asset \ Minification $ subject , callable $ proceed , $ contentType ) { $ result = $ proceed ( $ contentType ) ; if ( $ contentType == 'js' ) { $ result [ ] = 'trackedlink.net/_dmpt.js' ; $ result [ ] = 'trackedlink.net/_dmmpt.js' ; } return $ result ; }
Exclude external js from minification
39,123
public function sendCampaigns ( ) { foreach ( $ this -> storeManager -> getWebsites ( true ) as $ website ) { $ storeIds = $ website -> getStoreIds ( ) ; $ this -> _checkSendStatus ( $ website , $ storeIds ) ; $ emailsToSend = $ this -> _getEmailCampaigns ( $ storeIds ) ; $ campaignsToSend = $ this -> getCampaignsToSend ( $ emailsToSend , $ website ) ; $ this -> sendCampaignsViaEngagementCloud ( $ campaignsToSend ) ; } }
Sending the campaigns
39,124
private function getCampaignsToSend ( $ emailsToSend , $ website ) { $ campaignsToSend = [ ] ; foreach ( $ emailsToSend as $ campaign ) { $ email = $ campaign -> getEmail ( ) ; $ campaignId = $ campaign -> getCampaignId ( ) ; $ websiteId = $ website -> getId ( ) ; $ client = false ; if ( $ this -> helper -> isEnabled ( $ websiteId ) ) { $ client = $ this -> helper -> getWebsiteApiClient ( $ websiteId ) ; } if ( $ client && $ this -> isCampaignValid ( $ campaign ) ) { $ campaignsToSend [ $ campaignId ] [ 'client' ] = $ client ; $ contact = $ this -> helper -> getContact ( $ campaign -> getEmail ( ) , $ websiteId ) ; if ( $ contact && isset ( $ contact -> id ) ) { if ( $ campaign -> getEventName ( ) == 'Order Review' ) { $ this -> updateDataFieldsForORderReviewCampaigns ( $ campaign , $ websiteId , $ client , $ email ) ; } elseif ( $ campaign -> getEventName ( ) == \ Dotdigitalgroup \ Email \ Model \ Campaign :: CAMPAIGN_EVENT_LOST_BASKET ) { $ campaignCollection = $ this -> campaignCollection -> create ( ) ; if ( $ campaignCollection -> getNumberOfAcCampaignsWithStatusProcessingExistForContact ( $ email ) ) { continue ; } $ this -> helper -> updateLastQuoteId ( $ campaign -> getQuoteId ( ) , $ email , $ websiteId ) ; } $ campaignsToSend [ $ campaignId ] [ 'contacts' ] [ ] = $ contact -> id ; $ campaignsToSend [ $ campaignId ] [ 'ids' ] [ ] = $ campaign -> getId ( ) ; } else { $ campaign -> setSendStatus ( \ Dotdigitalgroup \ Email \ Model \ Campaign :: FAILED ) -> setMessage ( 'Send not permitted. Contact is suppressed.' ) ; $ this -> campaignResourceModel -> saveItem ( $ campaign ) ; } } } return $ campaignsToSend ; }
Get campaigns to send .
39,125
private function isCampaignValid ( $ campaign ) { if ( ! $ campaign -> getCampaignId ( ) ) { $ campaign -> setMessage ( 'Missing campaign id: ' . $ campaign -> getCampaignId ( ) ) -> setSendStatus ( \ Dotdigitalgroup \ Email \ Model \ Campaign :: FAILED ) ; $ this -> campaignResourceModel -> saveItem ( $ campaign ) ; return false ; } elseif ( ! $ campaign -> getEmail ( ) ) { $ campaign -> setMessage ( 'Missing email' ) -> setSendStatus ( \ Dotdigitalgroup \ Email \ Model \ Campaign :: FAILED ) ; $ this -> campaignResourceModel -> saveItem ( $ campaign ) ; return false ; } return true ; }
Check if campaign item is valid
39,126
private function sendCampaignsViaEngagementCloud ( $ campaignsToSend ) { foreach ( $ campaignsToSend as $ campaignId => $ data ) { if ( isset ( $ data [ 'contacts' ] ) && isset ( $ data [ 'client' ] ) ) { $ contacts = $ data [ 'contacts' ] ; $ client = $ data [ 'client' ] ; $ response = $ client -> postCampaignsSend ( $ campaignId , $ contacts ) ; if ( isset ( $ response -> message ) ) { $ this -> campaignResourceModel -> setMessage ( $ data [ 'ids' ] , $ response -> message ) ; } elseif ( isset ( $ response -> id ) ) { $ this -> campaignResourceModel -> setProcessing ( $ data [ 'ids' ] , $ response -> id ) ; } else { $ this -> campaignResourceModel -> setMessage ( $ data [ 'ids' ] , 'No send id returned.' ) ; } } } }
Send campaigns .
39,127
public function toOptionArray ( ) { $ fields = $ this -> dataHelper -> getOrderTableDescription ( ) ; $ customFields [ ] = [ 'label' => __ ( '---- Default Option ----' ) , 'value' => '0' , ] ; foreach ( $ fields as $ field ) { $ customFields [ ] = [ 'value' => $ field [ 'COLUMN_NAME' ] , 'label' => $ field [ 'COLUMN_NAME' ] , ] ; } return $ customFields ; }
Returns custom order attributes .
39,128
private function sendAjaxResponse ( $ error ) { $ message = [ 'err' => $ error ] ; $ this -> getResponse ( ) -> setHeader ( 'Content-type' , 'application/javascript' , true ) -> setBody ( 'signupCallback(' . $ this -> jsonHelper -> jsonEncode ( $ message ) . ')' ) -> sendResponse ( ) ; }
Send ajax response .
39,129
public function sync ( ) { $ response = [ 'success' => true , 'message' => 'Done.' ] ; $ websites = $ this -> helper -> getWebsites ( ) ; foreach ( $ websites as $ website ) { $ wishlistEnabled = $ this -> helper -> getWebsiteConfig ( \ Dotdigitalgroup \ Email \ Helper \ Config :: XML_PATH_CONNECTOR_SYNC_WISHLIST_ENABLED , $ website ) ; $ apiEnabled = $ this -> helper -> isEnabled ( $ website ) ; $ storeIds = $ website -> getStoreIds ( ) ; if ( $ wishlistEnabled && $ apiEnabled && ! empty ( $ storeIds ) ) { $ this -> start = microtime ( true ) ; $ this -> exportWishlistForWebsite ( $ website ) ; if ( isset ( $ this -> wishlists [ $ website -> getId ( ) ] ) ) { $ websiteWishlists = $ this -> wishlists [ $ website -> getId ( ) ] ; $ this -> importerFactory -> create ( ) -> registerQueue ( Importer :: IMPORT_TYPE_WISHLIST , $ websiteWishlists , Importer :: MODE_BULK , $ website -> getId ( ) ) ; $ this -> setImported ( $ this -> wishlistIds ) ; } if ( ! empty ( $ this -> wishlists ) ) { $ message = '----------- Wishlist bulk sync ----------- : ' . gmdate ( 'H:i:s' , microtime ( true ) - $ this -> start ) . ', Total synced = ' . $ this -> countWishlists ; $ this -> helper -> log ( $ message ) ; } $ this -> exportWishlistForWebsiteInSingle ( $ website ) ; } } $ response [ 'message' ] = 'wishlists updated: ' . $ this -> countWishlists ; return $ response ; }
Sync Wishlists .
39,130
public function exportWishlistForWebsiteInSingle ( \ Magento \ Store \ Api \ Data \ WebsiteInterface $ website ) { $ limit = $ this -> helper -> getWebsiteConfig ( \ Dotdigitalgroup \ Email \ Helper \ Config :: XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT , $ website ) ; $ collection = $ this -> getModifiedWishlistToImport ( $ website , $ limit ) ; $ this -> wishlistIds = [ ] ; $ wishlistIds = $ collection -> getColumnValues ( 'wishlist_id' ) ; $ wishlistCollection = $ this -> wishlist -> create ( ) -> getWishlistByIds ( $ wishlistIds ) ; foreach ( $ wishlistCollection as $ wishlist ) { $ wishlistId = $ wishlist -> getid ( ) ; $ wishlistItems = $ this -> itemCollection -> create ( ) -> addWishlistFilter ( $ wishlist ) ; $ connectorWishlist = $ this -> wishlistFactory -> create ( ) ; $ connectorWishlist -> setId ( $ wishlistId ) -> setUpdatedAt ( $ wishlist -> getUpdatedAt ( ) ) -> setCustomerId ( $ wishlist -> getCustomerId ( ) ) -> setEmail ( $ wishlist -> getEmail ( ) ) ; if ( $ wishlistItems -> getSize ( ) ) { foreach ( $ wishlistItems as $ item ) { try { $ product = $ item -> getProduct ( ) ; $ connectorWishlistItem = $ this -> createConnectorWishlistItem ( $ product , $ item ) ; if ( $ connectorWishlistItem ) { $ connectorWishlist -> setItem ( $ connectorWishlistItem ) ; } $ this -> countWishlists ++ ; } catch ( \ Exception $ e ) { continue ; } } $ this -> start = microtime ( true ) ; $ check = $ this -> importerFactory -> create ( ) -> registerQueue ( Importer :: IMPORT_TYPE_WISHLIST , $ connectorWishlist -> expose ( ) , Importer :: MODE_SINGLE , $ website -> getId ( ) ) ; if ( $ check ) { $ this -> wishlistIds [ ] = $ wishlistId ; } } else { $ check = $ this -> importerFactory -> create ( ) -> registerQueue ( Importer :: IMPORT_TYPE_WISHLIST , [ $ wishlist -> getId ( ) ] , Importer :: MODE_SINGLE_DELETE , $ website -> getId ( ) ) ; if ( $ check ) { $ this -> wishlistIds [ ] = $ wishlistId ; } } } if ( ! empty ( $ this -> wishlistIds ) ) { $ this -> setImported ( $ this -> wishlistIds , true ) ; } }
Export single wishlist for website .
39,131
public function getModifiedWishlistToImport ( \ Magento \ Store \ Api \ Data \ WebsiteInterface $ website , $ limit = 100 ) { return $ this -> wishlistCollection -> create ( ) -> getModifiedWishlistToImportByWebsite ( $ website , $ limit ) ; }
Get wishlists marked as modified for website .
39,132
public function collectAliases ( ) : array { $ aliases = array_merge ( $ this -> prepareAliases ( 'psr-0' ) , $ this -> prepareAliases ( 'psr-4' ) ) ; if ( $ this -> isRoot ( ) ) { $ aliases = array_merge ( $ aliases , $ this -> prepareAliases ( 'psr-0' , true ) , $ this -> prepareAliases ( 'psr-4' , true ) ) ; } return $ aliases ; }
Collects package aliases .
39,133
public function preparePath ( string $ file ) : string { if ( 0 === strncmp ( $ file , '$' , 1 ) ) { return $ file ; } $ skippable = 0 === strncmp ( $ file , '?' , 1 ) ? '?' : '' ; if ( $ skippable ) { $ file = substr ( $ file , 1 ) ; } if ( ! $ this -> getFilesystem ( ) -> isAbsolutePath ( $ file ) ) { $ prefix = $ this -> isRoot ( ) ? $ this -> getBaseDir ( ) : $ this -> getVendorDir ( ) . '/' . $ this -> getPrettyName ( ) ; $ file = $ prefix . '/' . $ file ; } return $ skippable . $ this -> getFilesystem ( ) -> normalizePath ( $ file ) ; }
Builds path inside of a package .
39,134
public function getBaseDir ( ) { if ( null === $ this -> baseDir ) { $ this -> baseDir = dirname ( $ this -> getVendorDir ( ) ) ; } return $ this -> baseDir ; }
Get absolute path to package base dir .
39,135
private function createDotenv ( $ dir , $ file ) { if ( method_exists ( Dotenv :: class , 'create' ) ) { return Dotenv :: create ( $ dir , $ file ) ; } else { return new Dotenv ( $ dir , $ file ) ; } }
Creates Dotenv object . Supports both 2 and 3 version of phpdotenv
39,136
protected function processPackage ( Package $ package ) { $ extra = $ package -> getExtra ( ) ; $ files = isset ( $ extra [ self :: EXTRA_OPTION_NAME ] ) ? $ extra [ self :: EXTRA_OPTION_NAME ] : null ; $ this -> originalFiles [ $ package -> getPrettyName ( ) ] = $ files ; if ( is_array ( $ files ) ) { $ this -> addFiles ( $ package , $ files ) ; } if ( $ package -> isRoot ( ) ) { $ this -> loadDotEnv ( $ package ) ; if ( ! empty ( $ extra [ self :: EXTRA_DEV_OPTION_NAME ] ) ) { $ this -> addFiles ( $ package , $ extra [ self :: EXTRA_DEV_OPTION_NAME ] ) ; } } $ aliases = $ package -> collectAliases ( ) ; $ this -> builder -> mergeAliases ( $ aliases ) ; $ this -> builder -> setPackage ( $ package -> getPrettyName ( ) , array_filter ( [ 'name' => $ package -> getPrettyName ( ) , 'version' => $ package -> getVersion ( ) , 'reference' => $ package -> getSourceReference ( ) ? : $ package -> getDistReference ( ) , 'aliases' => $ aliases , ] ) ) ; }
Scans the given package and collects packages data .
39,137
protected function iteratePackage ( Package $ package , $ includingDev = false ) { $ name = $ package -> getPrettyName ( ) ; static $ processed = [ ] ; if ( isset ( $ processed [ $ name ] ) ) { return ; } else { $ processed [ $ name ] = 1 ; } static $ depth = 0 ; ++ $ depth ; $ this -> iterateDependencies ( $ package ) ; if ( $ includingDev ) { $ this -> iterateDependencies ( $ package , true ) ; } if ( ! isset ( $ this -> orderedList [ $ name ] ) ) { $ this -> orderedList [ $ name ] = $ depth ; } -- $ depth ; }
Iterates through package dependencies .
39,138
protected function iterateDependencies ( Package $ package , $ dev = false ) { $ deps = $ dev ? $ package -> getDevRequires ( ) : $ package -> getRequires ( ) ; foreach ( array_keys ( $ deps ) as $ target ) { if ( isset ( $ this -> plainList [ $ target ] ) && empty ( $ this -> orderedList [ $ target ] ) ) { $ this -> iteratePackage ( $ this -> plainList [ $ target ] ) ; } } }
Iterates dependencies of the given package .
39,139
protected function loadFile ( $ path ) : array { $ reader = ReaderFactory :: get ( $ this -> builder , $ path ) ; return $ reader -> read ( $ path ) ; }
Reads config file .
39,140
protected function writePhpFile ( string $ path , $ data , bool $ withEnv , bool $ withDefines ) : void { static :: putFile ( $ path , $ this -> replaceMarkers ( implode ( "\n\n" , array_filter ( [ 'header' => '<?php' , 'baseDir' => '$baseDir = dirname(dirname(dirname(__DIR__)));' , 'BASEDIR' => "defined('COMPOSER_CONFIG_PLUGIN_BASEDIR') or define('COMPOSER_CONFIG_PLUGIN_BASEDIR', \$baseDir);" , 'dotenv' => $ withEnv ? "\$_ENV = array_merge((array) require __DIR__ . '/dotenv.php', (array) \$_ENV);" : '' , 'defines' => $ withDefines ? $ this -> builder -> getConfig ( 'defines' ) -> buildRequires ( ) : '' , 'content' => is_array ( $ data ) ? $ this -> renderVars ( $ data ) : $ data , ] ) ) ) . "\n" ) ; }
Writes complete PHP config file by full path .
39,141
protected static function putFile ( $ path , $ content ) : void { if ( file_exists ( $ path ) && $ content === file_get_contents ( $ path ) ) { return ; } if ( ! file_exists ( dirname ( $ path ) ) ) { mkdir ( dirname ( $ path ) , 0777 , true ) ; } if ( false === file_put_contents ( $ path , $ content ) ) { throw new FailedWriteException ( "Failed write file $path" ) ; } }
Writes file if content changed .
39,142
public function substituteOutputDirs ( array $ data ) : array { $ dir = static :: normalizePath ( dirname ( dirname ( dirname ( $ this -> getOutputDir ( ) ) ) ) ) ; return static :: substitutePaths ( $ data , $ dir , static :: BASE_DIR_MARKER ) ; }
Substitute output paths in given data array recursively with marker .
39,143
public static function normalizePath ( $ path , $ ds = self :: UNIX_DS ) : string { return rtrim ( strtr ( $ path , '/\\' , $ ds . $ ds ) , $ ds ) ; }
Normalizes given path with given directory separator . Default forced to Unix directory separator for substitutePaths to work properly in Windows .
39,144
public static function substitutePaths ( $ data , $ dir , $ alias ) : array { foreach ( $ data as & $ value ) { if ( is_string ( $ value ) ) { $ value = static :: substitutePath ( $ value , $ dir , $ alias ) ; } elseif ( is_array ( $ value ) ) { $ value = static :: substitutePaths ( $ value , $ dir , $ alias ) ; } } return $ data ; }
Substitute all paths in given array recursively with alias if applicable .
39,145
public static function findOutputDir ( $ vendor = null ) { if ( $ vendor ) { $ dir = $ vendor . '/hiqdev/' . basename ( dirname ( __DIR__ ) ) ; } else { $ dir = \ dirname ( __DIR__ ) ; } return $ dir . static :: OUTPUT_DIR_SUFFIX ; }
Returns default output dir .
39,146
public function buildUserConfigs ( array $ files ) : array { $ resolver = new Resolver ( $ files ) ; $ files = $ resolver -> get ( ) ; foreach ( $ files as $ name => $ paths ) { $ this -> getConfig ( $ name ) -> load ( $ paths ) -> build ( ) -> write ( ) ; } return $ files ; }
Builds configs by given files list .
39,147
public function insertCredentials ( $ request ) { $ request -> setParam ( 'Username' , $ this -> api_username ) ; if ( isset ( $ this -> session_uuid ) ) { $ request -> setParam ( 'Password' , $ this -> session_uuid ) ; } else { $ request -> setParam ( 'Password' , $ this -> api_password ) ; } return TRUE ; }
Callback for populating the outgoing request with the criterias needed for communication .
39,148
public function newSessionCookie ( ) { $ this -> session_uuid = NULL ; $ request = new Trustly_Data_JSONRPCRequest ( 'NewSessionCookie' ) ; $ response = parent :: call ( $ request ) ; if ( isset ( $ response ) ) { if ( $ response -> isSuccess ( ) ) { $ this -> session_uuid = $ response -> getResult ( 'sessionuuid' ) ; } } if ( ! isset ( $ this -> session_uuid ) ) { throw new Trustly_AuthentificationException ( ) ; } return $ response ; }
Call NewSessionCookie to obtain a session cookie we can use for the rest of our calls . This is automatically called when doing a call if we do not have a session . Call manually if needed at session timeout etc .
39,149
public function getResult ( $ name = NULL ) { if ( $ name === NULL ) { return $ this -> response_result ; } if ( is_array ( $ this -> response_result ) && isset ( $ this -> response_result [ $ name ] ) ) { return $ this -> response_result [ $ name ] ; } return NULL ; }
Get data from the result section of the response
39,150
public function vacuum ( $ data ) { if ( is_null ( $ data ) ) { return NULL ; } elseif ( is_array ( $ data ) ) { $ ret = array ( ) ; foreach ( $ data as $ k => $ v ) { $ nv = $ this -> vacuum ( $ v ) ; if ( isset ( $ nv ) ) { $ ret [ $ k ] = $ nv ; } } if ( count ( $ ret ) ) { return $ ret ; } return NULL ; } else { return $ data ; } }
Utility function to vacuum the supplied data end remove unset values . This is used to keep the requests cleaner rather then supplying NULL values in the payload
39,151
public function get ( $ name = NULL ) { if ( $ name === NULL ) { return $ this -> payload ; } else { if ( isset ( $ this -> payload [ $ name ] ) ) { return $ this -> payload [ $ name ] ; } } return NULL ; }
Get the specific data value from the payload or the full payload if no value is supplied
39,152
public static function ensureUTF8 ( $ str ) { if ( $ str == NULL ) { return NULL ; } $ enc = mb_detect_encoding ( $ str , array ( 'ISO-8859-1' , 'ISO-8859-15' , 'UTF-8' , 'ASCII' ) ) ; if ( $ enc !== FALSE ) { if ( $ enc == 'ISO-8859-1' || $ enc == 'ISO-8859-15' ) { $ str = mb_convert_encoding ( $ str , 'UTF-8' , $ enc ) ; } } return $ str ; }
Function to ensure that the given value is in UTF8 . Used to make sure all outgoing data is properly encoded in the call
39,153
public function pop ( $ name ) { $ v = NULL ; if ( isset ( $ this -> payload [ $ name ] ) ) { $ v = $ this -> payload [ $ name ] ; } unset ( $ this -> payload [ $ name ] ) ; return $ v ; }
pop a value from the payload i . e . fetch value and clear it in the payload .
39,154
public function json ( $ pretty = FALSE ) { if ( $ pretty ) { $ sorted = $ this -> payload ; $ this -> sortRecursive ( $ sorted ) ; return json_encode ( $ sorted , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) ; } else { return json_encode ( $ this -> payload ) ; } }
Get the payload in JSON form .
39,155
private function sortRecursive ( & $ data ) { if ( is_array ( $ data ) ) { foreach ( $ data as $ k => $ v ) { if ( is_array ( $ v ) ) { $ this -> sortRecursive ( $ v ) ; $ data [ $ k ] = $ v ; } } ksort ( $ data ) ; } }
Sort the data in the payload .
39,156
public function setParam ( $ name , $ value ) { $ this -> payload [ 'params' ] [ $ name ] = Trustly_Data :: ensureUTF8 ( $ value ) ; return $ value ; }
Set a value in the params section of the request
39,157
public function getParam ( $ name ) { if ( isset ( $ this -> payload [ 'params' ] [ $ name ] ) ) { return $ this -> payload [ 'params' ] [ $ name ] ; } return NULL ; }
Get the value of a params parameter in the request
39,158
public function setData ( $ name , $ value ) { if ( ! isset ( $ this -> payload [ 'params' ] [ 'Data' ] ) ) { $ this -> payload [ 'params' ] [ 'Data' ] = array ( ) ; } $ this -> payload [ 'params' ] [ 'Data' ] [ $ name ] = Trustly_Data :: ensureUTF8 ( $ value ) ; return $ value ; }
Set a value in the params - > Data part of the payload .
39,159
public function getData ( $ name = NULL ) { if ( isset ( $ name ) ) { if ( isset ( $ this -> payload [ 'params' ] [ 'Data' ] [ $ name ] ) ) { return $ this -> payload [ 'params' ] [ 'Data' ] [ $ name ] ; } } else { if ( isset ( $ this -> payload [ 'params' ] [ 'Data' ] ) ) { return $ this -> payload [ 'params' ] [ 'Data' ] ; } } return NULL ; }
Get the value of one parameter in the params - > Data section of the request . Or the entire Data section if no name is given .
39,160
public function setAttribute ( $ name , $ value ) { if ( ! isset ( $ this -> payload [ 'params' ] [ 'Data' ] ) ) { $ this -> payload [ 'params' ] [ 'Data' ] = array ( ) ; } if ( ! isset ( $ this -> payload [ 'params' ] [ 'Data' ] [ 'Attributes' ] ) ) { $ this -> payload [ 'params' ] [ 'Data' ] [ 'Attributes' ] = array ( ) ; } $ this -> payload [ 'params' ] [ 'Data' ] [ 'Attributes' ] [ $ name ] = Trustly_Data :: ensureUTF8 ( $ value ) ; return $ value ; }
Set a value in the params - > Data - > Attributes part of the payload .
39,161
public function getAttribute ( $ name ) { if ( isset ( $ this -> payload [ 'params' ] [ 'Data' ] [ 'Attributes' ] [ $ name ] ) ) { return $ this -> payload [ 'params' ] [ 'Data' ] [ 'Attributes' ] [ $ name ] ; } return NULL ; }
Get the value of one parameter in the params - > Data - > Attributes section of the request . Or the entire Attributes section if no name is given .
39,162
public function serializeData ( $ data ) { if ( is_array ( $ data ) ) { ksort ( $ data ) ; $ return = '' ; foreach ( $ data as $ key => $ value ) { if ( is_numeric ( $ key ) ) { $ return .= $ this -> serializeData ( $ value ) ; } else { $ return .= $ key . $ this -> serializeData ( $ value ) ; } } return $ return ; } else { return ( string ) $ data ; } }
Serializes the given data in a form suitable for creating a signature .
39,163
public function setHost ( $ host = NULL , $ port = NULL , $ is_https = NULL ) { if ( ! isset ( $ host ) ) { $ host = $ this -> api_host ; } if ( ! isset ( $ port ) ) { $ port = $ this -> api_port ; } if ( $ this -> loadTrustlyPublicKey ( $ host , $ port ) === FALSE ) { $ error = openssl_error_string ( ) ; throw new InvalidArgumentException ( "Cannot load Trustly public key file for host $host" . ( isset ( $ error ) ? ", error $error" : '' ) ) ; } if ( isset ( $ is_https ) ) { $ this -> api_is_https = $ is_https ; } }
Update the host settings within the API . Use this method to switch API peer .
39,164
public function baseURL ( ) { if ( $ this -> api_is_https ) { $ url = 'https://' . $ this -> api_host . ( $ this -> api_port != 443 ? ':' . $ this -> api_port : '' ) ; } else { $ url = 'http://' . $ this -> api_host . ( $ this -> api_port != 80 ? ':' . $ this -> api_port : '' ) ; } return $ url ; }
Return a properly formed url to communicate with this API .
39,165
public function call ( $ request ) { if ( $ this -> insertCredentials ( $ request ) !== TRUE ) { throw new Trustly_DataException ( 'Unable to add authorization criterias to outgoing request' ) ; } $ this -> last_request = $ request ; $ jsonstr = $ request -> json ( ) ; $ url = $ this -> url ( $ request ) ; list ( $ body , $ response_code ) = $ this -> post ( $ url , $ jsonstr ) ; $ result = $ this -> handleResponse ( $ request , $ body , $ response_code ) ; return $ result ; }
Call the trustly API with the given request .
39,166
public function getData ( $ name = NULL ) { $ data = NULL ; if ( isset ( $ this -> response_result [ 'data' ] ) ) { $ data = $ this -> response_result [ 'data' ] ; } else { return NULL ; } if ( isset ( $ name ) ) { if ( isset ( $ data [ $ name ] ) ) { return $ data [ $ name ] ; } } else { return $ data ; } }
Get data from the data section of the response
39,167
public function loadMerchantPrivateKey ( $ filename ) { $ cert = @ file_get_contents ( $ filename ) ; if ( $ cert === FALSE ) { return FALSE ; } return $ this -> useMerchantPrivateKey ( $ cert ) ; }
Load up the merchants key for signing data from the supplied filename . Inializes the internal openssl certificate needed for the signing
39,168
public function useMerchantPrivateKey ( $ cert ) { if ( $ cert !== FALSE ) { $ this -> merchant_privatekey = openssl_pkey_get_private ( $ cert ) ; return TRUE ; } return FALSE ; }
Use this RSA private key for signing outgoing requests .
39,169
public function signMerchantRequest ( $ request ) { if ( ! isset ( $ this -> merchant_privatekey ) ) { throw new Trustly_SignatureException ( 'No private key has been loaded for signing' ) ; } $ method = $ request -> getMethod ( ) ; if ( $ method === NULL ) { $ method = '' ; } $ uuid = $ request -> getUUID ( ) ; if ( $ uuid === NULL ) { $ uuid = '' ; } $ data = $ request -> getData ( ) ; $ serial_data = $ method . $ uuid . $ this -> serializeData ( $ data ) ; $ raw_signature = '' ; $ this -> clearOpenSSLError ( ) ; if ( openssl_sign ( $ serial_data , $ raw_signature , $ this -> merchant_privatekey , OPENSSL_ALGO_SHA1 ) === TRUE ) { return base64_encode ( $ raw_signature ) ; } throw new Trustly_SignatureException ( 'Failed to sign the outgoing merchant request. ' . openssl_error_string ( ) ) ; }
Insert a signature into the outgoing request .
39,170
protected function handleResponse ( $ request , $ body , $ response_code ) { $ response = new Trustly_Data_JSONRPCSignedResponse ( $ body , $ response_code ) ; if ( $ this -> verifyTrustlySignedResponse ( $ response ) !== TRUE ) { throw new Trustly_SignatureException ( 'Incomming message signature is not valid' , $ response ) ; } if ( $ response -> getUUID ( ) !== $ request -> getUUID ( ) ) { throw new Trustly_DataException ( 'Incoming message is not related to request. UUID mismatch' ) ; } return $ response ; }
Callback for handling the response from an API call . Takes the input data and create an instance of a response object .
39,171
public function notificationResponse ( $ request , $ success = TRUE ) { $ response = new Trustly_Data_JSONRPCNotificationResponse ( $ request , $ success ) ; $ signature = $ this -> signMerchantRequest ( $ response ) ; if ( $ signature === FALSE ) { return FALSE ; } $ response -> setSignature ( $ signature ) ; return $ response ; }
Given an object from an incoming notification request build a response object that can be used to respond to trustly with
39,172
public function call ( $ request ) { $ uuid = $ request -> getUUID ( ) ; if ( $ uuid === NULL ) { $ request -> setUUID ( $ this -> generateUUID ( ) ) ; } return parent :: call ( $ request ) ; }
Call the API with the prepared request
39,173
public function deposit ( $ notificationurl , $ enduserid , $ messageid , $ locale = NULL , $ amount = NULL , $ currency = NULL , $ country = NULL , $ mobilephone = NULL , $ firstname = NULL , $ lastname = NULL , $ nationalidentificationnumber = NULL , $ shopperstatement = NULL , $ ip = NULL , $ successurl = NULL , $ failurl = NULL , $ templateurl = NULL , $ urltarget = NULL , $ suggestedminamount = NULL , $ suggestedmaxamount = NULL , $ integrationmodule = NULL , $ holdnotifications = NULL , $ email = NULL , $ shippingaddresscountry = NULL , $ shippingaddresspostalcode = NULL , $ shippingaddresscity = NULL , $ shippingaddressline1 = NULL , $ shippingaddressline2 = NULL , $ shippingaddress = NULL , $ unchangeablenationalidentificationnumber = NULL ) { $ data = array ( 'NotificationURL' => $ notificationurl , 'EndUserID' => $ enduserid , 'MessageID' => $ messageid , ) ; $ attributes = array ( 'Locale' => $ locale , 'Amount' => $ amount , 'Currency' => $ currency , 'Country' => $ country , 'MobilePhone' => $ mobilephone , 'Firstname' => $ firstname , 'Lastname' => $ lastname , 'NationalIdentificationNumber' => $ nationalidentificationnumber , 'ShopperStatement' => $ shopperstatement , 'IP' => $ ip , 'SuccessURL' => $ successurl , 'FailURL' => $ failurl , 'TemplateURL' => $ templateurl , 'URLTarget' => $ urltarget , 'SuggestedMinAmount' => $ suggestedminamount , 'SuggestedMaxAmount' => $ suggestedmaxamount , 'IntegrationModule' => $ integrationmodule , 'Email' => $ email , 'ShippingAddressCountry' => $ shippingaddresscountry , 'ShippingAddressPostalcode' => $ shippingaddresspostalcode , 'ShippingAddressCity' => $ shippingaddresscity , 'ShippingAddressLine1' => $ shippingaddressline1 , 'ShippingAddressLine2' => $ shippingaddressline2 , 'ShippingAddress' => $ shippingaddress , ) ; if ( $ holdnotifications ) { $ attributes [ 'HoldNotifications' ] = 1 ; } if ( $ unchangeablenationalidentificationnumber ) { $ attributes [ 'UnchangeableNationalIdentificationNumber' ] = 1 ; } $ request = new Trustly_Data_JSONRPCRequest ( 'Deposit' , $ data , $ attributes ) ; return $ this -> call ( $ request ) ; }
Call the Deposit API Method .
39,174
public function refund ( $ orderid , $ amount , $ currency ) { $ data = array ( 'OrderID' => $ orderid , 'Amount' => $ amount , 'Currency' => $ currency , ) ; $ request = new Trustly_Data_JSONRPCRequest ( 'Refund' , $ data ) ; return $ this -> call ( $ request ) ; }
Call the Refund API Method .
39,175
public function withdraw ( $ notificationurl , $ enduserid , $ messageid , $ locale = NULL , $ currency = NULL , $ country = NULL , $ mobilephone = NULL , $ firstname = NULL , $ lastname = NULL , $ nationalidentificationnumber = NULL , $ clearinghouse = NULL , $ banknumber = NULL , $ accountnumber = NULL , $ holdnotifications = NULL , $ email = NULL , $ dateofbirth = NULL , $ addresscountry = NULL , $ addresspostalcode = NULL , $ addresscity = NULL , $ addressline1 = NULL , $ addressline2 = NULL , $ address = NULL ) { $ data = array ( 'NotificationURL' => $ notificationurl , 'EndUserID' => $ enduserid , 'MessageID' => $ messageid , 'Currency' => $ currency , 'Amount' => null ) ; $ attributes = array ( 'Locale' => $ locale , 'Country' => $ country , 'MobilePhone' => $ mobilephone , 'Firstname' => $ firstname , 'Lastname' => $ lastname , 'NationalIdentificationNumber' => $ nationalidentificationnumber , 'ClearingHouse' => $ clearinghouse , 'BankNumber' => $ banknumber , 'AccountNumber' => $ accountnumber , 'Email' => $ email , 'DateOfBirth' => $ dateofbirth , 'AddressCountry' => $ addresscountry , 'AddressPostalcode' => $ addresspostalcode , 'AddressCity' => $ addresscity , 'AddressLine1' => $ addressline1 , 'AddressLine2' => $ addressline2 , 'Address' => $ address , ) ; if ( $ holdnotifications ) { $ attributes [ 'HoldNotifications' ] = 1 ; } $ request = new Trustly_Data_JSONRPCRequest ( 'Withdraw' , $ data , $ attributes ) ; return $ this -> call ( $ request ) ; }
Call the Withdraw API Method .
39,176
public function approveWithdrawal ( $ orderid ) { $ data = array ( 'OrderID' => $ orderid , ) ; $ request = new Trustly_Data_JSONRPCRequest ( 'ApproveWithdrawal' , $ data ) ; return $ this -> call ( $ request ) ; }
Call the approveWithdrawal API Method .
39,177
public function denyWithdrawal ( $ orderid ) { $ data = array ( 'OrderID' => $ orderid , ) ; $ request = new Trustly_Data_JSONRPCRequest ( 'DenyWithdrawal' , $ data ) ; return $ this -> call ( $ request ) ; }
Call the denyWithdrawal API Method .
39,178
public function selectAccount ( $ notificationurl , $ enduserid , $ messageid , $ locale = NULL , $ country = NULL , $ ip = NULL , $ successurl = NULL , $ urltarget = NULL , $ mobilephone = NULL , $ firstname = NULL , $ lastname = NULL , $ holdnotifications = NULL , $ email = NULL , $ dateofbirth = NULL , $ requestdirectdebitmandate = NULL ) { $ data = array ( 'NotificationURL' => $ notificationurl , 'EndUserID' => $ enduserid , 'MessageID' => $ messageid , ) ; $ attributes = array ( 'Locale' => $ locale , 'Country' => $ country , 'IP' => $ ip , 'SuccessURL' => $ successurl , 'URLTarget' => $ urltarget , 'MobilePhone' => $ mobilephone , 'Firstname' => $ firstname , 'Lastname' => $ lastname , 'Email' => $ email , 'DateOfBirth' => $ dateofbirth , ) ; if ( $ holdnotifications ) { $ attributes [ 'HoldNotifications' ] = 1 ; } if ( $ requestdirectdebitmandate ) { $ attributes [ 'RequestDirectDebitMandate' ] = 1 ; } $ request = new Trustly_Data_JSONRPCRequest ( 'SelectAccount' , $ data , $ attributes ) ; return $ this -> call ( $ request ) ; }
Call the selectAccount API Method .
39,179
public function registerAccount ( $ enduserid , $ clearinghouse , $ banknumber , $ accountnumber , $ firstname , $ lastname , $ mobilephone = NULL , $ nationalidentificationnumber = NULL , $ address = NULL , $ email = NULL , $ dateofbirth = NULL , $ addresscountry = NULL , $ addresspostalcode = NULL , $ addresscity = NULL , $ addressline1 = NULL , $ addressline2 = NULL ) { $ data = array ( 'EndUserID' => $ enduserid , 'ClearingHouse' => $ clearinghouse , 'BankNumber' => $ banknumber , 'AccountNumber' => $ accountnumber , 'Firstname' => $ firstname , 'Lastname' => $ lastname , ) ; $ attributes = array ( 'MobilePhone' => $ mobilephone , 'NationalIdentificationNumber' => $ nationalidentificationnumber , 'Email' => $ email , 'DateOfBirth' => $ dateofbirth , 'AddressCountry' => $ addresscountry , 'AddressPostalcode' => $ addresspostalcode , 'AddressCity' => $ addresscity , 'AddressLine1' => $ addressline1 , 'AddressLine2' => $ addressline2 , 'Address' => $ address , ) ; $ request = new Trustly_Data_JSONRPCRequest ( 'RegisterAccount' , $ data , $ attributes ) ; return $ this -> call ( $ request ) ; }
Call the registerAccount API Method .
39,180
public function p2p ( $ notificationurl , $ enduserid , $ messageid , $ locale = NULL , $ amount = NULL , $ currency = NULL , $ country = NULL , $ mobilephone = NULL , $ firstname = NULL , $ lastname = NULL , $ nationalidentificationnumber = NULL , $ shopperstatement = NULL , $ ip = NULL , $ successurl = NULL , $ failurl = NULL , $ templateurl = NULL , $ urltarget = NULL , $ suggestedminamount = NULL , $ suggestedmaxamount = NULL , $ integrationmodule = NULL , $ holdnotifications = NULL , $ authorizeonly = NULL , $ templatedata = NULL ) { $ data = array ( 'NotificationURL' => $ notificationurl , 'EndUserID' => $ enduserid , 'MessageID' => $ messageid ) ; $ attributes = array ( 'AuthorizeOnly' => $ this -> apiBool ( $ authorizeonly ) , 'TemplateData' => $ templatedata , 'Locale' => $ locale , 'Amount' => $ amount , 'Currency' => $ currency , 'Country' => $ country , 'MobilePhone' => $ mobilephone , 'Firstname' => $ firstname , 'Lastname' => $ lastname , 'NationalIdentificationNumber' => $ nationalidentificationnumber , 'ShopperStatement' => $ shopperstatement , 'IP' => $ ip , 'SuccessURL' => $ successurl , 'FailURL' => $ failurl , 'TemplateURL' => $ templateurl , 'URLTarget' => $ urltarget , 'SuggestedMinAmount' => $ suggestedminamount , 'SuggestedMaxAmount' => $ suggestedmaxamount , 'IntegrationModule' => $ integrationmodule ) ; if ( $ holdnotifications ) { $ attributes [ 'HoldNotifications' ] = 1 ; } $ request = new Trustly_Data_JSONRPCRequest ( 'P2P' , $ data , $ attributes ) ; return $ this -> call ( $ request ) ; }
Call the P2P API Method .
39,181
public function capture ( $ orderid , $ amount , $ currency ) { $ data = array ( 'OrderID' => $ orderid , 'Amount' => $ amount , 'Currency' => $ currency ) ; $ attributes = array ( ) ; $ request = new Trustly_Data_JSONRPCRequest ( 'Capture' , $ data , $ attributes ) ; return $ this -> call ( $ request ) ; }
Call the Capture API Method .
39,182
public function void ( $ orderid ) { $ data = array ( 'OrderID' => $ orderid ) ; $ attributes = array ( ) ; $ request = new Trustly_Data_JSONRPCRequest ( 'Void' , $ data , $ attributes ) ; return $ this -> call ( $ request ) ; }
Call the Void API Method .
39,183
public function charge ( $ accountid , $ notificationurl , $ enduserid , $ messageid , $ amount , $ currency , $ shopperstatement = NULL ) { $ data = array ( 'AccountID' => $ accountid , 'NotificationURL' => $ notificationurl , 'EndUserID' => $ enduserid , 'MessageID' => $ messageid , 'Amount' => $ amount , 'Currency' => $ currency , ) ; $ attributes = array ( 'ShopperStatement' => $ shopperstatement , ) ; $ request = new Trustly_Data_JSONRPCRequest ( 'Charge' , $ data , $ attributes ) ; return $ this -> call ( $ request ) ; }
Call the Charge API Method .
39,184
public function getWithdrawals ( $ orderid ) { $ data = array ( 'OrderID' => $ orderid , ) ; $ request = new Trustly_Data_JSONRPCRequest ( 'getWithdrawals' , $ data ) ; return $ this -> call ( $ request ) ; }
Call the getWithdrawals API Method .
39,185
public function hello ( ) { $ api = new Trustly_Api_Unsigned ( $ this -> api_username , $ this -> api_password , $ this -> api_host , $ this -> api_port , $ this -> api_is_https ) ; return $ api -> hello ( ) ; }
Basic communication test to the API .
39,186
public function getParams ( $ name = NULL ) { if ( ! isset ( $ this -> payload [ 'params' ] ) ) { return NULL ; } $ params = $ this -> payload [ 'params' ] ; if ( isset ( $ name ) ) { if ( isset ( $ params [ $ name ] ) ) { return $ params [ $ name ] ; } } else { return $ params ; } return NULL ; }
Get value from or the entire params payload .
39,187
public function getData ( $ name = NULL ) { if ( ! isset ( $ this -> payload [ 'params' ] [ 'data' ] ) ) { return NULL ; } $ data = $ this -> payload [ 'params' ] [ 'data' ] ; if ( isset ( $ name ) ) { if ( isset ( $ data [ $ name ] ) ) { return $ data [ $ name ] ; } } else { return $ data ; } return NULL ; }
Get the value of a parameter in the params - > data section of the notification response .
39,188
public function setSuccess ( $ success = NULL ) { $ status = 'OK' ; if ( isset ( $ success ) && $ success !== TRUE ) { $ status = 'FAILED' ; } $ this -> setData ( 'status' , $ status ) ; return $ success ; }
Set the success status in the response .
39,189
public function setResult ( $ name , $ value ) { if ( ! isset ( $ this -> payload [ 'result' ] ) ) { $ this -> payload [ 'result' ] = array ( ) ; } $ this -> payload [ 'result' ] [ $ name ] = $ value ; return $ value ; }
Set a parameter in the result section of the notification response .
39,190
public function getResult ( $ name = NULL ) { $ result = NULL ; if ( isset ( $ this -> payload [ 'result' ] ) ) { $ result = $ this -> payload [ 'result' ] ; } else { return NULL ; } if ( isset ( $ name ) ) { if ( isset ( $ result [ $ name ] ) ) { return $ result [ $ name ] ; } } else { return $ result ; } }
Get the value of a parameter in the result section of the notification response .
39,191
public function setData ( $ name , $ value ) { if ( ! isset ( $ this -> payload [ 'result' ] ) ) { $ this -> payload [ 'result' ] = array ( ) ; } if ( ! isset ( $ this -> payload [ 'result' ] [ 'data' ] ) ) { $ this -> payload [ 'result' ] [ 'data' ] = array ( $ name => $ value ) ; } else { $ this -> payload [ 'result' ] [ 'data' ] [ $ name ] = $ value ; } return $ value ; }
Set a parameter in the result - > data section of the notification response .
39,192
public function requestUrl ( string $ url ) : EmbeddedAsset { $ cacheService = Craft :: $ app -> getCache ( ) ; $ cacheKey = 'embeddedasset:' . $ url ; $ embeddedAsset = $ cacheService -> get ( $ cacheKey ) ; if ( ! $ embeddedAsset ) { $ pluginSettings = EmbeddedAssets :: $ plugin -> getSettings ( ) ; $ options = [ 'min_image_width' => $ pluginSettings -> minImageSize , 'min_image_height' => $ pluginSettings -> minImageSize , 'oembed' => [ 'parameters' => [ ] ] , ] ; if ( ! empty ( $ pluginSettings -> parameters ) ) { foreach ( $ pluginSettings -> parameters as $ parameter ) { $ param = $ parameter [ 'param' ] ; $ value = $ parameter [ 'value' ] ; $ options [ 'oembed' ] [ 'parameters' ] [ $ param ] = $ value ; } } if ( $ pluginSettings -> embedlyKey ) $ options [ 'oembed' ] [ 'embedly_key' ] = $ pluginSettings -> embedlyKey ; if ( $ pluginSettings -> iframelyKey ) $ options [ 'oembed' ] [ 'iframely_key' ] = $ pluginSettings -> iframelyKey ; if ( $ pluginSettings -> googleKey ) $ options [ 'google' ] = [ 'key' => $ pluginSettings -> googleKey ] ; if ( $ pluginSettings -> soundcloudKey ) $ options [ 'soundcloud' ] = [ 'key' => $ pluginSettings -> soundcloudKey ] ; if ( $ pluginSettings -> facebookKey ) $ options [ 'facebook' ] = [ 'key' => $ pluginSettings -> facebookKey ] ; $ adapter = Embed :: create ( $ url , $ options ) ; $ array = $ this -> _convertFromAdapter ( $ adapter ) ; $ embeddedAsset = $ this -> createEmbeddedAsset ( $ array ) ; $ cacheService -> set ( $ cacheKey , $ embeddedAsset , $ pluginSettings -> cacheDuration ) ; } return $ embeddedAsset ; }
Requests embed data from a URL .
39,193
public function checkWhitelist ( string $ url ) : bool { $ pluginSettings = EmbeddedAssets :: $ plugin -> getSettings ( ) ; $ whitelist = array_merge ( $ pluginSettings -> whitelist , $ pluginSettings -> extraWhitelist ) ; foreach ( $ whitelist as $ whitelistUrl ) { if ( $ whitelistUrl ) { $ pattern = explode ( '*' , $ whitelistUrl ) ; $ pattern = array_map ( 'preg_quote' , $ pattern ) ; $ pattern = implode ( '[a-z][a-z0-9]*' , $ pattern ) ; $ pattern = "%^(https?:)?//([a-z0-9\-]+\\.)?$pattern([:/].*)?$%" ; if ( preg_match ( $ pattern , $ url ) ) { return true ; } } } return false ; }
Checks a URL against the whitelist set on the plugin settings model .
39,194
public function getEmbeddedAsset ( Asset $ asset ) { $ embeddedAsset = null ; if ( $ asset -> kind === Asset :: KIND_JSON ) { try { $ fileContents = stream_get_contents ( $ asset -> getStream ( ) ) ; $ decodedJson = Json :: decodeIfJson ( $ fileContents ) ; if ( is_array ( $ decodedJson ) ) { $ embeddedAsset = $ this -> createEmbeddedAsset ( $ decodedJson ) ; } } catch ( Exception $ e ) { $ embeddedAsset = null ; } } return $ embeddedAsset ; }
Retrieves an embedded asset model from an asset element if one exists .
39,195
public function createAsset ( EmbeddedAsset $ embeddedAsset , VolumeFolder $ folder ) : Asset { $ hasReplaceMb4 = method_exists ( StringHelper :: class , 'replaceMb4' ) ; $ assetsService = Craft :: $ app -> getAssets ( ) ; $ pluginSettings = EmbeddedAssets :: $ plugin -> getSettings ( ) ; $ tempFilePath = Assets :: tempFilePath ( ) ; $ fileContents = Json :: encode ( $ embeddedAsset , JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT ) ; FileHelper :: writeToFile ( $ tempFilePath , $ fileContents ) ; $ assetTitle = $ embeddedAsset -> title ? : $ embeddedAsset -> url ; if ( $ hasReplaceMb4 ) { $ assetTitle = StringHelper :: replaceMb4 ( $ assetTitle , '' ) ; } else if ( StringHelper :: containsMb4 ( $ assetTitle ) ) { $ assetTitle = preg_replace_callback ( '/./u' , function ( array $ match ) : string { return strlen ( $ match [ 0 ] ) >= 4 ? '' : $ match [ 0 ] ; } , $ assetTitle ) ; } $ fileName = Assets :: prepareAssetName ( $ assetTitle , false ) ; $ fileName = str_replace ( '.' , '' , $ fileName ) ; $ fileName = $ fileName ? : 'embedded-asset' ; $ fileName = StringHelper :: safeTruncate ( $ fileName , $ pluginSettings -> maxFileNameLength ) . '.json' ; $ fileName = $ assetsService -> getNameReplacementInFolder ( $ fileName , $ folder -> id ) ; $ asset = new Asset ( ) ; $ asset -> title = StringHelper :: safeTruncate ( $ assetTitle , $ pluginSettings -> maxAssetNameLength ) ; $ asset -> tempFilePath = $ tempFilePath ; $ asset -> filename = $ fileName ; $ asset -> newFolderId = $ folder -> id ; $ asset -> volumeId = $ folder -> volumeId ; $ asset -> avoidFilenameConflicts = true ; $ asset -> setScenario ( Asset :: SCENARIO_CREATE ) ; return $ asset ; }
Creates an asset element ready to be saved from an embedded asset model .
39,196
public function getEmbedCode ( EmbeddedAsset $ embeddedAsset ) { $ dom = null ; if ( $ embeddedAsset -> code ) { $ errors = libxml_use_internal_errors ( true ) ; $ entities = libxml_disable_entity_loader ( true ) ; try { $ dom = new DOMDocument ( ) ; $ code = "<div>$embeddedAsset->code</div>" ; $ isHtml = $ dom -> loadHTML ( $ code , LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD ) ; if ( ! $ isHtml ) { throw new ErrorException ( ) ; } } catch ( ErrorException $ e ) { $ dom = null ; } finally { libxml_use_internal_errors ( $ errors ) ; libxml_disable_entity_loader ( $ entities ) ; } } return $ dom ; }
Gets the embed code as DOM if one exists and is valid .
39,197
public function getImageToSize ( EmbeddedAsset $ embeddedAsset , int $ size ) { return is_array ( $ embeddedAsset -> images ) ? $ this -> _getImageToSize ( $ embeddedAsset -> images , $ size ) : null ; }
Returns the image from an embedded asset closest to some size . It favours images that most minimally exceed the supplied size .
39,198
public function getProviderIconToSize ( EmbeddedAsset $ embeddedAsset , int $ size ) { return is_array ( $ embeddedAsset -> providerIcons ) ? $ this -> _getImageToSize ( $ embeddedAsset -> providerIcons , $ size ) : null ; }
Returns the provider icon from an embedded asset closest to some size . It favours icons that most minimally exceed the supplied size .
39,199
private function _getImageToSize ( array $ images , int $ size ) { $ selectedImage = null ; $ selectedSize = 0 ; foreach ( $ images as $ image ) { if ( is_array ( $ image ) ) { $ imageWidth = isset ( $ image [ 'width' ] ) && is_numeric ( $ image [ 'width' ] ) ? $ image [ 'width' ] : 0 ; $ imageHeight = isset ( $ image [ 'height' ] ) && is_numeric ( $ image [ 'height' ] ) ? $ image [ 'height' ] : 0 ; $ imageSize = max ( $ imageWidth , $ imageHeight ) ; if ( ! $ selectedImage || ( $ selectedSize < $ size && $ imageSize > $ selectedSize ) || ( $ selectedSize > $ imageSize && $ imageSize > $ size ) ) { $ selectedImage = $ image ; $ selectedSize = $ imageSize ; } } } return $ selectedImage ; }
Helper method for retrieving an image closest to some size .