diff --git a/samples/addMerchant.php b/samples/addMerchant.php index 51918da..d28aa03 100644 --- a/samples/addMerchant.php +++ b/samples/addMerchant.php @@ -6,8 +6,8 @@ $result = \Paynl\Alliance\Merchant::add( array( // Required - 'companyName' => 'allianceAddTest', - 'cocNumber' => '54212458', + 'companyName' => 'Addv3Test', + 'cocNumber' => '54292456', 'street' => 'Kopersteden', 'houseNumber' => '10', 'postalCode' => '7547 TK', @@ -16,38 +16,52 @@ 'accounts' => array( // Minimum of 1 account, you can add more, one account must be primary, the other accounts cannot be primary array( - 'primary' => true, - // One account must be primary 'email' => 'email@test.nl', 'firstname' => 'Andy', 'lastname' => 'Pieters', 'gender' => 'male', 'authorisedToSign' => 2, //0 not authorised, 1 authorised independently, 2 shared authority to sign - 'ubo' => true, - // Ultimate beneficial owner (25% of more shares) + 'ubo' => 50, //percentage of shares + 'hasAccess'=> true, +// 'language' => 'nl', + 'useCompanyAuth' => true // All company rights ), array( - 'primary' => false, 'email' => 'email2@test.nl', 'firstname' => 'Mede', 'lastname' => 'Eigenaar', 'gender' => 'female', 'authorisedToSign' => 2, //0 not authorised, 1 authorised independently, 2 shared authority to sign - 'ubo' => true, - // Ultimate beneficial owner (25% of more shares) + 'ubo' => 25, //percentage of shares + 'hasAccess'=> true, +// 'language' => 'en', + 'useCompanyAuth' => false // All company rights ), array( - 'primary' => false, 'email' => 'email4@test.nl', 'firstname' => 'Mede', 'lastname' => 'Eigenaar', 'gender' => 'female', 'authorisedToSign' => 2, //0 not authorised, 1 authorised independently, 2 shared authority to sign - 'ubo' => true, - // Ultimate beneficial owner (25% of more shares) + 'ubo' => 25, //percentage of shares + 'hasAccess'=> false, +// 'language' => 'de', + 'useCompanyAuth' => false // All company rights + ), + array( + 'email' => 'email5@test.nl', + 'firstname' => 'Mede', + 'lastname' => 'Eigenaar2', + 'gender' => 'female', + 'authorisedToSign' => 0, + //0 not authorised, 1 authorised independently, 2 shared authority to sign + 'ubo' => false, //percentage of shares + 'hasAccess'=> true, +// 'language' => 'de', + 'useCompanyAuth' => false // All company rights ), ), @@ -64,7 +78,7 @@ 'bankAccountOwner' => 'Andy Pieters', 'bankAccountNumber' => 'NL91ABNA0417164300', 'bankAccountBIC' => 'ABNANL2A', - 'vatNumber' => 'NL123412413', +// 'vatNumber' => 'NL807960147B01', 'packageName' => 'Alliance', // Alliance or AlliancePlus // 'referralProfileId' => 'CP-1234-1234', // Only use this if you know what it is diff --git a/src/Api/AddMerchant.php b/src/Api/AddMerchant.php index c68797b..4689374 100644 --- a/src/Api/AddMerchant.php +++ b/src/Api/AddMerchant.php @@ -4,361 +4,93 @@ use Paynl\Error\Api as ApiError; -use Paynl\Error\Error; -use Paynl\Error\Required; use Paynl\Helper; class AddMerchant extends Api { - /* - * Company data - */ - - /** - * @var string - */ - private $_cocNumber; - /** - * @var string - */ - private $_vatNumber; - /** - * @var string - */ - private $_companyName; - /** - * @var string - */ - private $_street; - /** - * @var string - */ - private $_houseNumber; - /** - * @var string - */ - private $_postalCode; - /** - * @var string - */ - private $_city; - /** - * @var string - */ - private $_countryCode; - - /* - * Bank account data - */ - - /** - * @var string - */ - private $_bankAccountOwner; - /** - * @var string - */ - private $_bankAccountNumber; - /** - * @var string - */ - private $_bankAccountBic; + protected $version = 3; - /** - * - * @var sting day, week or month - */ - private $_invoiceInterval; + private $merchant; + private $accounts; + private $bankAccount; + private $settings; /** - * @var string Alliance or AlliancePlus - */ - private $_packageName; - /* - * Main account data - */ - /** - * @var string - */ - private $_email; - /** - * @var string - */ - private $_firstName; - /** - * @var string - */ - private $_lastName; - /** - * @var string 'male' or 'female' - */ - private $_gender; - /** - * @var int - */ - private $_languageId = 1; - /** - * @var bool - */ - private $_authorisedToSign; - /** - * @var bool - */ - private $_ubo; - /** - * @var int 0 : No e-mail, 1 : Regular registration e-mail, 2: Short registration e-mail - */ - private $_sendEmail; - private $_referralProfileId; - /** - * Set to true if you want to be able to add a debit invoice to the account of this merchant. - * Your invoice will be subtracted from the merchants account. - * You will need to ask the merchant for permission before you can set this value to true - * - * @var bool - */ - private $_settleBalance; - /** - * @var bool + * Set the merchant + * Format: + * array( + * name + * coc + * vat + * street + * houseNumber + * houseNumberAddition + * postalCode + * city + * countryCode + * ) + * @param array $merchant */ - private $_useCompanyAuth = true; - /** - * Array of signees, use the following format: - * ['email'] - * ['firstname'] - * ['lastname'] - * ['authorised_to_sign'] 0: not authorised, 1:authorized to sign independently, 2: shared authorized to sign - * - * @var array Signees - */ - private $_signees = array(); - - /** - * @param string $referralProfileId - */ - public function setReferralProfileId($referralProfileId) + public function setMerchant($merchant) { - $this->_referralProfileId = $referralProfileId; + $this->merchant = $merchant; } - /** - * @param string $cocNumber - */ - public function setCocNumber($cocNumber) - { - $this->_cocNumber = $cocNumber; - } /** - * @param string $vatNumber + * Add an account + * Format: + * array( + * email + * firstname + * lastname + * gender + * authorizedToSign + * ubo + * uboPercentage + * useCompanyAuth + * hasAccess + * language + * ) + * @param array $account */ - public function setVatNumber($vatNumber) - { - $this->_vatNumber = $vatNumber; + public function addAccount($account){ + $this->accounts[] = $account; } /** - * @param string $companyName + * Set the bankaccount + * Format: + * array( + * bankAccountOwner + * bankAccountNumber + * BankAccountBic + * ) + * @param array $bankaccount */ - public function setCompanyName($companyName) + public function setBankAccount($bankAccount) { - $this->_companyName = $companyName; + $this->bankAccount = $bankAccount; } /** - * @param string $street + * Account settings + * Format: + * array( + * packageName + * sendEmail + * settleBalance + * referralProfileId + * clearingInterval + * ) + * @param array $settings */ - public function setStreet($street) + public function setSettings($settings) { - $this->_street = $street; + $this->settings = $settings; } - /** - * @param string $houseNumber - */ - public function setHouseNumber($houseNumber) - { - $this->_houseNumber = $houseNumber; - } - - /** - * @param string $postalCode - */ - public function setPostalCode($postalCode) - { - $this->_postalCode = $postalCode; - } - /** - * @param string $city - */ - public function setCity($city) - { - $this->_city = $city; - } - - /** - * @param string $countryCode - */ - public function setCountryCode($countryCode) - { - if (strlen($countryCode) != 2) { - throw new Error('countryCode should be 2 characters long'); - } - - $this->_countryCode = strtoupper($countryCode); - } - - /** - * @param string $bankAccountOwner - */ - public function setBankAccountOwner($bankAccountOwner) - { - $this->_bankAccountOwner = $bankAccountOwner; - } - - /** - * @param string $bankAccountNumber - */ - public function setBankAccountNumber($bankAccountNumber) - { - $this->_bankAccountNumber = $bankAccountNumber; - } - - /** - * @param string $bankAccountBic - */ - public function setBankAccountBic($bankAccountBic) - { - $this->_bankAccountBic = $bankAccountBic; - } - - /** - * @param sting $invoiceInterval - */ - public function setInvoiceInterval($invoiceInterval) - { - if (!in_array($invoiceInterval, array('day', 'week', 'month'))) { - throw new Error("invoiceInterval is invalid. possible values: day, week or month"); - } - - $this->_invoiceInterval = $invoiceInterval; - } - - /** - * @param string $packageName - */ - public function setPackageName($packageName) - { - $this->_packageName = $packageName; - } - - /** - * @param string $email - */ - public function setEmail($email) - { - $this->_email = $email; - } - - /** - * @param string $firstName - */ - public function setFirstName($firstName) - { - $this->_firstName = $firstName; - } - - /** - * @param string $lastName - */ - public function setLastName($lastName) - { - $this->_lastName = $lastName; - } - - /** - * @param string $gender - */ - public function setGender($gender) - { - if (!in_array($gender, array('male', 'female'))) { - - } - $this->_gender = $gender; - } - - /** - * @param int $languageId - */ - public function setLanguageId($languageId) - { - $this->_languageId = (int)$languageId; - } - - /** - * @param boolean $authorisedToSign - */ - public function setAuthorisedToSign($authorisedToSign) - { - //TODO: The api only accepts true or false here, but should be 0, 1 or 2 - $this->_authorisedToSign = (bool)$authorisedToSign; - } - - /** - * @param boolean $ubo - */ - public function setUbo($ubo) - { - $this->_ubo = (bool)$ubo; - } - - /** - * @param int $sendEmail - */ - public function setSendEmail($sendEmail) - { - $this->_sendEmail = (int)$sendEmail; - } - - /** - * @param boolean $settleBalance - */ - public function setSettleBalance($settleBalance) - { - $this->_settleBalance = (bool)$settleBalance; - } - - /** - * @param boolean $useCompanyAuth - */ - public function setUseCompanyAuth($useCompanyAuth) - { - $this->_useCompanyAuth = (bool)$useCompanyAuth; - } - - /** - * @param string $email - * @param string $firstname - * @param string $lastname - * @param int $authorised_to_sign - * @param bool $ubo - * @throws Error - */ - public function addSignee($email, $firstname, $lastname, $authorised_to_sign, $ubo) - { - if (!in_array($authorised_to_sign, array(0, 1, 2))) { - throw new Error('authorised_to_sign can be 0, 1 or 2'); - } - $signee = array( - 'email' => $email, - 'firstname' => $firstname, - 'lastname' => $lastname, - 'authorised_to_sign' => $authorised_to_sign, - 'ubo' => $ubo //TODO: hier wordt nu nog niets mee gedaan - ); - $this->_signees[] = $signee; - } public function doRequest($endpoint = null, $version = null) { @@ -367,111 +99,17 @@ public function doRequest($endpoint = null, $version = null) protected function getData() { - if (isset($this->_email)) { - $this->data['email'] = $this->_email; - } else { - throw new Required('email'); - } - - if (isset($this->_firstName)) { - $this->data['firstName'] = $this->_firstName; - } else { - throw new Required('firstName'); - } - - if (isset($this->_lastName)) { - $this->data['lastName'] = $this->_lastName; - } else { - throw new Required('lastName'); - } - - if (isset($this->_companyName)) { - $this->data['companyName'] = $this->_companyName; - } else { - throw new Required('companyName'); - } - - if (isset($this->_cocNumber)) { - $this->data['cocNumber'] = $this->_cocNumber; - } else { - throw new Required('cocNumber'); - } - - if (isset($this->_gender)) { - $this->data['gender'] = $this->_gender; - } else { - throw new Required('gender'); - } - - if (isset($this->_street)) { - $this->data['street'] = $this->_street; - } else { - throw new Required('street'); - } - - if (isset($this->_houseNumber)) { - $this->data['houseNumber'] = $this->_houseNumber; - } else { - throw new Required('houseNumber'); - } - - if (isset($this->_postalCode)) { - $this->data['postalCode'] = $this->_postalCode; - } else { - throw new Required('postalCode'); - } - - if (isset($this->_city)) { - $this->data['city'] = $this->_city; - } else { - throw new Required('city'); - } - - if (isset($this->_countryCode)) { - $this->data['countryCode'] = $this->_countryCode; - } - - if (isset($this->_bankAccountOwner)) { - $this->data['bankAccountOwner'] = $this->_bankAccountOwner; - } - if (isset($this->_bankAccountNumber)) { - $this->data['bankAccountNumber'] = $this->_bankAccountNumber; - } - if (isset($this->_bankAccountBic)) { - $this->data['bankAccountBIC'] = $this->_bankAccountBic; - } - if (isset($this->_vatNumber)) { - $this->data['vatNumber'] = $this->_vatNumber; - } - if (isset($this->_languageId)) { - $this->data['languageId'] = $this->_languageId; - } - if (isset($this->_authorisedToSign)) { - $this->data['authorizedToSign'] = $this->_authorisedToSign; - } - if (isset($this->_ubo)) { - $this->data['ubo'] = $this->_ubo; - } - if (isset($this->_useCompanyAuth)) { - $this->data['useCompanyAuth'] = $this->_useCompanyAuth; - } - if (isset($this->_sendEmail)) { - $this->data['sendEmail'] = $this->_sendEmail; - } - if (isset($this->_invoiceInterval)) { - $this->data['invoiceInterval'] = $this->_invoiceInterval; - } - if (!empty($this->_signees)) { - $this->data['signees'] = $this->_signees; + if(!empty($this->merchant)){ + $this->data['merchant'] = $this->merchant; } - if (isset($this->_packageName)) { - $this->data['packageName'] = $this->_packageName; + if(!empty($this->accounts)){ + $this->data['accounts'] = $this->accounts; } - if (isset($this->_referralProfileId)) { - $this->data['referralProfileId'] = $this->_referralProfileId; + if(!empty($this->bankAccount)){ + $this->data['bankAccount'] = $this->bankAccount; } - if (isset($this->_settleBalance)) { - $this->data['settleBalance'] = (bool)$this->_settleBalance; + if(!empty($this->settings)){ + $this->data['settings'] = $this->settings; } return parent::getData(); diff --git a/src/Merchant.php b/src/Merchant.php index 3912b48..c7dfd15 100644 --- a/src/Merchant.php +++ b/src/Merchant.php @@ -76,52 +76,19 @@ public static function add($options) if (isset($options['accounts'])) { self::_addAccounts($options['accounts'], $api); } + $merchant = self::_getMerchant($options); + $api->setMerchant($merchant); - if (isset($options['companyName'])) { - $api->setCompanyName($options['companyName']); + $bankAccount = self::_getBankAccount($options); + if (!empty($bankAccount)) { + $api->setBankAccount($bankAccount); } - if (isset($options['cocNumber'])) { - $api->setCocNumber($options['cocNumber']); - } - if (isset($options['street'])) { - $api->setStreet($options['street']); - } - if (isset($options['houseNumber'])) { - $api->setHouseNumber($options['houseNumber']); - } - if (isset($options['postalCode'])) { - $api->setPostalCode($options['postalCode']); - } - if (isset($options['city'])) { - $api->setCity($options['city']); - } - if (isset($options['sendEmail'])) { - $api->setSendEmail($options['sendEmail']); - } - if (isset($options['countryCode'])) { - $api->setCountryCode($options['countryCode']); - } - if (isset($options['bankAccountOwner'])) { - $api->setBankAccountOwner($options['bankAccountOwner']); - } - if (isset($options['bankAccountNumber'])) { - $api->setBankAccountNumber($options['bankAccountNumber']); - } - if (isset($options['bankAccountBIC'])) { - $api->setBankAccountBic($options['bankAccountBIC']); - } - if (isset($options['packageName'])) { - $api->setPackageName($options['packageName']); - } - if (isset($options['settleBalance'])) { - $api->setSettleBalance($options['settleBalance']); - } - if(isset($options['referralProfileId'])){ - $api->setReferralProfileId($options['referralProfileId']); - } - if (isset($options['payoutInterval'])) { - $api->setInvoiceInterval($options['payoutInterval']); + + $settings = self::_getSettings($options); + if (!empty($settings)) { + $api->setSettings($settings); } + $result = $api->doRequest(); return new Result\Merchant\Add($result); @@ -140,67 +107,152 @@ private static function _addAccounts(array $accounts, Api\AddMerchant $api) if (count($accounts) == 0) { throw new Required('accounts'); } - $primaryAccount = null; - $signees = array(); - if (count($accounts) == 1) { - $primaryAccount = array_pop($accounts); - } else { - foreach ($accounts as $account) { - if ($account['primary']) { - if (!is_null($primaryAccount)) { - throw new Error('You can only add 1 primary account'); - } - $primaryAccount = $account; + + foreach ($accounts as $account) { + if (!isset($account['email'])) { + throw new Required('account - email'); + } + if (!isset($account['firstname'])) { + throw new Required('account - firstname'); + } + if (!isset($account['lastname'])) { + throw new Required('account - lastname'); + } + if (!isset($account['gender'])) { + throw new Required('account - gender'); + } + + if (!isset($account['authorizedToSign'])) { + if (isset($account['authorisedToSign'])) { + $account['authorizedToSign'] = $account['authorisedToSign']; } else { - array_push($signees, $account); + throw new Required('account - authorizedToSign'); } } + + if (!isset($account['authorizedToSign'])) { + if (!isset($account['authorisedToSign'])) { + throw new Required('account - authorizedToSign'); + } + $account['authorizedToSign'] = $account['authorisedToSign']; + } + + if (!isset($account['ubo'])) { + throw new Required('account - ubo'); + } + if (!isset($account['uboPercentage'])) { + if (is_numeric($account['ubo']) && $account['ubo'] > 0 && $account['ubo'] <= 100) { + $account['uboPercentage'] = $account['ubo']; + $account['ubo'] = true; + } + } + $account['ubo'] = (integer)$account['ubo']; + + if(isset($account['hasAccess'])){ + $account['hasAccess'] = (integer) $account['hasAccess']; + } + if(isset($account['useCompanyAuth'])){ + $account['useCompanyAuth'] = (integer) $account['useCompanyAuth']; + } + + $api->addAccount($account); + + } + } + + /** + * @param array $options + */ + private static function _getMerchant($options) + { + $merchant = array(); + + if (!isset($options['companyName'])) { + throw new Required('companyName'); } - if (is_null($primaryAccount)) { - throw new Error('One account must be the primary account'); + $merchant['name'] = $options['companyName']; + + if (!isset($options['cocNumber'])) { + throw new Required('cocNumber'); } - if (isset($primaryAccount['email'])) { - $api->setEmail($primaryAccount['email']); + $merchant['coc'] = $options['cocNumber']; + + if (!isset($options['street'])) { + throw new Required('street'); } - if (isset($primaryAccount['firstname'])) { - $api->setFirstName($primaryAccount['firstname']); + $merchant['street'] = $options['street']; + + if (!isset($options['houseNumber'])) { + throw new Required('houseNumber'); } - if (isset($primaryAccount['lastname'])) { - $api->setLastName($primaryAccount['lastname']); + $merchant['houseNumber'] = $options['houseNumber']; + + if (!isset($options['postalCode'])) { + throw new Required('postalCode'); } - if (isset($primaryAccount['gender'])) { - $api->setGender($primaryAccount['gender']); + $merchant['postalCode'] = $options['postalCode']; + + if (!isset($options['city'])) { + throw new Required('city'); } - if (isset($primaryAccount['authorisedToSign'])) { - $api->setAuthorisedToSign($primaryAccount['authorisedToSign']); + $merchant['city'] = $options['city']; + + if (!isset($options['countryCode'])) { + throw new Required('countryCode'); } - if (isset($primaryAccount['ubo'])) { - $api->setUbo($primaryAccount['ubo']); + $merchant['countryCode'] = $options['countryCode']; + + /** + * Optional + */ + if (isset($options['vatNumber'])) { + $merchant['vat'] = $options['vatNumber']; } - if (!empty($signees)) { - foreach ($signees as $signee) { - if (empty($signee['email'])) { - throw new Required('account - email'); - } - if (empty($signee['firstname'])) { - throw new Required('account - firstname'); - } - if (empty($signee['lastname'])) { - throw new Required('account - lastname'); - } - if (empty($signee['gender'])) { - throw new Required('account - gender'); - } - if (empty($signee['authorisedToSign'])) { - $signee['authorisedToSign'] = 0; - } - if (empty($signee['ubo'])) { - $signee['ubo'] = 0; - } - $api->addSignee($signee['email'], $signee['firstname'], $signee['lastname'], - $signee['authorisedToSign'], $signee['ubo']); - } + if (isset($options['houseNumberAddition'])) { + $merchant['houseNumberAddition'] = $options['houseNumberAddition']; + } + return $merchant; + } + + private static function _getBankAccount($options) + { + $bankAccount = array(); + if (isset($options['bankAccountOwner'])) { + $bankAccount['bankAccountOwner'] = $options['bankAccountOwner']; + } + if (isset($options['bankAccountNumber'])) { + $bankAccount['bankAccountNumber'] = $options['bankAccountNumber']; + } + if (isset($options['bankAccountBIC'])) { + $bankAccount['bankAccountBIC'] = $options['bankAccountBIC']; + } + return $bankAccount; + } + + private static function _getSettings($options) + { + $settings = array(); + + if (isset($options['packageName'])) { + $settings['packageName'] = $options['packageName']; + } + if (isset($options['packageName'])) { + $settings['packageName'] = $options['packageName']; + } + + if (isset($options['sendEmail'])) { + $settings['sendEmail'] = $options['sendEmail']; + } + if (isset($options['settleBalance'])) { + $settings['settleBalance'] = (integer)$options['settleBalance']; + } + if (isset($options['referralProfileId'])) { + $settings['referralProfileId'] = $options['referralProfileId']; + } + if (isset($options['clearingInterval'])) { + $settings['clearingInterval'] = $options['clearingInterval']; } + return $settings; } /**