Skip to content
Open
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
31 changes: 31 additions & 0 deletions src/Model/Request/SecciRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/*
* Copyright (c) Ratepay GmbH
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace RatePAY\Model\Request;

class SecciRequest extends AbstractRequest
{
use TraitRequestContent;

/**
* Request rule set.
*
* @return bool
*/
public function rule()
{
if (key_exists('value', $this->getHead()->admittedFields['TransactionId'])) {
$this->setErrorMsg('Secci Request does not allow transaction id');

return false;
}

return true;
}
}
7 changes: 7 additions & 0 deletions src/Model/Request/SubModel/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use RatePAY\Model\Request\SubModel\Content\InstallmentCalculation;
use RatePAY\Model\Request\SubModel\Content\Invoicing;
use RatePAY\Model\Request\SubModel\Content\Payment;
use RatePAY\Model\Request\SubModel\Content\Secci;
use RatePAY\Model\Request\SubModel\Content\ShoppingBasket;

/**
Expand All @@ -29,6 +30,8 @@
* @method InstallmentCalculation getInstallmentCalculation()
* @method $this setAdditional(Additional $additional)
* @method Additional getAdditional()
* @method $this setSecci(Secci $secci)
* @method Secci getSecci()
*/
class Content extends AbstractModel
{
Expand Down Expand Up @@ -75,5 +78,9 @@ class Content extends AbstractModel
'mandatory' => false,
'instanceOf' => 'Content\\Additional',
],
'Secci' => [
'mandatory' => false,
'instanceOf' => 'Content\\Secci',
],
];
}
20 changes: 10 additions & 10 deletions src/Model/Request/SubModel/Content/Payment/InstallmentDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
use RatePAY\Model\Request\SubModel\AbstractModel;

/**
* @method $this setInstallmentNumber(string $installmentNumber)
* @method string getInstallmentNumber()
* @method $this setInstallmentAmount(float $installmentAmount)
* @method float getInstallmentAmount()
* @method $this setLastInstallmentAmount(InstallmentDetails $lastInstallmentAmount)
* @method InstallmentDetails getLastInstallmentAmount()
* @method $this setInterestRate(string $interestRate)
* @method string getInterestRate()
* @method $this setPaymentFirstday(string $paymentFirstday)
* @method string getPaymentFirstday()
* @method $this setInstallmentNumber(string $installmentNumber)
* @method string getInstallmentNumber()
* @method $this setInstallmentAmount(float $installmentAmount)
* @method float getInstallmentAmount()
* @method $this setLastInstallmentAmount(float $lastInstallmentAmount)
* @method float getLastInstallmentAmount()
* @method $this setInterestRate(string $interestRate)
* @method string getInterestRate()
* @method $this setPaymentFirstday(string $paymentFirstday)
* @method string getPaymentFirstday()
*/
class InstallmentDetails extends AbstractModel
{
Expand Down
149 changes: 149 additions & 0 deletions src/Model/Request/SubModel/Content/Secci.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?php

/*
* Copyright (c) Ratepay GmbH
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace RatePAY\Model\Request\SubModel\Content;

use RatePAY\Model\Request\SubModel\AbstractModel;

/**
* @method string getDeliveryMethod()
* @method string getEmail()
* @method string getAction()
* @method string getLanguage()
* @method string getCountryCode()
*/
class Secci extends AbstractModel
{
/**
* List of admitted fields.
* Each field is public accessible by certain getter and setter.
* E.g:
* Set delivery method value by using setDeliveryMethod(var). Get delivery method by using getDeliveryMethod(). (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
* uppercase = change value to uppercase
*
* @var array
*/
public $admittedFields = [
'DeliveryMethod' => [
'mandatory' => true,
'uppercase' => true,
],
'Email' => [
'mandatoryByRule' => true,
],
'Action' => [
'mandatoryByRule' => true,
'uppercase' => true,
],
'Language' => [
'mandatory' => false,
'uppercase' => true,
],
'CountryCode' => [
'mandatory' => false,
'uppercase' => true,
],
];

/**
* Secci rule : if DeliveryMethod is EMAIL, Email parameter must be given. if DeliveryMethod is PDF, Action parameter must be either PRINT or DOWNLOAD.
*
* @return bool
*/
protected function rule()
{
if ('EMAIL' == $this->admittedFields['DeliveryMethod']['value'] &&
(!key_exists('value', $this->admittedFields['Email']))
) {
$this->setErrorMsg('email details missing');

return false;
}

if ('PDF' == $this->admittedFields['DeliveryMethod']['value'] &&
(!key_exists('value', $this->admittedFields['Action']) || !in_array(strtoupper($this->admittedFields['Action']['value']), ['PRINT', 'DOWNLOAD']))
) {
$this->setErrorMsg('action details missing or incorrect');

return false;
}

return true;
}

/**
* @param string $deliveryMethod
*
* @return self
*
* @throws \RatePAY\Exception\ModelException
*/
public function setDeliveryMethod($deliveryMethod)
{
return $this->__set('DeliveryMethod', $deliveryMethod);
}

/**
* @param string $email
*
* @return self
*
* @throws \RatePAY\Exception\ModelException
*/
public function setEmail($email)
{
return $this->__set('Email', $email);
}

/**
* @param string $action
*
* @return self
*
* @throws \RatePAY\Exception\ModelException
*/
public function setAction($action)
{
return $this->__set('Action', $action);
}

/**
* @param string $language
*
* @return self
*
* @throws \RatePAY\Exception\ModelException
*/
public function setLanguage($language)
{
return $this->__set('Language', $language);
}

/**
* @param string $countryCode
*
* @return self
*
* @throws \RatePAY\Exception\ModelException
*/
public function setCountryCode($countryCode)
{
return $this->__set('CountryCode', $countryCode);
}
}
5 changes: 5 additions & 0 deletions src/Model/Request/SubModel/Head.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* @method string getOperation()
* @method $this setSubtype(string $subType)
* @method string getSubtype()
* @method $this setAttestationToken(string $attestationToken)
* @method string getAttestationToken()
* @method $this setCredential(Credential $credential)
* @method Credential getCredential()
* @method $this setExternal(External $external)
Expand Down Expand Up @@ -83,6 +85,9 @@ class Head extends AbstractModel
'mandatory' => true,
'instanceOf' => 'Head\\Meta',
],
'AttestationToken' => [
'mandatory' => false,
],
];

