diff --git a/src/Api/Transaction/ConfirmExternalPayment.php b/src/Api/Transaction/ConfirmExternalPayment.php new file mode 100644 index 00000000..eeb4c100 --- /dev/null +++ b/src/Api/Transaction/ConfirmExternalPayment.php @@ -0,0 +1,113 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +namespace Paynl\Api\Transaction; + +use Paynl\Error; + +/** + * Description of Confirm External Payment + * + * @author Marcel Schoolenberg + */ +class ConfirmExternalPayment extends Transaction +{ + protected $apiTokenRequired = true; + + /** + * @var string + */ + private $transactionId; + + /** + * @var string + */ + private $customerId; + + /** + * @var string + */ + private $customerName; + + /** + * @var string + */ + private $paymentType; + + /** + * Set the transactionId + * + * @param string $transactionId + */ + public function setTransactionId($transactionId){ + $this->transactionId = $transactionId; + } + + /** + * Set the customerId + * + * @param string $customerId + */ + public function setCustomerId($customerId){ + $this->customerId = $customerId; + } + + /** + * Set the customerName + * + * @param string $customerName + */ + public function setCustomerName($customerName){ + $this->customerName = $customerName; + } + + /** + * Set the paymentType + * + * @param string $paymentType + */ + public function setPaymentType($paymentType){ + $this->paymentType = $paymentType; + } + + /** + * @inheritdoc + * @throws Error\Required TransactionId is required + */ + protected function getData() { + if(empty($this->transactionId)){ + throw new Error\Required('TransactionId required'); + } + + if(empty($this->customerId)){ + throw new Error\Required('CustomerId required'); + } + + $this->data['transactionId'] = $this->transactionId; + $this->data['customerId'] = $this->customerId; + + return parent::getData(); + } + + /** + * @inheritdoc + */ + public function doRequest($endpoint = null, $version = null) { + return parent::doRequest('transaction/confirmExternalPayment'); + } +} \ No newline at end of file diff --git a/src/Result/Transaction/ConfirmExternalPayment.php b/src/Result/Transaction/ConfirmExternalPayment.php new file mode 100644 index 00000000..b21f3c9f --- /dev/null +++ b/src/Result/Transaction/ConfirmExternalPayment.php @@ -0,0 +1,85 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +namespace Paynl\Result\Transaction; + +use Paynl\Result\Result; + +/** + * Result class for a Confirm External Payment + * + * @author Marcel Schoolenberg + */ +class ConfirmExternalPayment extends Result +{ + /** + * @return string The transactionId + */ + public function getTransactionId() + { + return $this->data['transactionId']; + } + + /** + * @return string The CustomerId + */ + public function getCustomerId() + { + return $this->data['customerId']; + } + + /** + * @return string The CustomerName + */ + public function getCustomerName() + { + return $this->data['customerName']; + } + + /** + * @return string The PaymentType + */ + public function getPaymentType() + { + return $this->data['paymentType']; + } + + /** + * @return boolean success + */ + public function getSuccess() + { + return (boolean) $this->data['result']; + } + + /** + * @return string errorMessage + */ + public function getErrorMessage() + { + return $this->data['errorMessage']; + } + + /** + * @return string errorId + */ + public function getErrorId() + { + return $this->data['errorId']; + } +} \ No newline at end of file diff --git a/src/Transaction.php b/src/Transaction.php index 7882060e..6fb715c1 100644 --- a/src/Transaction.php +++ b/src/Transaction.php @@ -400,4 +400,36 @@ public static function addRecurring($options = array()) return new Result\AddRecurring($result); } + + /** + * Create a external payment + * + * @param array $options An array that contains the following elements: transactionId (required), customerId (required), customerName, paymentType + * + * @return \Paynl\Result\Transaction\ConfirmExternalPayment + */ + public function confirmExternalPayment($options = array()) + { + $api = new Api\ConfirmExternalPayment(); + + if (isset($options['transactionId'])) { + $api->setTransactionId($options['transactionId']); + } + + if (isset($options['customerId'])) { + $api->setCustomerId($options['customerId']); + } + + if (isset($options['customerName'])) { + $api->setCustomerName($options['customerName']); + } + + if (isset($options['paymentType'])) { + $api->setPaymentType($options['paymentType']); + } + + $result = $api->doRequest(); + + return new Result\ConfirmExternalPayment($result); + } }