• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlocati / PayWay / 5212705470

pending completion
5212705470

push

github

mlocati
Initial version

1803 of 1803 new or added lines in 47 files covered. (100.0%)

1313 of 1803 relevant lines covered (72.82%)

1.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.6
/src/Init/Request/Serializer.php
1
<?php
2

3
namespace MLocati\PayWay\Init\Request;
4

5
use MLocati\PayWay\Init\Request;
6
use MLocati\PayWay\Service\SerializerTrait;
7

8
class Serializer
9
{
10
    use SerializerTrait;
11

12
    const NS_SOAPENVELOPE = 'http://schemas.xmlsoap.org/soap/envelope/';
13

14
    const NS_IGFS = 'http://services.api.web.cg.igfs.apps.netsw.it/';
15

16
    /**
17
     * @param string $signatureKey
18
     *
19
     * @throws \MLocati\PayWay\Exception\MissingRequiredField
20
     * @throws \MLocati\PayWay\Exception\FieldValueTooLong
21
     * @throws \MLocati\PayWay\Exception\FieldValueOutOfRange
22
     * @throws \MLocati\PayWay\Exception\InvalidFieldUrl
23
     * @throws \MLocati\PayWay\Exception\UnableToCreateSignature
24
     *
25
     * @return string
26
     */
27
    public function serialize(Request $request, $signatureKey)
28
    {
29
        $doc = $this->createDocument($request, $signatureKey);
3✔
30

31
        return $doc->saveXML();
3✔
32
    }
33

34
    /**
35
     * @param string $signatureKey
36
     *
37
     * @throws \MLocati\PayWay\Exception\UnableToCreateSignature
38
     *
39
     * @return \DOMDocument
40
     */
41
    public function createDocument(Request $request, $signatureKey)
42
    {
43
        $request->check();
4✔
44
        $init = $this->createSoapEnvelope('Init');
4✔
45
        $doc = $init->ownerDocument;
4✔
46
        $init->appendChild($xRequest = $doc->createElement('request'));
4✔
47
        $this->appendNode($xRequest, 'apiVersion', $request->getApiVersion());
4✔
48
        $this->appendNode($xRequest, 'tid', $request->getTID());
4✔
49
        $this->appendNode($xRequest, 'merIC', $request->getMerID());
4✔
50
        $this->appendNode($xRequest, 'payInstr', $request->getPayInstr());
4✔
51
        $this->appendNode($xRequest, 'reqTime', $this->serializeDateTime($request->getReqTime()));
4✔
52
        $this->appendNode($xRequest, 'signature', $request->getSignature($signatureKey));
4✔
53
        $this->appendNode($xRequest, 'shopID', $request->getShopID());
4✔
54
        $this->appendNode($xRequest, 'shopUserRef', $request->getShopUserRef());
4✔
55
        $this->appendNode($xRequest, 'shopUserName', $request->getShopUserName());
4✔
56
        $this->appendNode($xRequest, 'shopUserAccount', $request->getShopUserAccount());
4✔
57
        $this->appendNode($xRequest, 'shopUserMobilePhone', $request->getShopUserMobilePhone());
4✔
58
        $this->appendNode($xRequest, 'shopUserIMEI', $request->getShopUserIMEI());
4✔
59
        $this->appendNode($xRequest, 'trType', $request->getTrType());
4✔
60
        $this->appendNode($xRequest, 'amount', $this->serializeInteger($request->getAmountAsCents()));
4✔
61
        $this->appendNode($xRequest, 'currencyCode', $request->getCurrencyCode());
4✔
62
        $this->appendNode($xRequest, 'langID', $request->getLangID());
4✔
63
        $this->appendNode($xRequest, 'notifyURL', $request->getNotifyURL());
4✔
64
        $this->appendNode($xRequest, 'errorURL', $request->getErrorURL());
4✔
65
        $this->appendNode($xRequest, 'callbackURL', $request->getCallbackURL());
4✔
66
        $this->appendNode($xRequest, 'addInfo1', $request->getAddInfo1());
4✔
67
        $this->appendNode($xRequest, 'addInfo2', $request->getAddInfo2());
4✔
68
        $this->appendNode($xRequest, 'addInfo3', $request->getAddInfo3());
4✔
69
        $this->appendNode($xRequest, 'addInfo4', $request->getAddInfo4());
4✔
70
        $this->appendNode($xRequest, 'addInfo5', $request->getAddInfo5());
4✔
71
        $this->appendNode($xRequest, 'payInstrToken', $request->getPayInstrToken());
4✔
72
        $this->appendNode($xRequest, 'billingID', $request->getBillingID());
4✔
73
        $this->appendNode($xRequest, 'regenPayInstrToken', $this->serializeBoolean($request->isRegenPayInstrToken()));
4✔
74
        $this->appendNode($xRequest, 'keepOnRegenPayInstrToken', $this->serializeBoolean($request->isKeepOnRegenPayInstrToken()));
4✔
75
        $this->appendNode($xRequest, 'payInstrTokenExpire', $this->serializeDateTime($request->getPayInstrTokenExpire()));
4✔
76
        $this->appendNode($xRequest, 'payInstrTokenUsageLimit', $this->serializeInteger($request->getPayInstrTokenUsageLimit()));
4✔
77
        $this->appendNode($xRequest, 'payInstrTokenAlg', $request->getPayInstrTokenAlg());
4✔
78
        $this->appendNode($xRequest, 'accountName', $request->getAccountName());
4✔
79
        $level3Info = $request->getLevel3Info();
4✔
80
        $xLevel3Info = $doc->createElement('level3Info');
4✔
81
        $this->appendNode($xLevel3Info, 'invoiceNumber', $level3Info->getInvoiceNumber());
4✔
82
        $this->appendNode($xLevel3Info, 'senderPostalCode', $level3Info->getSenderPostalCode());
4✔
83
        $this->appendNode($xLevel3Info, 'senderCountryCode', $level3Info->getSenderCountryCode());
4✔
84
        $this->appendNode($xLevel3Info, 'destinationName', $level3Info->getDestinationName());
4✔
85
        $this->appendNode($xLevel3Info, 'destinationStreet', $level3Info->getDestinationStreet());
4✔
86
        $this->appendNode($xLevel3Info, 'destinationStreet2', $level3Info->getDestinationStreet2());
4✔
87
        $this->appendNode($xLevel3Info, 'destinationStreet3', $level3Info->getDestinationStreet3());
4✔
88
        $this->appendNode($xLevel3Info, 'destinationCity', $level3Info->getDestinationCity());
4✔
89
        $this->appendNode($xLevel3Info, 'destinationState', $level3Info->getDestinationState());
4✔
90
        $this->appendNode($xLevel3Info, 'destinationPostalCode', $level3Info->getDestinationPostalCode());
4✔
91
        $this->appendNode($xLevel3Info, 'destinationCountryCode', $level3Info->getDestinationCountryCode());
4✔
92
        $this->appendNode($xLevel3Info, 'destinationPhone', $level3Info->getDestinationPhone());
4✔
93
        $this->appendNode($xLevel3Info, 'destinationFax', $level3Info->getDestinationFax());
4✔
94
        $this->appendNode($xLevel3Info, 'destinationEmail', $level3Info->getDestinationEmail());
4✔
95
        $this->appendNode($xLevel3Info, 'destinationDate', $this->serializeDateTime($level3Info->getDestinationDate()));
4✔
96
        $this->appendNode($xLevel3Info, 'billingName', $level3Info->getBillingName());
4✔
97
        $this->appendNode($xLevel3Info, 'billingStreet', $level3Info->getBillingStreet());
4✔
98
        $this->appendNode($xLevel3Info, 'billingStreet2', $level3Info->getBillingStreet2());
4✔
99
        $this->appendNode($xLevel3Info, 'billingStreet3', $level3Info->getBillingStreet3());
4✔
100
        $this->appendNode($xLevel3Info, 'billingCity', $level3Info->getBillingCity());
4✔
101
        $this->appendNode($xLevel3Info, 'billingState', $level3Info->getBillingState());
4✔
102
        $this->appendNode($xLevel3Info, 'billingPostalCode', $level3Info->getBillingPostalCode());
4✔
103
        $this->appendNode($xLevel3Info, 'billingCountryCode', $level3Info->getBillingCountryCode());
4✔
104
        $this->appendNode($xLevel3Info, 'billingPhone', $level3Info->getBillingPhone());
4✔
105
        $this->appendNode($xLevel3Info, 'billingFax', $level3Info->getBillingFax());
4✔
106
        $this->appendNode($xLevel3Info, 'billingEmail', $level3Info->getBillingEmail());
4✔
107
        $this->appendNode($xLevel3Info, 'freightAmount', $this->serializeInteger($level3Info->getFreightAmountAsCents()));
4✔
108
        $this->appendNode($xLevel3Info, 'taxAmount', $this->serializeInteger($level3Info->getTaxAmountAsCents()));
4✔
109
        $this->appendNode($xLevel3Info, 'vat', $level3Info->getVat());
4✔
110
        $this->appendNode($xLevel3Info, 'note', $level3Info->getNote());
4✔
111
        foreach ($level3Info->getProducts() as $product) {
4✔
112
            $xProduct = $doc->createElement('product');
1✔
113
            $this->appendNode($xProduct, 'productCode', $product->getProductCode());
1✔
114
            $this->appendNode($xProduct, 'productDescription', $product->getProductDescription());
1✔
115
            $this->appendNode($xProduct, 'items', $this->serializeInteger($product->getItems()));
1✔
116
            $this->appendNode($xProduct, 'amount', $this->serializeInteger($product->getAmountAsCents()));
1✔
117
            $this->appendNode($xProduct, 'imgURL', $product->getImgURL());
1✔
118
            if ($xProduct->childNodes->count() > 0) {
1✔
119
                $xLevel3Info->appendChild($xProduct);
1✔
120
            }
121
        }
122
        if ($xLevel3Info->childNodes->count() > 0) {
4✔
123
            $xRequest->appendChild($xLevel3Info);
1✔
124
        }
125
        $mandateInfo = $request->getMandateInfo();
4✔
126
        $xMandateInfo = $doc->createElement('mandateInfo');
4✔
127
        $this->appendNode($xMandateInfo, 'mandateID', $mandateInfo->getMandateID());
4✔
128
        $this->appendNode($xMandateInfo, 'contractID', $mandateInfo->getContractID());
4✔
129
        $this->appendNode($xMandateInfo, 'sequenceType', $mandateInfo->getSequenceType());
4✔
130
        $this->appendNode($xMandateInfo, 'frequency', $mandateInfo->getFrequency());
4✔
131
        $this->appendNode($xMandateInfo, 'durationStartDate', $this->serializeDateTime($mandateInfo->getDurationStartDate()));
4✔
132
        $this->appendNode($xMandateInfo, 'durationEndDate', $this->serializeDateTime($mandateInfo->getDurationEndDate()));
4✔
133
        $this->appendNode($xMandateInfo, 'firstCollectionDate', $this->serializeDateTime($mandateInfo->getFirstCollectionDate()));
4✔
134
        $this->appendNode($xMandateInfo, 'finalCollectionDate', $this->serializeDateTime($mandateInfo->getFinalCollectionDate()));
4✔
135
        $this->appendNode($xMandateInfo, 'maxAmount', $this->serializeInteger($mandateInfo->getMaxAmountAsCents()));
4✔
136
        if ($xMandateInfo->childNodes->count() > 0) {
4✔
137
            $xRequest->appendChild($xMandateInfo);
×
138
        }
139
        $this->appendNode($xRequest, 'description', $request->getDescription());
4✔
140
        $this->appendNode($xRequest, 'paymentReason', $request->getPaymentReason());
4✔
141
        $this->appendNode($xRequest, 'freeText', $request->getFreeText());
4✔
142
        $this->appendNode($xRequest, 'topUpID', $request->getTopUpID());
4✔
143
        $this->appendNode($xRequest, 'firstTopUp', $this->serializeBoolean($request->isFirstTopUp()));
4✔
144
        $this->appendNode($xRequest, 'payInstrTokenAsTopUpID', $this->serializeBoolean($request->isPayInstrTokenAsTopUpID()));
4✔
145
        $this->appendNode($xRequest, 'recurrentIndicator', $this->serializeBoolean($request->isRecurrentIndicator()));
4✔
146
        $this->appendNode($xRequest, 'txIndicatorType', $request->getTxIndicatorType());
4✔
147
        $this->appendNode($xRequest, 'traceChainId', $request->getTraceChainId());
4✔
148
        $this->appendNode($xRequest, 'scaExemptionType', $request->getScaExemptionType());
4✔
149
        $this->appendNode($xRequest, 'validityExpire', $this->serializeDateTime($request->getValidityExpire()));
4✔
150
        $this->appendNode($xRequest, 'minExpireMonth', $this->serializeInteger($request->getMinExpireMonth()));
4✔
151
        $this->appendNode($xRequest, 'minExpireYear', $this->serializeInteger($request->getMinExpireYear()));
4✔
152
        foreach ($request->getTermInfos() as $termInfo) {
4✔
153
            $xTermInfo = $doc->createElement('termInfo');
×
154
            $this->appendNode($xTermInfo, 'tid', $termInfo->getTid());
×
155
            $this->appendNode($xTermInfo, 'payInstrToken', $termInfo->getPayInstrToken());
×
156
            $this->appendNode($xTermInfo, 'billingID', $termInfo->getBillingID());
×
157
            if ($xTermInfo->childNodes->count() > 0) {
×
158
                $xRequest->appendChild($xTermInfo);
×
159
            }
160
        }
161
        foreach ($request->getPayInstrAddData() as $key => $value) {
4✔
162
            $xPayInstrAddData = $this->appendNode($xRequest, 'payInstrAddData', '', true);
×
163
            $this->appendNode($xPayInstrAddData, 'key', (string) $key, true);
×
164
            $this->appendNode($xPayInstrAddData, 'value', $value, true);
×
165
        }
166

167
        return $doc;
4✔
168
    }
169
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc