Skip to content

Commit

Permalink
Merge pull request #32 from afosto/feature/vouchers-activate
Browse files Browse the repository at this point in the history
Add Voucher Activate call
  • Loading branch information
Andy Pieters authored Nov 11, 2016
2 parents 8a08840 + 3cf8ba5 commit ee9d24e
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
104 changes: 104 additions & 0 deletions src/Api/Voucher/Activate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

namespace Paynl\Api\Voucher;

use Paynl\Error\Error;
use Paynl\Error\Required as ErrorRequired;

class Activate extends Voucher
{

protected $apiTokenRequired = true;
protected $serviceIdRequired = true;

/**
* @var string The voucher card number
*/
private $_cardNumber;
/**
* @var string The voucher pin code
*/
private $_pincode;
/**
* @var string The voucher amount
*/
private $_amount;
/**
* @var string The PosId that activates the voucher ( reference id )
*/
private $_posId;

/**
* @param mixed $posId
*/
public function setPosId($posId)
{
$this->_posId = $posId;
}

/**
* @param string $cardNumber
*/
public function setCardNumber($cardNumber)
{
$this->_cardNumber = $cardNumber;
}

/**
* @param string $pincode
*/
public function setPincode($pincode)
{
$this->_pincode = $pincode;
}

/**
* Set the amount(in cents) of the transaction
*
* @param int $amount
*
* @throws Error
*/
public function setAmount($amount)
{
if(is_numeric($amount)){
$this->_amount = $amount;
}else{
throw new Error('Amount is niet numeriek', 1);
}
}

protected function getData()
{
if(!empty($this->_pincode)){
$data['pincode'] = $this->_pincode;
}
if(empty($this->_cardNumber)){
throw new ErrorRequired('cardNumber is niet geset', 1);
}else{
$data['cardNumber'] = $this->_cardNumber;
}

if(empty($this->_amount)){
throw new ErrorRequired('Amount is niet geset', 1);
}else{
$data['amount'] = $this->_amount;
}

if(empty($this->_posId)){
throw new ErrorRequired('posId is niet geset', 1);
}else{
$data['posId'] = $this->_posId;
}


$this->data = array_merge($data, $this->data);

return parent::getData();
}

public function doRequest($endpoint = null, $version = null)
{
return parent::doRequest('voucher/activate');
}
}
22 changes: 22 additions & 0 deletions src/Voucher.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,26 @@ public static function charge($options = [])
return $result['request']['result'] == 1;

}

public static function activate($options = []){
$api = new Api\Activate();

if(isset($options['pincode'])){
$api->setPincode($options['pincode']);
}
if(isset($options['cardNumber'])){
$api->setCardNumber($options['cardNumber']);
}
if(isset($options['amount'])){
$api->setAmount(round($options['amount'] * 100));
}
if(isset($options['posId'])){
$api->setPosId($options['posId']);
}
$result = $api->doRequest();

return $result['request']['result'] == 1;
}


}

0 comments on commit ee9d24e

Please sign in to comment.