Skip to content

Commit

Permalink
Merge pull request #21 from SPie/request-dcc-parameter
Browse files Browse the repository at this point in the history
Added DCC Data
  • Loading branch information
Marco authored Aug 22, 2022
2 parents f9abb20 + 7fc8cb0 commit caad122
Show file tree
Hide file tree
Showing 6 changed files with 376 additions and 4 deletions.
231 changes: 231 additions & 0 deletions src/Data/PaymentData/DccData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
<?php

namespace Ixopay\Client\Data\PaymentData;

class DccData
{
/**
* @var bool
*/
private $requestDcc;

/**
* @var string|null
*/
private $remoteIdentifier;

/**
* @var float|null
*/
private $originalAmount;

/**
* @var string|null
*/
private $originalCurrency;

/**
* @var float|null
*/
private $convertedAmount;

/**
* @var string|null
*/
private $convertedCurrency;

/**
* @var float|null
*/
private $conversionRate;

/**
* @var float|null
*/
private $markUp;

/**
* @var string|null
*/
private $selectedCurrency;

/**
* @param bool $requestDcc
*
* @return $this
*/
public function setRequestDcc($requestDcc)
{
$this->requestDcc = $requestDcc;

return $this;
}

/**
* @return bool
*/
public function isRequestDcc()
{
return $this->requestDcc;
}

/**
* @param string $remoteIdentifier
*
* @return $this
*/
public function setRemoteIdentifier($remoteIdentifier)
{
$this->remoteIdentifier = $remoteIdentifier;

return $this;
}

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

/**
* @param float $originalAmount
*
* @return $this
*/
public function setOriginalAmount($originalAmount)
{
$this->originalAmount = $originalAmount;

return $this;
}

/**
* @return float|null
*/
public function getOriginalAmount()
{
return $this->originalAmount;
}

/**
* @param string $originalCurrency
*
* @return $this
*/
public function setOriginalCurrency($originalCurrency)
{
$this->originalCurrency = $originalCurrency;

return $this;
}

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

/**
* @param float $convertedAmount
*
* @return $this
*/
public function setConvertedAmount($convertedAmount)
{
$this->convertedAmount = $convertedAmount;

return $this;
}

/**
* @return float|null
*/
public function getConvertedAmount()
{
return $this->convertedAmount;
}

/**
* @param string $convertedCurrency
*
* @return $this
*/
public function setConvertedCurrency($convertedCurrency)
{
$this->convertedCurrency = $convertedCurrency;

return $this;
}

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

/**
* @param float $conversionRate
*
* @return $this
*/
public function setConversionRate($conversionRate)
{
$this->conversionRate = $conversionRate;

return $this;
}

/**
* @return float|null
*/
public function getConversionRate()
{
return $this->conversionRate;
}

/**
* @param float|null $markUp
*
* @return $this
*/
public function setMarkUp($markUp)
{
$this->markUp = $markUp;

return $this;
}

/**
* @return float|null
*/
public function getMarkUp()
{
return $this->markUp;
}

/**
* @param string $selectedCurrency
*
* @return $this
*/
public function setSelectedCurrency($selectedCurrency)
{
$this->selectedCurrency = $selectedCurrency;

return $this;
}

/**
* @return string
*/
public function getSelectedCurrency()
{
return $this->selectedCurrency;
}
}
46 changes: 45 additions & 1 deletion src/Json/JsonGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Ixopay\Client\Schedule\ScheduleWithTransaction;
use Ixopay\Client\Schedule\StartSchedule;
use Ixopay\Client\Transaction\Base\AbstractTransaction;
use Ixopay\Client\Transaction\Base\DccDataInterface;
use Ixopay\Client\Transaction\Capture;
use Ixopay\Client\Transaction\Debit;
use Ixopay\Client\Transaction\Deregister;
Expand Down Expand Up @@ -172,7 +173,7 @@ protected function createDebit($transaction, $language){

$this->updateData($transaction, $data);

return $data;
return $this->addRequestDcc($data, $transaction);
}

/**
Expand Down Expand Up @@ -716,4 +717,47 @@ protected function updateData($transaction, &$data)
$data['payByLink'] = $this->createPayByLinkData($payByLinkData);
}
}

private function addRequestDcc(array $data, DccDataInterface $transaction)
{
if ($transaction->getRequestDcc()) {
$data['requestDcc'] = true;
}

if (!$transaction->getDccData()) {
return $data;
}

$dccData = [];
if (!empty($transaction->getDccData()->getRemoteIdentifier())) {
$dccData['remoteIdentifier'] = $transaction->getDccData()->getRemoteIdentifier();
}
if (!empty($transaction->getDccData()->getOriginalAmount())) {
$dccData['originalAmount'] = $transaction->getDccData()->getOriginalAmount();
}
if (!empty($transaction->getDccData()->getOriginalCurrency())) {
$dccData['originalCurrency'] = $transaction->getDccData()->getOriginalCurrency();
}
if (!empty($transaction->getDccData()->getConvertedAmount())) {
$dccData['convertedAmount'] = $transaction->getDccData()->getConvertedAmount();
}
if (!empty($transaction->getDccData()->getConvertedCurrency())) {
$dccData['convertedCurrency'] = $transaction->getDccData()->getConvertedCurrency();
}
if (!empty($transaction->getDccData()->getConversionRate())) {
$dccData['conversionRate'] = $transaction->getDccData()->getConversionRate();
}
if (!empty($transaction->getDccData()->getSelectedCurrency())) {
$dccData['selectedCurrency'] = $transaction->getDccData()->getSelectedCurrency();
}
if (!empty($transaction->getDccData()->getMarkUp())) {
$dccData['markUp'] = $transaction->getDccData()->getMarkUp();
}

if (!empty($dccData)) {
$data['dccData'] = $dccData;
}

return $data;
}
}
32 changes: 32 additions & 0 deletions src/Transaction/Base/DccDataInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Ixopay\Client\Transaction\Base;

use Ixopay\Client\Data\PaymentData\DccData;

interface DccDataInterface
{
/**
* @param bool $requestDcc
*
* @return $this
*/
public function setRequestDcc($requestDcc);

/**
* @return bool
*/
public function getRequestDcc();

/**
* @param DccData|null $dccData
*
* @return $this
*/
public function setDccData($dccData);

/**
* @return DccData|null
*/
public function getDccData();
}
58 changes: 58 additions & 0 deletions src/Transaction/Base/DccDataTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Ixopay\Client\Transaction\Base;

use Ixopay\Client\Data\PaymentData\DccData;

trait DccDataTrait
{
/**
* @var bool
*/
private $requestDcc = false;

/**
* @var DccData|null
*/
private $dccData = null;

/**
* @param bool $requestDcc
*
* @return $this
*/
public function setRequestDcc($requestDcc)
{
$this->requestDcc = $requestDcc;

return $this;
}

/**
* @return bool
*/
public function getRequestDcc()
{
return $this->requestDcc;
}

/**
* @param DccData|null $dccData
*
* @return $this
*/
public function setDccData($dccData)
{
$this->dccData = $dccData;

return $this;
}

/**
* @return DccData
*/
public function getDccData()
{
return $this->dccData;
}
}
Loading

0 comments on commit caad122

Please sign in to comment.