GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

EbayEnterprise_GiftCard_Model_Giftcard::getApi()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 11
rs 9.4285
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
/**
3
 * Copyright (c) 2013-2014 eBay Enterprise, Inc.
4
 *
5
 * NOTICE OF LICENSE
6
 *
7
 * This source file is subject to the Open Software License (OSL 3.0)
8
 * that is bundled with this package in the file LICENSE.md.
9
 * It is also available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * @copyright   Copyright (c) 2013-2014 eBay Enterprise, Inc. (http://www.ebayenterprise.com/)
13
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
14
 */
15
16
use eBayEnterprise\RetailOrderManagement\Api\IBidirectionalApi;
17
use eBayEnterprise\RetailOrderManagement\Api\Exception\NetworkError;
18
use eBayEnterprise\RetailOrderManagement\Api\Exception\UnsupportedHttpAction;
19
use eBayEnterprise\RetailOrderManagement\Api\Exception\UnsupportedOperation;
20
use eBayEnterprise\RetailOrderManagement\Payload;
21
use eBayEnterprise\RetailOrderManagement\Payload\Exception\InvalidPayload;
22
use Psr\Log\LoggerInterface;
23
use Psr\Log\NullLogger;
24
25
/**
26
 * Model representing a gift card that has been applied to an order.
27
 */
