Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added API to withdraw / transfer to bank account #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion library/BarionClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 -------- */

/*
Expand Down Expand Up @@ -349,4 +370,4 @@ private function GetFromBarion($url, $data)

return $output;
}
}
}
50 changes: 50 additions & 0 deletions library/models/common/BankAccountModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* Copyright 2016 Barion Payment Inc. All Rights Reserved.
* <p/>
* 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
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* 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');
}
}
}
52 changes: 52 additions & 0 deletions library/models/withdraw/BankTransferRequestModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* Copyright 2016 Barion Payment Inc. All Rights Reserved.
* <p/>
* 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
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* 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'));
}
}
}
52 changes: 52 additions & 0 deletions library/models/withdraw/BankTransferResponseModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* Copyright 2016 Barion Payment Inc. All Rights Reserved.
* <p/>
* 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
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* 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'));
}
}
}