diff --git a/src/Api/Voucher/Activate.php b/src/Api/Voucher/Activate.php new file mode 100644 index 00000000..b23695a3 --- /dev/null +++ b/src/Api/Voucher/Activate.php @@ -0,0 +1,104 @@ +_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'); + } +} \ No newline at end of file diff --git a/src/Voucher.php b/src/Voucher.php index 85984433..efbb6843 100644 --- a/src/Voucher.php +++ b/src/Voucher.php @@ -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; + } + + } \ No newline at end of file