Skip to content

Commit

Permalink
Merge branch 'feature/splitTx' into v3
Browse files Browse the repository at this point in the history
  • Loading branch information
sbuche committed Dec 9, 2021
2 parents 1a92eed + c9ab3b3 commit 0572fb7
Show file tree
Hide file tree
Showing 12 changed files with 384 additions and 7 deletions.
172 changes: 172 additions & 0 deletions src/Data/TransactionSplit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
<?php


namespace Ixopay\Client\Data;


class TransactionSplit
{
/**
* @var int
*/
private $id;

/**
* @var string
*/
private $transactionInternalId;

/**
* @var string
*/
private $amount;

/**
* @var string
*/
private $currency;

/**
* @var string
*/
private $sellerMerchantGuid;

/**
* @var string
*/
private $sellerMerchantExternalId;

/** @var string */
private $commissionFeeAmount;

/** @var string */
private $commissionFeeCurrency;

/**
* @return int
*/
public function getId()
{
return $this->id;
}

/**
* @param int $id
*/
public function setId($id)
{
$this->id = $id;
}

/**
* @return string
*/
public function getTransactionInternalId()
{
return $this->transactionInternalId;
}

/**
* @param string $transactionInternalId
*/
public function setTransactionInternalId($transactionInternalId)
{
$this->transactionInternalId = $transactionInternalId;
}

/**
* @return string
*/
public function getAmount()
{
return $this->amount;
}

/**
* @param string $amount
*/
public function setAmount($amount)
{
$this->amount = $amount;
}

/**
* @return string
*/
public function getCurrency()
{
return $this->currency;
}

/**
* @param string $currency
*/
public function setCurrency($currency)
{
$this->currency = $currency;
}

/**
* @return string
*/
public function getSellerMerchantGuid()
{
return $this->sellerMerchantGuid;
}

/**
* @param string $sellerMerchantGuid
*/
public function setSellerMerchantGuid($sellerMerchantGuid)
{
$this->sellerMerchantGuid = $sellerMerchantGuid;
}

/**
* @return string
*/
public function getSellerMerchantExternalId()
{
return $this->sellerMerchantExternalId;
}

/**
* @param string $sellerMerchantExternalId
*/
public function setSellerMerchantExternalId($sellerMerchantExternalId)
{
$this->sellerMerchantExternalId = $sellerMerchantExternalId;
}

/**
* @return string
*/
public function getCommissionFeeAmount()
{
return $this->commissionFeeAmount;
}

/**
* @param string $commissionFeeAmount
*/
public function setCommissionFeeAmount($commissionFeeAmount)
{
$this->commissionFeeAmount = $commissionFeeAmount;
}

/**
* @return string
*/
public function getCommissionFeeCurrency()
{
return $this->commissionFeeCurrency;
}

/**
* @param string $commissionFeeCurrency
*/
public function setCommissionFeeCurrency($commissionFeeCurrency)
{
$this->commissionFeeCurrency = $commissionFeeCurrency;
}
}
39 changes: 39 additions & 0 deletions src/Json/JsonGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Ixopay\Client\Data\PaymentData\IbanData;
use Ixopay\Client\Data\PaymentData\PaymentData;
use Ixopay\Client\Data\PaymentData\WalletData;
use Ixopay\Client\Data\TransactionSplit;
use Ixopay\Client\Data\ThreeDSecureData;
use Ixopay\Client\Schedule\ContinueSchedule;
use Ixopay\Client\Schedule\ScheduleData;
Expand Down Expand Up @@ -157,6 +158,7 @@ protected function createDebit($transaction, $language){
'transactionToken' => $transaction->getTransactionToken(),
'description' => $transaction->getDescription(),
'items' => $this->createItems($transaction->getItems()),
'splits' => $this->createSplits($transaction->getTransactionSplits()),
'withRegister' => $transaction->isWithRegister(),
'transactionIndicator' => $transaction->getTransactionIndicator(),
'customer' => $this->createCustomer($transaction->getCustomer()),
Expand Down Expand Up @@ -219,6 +221,7 @@ protected function createCapture($transaction){
'amount' => (string)$transaction->getAmount(),
'currency' => $transaction->getCurrency(),
'items' => $this->createItems($transaction->getItems()),
'splits' => $this->createSplits($transaction->getTransactionSplits()),
];

return $data;
Expand All @@ -235,6 +238,7 @@ protected function createVoid($transaction){
/** @var VoidTransaction $transaction */
$data = [
'referenceUuid' => $transaction->getReferenceUuid(),
'description' => $transaction->getDescription(),
];

return $data;
Expand Down Expand Up @@ -302,6 +306,7 @@ protected function createRefund($transaction){
'transactionToken' => $transaction->getTransactionToken(),
'description' => $transaction->getDescription(),
'items' => $this->createItems($transaction->getItems()),
'splits' => $this->createSplits($transaction->getTransactionSplits()),
];

return $data;
Expand All @@ -328,6 +333,7 @@ protected function createPayout($transaction, $language){
'transactionToken' => $transaction->getTransactionToken(),
'description' => $transaction->getDescription(),
'items' => $this->createItems($transaction->getItems()),
'splits' => $this->createSplits($transaction->getTransactionSplits()),
'customer' => $this->createCustomer($transaction->getCustomer()),
'language' => $language,
];
Expand Down Expand Up @@ -368,6 +374,39 @@ protected function createItems($items){
return $data;
}

/**
* splits data
*
* @param $transactionSplits
*
* @return array
*/
protected function createSplits($transactionSplits){

if(!$transactionSplits){
return null;
}

$data = [];

/** @var TransactionSplit $split */
foreach($transactionSplits as $split){
$data[] = [
'identification' => $split->getTransactionInternalId(),
'amount' => $split->getAmount(),
'currency' => $split->getCurrency(),
'sellerMerchantGuid' => $split->getSellerMerchantGuid(),
'sellerMerchantExternalId' => $split->getSellerMerchantExternalId(),
'commissionFee' => [
'amount' => $split->getCommissionFeeAmount(),
'currency' => $split->getCommissionFeeCurrency()
]
];
}

return $data;
}

/**
* customer data
* - includes paymentData
Expand Down
41 changes: 41 additions & 0 deletions src/Json/JsonParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Ixopay\Client\Data\Result\ScheduleResultData;
use Ixopay\Client\Data\Result\WalletData as ReturnWalletData;
use Ixopay\Client\Data\RiskCheckData;
use Ixopay\Client\Data\TransactionSplit;
use Ixopay\Client\Options\OptionsResult;
use Ixopay\Client\Schedule\ScheduleResult;
use Ixopay\Client\StatusApi\StatusResult;
Expand Down Expand Up @@ -171,6 +172,11 @@ public function parseStatusResult($jsonString) {
$result->setCustomerProfileData($customerProfileData);
}

if(isset($json['splits'])) {
$splits = $this->parseTransactionSplits($json['splits']);
$result->setTransactionSplits($splits);
}

return $result;
}

Expand Down Expand Up @@ -506,4 +512,39 @@ protected function arrGet($arr, $key, $default=null){
}
return $default;
}

/**
* @param $data
*
* @return TransactionSplit
*/
protected function parseTransactionSplit($data){
$split = new TransactionSplit();
$split->setTransactionInternalId($this->arrGet($data, 'identification'));
$split->setAmount($this->arrGet($data, 'amount'));
$split->setCurrency($this->arrGet($data, 'currency'));
$split->setSellerMerchantGuid($this->arrGet($data, 'sellerMerchantGuid'));
$split->setSellerMerchantExternalId($this->arrGet($data, 'sellerMerchantExternalId'));

if (isset($data['commissionFee'])) {
$commissionFee = $data['commissionFee'];
$split->setCommissionFeeAmount($this->arrGet($commissionFee, 'amount'));
$split->setCommissionFeeCurrency($this->arrGet($commissionFee, 'currency'));
}

return $split;
}

/**
* @param $data
*
* @return array
*/
protected function parseTransactionSplits($data){
$splits = [];
foreach($data as $split){
$splits[] = $this->parseTransactionSplit($split);
}
return $splits;
}
}
22 changes: 22 additions & 0 deletions src/StatusApi/StatusResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Ixopay\Client\Data\CustomerProfileData;
use Ixopay\Client\Data\Result\ResultData;
use Ixopay\Client\Data\Result\ScheduleResultData;
use Ixopay\Client\Data\TransactionSplit;
use Ixopay\Client\Transaction\Error;

/**
Expand Down Expand Up @@ -170,6 +171,11 @@ class StatusResult {
*/
protected $errorCode = null;

/**
* @var TransactionSplit[]
*/
protected $transactionSplits = [];

/**
* @return bool
*/
Expand Down Expand Up @@ -615,6 +621,22 @@ public function setErrorCode($errorCode)
return $this;
}

/**
* @return TransactionSplit[]
*/
public function getTransactionSplits()
{
return $this->transactionSplits;
}

/**
* @param TransactionSplit[] $transactionSplits
*/
public function setTransactionSplits($transactionSplits)
{
$this->transactionSplits = $transactionSplits;
}

/**
* @return array
*/
Expand Down
30 changes: 30 additions & 0 deletions src/Transaction/Base/TransactionSplitsInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Ixopay\Client\Transaction\Base;
use Ixopay\Client\Data\TransactionSplit;

/**
* Interface SplitsInterface
*
* @package Ixopay\Client\Transaction\Base
*/
interface TransactionSplitsInterface {

/**
* @param TransactionSplit[] $transactionSplits
* @return void
*/
public function setTransactionSplits($transactionSplits);

/**
* @return TransactionSplit[]
*/
public function getTransactionSplits();

/**
* @param TransactionSplit $transactionSplit
* @return void
*/
public function addTransactionSplit(TransactionSplit $transactionSplit);

}
Loading

0 comments on commit 0572fb7

Please sign in to comment.