<?php
namespace App\Amadeus\StructureParser\Types; class FormOfPayment { public $components = []; public function insert(\App\Amadeus\StructureParser\Types\FormOfPaymentComponent $component) { $this->components[] = $component; } public function load_PAYMNT($PAYMNT) { if($PAYMNT['new']){ foreach ($PAYMNT['new'] as $PAY) { if ($PAY['type']=='government') { $p = new \App\Amadeus\StructureParser\Types\FormOfPaymentComponentGovernment(); $p->type = $PAY['type']; $p->accountCode = $PAY['accountCode']; $p->travelOrderNo = $PAY['travelOrderNo']; $p->travelOrderDateStr= $PAY['travelOrderDateStr']; } else { $p = new \App\Amadeus\StructureParser\Types\FormOfPaymentComponentCC(); $p->type = $PAY['type']; $p->amount = $PAY['amount']; $p->currency = $PAY['currency']; $p->companyIndicator = $PAY['companyIndicator']; $p->number = $PAY['number']; $p->currency = $PAY['currency']; $p->approvalCode = $PAY['approvalCode']; $p->invoiceNo = $PAY['invoiceNo']; $p->setCcExpiryDate($PAY['expDate']); } $this->insert($p); } } } public function getShortNotation() { $return = []; foreach($this->components as $comp){ $return[] = $comp->type; } sort($return); $return = array_unique($return); return implode("+", $return); } public function isPaidWith($paymentType) { foreach($this->components as $comp){ if($comp->type==$paymentType){ return true; } } return false; } public function getPaymentByType($paymentType, $index=null) { $return = []; foreach($this->components as $comp){ if($comp->type==$paymentType){ $return[] = $comp; } } if($index===null){ return $return; } return $return[$index]; } public function hasData() { return (bool)$this->components; } } 