diff --git a/samples/directDebit/delete.php b/samples/directDebit/delete.php new file mode 100644 index 00000000..e5605554 --- /dev/null +++ b/samples/directDebit/delete.php @@ -0,0 +1,12 @@ +getMessage(); +} diff --git a/samples/directDebit/update.php b/samples/directDebit/update.php new file mode 100644 index 00000000..988063b0 --- /dev/null +++ b/samples/directDebit/update.php @@ -0,0 +1,32 @@ + 0.1, // The amount to be paid. + 'bankaccountHolder' => 'N. Klant', // The name of the customer. + 'bankaccountNumber' => 'NL00RAB0123456789', // The bankaccount number of the customer. + 'bankaccountBic' => 'RABONL2U', // The BIC of the bank. + 'processDate' => new \DateTime('tomorrow'), // Date on which the directdebit needs to be processed. + 'intervalValue' => 1, // Need for recurring part, if intervalValue is 2 and intervalPeriod is 1 than process the directdebit every two weeks. + 'intervalPeriod' => 2, // 1 : Week, 2 : Month, 3: Quarter, 4 : Half year, 5: Year, 6: Day + 'intervalQuantity' => 12, // Indicated the number of times this order should be executed. + 'description' => 'De omschrijving', // First description to include with the payment. + 'ipAddress' => '192.168.20.123', // The IP address of the customer. + 'email' => 'naam@email.com', // The email address of the customer. + 'promotorId' => '123456789', // The ID of the webmaster / promotor. + 'tool' => 'sdk', // The used tool code. + 'info' => 'info', // The used info code. + 'object' => 'object', // The used object. + 'extra1' => 'extra1', // The first free value. + 'extra2' => 'extra2', // The second free value. + 'extra3' => 'extra3', // The third free value. + + )); +} catch (\Paynl\Error\Error $e) { + echo "Error: ".$e->getMessage(); +} diff --git a/src/Api/Api.php b/src/Api/Api.php index 6537930f..90102584 100644 --- a/src/Api/Api.php +++ b/src/Api/Api.php @@ -63,21 +63,20 @@ public function doRequest($endpoint, $version = null) if (!empty($auth)) { $curl->setBasicAuthentication($auth['username'], $auth['password']); - } - - + } + $curl->setOpt(CURLOPT_SSL_VERIFYPEER, Config::getVerifyPeer()); $result = $curl->post($uri, $data); - + if (isset($result->status) && $result->status === 'FALSE') { throw new Error\Api($result->error); - } + } if ($curl->error) { throw new Error\Error($curl->errorMessage); } - + return $this->processResult($result); } @@ -91,7 +90,7 @@ protected function getData() Helper::requireServiceId(); $this->data['serviceId'] = Config::getServiceId(); - } + } return $this->data; } diff --git a/src/Api/DirectDebit/DebitAdd.php b/src/Api/DirectDebit/DebitAdd.php index 0f373065..b22419c2 100644 --- a/src/Api/DirectDebit/DebitAdd.php +++ b/src/Api/DirectDebit/DebitAdd.php @@ -5,7 +5,7 @@ use Paynl\Error\Required; /** - * @author Andy Pieters + * @author PAY. */ class DebitAdd extends DirectDebit { diff --git a/src/Api/DirectDebit/Delete.php b/src/Api/DirectDebit/Delete.php index ed013593..3bc00827 100644 --- a/src/Api/DirectDebit/Delete.php +++ b/src/Api/DirectDebit/Delete.php @@ -3,9 +3,12 @@ namespace Paynl\Api\DirectDebit; use Paynl\Error\Required; - +use Paynl\Config; class Delete extends DirectDebit { + + protected $apiTokenRequired = true; + /** * @var string The mandateId of the directdebit. */ @@ -29,8 +32,11 @@ protected function getData() throw new Required('mandateId'); } - $this->data['mandateId'] = $this->_mandateId; + $this->data['token'] = Config::getTokenCode(); + $this->data['serviceId'] = Config::getServiceId(); + $this->data['mandateId'] = $this->_mandateId; + return parent::getData(); } @@ -38,7 +44,7 @@ protected function getData() * @inheritdoc */ public function doRequest($endpoint = null, $version = null) - { + { return parent::doRequest('DirectDebit/delete'); } } diff --git a/src/Api/DirectDebit/DirectDebit.php b/src/Api/DirectDebit/DirectDebit.php index a4ea1067..bc40c0d9 100644 --- a/src/Api/DirectDebit/DirectDebit.php +++ b/src/Api/DirectDebit/DirectDebit.php @@ -5,7 +5,7 @@ use Paynl\Api\Api; /** - * @author Andy Pieters + * @author PAY. */ class DirectDebit extends Api { diff --git a/src/Api/DirectDebit/Update.php b/src/Api/DirectDebit/Update.php index ba38b0b0..b48dbea5 100644 --- a/src/Api/DirectDebit/Update.php +++ b/src/Api/DirectDebit/Update.php @@ -91,6 +91,7 @@ class Update extends DirectDebit public function setMandateId($mandateId) { $this->_mandateId = $mandateId; + } /** @@ -243,11 +244,13 @@ public function setExtra3($extra3) */ protected function getData() { + + if (empty($this->_mandateId)) { throw new Required('mandateId'); } - $this->data['mandateId']; + $this->data['mandateId'] = $this->_mandateId; if (!empty($this->_amount)) { $this->data['amount'] = $this->_amount; @@ -311,7 +314,7 @@ protected function getData() * @inheritdoc */ public function doRequest($endpoint = '', $version = null) - { + { return parent::doRequest('DirectDebit/update'); } } diff --git a/src/DirectDebit.php b/src/DirectDebit.php index 8e28c74a..24b058bc 100644 --- a/src/DirectDebit.php +++ b/src/DirectDebit.php @@ -102,13 +102,19 @@ public function delete($mandateId) public function update($mandateId, $options) { + + if (empty($mandateId)) { throw new Required('mandateId'); } + + $api = new Api\Update(); $api->setMandateId($mandateId); + + if (!empty($options['amount'])) { $api->setAmount(round($options['amount'] * 100)); } @@ -167,6 +173,7 @@ public function update($mandateId, $options) if (!empty($options['extra3'])) { $api->setExtra3($options['extra3']); } + return $api->doRequest(); } }