/**
Expand Down
117 changes: 117 additions & 0 deletions src/Model/Response/SecciRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php

/*
* Copyright (c) Ratepay GmbH
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace RatePAY\Model\Response;

class SecciRequest extends AbstractResponse
{
/**
* Validates response.
*/
public function validateResponse()
{
if ($this->getStatusCode() == 'OK' && $this->getResultCode() == 504) {
if (!isset($this->getResponse()->content->{'secci-result'})) {
return;
}
$secciResult = $this->getResponse()->content->{'secci-result'};

$attestationToken = $this->getNodeValue($secciResult, 'attestation-token');
$documentId = $this->getNodeValue($secciResult, 'document-id');
if ($attestationToken === null || $documentId === null) {
return;
}

$document = null;
$contentType = null;
if (isset($secciResult->{'document'})) {
$document = $this->getNodeValue($secciResult, 'document');
$contentType = $this->getNodeValue($secciResult, 'content-type');
// Document is base64 encoded and must be decodable
if ($document === null || $contentType === null || base64_decode($document, true) === false) {
return;
}
}

$this->setResult(['attestationToken' => $attestationToken]);
$this->setResult(['documentId' => $documentId]);
if ($document !== null) {
$this->setResult(['document' => $document]);
$this->setResult(['contentType' => $contentType]);
}
$this->setSuccessful();
}
}

/**
* Returns the trimmed value of a child node or null if the node is missing or empty.
*
* @param \SimpleXMLElement $parent
* @param string $name
*
* @return string|null
*/
private function getNodeValue($parent, $name)
{
if (!isset($parent->{$name})) {
return null;
}

$value = trim((string) $parent->{$name});

return ($value !== '') ? $value : null;
}

/**
* Returns attestation token.
*
* @return string|null
*/
public function getAttestationToken()
{
return (key_exists('attestationToken', $this->result)) ? $this->result['attestationToken'] : null;
}

/**
* Returns document id.
*
* @return string|null
*/
public function getDocumentId()
{
return (key_exists('documentId', $this->result)) ? $this->result['documentId'] : null;
}

/**
* Returns document.
*
* @return string|null
*/
public function getDocument()
{
// Document variable comes as base64 encoded string!
if (!key_exists('document', $this->result)) {
return null;
}

$document = base64_decode($this->result['document'], true);

return ($document !== false) ? $document : null;
}

/**
* Returns content type of the document.
*
* @return string|null
*/
public function getContentType()
{
return (key_exists('contentType', $this->result)) ? $this->result['contentType'] : null;
}
}
2 changes: 2 additions & 0 deletions src/Service/ModelMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ModelMapper
'PaymentChange' => 'PaymentChange',
'PaymentConfirm' => 'PaymentConfirm',
'ProfileRequest' => 'ProfileRequest',
'SecciRequest' => 'SecciRequest',
];

private static $subModelNamePathMapping = [
Expand Down Expand Up @@ -57,6 +58,7 @@ class ModelMapper
'Payment' => 'Content\\Payment',
'InstallmentDetails' => 'Content\\Payment\\InstallmentDetails',
'Invoicing' => 'Content\\Invoicing',
'Secci' => 'Content\\Secci',
];

public static function getFullPathRequestModel($requestedModel)
Expand Down
Loading
Loading