28
class EbayEnterprise_GiftCard_Model_Giftcard implements EbayEnterprise_GiftCard_Model_IGiftcard
29
{
30
    const BALANCE_REQUST_ID_PREFIX = 'GCB-';
31
    const REDEEM_REQUST_ID_PREFIX = 'GCR-';
32
    const VOID_REQUST_ID_PREFIX = 'GCV-';
33
    const REQUEST_FAILED_MESSAGE = 'EbayEnterprise_GiftCard_Request_Failed';
34
    const BALANCE_REQUEST_FAILED_MESSAGE = 'EbayEnterprise_GiftCard_Request_Failed_Balance';
35
    const REDEEM_REQUEST_FAILED_MESSAGE = 'EbayEnterprise_GiftCard_Request_Failed_Redeem';
36
    const VOID_REQUEST_FAILED_MESSAGE = 'EbayEnterprise_GiftCard_Request_Failed_Void';
37
38
    /**
39
     * Externalization of gift card data - number, pin, tender type, etc. When
40
     * persisting gift card data in the session, only the memo object will be
41
     * put into the session and gift card models will be restored or reconstructed
42
     * using memo data from the session.
43
     *
44
     * @var EbayEnterprise_GiftCard_Model_Giftcard_Memo
45
     */
46
    protected $memo;
47
    /** @var EbayEnterprise_GiftCard_Helper_Data **/
48
    protected $helper;
49
    /** @var EbayEnterprise_Eb2cCore_Helper_Data **/
50
    protected $coreHelper;
51
    /** @var EbayEnterprise_MageLog_Helper_Data **/
52
    protected $logger;
53
    /** @var LoggerInterface **/
54
    protected $apiLogger;
55
    /** @var EbayEnterprise_MageLog_Helper_Context */
56
    protected $context;
57
    /** @var EbayEnterprise_GiftCard_Model_Mask */
58
    protected $mask;
59
    /** @var string */
60
    protected $tenderType;
61
    /** @var EbayEnterprise_GiftCard_Helper_Tendertype */
62
    protected $tenderTypeHelper;
63
    /** @var EbayEnterprise_Eb2cCore_Model_Config_Registry */
64
    protected $config;
65
66
    /**
67
     * @param array $initParams May contain:
68
     *                          - 'helper' => EbayEnterprise_GiftCard_Helper_Data
69
     *                          - 'core_helper' => EbayEnterprise_Eb2cCore_Helper_Data
70
     *                          - 'logger' => EbayEnterprise_MageLog_Helper_Data
71
     *                          - 'context' => EbayEnterprise_MageLog_Helper_Context
72
     *                          - 'api_logger' => LoggerInterface
73
     *                          - 'mask' => EbayEnterprise_GiftCard_Model_Mask
74
     *                          - 'config' => EbayEnterprise_Eb2cCore_Model_Config_Registry
75
     */
76 View Code Duplication
    public function __construct(array $initParams = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
    {
78
        list(
79
            $this->tenderTypeHelper,
80
            $this->helper,
81
            $this->coreHelper,
82
            $this->logger,
83
            $this->context,
84
            $this->apiLogger,
85
            $this->mask,
86
            $this->memo,
87
            $this->config
88
        ) = $this->checkTypes(
89
            $this->nullCoalesce($initParams, 'tender_type_helper', Mage::helper('ebayenterprise_giftcard/tendertype')),
90
            $this->nullCoalesce($initParams, 'helper', Mage::helper('ebayenterprise_giftcard')),
91
            $this->nullCoalesce($initParams, 'core_helper', Mage::helper('eb2ccore')),
92
            $this->nullCoalesce($initParams, 'logger', Mage::helper('ebayenterprise_magelog')),
93
            $this->nullCoalesce($initParams, 'context', Mage::helper('ebayenterprise_magelog/context')),
94
            $this->nullCoalesce($initParams, 'api_logger', new NullLogger),
95
            $this->nullCoalesce($initParams, 'mask', Mage::getModel('ebayenterprise_giftcard/mask')),
96
            $this->nullCoalesce($initParams, 'memo', Mage::getModel('ebayenterprise_giftcard/giftcard_memo')),
97
            $this->nullCoalesce($initParams, 'config', Mage::helper('ebayenterprise_giftcard')->getConfigModel())
98
        );
99
    }
100
101
    /**
102
     * Type checks for self::__construct $initParams.
103
     * @param  EbayEnterprise_Giftcard_Helper_Tendertype
104
     * @param  EbayEnterprise_Giftcard_Helper_Data
105
     * @param  EbayEnterprise_Eb2cCore_Helper_Data
106
     * @param  EbayEnterprise_MageLog_Helper_Data
107
     * @param  EbayEnterprise_MageLog_Helper_Context
108
     * @param  LoggerInterface
109
     * @param  EbayEnterprise_GiftCard_Model_Mask
110
     * @param  EbayEnterprise_GiftCard_Model_Giftcard_Memo
111
     * @param  EbayEnterprise_Eb2cCore_Model_Config_Registry
112
     * @return mixed[]
113
     */
114
    protected function checkTypes(
0 ignored issues
show
Unused Code introduced by
The method parameter $tenderTypeHelper is never used
Loading history...
Unused Code introduced by
The method parameter $helper is never used
Loading history...
Unused Code introduced by
The method parameter $coreHelper is never used
Loading history...
Unused Code introduced by
The method parameter $logger is never used
Loading history...
Unused Code introduced by
The method parameter $context is never used
Loading history...
Unused Code introduced by
The method parameter $apiLogger is never used
Loading history...
Unused Code introduced by
The method parameter $mask is never used
Loading history...
Unused Code introduced by
The method parameter $memo is never used
Loading history...
Unused Code introduced by
The method parameter $config is never used
Loading history...
115
        EbayEnterprise_Giftcard_Helper_Tendertype $tenderTypeHelper,
0 ignored issues
show
Unused Code introduced by
The parameter $tenderTypeHelper is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
116
        EbayEnterprise_Giftcard_Helper_Data $helper,
0 ignored issues
show
Unused Code introduced by
The parameter $helper is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
117
        EbayEnterprise_Eb2cCore_Helper_Data $coreHelper,
0 ignored issues
show
Unused Code introduced by
The parameter $coreHelper is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
118
        EbayEnterprise_MageLog_Helper_Data $logger,
0 ignored issues
show
Unused Code introduced by
The parameter $logger is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
119
        EbayEnterprise_MageLog_Helper_Context $context,
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
120
        LoggerInterface $apiLogger,
0 ignored issues
show
Unused Code introduced by
The parameter $apiLogger is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
121
        EbayEnterprise_GiftCard_Model_Mask $mask,
0 ignored issues
show
Unused Code introduced by
The parameter $mask is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
122
        EbayEnterprise_GiftCard_Model_Giftcard_Memo $memo,
0 ignored issues
show
Unused Code introduced by
The parameter $memo is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
123
        EbayEnterprise_Eb2cCore_Model_Config_Registry $config
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
124
    ) {
125
        return func_get_args();
126
    }
127
128
    /**
129
     * Return the value at field in array if it exists. Otherwise, use the
130
     * default value.
131
     * @param  array      $arr
132
     * @param  string|int $field Valid array key
133
     * @param  mixed      $default
134
     * @return mixed
135
     */
136
    protected function nullCoalesce(array $arr, $field, $default)
137
    {
138
        return isset($arr[$field]) ? $arr[$field] : $default;
139
    }
140
141
    public function setOrderId($orderId)
142
    {
143
        $this->memo->setOrderId($orderId);
144
        return $this;
145
    }
146
147
    public function getOrderId()
148
    {
149
        return $this->memo->getOrderId();
150
    }
151
152
    /**
153
     * Set the card number of the gift card. If the card number is changed after
154
     * receiving a tokenized card number, the tokenized card number will be
155
     * cleared out as it is not expected to be relevant to the new card number.
156
     * @param string $cardNumber
157
     * @return self
158
     */
159
    public function setCardNumber($cardNumber)
160
    {
161
        // Tokenized number is no longer valid after changing the non-tokenized number.
162
        if ($this->memo->getCardNumber() !== $cardNumber) {
163
            $this->memo->setTokenizedCardNumber(null);
164
        }
165
        $this->memo->setCardNumber($cardNumber);
166
        return $this;
167
    }
168
169
    public function getCardNumber()
170
    {
171
        return $this->memo->getCardNumber();
172
    }
173
174
    /**
175
     * get the tender type for the giftcard. perform a lookup
176
     * using the tendertype service if not yet set.
177
     *
178
     * @see EbayEnterprise_GiftCard_Helper_Tendertype::lookupTenderType
179
     * @return string
180
     */
181
    public function getTenderType()
182
    {
183
        if (!$this->memo->getTenderType()) {
184
            $this->memo->setTenderType($this->tenderTypeHelper->lookupTenderType(
185
                $this->getCardNumber(),
186
                $this->getBalanceCurrencyCode(),
187
                $this->getPanIsToken()
188
            ));
189
        }
190
        return $this->memo->getTenderType();
191
    }
192
193
    public function setTokenizedCardNumber($tokenizedCardNumber)
194
    {
195
        $this->memo->setTokenizedCardNumber($tokenizedCardNumber);
196
        return $this;
197
    }
198
199
    public function getTokenizedCardNumber()
200
    {
201
        return $this->memo->getTokenizedCardNumber();
202
    }
203
204
    public function setPin($pin)
205
    {
206
        $this->memo->setPin($pin);
207
        return $this;
208
    }
209
210
    public function getPin()
211
    {
212
        return $this->memo->getPin();
213
    }
214
215
    public function setPanIsToken($isToken)
216
    {
217
        $this->memo->setPanIsToken($isToken);
218
        return $this;
219
    }
220
221
    public function getPanIsToken()
222
    {
223
        return $this->memo->getPanIsToken();
224
    }
225
226
    public function setBalanceRequestId($requestId)
227
    {
228
        $this->memo->setBalanceRequestId($requestId);
229
        return $this;
230
    }
231
232
    public function getBalanceRequestId()
233
    {
234
        return $this->memo->getBalanceRequestId();
235
    }
236
237
    public function setRedeemRequestId($requestId)
238
    {
239
        $this->memo->setRedeemRequestId($requestId);
240
        return $this;
241
    }
242
243
    public function getRedeemRequestId()
244
    {
245
        return $this->memo->getRedeemRequestId();
246
    }
247
248
    public function setRedeemVoidRequestId($requestId)
249
    {
250
        $this->memo->setRedeemVoidRequestId($requestId);
251
        return $this;
252
    }
253
254
    public function getRedeemVoidRequestId()
255
    {
256
        return $this->memo->getRedeemVoidRequestId();
257
    }
258
259
    public function setAmountToRedeem($amount)
260
    {
261
        $this->memo->setAmountToRedeem($amount);
262
        return $this;
263
    }
264
265
    public function getAmountToRedeem()
266
    {
267
        return $this->memo->getAmountToRedeem();
268
    }
269
270
    public function setAmountRedeemed($amount)
271
    {
272
        $this->memo->setAmountRedeemed($amount);
273
        return $this;
274
    }
275
276
    public function getAmountRedeemed()
277
    {
278
        return $this->memo->getAmountRedeemed();
279
    }
280
281
    public function setRedeemCurrencyCode($currencyCode)
282
    {
283
        $this->memo->setRedeemCurrencyCode($currencyCode);
284
        return $this;
285
    }
286
287
    public function getRedeemCurrencyCode()
288
    {
289
        // if no currency code has been set, default to the current store's currency code
290
        if (is_null($this->memo->getRedeemCurrencyCode())) {
291
            $this->memo->setRedeemCurrencyCode(Mage::app()->getStore()->getCurrentCurrencyCode());
292
        }
293
        return $this->memo->getRedeemCurrencyCode();
294
    }
295
296
    public function setBalanceAmount($amount)
297
    {
298
        $this->memo->setBalanceAmount($amount);
299
        return $this;
300
    }
301
302
    public function getBalanceAmount()
303
    {
304
        return $this->memo->getBalanceAmount();
305
    }
306
307
    public function setBalanceCurrencyCode($currencyCode)
308
    {
309
        $this->memo->setBalanceCurrencyCode($currencyCode);
310
        return $this;
311
    }
312
313
    public function getBalanceCurrencyCode()
314
    {
315
        // if no currency code has been set, default to the current store's currency code
316
        if (is_null($this->memo->getBalanceCurrencyCode())) {
317
            $this->memo->setBalanceCurrencyCode(Mage::app()->getStore()->getCurrentCurrencyCode());
318
        }
319
        return $this->memo->getBalanceCurrencyCode();
320
    }
321
322
    public function setIsRedeemed($isRedeemed)
323
    {
324
        $this->memo->setIsRedeemed($isRedeemed);
325
        return $this;
326
    }
327
328
    public function getIsRedeemed()
329
    {
330
        return $this->memo->getIsRedeemed();
331
    }
332
333
    public function setRedeemedAt(DateTime $redeemedAt)
334
    {
335
        $this->memo->setRedeemedAt($redeemedAt);
336
        return $this;
337
    }
338
339
    public function getRedeemedAt()
340
    {
341
        return $this->memo->getRedeemedAt();
342
    }
343
344
    /**
345
     * Restore data from an external memo to the gift card.
346
     *
347
     * Intended as a means of restoring state to the gift card from data
348
     * in the session or otherwise externalized.
349
     *
350
     * @param EbayEnterprise_GiftCard_Model_Giftcard_Memo
351
     * @return self
352
     */
353
    public function restoreFromMemo(EbayEnterprise_GiftCard_Model_Giftcard_Memo $memo)
354
    {
355
        $this->memo = $memo;
356
        return $this;
357
    }
358
359
    /**
360
     * Get the memo used to encapsulate gift card data for storage.
361
     *
362
     * @return EbayEnterprise_GiftCard_Model_Giftcard_Memo
363
     */
364
    public function getMemo()
365
    {
366
        return $this->memo;
367
    }
368
369
    /**
370
     * Log the different requests consistently.
371
     *
372
     * @param string $type 'balance', 'redeem', 'void'
373
     * @param string $body the serialized xml body
0 ignored issues
show
Bug introduced by
There is no parameter named $body. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
374
     * @param string $direction 'request' or 'response'
375
     */
376
    protected function logApiCall($type, $direction)
377
    {
378
        $logData = ['type' => $type, 'direction' => $direction];
379
        $logMessage = 'Processing gift card {type} {direction}.';
380
        $this->logger->info($logMessage, $this->context->getMetaData(__CLASS__, $logData));
381
    }
382
383
384 View Code Duplication
    public function checkBalance()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
385
    {
386
        $api = $this->getApi($this->config->apiOperationBalance);
0 ignored issues
show
Documentation introduced by
The property apiOperationBalance does not exist on object<EbayEnterprise_Eb..._Model_Config_Registry>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
387
        $this->prepareApiForBalanceCheck($api);
388
        $this->logApiCall('balance', 'request');
389
        $this->logStoredValuePayload($api, true, 'Sending StoredValueBalanceRequest.');
390
        $this->sendRequest($api);
391
        $this->logApiCall('balance', 'response');
392
        $this->logStoredValuePayload($api, false, 'Received StoredValueBalanceReply response.');
393
        $this->handleBalanceResponse($api);
394
        return $this;
395
    }
396
397 View Code Duplication
    public function redeem()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
398
    {
399
        $api = $this->getApi($this->config->apiOperationRedeem);
0 ignored issues
show
Documentation introduced by
The property apiOperationRedeem does not exist on object<EbayEnterprise_Eb..._Model_Config_Registry>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
400
        $this->prepareApiForRedeem($api);
401
        $this->logApiCall('redeem', 'request');
402
        $this->logStoredValuePayload($api, true, 'Sending StoredValueRedeemRequest.');
403
        $this->sendRequest($api);
404
        $this->logApiCall('redeem', 'response');
405
        $this->logStoredValuePayload($api, false, 'Received StoredValueRedeemReply response.');
406
        $this->handleRedeemResponse($api);
407
        return $this;
408
    }
409
410 View Code Duplication
    public function void()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
411
    {
412
        $api = $this->getApi($this->config->apiOperationVoid);
0 ignored issues
show
Documentation introduced by
The property apiOperationVoid does not exist on object<EbayEnterprise_Eb..._Model_Config_Registry>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
413
        $this->prepareApiForVoid($api);
414
        $this->logApiCall('void', 'request');
415
        $this->logStoredValuePayload($api, true, 'Sending StoredValueRedeemVoidRequest.');
416
        $this->sendRequest($api);
417
        $this->logApiCall('void', 'response');
418
        $this->logStoredValuePayload($api, false, 'Received StoredValueRedeemVoidReply response.');
419
        $this->handleVoidResponse($api);
420
        return $this;
421
    }
422
423
    /**
424
     * Get a new SDK Api instance for an API call.
425
     * @param  string $operation
426
     * @return IBidirectionalApi
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use Api\HttpApi.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
427
     */
428
    protected function getApi($operation)
429
    {
430
        return $this->coreHelper->getSdkApi(
431
            $this->config->apiService,
0 ignored issues
show
Documentation introduced by
The property apiService does not exist on object<EbayEnterprise_Eb..._Model_Config_Registry>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
432
            $operation,
433
            [$this->getTenderType()],
434
            // Use a special logger just for the SDK logging, prevents
435
            // the SDK from logging any PII.
436
            $this->apiLogger
437
        );
438
    }
439
440
    /**
441
     * Prepare an API instance for a balance request - fill out and set the
442
     * request payload with gift card data.
443
     * @param  IBidirectionalApi $api
444
     * @return self
445
     */
446
    protected function prepareApiForBalanceCheck(IBidirectionalApi $api)
447
    {
448
        $this->setBalanceRequestId($this->coreHelper->generateRequestId(self::BALANCE_REQUST_ID_PREFIX));
449
        $payload = $api->getRequestBody();
450
        $payload
451
            ->setRequestId($this->getBalanceRequestId())
452
            ->setPin($this->getPin())
453
            ->setCurrencyCode($this->getBalanceCurrencyCode());
454
        $this->setPayloadAccountUniqueId($payload);
0 ignored issues
show
Documentation introduced by
$payload is of type object<eBayEnterprise\Re...ement\Payload\IPayload>, but the function expects a object<eBayEnterprise\Re...PaymentAccountUniqueId>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
455
        $api->setRequestBody($payload);
456
        return $this;
457
    }
458
459
    /**
460
     * Prepare an API instance for a balance request - fill out and set the
461
     * request payload with gift card data.
462
     * @param  IBidirectionalApi $api
463
     * @return self
464
     */
465 View Code Duplication
    protected function prepareApiForRedeem(IBidirectionalApi $api)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
466
    {
467
        $this->setRedeemRequestId($this->coreHelper->generateRequestId(self::REDEEM_REQUST_ID_PREFIX));
468
        $payload = $api->getRequestBody();
469
        $payload
470
            ->setRequestId($this->getRedeemRequestId())
471
            ->setPin($this->getPin())
472
            ->setAmount($this->getAmountToRedeem())
473
            ->setCurrencyCode($this->getRedeemCurrencyCode());
474
        $this->setPayloadPaymentContext($payload);
0 ignored issues
show
Documentation introduced by
$payload is of type object<eBayEnterprise\Re...ement\Payload\IPayload>, but the function expects a object<eBayEnterprise\Re...ayment\IPaymentContext>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
475
        $api->setRequestBody($payload);
476
        return $this;
477
    }
478
479
    /**
480
     * Prepare an API instance for a balance request - fill out and set the
481
     * request payload with gift card data.
482
     * @param  IBidirectionalApi $api
483
     * @return self
484
     */
485 View Code Duplication
    protected function prepareApiForVoid(IBidirectionalApi $api)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
486
    {
487
        $this->setRedeemVoidRequestId($this->coreHelper->generateRequestId(self::VOID_REQUST_ID_PREFIX));
488
        $payload = $api->getRequestBody();
489
        $payload
490
            ->setRequestId($this->getRedeemVoidRequestId())
491
            ->setPin($this->getPin())
492
            ->setAmount($this->getAmountRedeemed())
493
            ->setCurrencyCode($this->getRedeemCurrencyCode());
494
        $this->setPayloadPaymentContext($payload);
0 ignored issues
show
Documentation introduced by
$payload is of type object<eBayEnterprise\Re...ement\Payload\IPayload>, but the function expects a object<eBayEnterprise\Re...ayment\IPaymentContext>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
495
        $api->setRequestBody($payload);
496
        return $this;
497
    }
498
499
    /**
500
     * Set the payment context on the payload - consists of an order id and
501
     * a paymend account unique id.
502
     * @param Payload\Payment\IPaymentContext $payload
503
     * @return self
504
     */
505
    protected function setPayloadPaymentContext(Payload\Payment\IPaymentContext $payload)
506
    {
507
        $payload->setOrderId($this->getOrderId());
508
        return $this->setPayloadAccountUniqueId($payload);
509
    }
510
511
    /**
512
     * Set payment account unique id fields on the payload.
513
     * @param Payload\Payment\IPaymentAccountUniqueId $payload
514
     * @return self
515
     */
516
    protected function setPayloadAccountUniqueId(Payload\Payment\IPaymentAccountUniqueId $payload)
517
    {
518
        $tokenizedCardNumber = $this->getTokenizedCardNumber();
519
        $hasTokenizedNumber = !is_null($tokenizedCardNumber);
520
        $payload
521
            ->setCardNumber($hasTokenizedNumber ? $tokenizedCardNumber : $this->getCardNumber())
522
            ->setPanIsToken($hasTokenizedNumber);
523
        return $this;
524
    }
525
526
    /**
527
     * Send the request via the SDK
528
     * @param  IBidirectionalApi $api
529
     * @return self
530
     * @throws EbayEnterprise_GiftCard_Exception If request cannot be made successfully
531
     */
532
    protected function sendRequest(IBidirectionalApi $api)
533
    {
534
        $logger = $this->logger;
535
        $logContext = $this->context;
536
        try {
537
            $api->send();
538
        } catch (InvalidPayload $e) {
539
            $logMessage = 'Invalid payload for stored value request. See exception log for more details.';
540
            $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
541
            $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
542
            throw Mage::exception('EbayEnterprise_GiftCard', $this->helper->__(self::REQUEST_FAILED_MESSAGE));
543
        } catch (NetworkError $e) {
544
            $logMessage = 'Caught a network error sending stored value request. See exception log for more details.';
545
            $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
546
            $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
547
            throw Mage::exception('EbayEnterprise_GiftCard_Exception_Network', $this->helper->__(self::REQUEST_FAILED_MESSAGE));
548
        } catch (UnsupportedOperation $e) {
549
            $logMessage = 'The stored value card operation is unsupported in the current configuration. See exception log for more details.';
550
            $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
551
            $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
552
            throw $e;
553
        } catch (UnsupportedHttpAction $e) {
554
            $logMessage = 'The stored value card operation is configured with an unsupported HTTP action. See exception log for more details.';
555
            $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
556
            $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
557
            throw $e;
558
        } catch (Exception $e) {
559
            $logMessage = 'Encountered unexpected exception from stored value card operation. See exception log for more details.';
560
            $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
561
            $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
562
            throw $e;
563
        }
564
        return $this;
565
    }
566
567
    /**
568
     * Check for the balance response to be successful. If it was, update the
569
     * gift card with response data. If not, thrown an exception, indicating the
570
     * request failed.
571
     * @param  IBidirectionalApi $api
572
     * @return self
573
     * @throws EbayEnterprise_GiftCard_Exception If the reply is not successful.
574
     */
575
    protected function handleBalanceResponse(IBidirectionalApi $api)
576
    {
577
        $response = $api->getResponseBody();
578
        if (!$response->isSuccessful()) {
579
            throw Mage::exception('EbayEnterprise_GiftCard', self::BALANCE_REQUEST_FAILED_MESSAGE);
580
        }
581
        return $this->extractPayloadAccountUniqueId($response)
0 ignored issues
show
Documentation introduced by
$response is of type object<eBayEnterprise\Re...ement\Payload\IPayload>, but the function expects a object<eBayEnterprise\Re...PaymentAccountUniqueId>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
582
            ->setBalanceAmount($response->getBalanceAmount())
583
            ->setBalanceCurrencyCode($response->getCurrencyCode());
584
    }
585
586
    /**
587
     * Check for the gift card to have been redeemed. If it was, update the
588
     * gift card with response data. If not, thrown an exception, indicating the
589
     * request failed.
590
     * @param  IBidirectionalApi $api
591
     * @return self
592
     * @throws EbayEnterprise_GiftCard_Exception If the card was not redeemed
593
     */
594
    protected function handleRedeemResponse(IBidirectionalApi $api)
595
    {
596
        $response = $api->getResponseBody();
597
        if (!$response->wasRedeemed()) {
598
            // redeem failed so empty out any redeem amount
599
            $this->setAmountRedeemed(0.00);
600
            throw Mage::exception('EbayEnterprise_GiftCard', self::REDEEM_REQUEST_FAILED_MESSAGE);
601
        }
602
        return $this->extractPayloadAccountUniqueId($response)
0 ignored issues
show
Documentation introduced by
$response is of type object<eBayEnterprise\Re...ement\Payload\IPayload>, but the function expects a object<eBayEnterprise\Re...PaymentAccountUniqueId>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
603
            ->setBalanceAmount($response->getBalanceAmount())
604
            ->setBalanceCurrencyCode($response->getBalanceCurrencyCode())
605
            ->setAmountRedeemed($response->getAmountRedeemed())
606
            ->setRedeemCurrencyCode($response->getCurrencyCodeRedeemed())
607
            ->setRedeemedAt(new DateTime)
608
            ->setIsRedeemed(true);
609
    }
610
611
    /**
612
     * Check for the gift card redeem to have been voided. If it was, update the
613
     * gift card with response data. If not, thrown an exception, indicating the
614
     * request failed.
615
     * @param  IBidirectionalApi $api
616
     * @return self
617
     * @throws EbayEnterprise_GiftCard_Exception If the redeem was not voided
618
     */
619
    protected function handleVoidResponse(IBidirectionalApi $api)
620
    {
621
        $response = $api->getResponseBody();
622
        if (!$response->wasVoided()) {
623
            throw Mage::exception('EbayEnterprise_GiftCard', self::VOID_REQUEST_FAILED_MESSAGE);
624
        }
625
        return $this->extractPayloadAccountUniqueId($response)
0 ignored issues
show
Documentation introduced by
$response is of type object<eBayEnterprise\Re...ement\Payload\IPayload>, but the function expects a object<eBayEnterprise\Re...PaymentAccountUniqueId>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
626
            // after voiding a redemption, new balance will be the current
627
            // balance plus the amount voided (which is the same as the
628
            // amount originally redeemed)
629
            ->setBalanceAmount($this->getBalanceAmount() + $this->getAmountRedeemed())
630
            // redeem has been voided, so amount redeemed drops back to 0 and
631
            // card should no longer be considered to have been redeemed
632
            ->setAmountRedeemed(0.00)
633
            ->setIsRedeemed(false);
634
    }
635
636
    /**
637
     * Extract payment context form the payload - ignoring order id in the reply
638
     * as Magento is currently the master source for order ids when creating orders.
639
     * @param  Payload\Payment\IPaymentContext $payload
640
     * @return self
641
     */
642
    protected function extractPayloadPaymentContext(Payload\Payment\IPaymentContext $payload)
643
    {
644
        return $this->extractPayloadAccountUniqueId($payload);
645
    }
646
647
    /**
648
     * Update the gift card with account unique id data from the payload.
649
     * @param  Payload\Payment\IPaymentAccountUniqueId $payload
650
     * @return self
651
     */
652
    protected function extractPayloadAccountUniqueId(Payload\Payment\IPaymentAccountUniqueId $payload)
653
    {
654
        if ($payload->getPanIsToken()) {
655
            $this->setTokenizedCardNumber($payload->getCardNumber());
656
        } else {
657
            $this->setCardNumber($payload->getCardNumber());
658
        }
659
        return $this;
660
    }
661
662
    /**
663
     * Log request and response of stored value various service API calls.
664
     *
665
     * @param IBidirectionalApi
666
     * @param bool
667
     * @param string
668
     */
669
    protected function logStoredValuePayload(IBidirectionalApi $api, $isRequest, $logMessage)
670
    {
671
        /** @var string */
672
        $method = 'getRequestBody';
673
        /** @var string */
674
        $metaDataKey = 'rom_request_body';
675
        if (!$isRequest) {
676
            $method = 'getResponseBody';
677
            $metaDataKey = 'rom_response_body';
678
        }
679
        /** @var string */
680
        $cleanedXml = $this->mask->maskXmlNodes($api->$method()->serialize());
681
        $this->logger->debug($logMessage, $this->context->getMetaData(__CLASS__, [$metaDataKey => $cleanedXml]));
682
        return $this;
683
    }
684
}
685