Skip to content

Commit

Permalink
Add function Confirm External Payment
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelschoolenberg committed Jul 11, 2018
1 parent 75e3dc6 commit f4ce283
Show file tree
Hide file tree
Showing 3 changed files with 230 additions and 0 deletions.
113 changes: 113 additions & 0 deletions src/Api/Transaction/ConfirmExternalPayment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php
/*
* Copyright (C) 2018 Andy Pieters <[email protected]>
*
* 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 <http://www.gnu.org/licenses/>.
*/

namespace Paynl\Api\Transaction;

use Paynl\Error;

/**
* Description of Confirm External Payment
*
* @author Marcel Schoolenberg <[email protected]>
*/
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');
}
}
85 changes: 85 additions & 0 deletions src/Result/Transaction/ConfirmExternalPayment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
/*
* Copyright (C) 2018 Andy Pieters <[email protected]>
*
* 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 <http://www.gnu.org/licenses/>.
*/

namespace Paynl\Result\Transaction;

use Paynl\Result\Result;

/**
* Result class for a Confirm External Payment
*
* @author Marcel Schoolenberg <[email protected]>
*/
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'];
}
}
32 changes: 32 additions & 0 deletions src/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,4 +378,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);
}
}

0 comments on commit f4ce283

Please sign in to comment.