Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 63 additions & 9 deletions src/Model/Request/SubModel/Head/External/Tracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
namespace RatePAY\Model\Request\SubModel\Head\External;

use RatePAY\Model\Request\SubModel\AbstractModel;
use RatePAY\Model\Request\SubModel\Head\External\Tracking\Id;

/**
* @method $this setId(string $id)
* @method string getId()
* @method $this setProvider(string $provider)
* @method string getProvider()
* @method Id addId(Id $id)
*/
class Tracking extends AbstractModel
{
Expand All @@ -43,12 +41,68 @@ class Tracking extends AbstractModel
*/
public $admittedFields = [
'Id' => [
'mandatory' => true,
'multiple' => true,
'instanceOf' => 'Head\\External\\Tracking\\Id',
],
'Provider' => [
'mandatory' => false,
'cdata' => true,
],
'Provider' => [
'mandatory' => false,
'isAttributeTo' => 'Id',
],
];

/**
* @return Id[]
*/
public function getIds()
{
return $this->__get('Id');
}

/**
* {@inheritDoc}
*/
public function commonSetter($field, $arguments)
{
if ($field === 'Id' && $arguments[0] instanceof Tracking\Id === false) {
return $this->setId($arguments[0]);
}
if ($field === 'Provider') {
return $this->setProvider($arguments[0]);
}

return parent::commonSetter($field, $arguments);
}

/**
* @param $id
*
* @return Tracking
*
* @deprecated please use the SubModel "\RatePAY\Model\Request\SubModel\Head\External\Tracking\Id" to set the TrackingId
*/
public function setId($id)
{
$this->addId((new Id())->setId($id));

return $this;
}

/**
* @param $provider
*
* @return Tracking
*
* @deprecated please use the SubModel "\RatePAY\Model\Request\SubModel\Head\External\Tracking\Id" to set the TrackingId
*/
public function setProvider($provider)
{
$ids = $this->getIds();
if (!isset($ids[0]) || $ids[0] === null || count($ids) === 0) {
throw new \RuntimeException('please set the Id first');
}
$id = $ids[count($ids) - 1];
$id->setProvider($provider);

return $this;
}
}
63 changes: 63 additions & 0 deletions src/Model/Request/SubModel/Head/External/Tracking/Id.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/*
* Ratepay PHP-Library
*
* This document contains trade secret data which are the property of
* Ratepay GmbH, Berlin, Germany. Information contained herein must not be used,
* copied or disclosed in whole or part unless permitted in writing by Ratepay GmbH.
* All rights reserved by Ratepay GmbH.
*
* Copyright (c) 2019 Ratepay GmbH / Berlin / Germany
*/

namespace RatePAY\Model\Request\SubModel\Head\External\Tracking;

use RatePAY\Model\Request\SubModel\AbstractModel;

/**
* @method string getId()
* @method $this setProvider(string $provider)
* @method string getProvider()
*/
class Id extends AbstractModel
{
/**
* List of admitted fields.
* Each field is public accessible by certain getter and setter.
* E.g:
* Set id by using setId(var). Get id by using getId(). (Please consider the camel case).
*
* Settings:
* mandatory = field is mandatory (or optional)
* mandatoryByRule = field is mandatory if rule is passed
* optionalByRule = field will only returned if rule is passed
* default = default value if no different value is set
* isAttribute = field is xml attribute to parent object
* isAttributeTo = field is xml attribute to field (in value)
* instanceOf = value has to be an instance of class (in value)
* cdata = value will be wrapped in CDATA tag
*
* @var array
*/
public $admittedFields = [
'Description' => [ // This field will be converted to the inner xml data. this will be identified by the field name "description"
'mandatory' => false,
'cdata' => true,
],
'Provider' => [
'mandatory' => false,
'isAttribute' => true,
],
];

/**
* @param string $id
*
* @return Id
*/
public function setId($id)
{
return $this->__set('Description', $id);
}
}