Skip to content

Commit

Permalink
Refactoring of MopDescription
Browse files Browse the repository at this point in the history
  • Loading branch information
DerMika committed Feb 23, 2017
1 parent a94315e commit 34e8350
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 76 deletions.
123 changes: 48 additions & 75 deletions src/Amadeus/Client/Struct/Fop/MopDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,94 +126,65 @@ protected function loadPaymentModule(MopInfo $options)
$options->paySupData
)) {
$this->paymentModule = new PaymentModule($options->fopType);
$this->paymentModule->loadPaymentData($options);

if (!empty($options->payMerchant)) {
$this->checkAndCreatePaymentData();
$this->paymentModule->paymentData->merchantInformation = new MerchantInformation($options->payMerchant);
}

if (!empty($options->transactionDate)) {
$this->checkAndCreatePaymentData();
$this->paymentModule->paymentData->transactionDateTime = new TransactionDateTime(
null,
$options->transactionDate
);
}

if (!empty($options->payments)) {
$this->checkAndCreatePaymentData();
$this->paymentModule->paymentData->monetaryInformation[] = new MonetaryInformation($options->payments);
}
$this->loadMopInformation($options);

if (!empty($options->installmentsInfo)) {
$this->checkAndCreatePaymentData();
$this->paymentModule->paymentData->extendedPaymentInfo = new ExtendedPaymentInfo(
$options->installmentsInfo
);
}

if (!empty($options->fraudScreening)) {
$this->checkAndCreatePaymentData();
$this->paymentModule->paymentData->fraudScreeningData = new FraudScreeningData(
$options->fraudScreening
);
}
$this->loadPaymentSupplementaryData($options);
}
}

if (!empty($options->payIds)) {
$this->checkAndCreatePaymentData();
foreach ($options->payIds as $payId) {
$this->paymentModule->paymentData->paymentId[] = new PaymentId(
$payId->id,
$payId->type
);
}
}
/**
* Load Supplementary data
*
* @param MopInfo $options
*/
protected function loadPaymentSupplementaryData(MopInfo $options)
{
foreach ($options->paySupData as $paySupData) {
$this->paymentModule->paymentSupplementaryData[] = new PaymentSupplementaryData(
$paySupData->function,
$paySupData->data
);
}
}

