From 3556ee1c75c7343d4cf6d90f4de4cee6a93b9d1f Mon Sep 17 00:00:00 2001 From: Manuel Huez Date: Fri, 20 Apr 2018 15:03:51 +0200 Subject: [PATCH] Add ProcessOutExceptionInterface. Fixes #8. --- README.md | 2 +- init.php | 3 + src/Exceptions/AuthenticationException.php | 2 +- src/Exceptions/GenericException.php | 2 +- src/Exceptions/InternalException.php | 2 +- src/Exceptions/NotFoundException.php | 2 +- .../ProcessOutExceptionInterface.php | 14 + src/Exceptions/ValidationException.php | 2 +- src/Payout.php | 737 ++++++++++++++++++ src/PayoutItem.php | 437 +++++++++++ src/ProcessOut.php | 18 + src/Project.php | 82 +- src/TransactionOperation.php | 31 + 13 files changed, 1327 insertions(+), 7 deletions(-) create mode 100644 src/Exceptions/ProcessOutExceptionInterface.php create mode 100755 src/Payout.php create mode 100755 src/PayoutItem.php diff --git a/README.md b/README.md index c79c1a2..4255c92 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ The package's installation is done using composer. Simply add these lines to you ```json { "require": { - "ProcessOut/ProcessOut-php": "^6.5.0" + "ProcessOut/ProcessOut-php": "^6.6.0" } } ``` diff --git a/init.php b/init.php index 8bb00e3..30c58f7 100644 --- a/init.php +++ b/init.php @@ -2,6 +2,7 @@ include_once(dirname(__FILE__) . "/src/ProcessOut.php"); +include_once(dirname(__FILE__) . "/src/Exceptions/ProcessOutExceptionInterface.php"); include_once(dirname(__FILE__) . "/src/Exceptions/AuthenticationException.php"); include_once(dirname(__FILE__) . "/src/Exceptions/GenericException.php"); include_once(dirname(__FILE__) . "/src/Exceptions/InternalException.php"); @@ -29,6 +30,8 @@ include_once(dirname(__FILE__) . "/src/InvoiceDetail.php"); include_once(dirname(__FILE__) . "/src/CustomerAction.php"); include_once(dirname(__FILE__) . "/src/DunningAction.php"); +include_once(dirname(__FILE__) . "/src/Payout.php"); +include_once(dirname(__FILE__) . "/src/PayoutItem.php"); include_once(dirname(__FILE__) . "/src/Plan.php"); include_once(dirname(__FILE__) . "/src/Product.php"); include_once(dirname(__FILE__) . "/src/Project.php"); diff --git a/src/Exceptions/AuthenticationException.php b/src/Exceptions/AuthenticationException.php index 531446a..8db94ed 100644 --- a/src/Exceptions/AuthenticationException.php +++ b/src/Exceptions/AuthenticationException.php @@ -4,7 +4,7 @@ use \Exception; -class AuthenticationException extends Exception +class AuthenticationException extends Exception implements ProcessOutExceptionInterface { protected $errorCode; diff --git a/src/Exceptions/GenericException.php b/src/Exceptions/GenericException.php index b258cd3..fcd7c67 100644 --- a/src/Exceptions/GenericException.php +++ b/src/Exceptions/GenericException.php @@ -4,7 +4,7 @@ use \Exception; -class GenericException extends Exception +class GenericException extends Exception implements ProcessOutExceptionInterface { protected $errorCode; diff --git a/src/Exceptions/InternalException.php b/src/Exceptions/InternalException.php index 66803e2..492a1cb 100644 --- a/src/Exceptions/InternalException.php +++ b/src/Exceptions/InternalException.php @@ -4,7 +4,7 @@ use \Exception; -class InternalException extends Exception +class InternalException extends Exception implements ProcessOutExceptionInterface { protected $errorCode; diff --git a/src/Exceptions/NotFoundException.php b/src/Exceptions/NotFoundException.php index a2aedf7..f4e04a5 100644 --- a/src/Exceptions/NotFoundException.php +++ b/src/Exceptions/NotFoundException.php @@ -4,7 +4,7 @@ use \Exception; -class NotFoundException extends Exception +class NotFoundException extends Exception implements ProcessOutExceptionInterface { protected $errorCode; diff --git a/src/Exceptions/ProcessOutExceptionInterface.php b/src/Exceptions/ProcessOutExceptionInterface.php new file mode 100644 index 0000000..841779e --- /dev/null +++ b/src/Exceptions/ProcessOutExceptionInterface.php @@ -0,0 +1,14 @@ +client = $client; + + $this->fillWithData($prefill); + } + + + /** + * Get Id + * ID of the payout + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * Set Id + * ID of the payout + * @param string $value + * @return $this + */ + public function setId($value) + { + $this->id = $value; + return $this; + } + + /** + * Get Project + * Project to which the payout belongs + * @return object + */ + public function getProject() + { + return $this->project; + } + + /** + * Set Project + * Project to which the payout belongs + * @param object $value + * @return $this + */ + public function setProject($value) + { + if (is_object($value)) + $this->project = $value; + else + { + $obj = new Project($this->client); + $obj->fillWithData($value); + $this->project = $obj; + } + return $this; + } + + /** + * Get ProjectId + * ID of the project to which the payout belongs + * @return string + */ + public function getProjectId() + { + return $this->projectId; + } + + /** + * Set ProjectId + * ID of the project to which the payout belongs + * @param string $value + * @return $this + */ + public function setProjectId($value) + { + $this->projectId = $value; + return $this; + } + + /** + * Get Status + * Status of the payout + * @return string + */ + public function getStatus() + { + return $this->status; + } + + /** + * Set Status + * Status of the payout + * @param string $value + * @return $this + */ + public function setStatus($value) + { + $this->status = $value; + return $this; + } + + /** + * Get Amount + * Amount of the payout + * @return string + */ + public function getAmount() + { + return $this->amount; + } + + /** + * Set Amount + * Amount of the payout + * @param string $value + * @return $this + */ + public function setAmount($value) + { + $this->amount = $value; + return $this; + } + + /** + * Get Currency + * Currency of the payout + * @return string + */ + public function getCurrency() + { + return $this->currency; + } + + /** + * Set Currency + * Currency of the payout + * @param string $value + * @return $this + */ + public function setCurrency($value) + { + $this->currency = $value; + return $this; + } + + /** + * Get Metadata + * Metadata related to the payout, in the form of a dictionary (key-value pair) + * @return array + */ + public function getMetadata() + { + return $this->metadata; + } + + /** + * Set Metadata + * Metadata related to the payout, in the form of a dictionary (key-value pair) + * @param array $value + * @return $this + */ + public function setMetadata($value) + { + $this->metadata = $value; + return $this; + } + + /** + * Get BankName + * Name of the bank to which the payout was issued, if available + * @return string + */ + public function getBankName() + { + return $this->bankName; + } + + /** + * Set BankName + * Name of the bank to which the payout was issued, if available + * @param string $value + * @return $this + */ + public function setBankName($value) + { + $this->bankName = $value; + return $this; + } + + /** + * Get BankSummary + * Summary of the bank to which the payout was issued, if available + * @return string + */ + public function getBankSummary() + { + return $this->bankSummary; + } + + /** + * Set BankSummary + * Summary of the bank to which the payout was issued, if available + * @param string $value + * @return $this + */ + public function setBankSummary($value) + { + $this->bankSummary = $value; + return $this; + } + + /** + * Get SalesTransactions + * Number of completed transactions linked to the payout, if available + * @return int + */ + public function getSalesTransactions() + { + return $this->salesTransactions; + } + + /** + * Set SalesTransactions + * Number of completed transactions linked to the payout, if available + * @param int $value + * @return $this + */ + public function setSalesTransactions($value) + { + $this->salesTransactions = $value; + return $this; + } + + /** + * Get SalesVolume + * Volume of completed transactions linked to the payout, if available + * @return string + */ + public function getSalesVolume() + { + return $this->salesVolume; + } + + /** + * Set SalesVolume + * Volume of completed transactions linked to the payout, if available + * @param string $value + * @return $this + */ + public function setSalesVolume($value) + { + $this->salesVolume = $value; + return $this; + } + + /** + * Get RefundsTransactions + * Number of refunded transactions linked to the payout, if available + * @return int + */ + public function getRefundsTransactions() + { + return $this->refundsTransactions; + } + + /** + * Set RefundsTransactions + * Number of refunded transactions linked to the payout, if available + * @param int $value + * @return $this + */ + public function setRefundsTransactions($value) + { + $this->refundsTransactions = $value; + return $this; + } + + /** + * Get RefundsVolume + * Volume of refunded transactions linked to the payout, if available + * @return string + */ + public function getRefundsVolume() + { + return $this->refundsVolume; + } + + /** + * Set RefundsVolume + * Volume of refunded transactions linked to the payout, if available + * @param string $value + * @return $this + */ + public function setRefundsVolume($value) + { + $this->refundsVolume = $value; + return $this; + } + + /** + * Get ChargebacksTransactions + * Number of chargebacked transactions linked to the payout, if available + * @return int + */ + public function getChargebacksTransactions() + { + return $this->chargebacksTransactions; + } + + /** + * Set ChargebacksTransactions + * Number of chargebacked transactions linked to the payout, if available + * @param int $value + * @return $this + */ + public function setChargebacksTransactions($value) + { + $this->chargebacksTransactions = $value; + return $this; + } + + /** + * Get ChargebacksVolume + * Volume of chargebacked transactions linked to the payout, if available + * @return string + */ + public function getChargebacksVolume() + { + return $this->chargebacksVolume; + } + + /** + * Set ChargebacksVolume + * Volume of chargebacked transactions linked to the payout, if available + * @param string $value + * @return $this + */ + public function setChargebacksVolume($value) + { + $this->chargebacksVolume = $value; + return $this; + } + + /** + * Get Fees + * Fees linked to the payout, if available + * @return string + */ + public function getFees() + { + return $this->fees; + } + + /** + * Set Fees + * Fees linked to the payout, if available + * @param string $value + * @return $this + */ + public function setFees($value) + { + $this->fees = $value; + return $this; + } + + /** + * Get Adjustments + * Adjustments linked to the payout, if available + * @return string + */ + public function getAdjustments() + { + return $this->adjustments; + } + + /** + * Set Adjustments + * Adjustments linked to the payout, if available + * @param string $value + * @return $this + */ + public function setAdjustments($value) + { + $this->adjustments = $value; + return $this; + } + + /** + * Get Reserve + * Reserve kept on the payout, if available + * @return string + */ + public function getReserve() + { + return $this->reserve; + } + + /** + * Set Reserve + * Reserve kept on the payout, if available + * @param string $value + * @return $this + */ + public function setReserve($value) + { + $this->reserve = $value; + return $this; + } + + /** + * Get CreatedAt + * Date at which the payout was created + * @return string + */ + public function getCreatedAt() + { + return $this->createdAt; + } + + /** + * Set CreatedAt + * Date at which the payout was created + * @param string $value + * @return $this + */ + public function setCreatedAt($value) + { + $this->createdAt = $value; + return $this; + } + + + /** + * Fills the current object with the new values pulled from the data + * @param array $data + * @return Payout + */ + public function fillWithData($data) + { + if(! empty($data['id'])) + $this->setId($data['id']); + + if(! empty($data['project'])) + $this->setProject($data['project']); + + if(! empty($data['project_id'])) + $this->setProjectId($data['project_id']); + + if(! empty($data['status'])) + $this->setStatus($data['status']); + + if(! empty($data['amount'])) + $this->setAmount($data['amount']); + + if(! empty($data['currency'])) + $this->setCurrency($data['currency']); + + if(! empty($data['metadata'])) + $this->setMetadata($data['metadata']); + + if(! empty($data['bank_name'])) + $this->setBankName($data['bank_name']); + + if(! empty($data['bank_summary'])) + $this->setBankSummary($data['bank_summary']); + + if(! empty($data['sales_transactions'])) + $this->setSalesTransactions($data['sales_transactions']); + + if(! empty($data['sales_volume'])) + $this->setSalesVolume($data['sales_volume']); + + if(! empty($data['refunds_transactions'])) + $this->setRefundsTransactions($data['refunds_transactions']); + + if(! empty($data['refunds_volume'])) + $this->setRefundsVolume($data['refunds_volume']); + + if(! empty($data['chargebacks_transactions'])) + $this->setChargebacksTransactions($data['chargebacks_transactions']); + + if(! empty($data['chargebacks_volume'])) + $this->setChargebacksVolume($data['chargebacks_volume']); + + if(! empty($data['fees'])) + $this->setFees($data['fees']); + + if(! empty($data['adjustments'])) + $this->setAdjustments($data['adjustments']); + + if(! empty($data['reserve'])) + $this->setReserve($data['reserve']); + + if(! empty($data['created_at'])) + $this->setCreatedAt($data['created_at']); + + return $this; + } + + + /** + * Get all the items linked to the payout. + * @param array $options + * @return array + */ + public function fetchItems($options = array()) + { + $this->fillWithData($options); + + $request = new Request($this->client); + $path = "/payouts/" . urlencode($this->getId()) . "/items"; + + $data = array( + + ); + + $response = $request->get($path, $data, $options); + $returnValues = array(); + + + // Handling for field items + $a = array(); + $body = $response->getBody(); + foreach($body['items'] as $v) + { + $tmp = new PayoutItem($this->client); + $tmp->fillWithData($v); + $a[] = $tmp; + } + $returnValues['Items'] = $a; + + return array_values($returnValues)[0]; + } + + /** + * Get all the payouts. + * @param array $options + * @return array + */ + public function all($options = array()) + { + $this->fillWithData($options); + + $request = new Request($this->client); + $path = "/payouts"; + + $data = array( + + ); + + $response = $request->get($path, $data, $options); + $returnValues = array(); + + + // Handling for field payouts + $a = array(); + $body = $response->getBody(); + foreach($body['payouts'] as $v) + { + $tmp = new Payout($this->client); + $tmp->fillWithData($v); + $a[] = $tmp; + } + $returnValues['Payouts'] = $a; + + return array_values($returnValues)[0]; + } + + /** + * Find a payout by its ID. + * @param string $payoutId + * @param array $options + * @return $this + */ + public function find($payoutId, $options = array()) + { + $this->fillWithData($options); + + $request = new Request($this->client); + $path = "/payouts/" . urlencode($payoutId) . ""; + + $data = array( + + ); + + $response = $request->get($path, $data, $options); + $returnValues = array(); + + + // Handling for field payout + $body = $response->getBody(); + $body = $body['payout']; + $returnValues['find'] = $this->fillWithData($body); + + return array_values($returnValues)[0]; + } + +} diff --git a/src/PayoutItem.php b/src/PayoutItem.php new file mode 100755 index 0000000..d76dec3 --- /dev/null +++ b/src/PayoutItem.php @@ -0,0 +1,437 @@ +client = $client; + + $this->fillWithData($prefill); + } + + + /** + * Get Id + * ID of the payout item + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * Set Id + * ID of the payout item + * @param string $value + * @return $this + */ + public function setId($value) + { + $this->id = $value; + return $this; + } + + /** + * Get Project + * Project to which the payout item belongs + * @return object + */ + public function getProject() + { + return $this->project; + } + + /** + * Set Project + * Project to which the payout item belongs + * @param object $value + * @return $this + */ + public function setProject($value) + { + if (is_object($value)) + $this->project = $value; + else + { + $obj = new Project($this->client); + $obj->fillWithData($value); + $this->project = $obj; + } + return $this; + } + + /** + * Get ProjectId + * ID of the project to which the payout item belongs + * @return string + */ + public function getProjectId() + { + return $this->projectId; + } + + /** + * Set ProjectId + * ID of the project to which the payout item belongs + * @param string $value + * @return $this + */ + public function setProjectId($value) + { + $this->projectId = $value; + return $this; + } + + /** + * Get Payout + * Payout to which the item belongs + * @return object + */ + public function getPayout() + { + return $this->payout; + } + + /** + * Set Payout + * Payout to which the item belongs + * @param object $value + * @return $this + */ + public function setPayout($value) + { + if (is_object($value)) + $this->payout = $value; + else + { + $obj = new Payout($this->client); + $obj->fillWithData($value); + $this->payout = $obj; + } + return $this; + } + + /** + * Get PayoutId + * ID of the payout to which the item belongs + * @return string + */ + public function getPayoutId() + { + return $this->payoutId; + } + + /** + * Set PayoutId + * ID of the payout to which the item belongs + * @param string $value + * @return $this + */ + public function setPayoutId($value) + { + $this->payoutId = $value; + return $this; + } + + /** + * Get Transaction + * Transaction linked to this payout item. Can be null + * @return object + */ + public function getTransaction() + { + return $this->transaction; + } + + /** + * Set Transaction + * Transaction linked to this payout item. Can be null + * @param object $value + * @return $this + */ + public function setTransaction($value) + { + if (is_object($value)) + $this->transaction = $value; + else + { + $obj = new Transaction($this->client); + $obj->fillWithData($value); + $this->transaction = $obj; + } + return $this; + } + + /** + * Get TransactionId + * ID of the transaction linked to this payout item. Can be null + * @return string + */ + public function getTransactionId() + { + return $this->transactionId; + } + + /** + * Set TransactionId + * ID of the transaction linked to this payout item. Can be null + * @param string $value + * @return $this + */ + public function setTransactionId($value) + { + $this->transactionId = $value; + return $this; + } + + /** + * Get Type + * Type of the payout item + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * Set Type + * Type of the payout item + * @param string $value + * @return $this + */ + public function setType($value) + { + $this->type = $value; + return $this; + } + + /** + * Get GatewayId + * ID of the payout item from the payment gateway + * @return string + */ + public function getGatewayId() + { + return $this->gatewayId; + } + + /** + * Set GatewayId + * ID of the payout item from the payment gateway + * @param string $value + * @return $this + */ + public function setGatewayId($value) + { + $this->gatewayId = $value; + return $this; + } + + /** + * Get Fee + * Fee linked to this specific payout item. Can be null or 0. + * @return string + */ + public function getFee() + { + return $this->fee; + } + + /** + * Set Fee + * Fee linked to this specific payout item. Can be null or 0. + * @param string $value + * @return $this + */ + public function setFee($value) + { + $this->fee = $value; + return $this; + } + + /** + * Get Metadata + * Metadata related to the payout item, in the form of a dictionary (key-value pair) + * @return array + */ + public function getMetadata() + { + return $this->metadata; + } + + /** + * Set Metadata + * Metadata related to the payout item, in the form of a dictionary (key-value pair) + * @param array $value + * @return $this + */ + public function setMetadata($value) + { + $this->metadata = $value; + return $this; + } + + /** + * Get CreatedAt + * Date at which the payout item was created + * @return string + */ + public function getCreatedAt() + { + return $this->createdAt; + } + + /** + * Set CreatedAt + * Date at which the payout item was created + * @param string $value + * @return $this + */ + public function setCreatedAt($value) + { + $this->createdAt = $value; + return $this; + } + + + /** + * Fills the current object with the new values pulled from the data + * @param array $data + * @return PayoutItem + */ + public function fillWithData($data) + { + if(! empty($data['id'])) + $this->setId($data['id']); + + if(! empty($data['project'])) + $this->setProject($data['project']); + + if(! empty($data['project_id'])) + $this->setProjectId($data['project_id']); + + if(! empty($data['payout'])) + $this->setPayout($data['payout']); + + if(! empty($data['payout_id'])) + $this->setPayoutId($data['payout_id']); + + if(! empty($data['transaction'])) + $this->setTransaction($data['transaction']); + + if(! empty($data['transaction_id'])) + $this->setTransactionId($data['transaction_id']); + + if(! empty($data['type'])) + $this->setType($data['type']); + + if(! empty($data['gateway_id'])) + $this->setGatewayId($data['gateway_id']); + + if(! empty($data['fee'])) + $this->setFee($data['fee']); + + if(! empty($data['metadata'])) + $this->setMetadata($data['metadata']); + + if(! empty($data['created_at'])) + $this->setCreatedAt($data['created_at']); + + return $this; + } + + +} diff --git a/src/ProcessOut.php b/src/ProcessOut.php index c18c665..a677141 100644 --- a/src/ProcessOut.php +++ b/src/ProcessOut.php @@ -235,6 +235,24 @@ public function newDunningAction($prefill = array()) { return new DunningAction($this, $prefill); } + /** + * Create a new Payout instance + * @param array|null $prefill array used to prefill the object + * @return Payout + */ + public function newPayout($prefill = array()) { + return new Payout($this, $prefill); + } + + /** + * Create a new PayoutItem instance + * @param array|null $prefill array used to prefill the object + * @return PayoutItem + */ + public function newPayoutItem($prefill = array()) { + return new PayoutItem($this, $prefill); + } + /** * Create a new Plan instance * @param array|null $prefill array used to prefill the object diff --git a/src/Project.php b/src/Project.php index e8e6754..b7f745b 100755 --- a/src/Project.php +++ b/src/Project.php @@ -408,6 +408,86 @@ public function fillWithData($data) } + /** + * Fetch the current project information. + * @param array $options + * @return $this + */ + public function fetch($options = array()) + { + $this->fillWithData($options); + + $request = new Request($this->client); + $path = "/projects/" . urlencode($this->getId()) . ""; + + $data = array( + + ); + + $response = $request->get($path, $data, $options); + $returnValues = array(); + + + // Handling for field project + $body = $response->getBody(); + $body = $body['project']; + $returnValues['fetch'] = $this->fillWithData($body); + + return array_values($returnValues)[0]; + } + + /** + * Save the updated project's attributes. + * @param array $options + * @return $this + */ + public function save($options = array()) + { + $this->fillWithData($options); + + $request = new Request($this->client); + $path = "/projects/" . urlencode($this->getId()) . ""; + + $data = array( + + ); + + $response = $request->put($path, $data, $options); + $returnValues = array(); + + + // Handling for field project + $body = $response->getBody(); + $body = $body['project']; + $returnValues['save'] = $this->fillWithData($body); + + return array_values($returnValues)[0]; + } + + /** + * Delete the project. Be careful! Executing this request will prevent any further interaction with the API that uses this project. + * @param array $options + * @return bool + */ + public function delete($options = array()) + { + $this->fillWithData($options); + + $request = new Request($this->client); + $path = "/projects/{project_id}"; + + $data = array( + + ); + + $response = $request->delete($path, $data, $options); + $returnValues = array(); + + $returnValues['success'] = $response->isSuccess(); + + return array_values($returnValues)[0]; + } + /** * Regenerate the project private key. Make sure to store the new private key and use it in any future request. * @param array $options @@ -441,7 +521,7 @@ public function regeneratePrivateKey($options = array()) * @param array $options * @return array */ - public function allSupervised($options = array()) + public function fetchSupervised($options = array()) { $this->fillWithData($options); diff --git a/src/TransactionOperation.php b/src/TransactionOperation.php index 3e44ae6..1b43eeb 100755 --- a/src/TransactionOperation.php +++ b/src/TransactionOperation.php @@ -88,6 +88,12 @@ class TransactionOperation */ protected $type; + /** + * ID of the operation done through the PSP + * @var string + */ + protected $gatewayOperationId; + /** * Error code returned when attempting the operation, if any * @var string @@ -410,6 +416,28 @@ public function setType($value) return $this; } + /** + * Get GatewayOperationId + * ID of the operation done through the PSP + * @return string + */ + public function getGatewayOperationId() + { + return $this->gatewayOperationId; + } + + /** + * Set GatewayOperationId + * ID of the operation done through the PSP + * @param string $value + * @return $this + */ + public function setGatewayOperationId($value) + { + $this->gatewayOperationId = $value; + return $this; + } + /** * Get ErrorCode * Error code returned when attempting the operation, if any @@ -542,6 +570,9 @@ public function fillWithData($data) if(! empty($data['type'])) $this->setType($data['type']); + if(! empty($data['gateway_operation_id'])) + $this->setGatewayOperationId($data['gateway_operation_id']); + if(! empty($data['error_code'])) $this->setErrorCode($data['error_code']);