From 48bbe3f11707bcfd10338151b3c2bab5337b9c05 Mon Sep 17 00:00:00 2001 From: Istvan David Date: Fri, 19 Feb 2021 15:26:00 +0100 Subject: [PATCH] Added API to withdraw / transfer to bank account --- library/BarionClient.php | 23 +++++++- library/models/common/BankAccountModel.php | 50 ++++++++++++++++++ .../withdraw/BankTransferRequestModel.php | 52 +++++++++++++++++++ .../withdraw/BankTransferResponseModel.php | 52 +++++++++++++++++++ 4 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 library/models/common/BankAccountModel.php create mode 100644 library/models/withdraw/BankTransferRequestModel.php create mode 100644 library/models/withdraw/BankTransferResponseModel.php diff --git a/library/BarionClient.php b/library/BarionClient.php index 8f6cfb9..a3ce183 100755 --- a/library/BarionClient.php +++ b/library/BarionClient.php @@ -239,6 +239,27 @@ public function GetPaymentQRImage($username, $password, $paymentId, $qrCodeSize return $response; } + /** + * Transfer the specified amount to a bank account + * + * @param string $model The BankTransferRequestModel to be passed + * @return BankTransferResponseModel Returns the response from the Barion API + */ + public function BankTransfer(BankTransferRequestModel $model) + { + $model->POSKey = $this->POSKey; + $url = $this->BARION_API_URL . "/v" . $this->APIVersion . API_ENDPOINT_BANKTRANSFER; + $response = $this->PostToBarion($url, $model); + + $ps = new BankTransferResponseModel(); + if (!empty($response)) { + $json = json_decode($response, true); + $ps->fromJson($json); + } + return $ps; + } + + /* -------- CURL HTTP REQUEST IMPLEMENTATIONS -------- */ /* @@ -349,4 +370,4 @@ private function GetFromBarion($url, $data) return $output; } -} \ No newline at end of file +} diff --git a/library/models/common/BankAccountModel.php b/library/models/common/BankAccountModel.php new file mode 100644 index 0000000..cc592b2 --- /dev/null +++ b/library/models/common/BankAccountModel.php @@ -0,0 +1,50 @@ + + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +class BankAccountModel implements iBarionModel +{ + public $Country; + public $Format; + public $AccountNumber; + public $Address; + public $BankName; + public $BankAddress; + public $SwiftCode; + + function __construct() + { + $this->Country = ""; + $this->Format = ""; + $this->AccountNumber = ""; + $this->Address = ""; + $this->BankName = ""; + $this->BankAddress = ""; + } + + public function fromJson($json) + { + if (!empty($json)) { + $this->Country = jget($json, 'Country'); + $this->Format = jget($json, 'Format'); + $this->AccountNumber = jget($json, 'AccountNumber'); + $this->Address = jget($json, 'Address'); + $this->BankName = jget($json, 'BankName'); + $this->BankAddress = jget($json, 'BankAddress'); + $this->SwiftCode = jget($json, 'SwiftCode'); + } + } +} diff --git a/library/models/withdraw/BankTransferRequestModel.php b/library/models/withdraw/BankTransferRequestModel.php new file mode 100644 index 0000000..c05bb0a --- /dev/null +++ b/library/models/withdraw/BankTransferRequestModel.php @@ -0,0 +1,52 @@ + + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +class BankTransferRequestModel implements iBarionModel +{ + public $UserName; + public $Password; + public $Currency; + public $Amount; + public $RecipientName; + public $Comment; + public $BankAccount; + + function __construct() + { + $this->UserName = ""; + $this->Password = ""; + $this->Currency = ""; + $this->Amount = 0; + $this->RecipientName = ""; + $this->Comment = ""; + $this->BankAccount = new BankAccountModel(); + } + + public function fromJson($json) + { + if (!empty($json)) { + $this->UserName = jget($json, 'UserName'); + $this->Password = jget($json, 'Password'); + $this->Currency = jget($json, 'Currency'); + $this->Amount = jget($json, 'Amount'); + $this->RecipientName = jget($json, 'RecipientName'); + $this->Comment = jget($json, 'Comment'); + $this->BankAccount = new BankAccountModel(); + $this->BankAccount->fromJson(jget($json, 'BankAccount')); + } + } +} diff --git a/library/models/withdraw/BankTransferResponseModel.php b/library/models/withdraw/BankTransferResponseModel.php new file mode 100644 index 0000000..8450129 --- /dev/null +++ b/library/models/withdraw/BankTransferResponseModel.php @@ -0,0 +1,52 @@ + + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +class BankTransferResponseModel extends BaseResponseModel implements iBarionModel +{ + public $TransactionId; + public $Currency; + public $Amount; + public $RecipientName; + public $Comment; + public $BankAccount; + + function __construct() + { + parent::__construct(); + $this->TransactionId = ""; + $this->Currency = "EUR"; + $this->Amount = 0; + $this->RecipientName = ""; + $this->Comment = ""; + $this->BankAccount = new BankAccountModel(); + } + + public function fromJson($json) + { + if (!empty($json)) { + parent::fromJson($json); + $this->TransactionId = jget($json, 'TransactionId'); + $this->Currency = jget($json, 'Currency'); + $this->Amount = jget($json, 'Amount'); + $this->RecipientName = jget($json, 'RecipientName'); + $this->Comment = jget($json, 'Comment'); + $this->ErrorCode = jget($json, 'ErrorCode'); + $this->BankAccount = new BankAccountModel(); + $this->BankAccount->fromJson(jget($json, 'BankAccount')); + } + } +} \ No newline at end of file