if (!empty($options->mopPaymentType)) {
$this->checkAndCreateMopInformation();
$this->paymentModule->mopInformation->fopInformation = new FopInformation($options->mopPaymentType);
}
/**
* Load MopInformation
*
* @param MopInfo $options
*/
protected function loadMopInformation(MopInfo $options)
{
if (!empty($options->mopPaymentType)) {
$this->checkAndCreateMopInformation();
$this->paymentModule->mopInformation->fopInformation = new FopInformation($options->mopPaymentType);
}

if (!empty($options->creditCardInfo)) {
$this->checkAndCreateMopInformation();
$this->paymentModule->mopInformation->creditCardData = new CreditCardData($options->creditCardInfo);
if ($this->checkAnyNotEmpty(
if (!empty($options->creditCardInfo)) {
$this->checkAndCreateMopInformation();
$this->paymentModule->mopInformation->creditCardData = new CreditCardData($options->creditCardInfo);
if ($this->checkAnyNotEmpty(
$options->creditCardInfo->approvalCode,
$options->creditCardInfo->threeDSecure
)
) {
$this->checkAndCreateMopDetailedData($options->fopType);
$this->paymentModule->mopDetailedData->creditCardDetailedData = new CreditCardDetailedData(
$options->creditCardInfo->approvalCode,
$options->creditCardInfo->sourceOfApproval,
$options->creditCardInfo->threeDSecure
)) {
$this->checkAndCreateMopDetailedData($options->fopType);
$this->paymentModule->mopDetailedData->creditCardDetailedData = new CreditCardDetailedData(
$options->creditCardInfo->approvalCode,
$options->creditCardInfo->sourceOfApproval,
$options->creditCardInfo->threeDSecure
);
}
}

if (!empty($options->invoiceInfo)) {
$this->checkAndCreateMopInformation();
$this->paymentModule->mopInformation->invoiceDataGroup = new InvoiceDataGroup($options->invoiceInfo);
}

foreach ($options->paySupData as $paySupData) {
$this->paymentModule->paymentSupplementaryData[] = new PaymentSupplementaryData(
$paySupData->function,
$paySupData->data
);
}
}
}

/**
* Create Payment Data node if needed
*/
private function checkAndCreatePaymentData()
{
if (is_null($this->paymentModule->paymentData)) {
$this->paymentModule->paymentData = new PaymentData();
if (!empty($options->invoiceInfo)) {
$this->checkAndCreateMopInformation();
$this->paymentModule->mopInformation->invoiceDataGroup = new InvoiceDataGroup($options->invoiceInfo);
}
}


/**
* Create MopInformation node if needed
*/
Expand All @@ -225,7 +196,9 @@ private function checkAndCreateMopInformation()
}

/**
* @param $fopType
* Create MopDetailedData node if needed
*
* @param string $fopType
*/
private function checkAndCreateMopDetailedData($fopType)
{
Expand Down
45 changes: 45 additions & 0 deletions src/Amadeus/Client/Struct/Fop/PaymentData.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@

namespace Amadeus\Client\Struct\Fop;

use Amadeus\Client\RequestOptions\Fop\FraudScreeningOptions;
use Amadeus\Client\RequestOptions\Fop\InstallmentsInfo;
use Amadeus\Client\RequestOptions\Fop\PayId;
use Amadeus\Client\RequestOptions\Fop\Payment;

/**
* PaymentData
*
Expand Down Expand Up @@ -94,4 +99,44 @@ class PaymentData
* @var PaymentDataMap[]
*/
public $paymentDataMap = [];

/**
* PaymentData constructor.
*
* @param string|null $payMerchant
* @param \DateTime|null $transactionDate
* @param Payment[] $payments
* @param InstallmentsInfo|null $installmentsInfo
* @param FraudScreeningOptions|null $fraudScreening
* @param PayId[] $payIds
*/
public function __construct($payMerchant, $transactionDate, $payments, $installmentsInfo, $fraudScreening, $payIds)
{
if (!empty($payMerchant)) {
$this->merchantInformation = new MerchantInformation($payMerchant);
}

if (!empty($transactionDate)) {
$this->transactionDateTime = new TransactionDateTime(null, $transactionDate);
}

if (!empty($payments)) {
$this->monetaryInformation[] = new MonetaryInformation($payments);
}

if (!empty($installmentsInfo)) {
$this->extendedPaymentInfo = new ExtendedPaymentInfo($installmentsInfo);
}

if (!empty($fraudScreening)) {
$this->fraudScreeningData = new FraudScreeningData($fraudScreening);
}

foreach ($payIds as $payId) {
$this->paymentId[] = new PaymentId(
$payId->id,
$payId->type
);
}
}
}
31 changes: 30 additions & 1 deletion src/Amadeus/Client/Struct/Fop/PaymentModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@

namespace Amadeus\Client\Struct\Fop;

use Amadeus\Client\RequestOptions\Fop\MopInfo;
use Amadeus\Client\Struct\WsMessageUtility;

/**
* PaymentModule
*
* @package Amadeus\Client\Struct\Fop
* @author Dieter Devlieghere <dieter.devlieghere@benelux.amadeus.com>
*/
class PaymentModule
class PaymentModule extends WsMessageUtility
{
/**
* @var GroupUsage
Expand Down Expand Up @@ -74,4 +77,30 @@ public function __construct($fopType)
{
$this->groupUsage = new GroupUsage($fopType);
}

/**
* Load all paymentData
*
* @param MopInfo $options
*/
public function loadPaymentData(MopInfo $options)
{
if ($this->checkAnyNotEmpty(
$options->payMerchant,
$options->transactionDate,
$options->payments,
$options->installmentsInfo,
$options->fraudScreening,
$options->payIds
)) {
$this->paymentData = new PaymentData(
$options->payMerchant,
$options->transactionDate,
$options->payments,
$options->installmentsInfo,
$options->fraudScreening,
$options->payIds
);
}
}
}

0 comments on commit 34e8350

Please sign in to comment.