Skip to content

Commit

Permalink
Merge pull request #101 from paynl/feature/DirectDebit-fixes
Browse files Browse the repository at this point in the history
Fix issues with Delete and Update, Add samples for Delete and Update.
  • Loading branch information
woutse authored Apr 14, 2020
2 parents 8c5405f + f8353ee commit ae6ccc2
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 14 deletions.
12 changes: 12 additions & 0 deletions samples/directDebit/delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
require_once 'vendor/autoload.php';
require_once 'config.php';
try {
$result = \Paynl\DirectDebit::delete(
// Required
'IO-1234-1234-1234' // The mandateId of the directdebit.
);
var_dump($result);
} catch (\Paynl\Error\Error $e) {
echo "Error: ".$e->getMessage();
}
32 changes: 32 additions & 0 deletions samples/directDebit/update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
require_once '../../vendor/autoload.php';
require_once '../config.php';
try {
$result = \Paynl\DirectDebit::update(
// Required
'IO-1234-1234-1234', // The mandateId of the directdebit.
// Optional
array(
'amount' => 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' => '[email protected]', // 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();
}
13 changes: 6 additions & 7 deletions src/Api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -91,7 +90,7 @@ protected function getData()
Helper::requireServiceId();

$this->data['serviceId'] = Config::getServiceId();
}
}
return $this->data;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Api/DirectDebit/DebitAdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Paynl\Error\Required;

/**
* @author Andy Pieters <andy@pay.nl>
* @author PAY. <support@pay.nl>
*/
class DebitAdd extends DirectDebit
{
Expand Down
12 changes: 9 additions & 3 deletions src/Api/DirectDebit/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -29,16 +32,19 @@ 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();
}

/**
* @inheritdoc
*/
public function doRequest($endpoint = null, $version = null)
{
{
return parent::doRequest('DirectDebit/delete');
}
}
2 changes: 1 addition & 1 deletion src/Api/DirectDebit/DirectDebit.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Paynl\Api\Api;

/**
* @author Andy Pieters <andy@pay.nl>
* @author PAY. <support@pay.nl>
*/
class DirectDebit extends Api
{
Expand Down
7 changes: 5 additions & 2 deletions src/Api/DirectDebit/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class Update extends DirectDebit
public function setMandateId($mandateId)
{
$this->_mandateId = $mandateId;

}

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -311,7 +314,7 @@ protected function getData()
* @inheritdoc
*/
public function doRequest($endpoint = '', $version = null)
{
{
return parent::doRequest('DirectDebit/update');
}
}
7 changes: 7 additions & 0 deletions src/DirectDebit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -167,6 +173,7 @@ public function update($mandateId, $options)
if (!empty($options['extra3'])) {
$api->setExtra3($options['extra3']);
}

return $api->doRequest();
}
}

0 comments on commit ae6ccc2

Please sign in to comment.