diff --git a/src/Data/PaymentData/DccData.php b/src/Data/PaymentData/DccData.php new file mode 100644 index 0000000..12b715f --- /dev/null +++ b/src/Data/PaymentData/DccData.php @@ -0,0 +1,231 @@ +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; + } +} diff --git a/src/Json/JsonGenerator.php b/src/Json/JsonGenerator.php index d6ed485..b00f232 100644 --- a/src/Json/JsonGenerator.php +++ b/src/Json/JsonGenerator.php @@ -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; @@ -172,7 +173,7 @@ protected function createDebit($transaction, $language){ $this->updateData($transaction, $data); - return $data; + return $this->addRequestDcc($data, $transaction); } /** @@ -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; + } } diff --git a/src/Transaction/Base/DccDataInterface.php b/src/Transaction/Base/DccDataInterface.php new file mode 100644 index 0000000..43c44c2 --- /dev/null +++ b/src/Transaction/Base/DccDataInterface.php @@ -0,0 +1,32 @@ +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; + } +} diff --git a/src/Transaction/Debit.php b/src/Transaction/Debit.php index 010e26b..9594963 100644 --- a/src/Transaction/Debit.php +++ b/src/Transaction/Debit.php @@ -16,6 +16,8 @@ use Ixopay\Client\Transaction\Base\OffsiteInterface; use Ixopay\Client\Transaction\Base\OffsiteTrait; use Ixopay\Client\Transaction\Base\PayByLinkTrait; +use Ixopay\Client\Transaction\Base\DccDataInterface; +use Ixopay\Client\Transaction\Base\DccDataTrait; use Ixopay\Client\Transaction\Base\ScheduleInterface; use Ixopay\Client\Transaction\Base\ScheduleTrait; use Ixopay\Client\Transaction\Base\TransactionSplitsInterface; @@ -37,9 +39,9 @@ class Debit extends AbstractTransactionWithReference OffsiteInterface, ScheduleInterface, ThreeDSecureInterface, - IndicatorInterface + IndicatorInterface, + DccDataInterface { - use AddToCustomerProfileTrait; use AmountableTrait; use CustomerTrait; @@ -50,6 +52,7 @@ class Debit extends AbstractTransactionWithReference use ThreeDSecureTrait; use PayByLinkTrait; use IndicatorTrait; + use DccDataTrait; const TRANSACTION_INDICATOR_SINGLE = 'SINGLE'; const TRANSACTION_INDICATOR_INITIAL = 'INITIAL'; diff --git a/src/Transaction/Preauthorize.php b/src/Transaction/Preauthorize.php index 8dcaa25..55b87d8 100644 --- a/src/Transaction/Preauthorize.php +++ b/src/Transaction/Preauthorize.php @@ -16,6 +16,8 @@ use Ixopay\Client\Transaction\Base\OffsiteInterface; use Ixopay\Client\Transaction\Base\OffsiteTrait; use Ixopay\Client\Transaction\Base\PayByLinkTrait; +use Ixopay\Client\Transaction\Base\DccDataInterface; +use Ixopay\Client\Transaction\Base\DccDataTrait; use Ixopay\Client\Transaction\Base\ScheduleInterface; use Ixopay\Client\Transaction\Base\ScheduleTrait; use Ixopay\Client\Transaction\Base\TransactionSplitsInterface; @@ -37,7 +39,8 @@ class Preauthorize extends AbstractTransactionWithReference OffsiteInterface, ScheduleInterface, ThreeDSecureInterface, - IndicatorInterface + IndicatorInterface, + DccDataInterface { use AddToCustomerProfileTrait; @@ -50,6 +53,7 @@ class Preauthorize extends AbstractTransactionWithReference use ThreeDSecureTrait; use PayByLinkTrait; use IndicatorTrait; + use DccDataTrait; const TRANSACTION_INDICATOR_SINGLE = 'SINGLE'; const TRANSACTION_INDICATOR_INITIAL = 'INITIAL';