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\Payload\Order\IPaymentContainer; |
17
|
|
|
|
18
|
|
|
class EbayEnterprise_Giftcard_Model_Order_Create_Payment |
19
|
|
|
{ |
20
|
|
|
/** @var EbayEnterprise_GiftCard_Model_IContainer */ |
21
|
|
|
protected $_giftcardContainer; |
22
|
|
|
public function __construct(array $args = []) |
23
|
|
|
{ |
24
|
|
|
list( |
25
|
|
|
$this->_giftcardContainer |
26
|
|
|
) = $this->_enforceTypes( |
27
|
|
|
$this->_nullCoalesce('giftcard_container', $args, Mage::getModel('ebayenterprise_giftcard/container')) |
28
|
|
|
); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* ensure correct types |
33
|
|
|
* @param EbayEnterprise_GiftCard_Model_IContainer $container |
34
|
|
|
* @return array |
|
|
|
|
35
|
|
|
*/ |
36
|
|
|
protected function _enforceTypes(EbayEnterprise_GiftCard_Model_IContainer $container) |
37
|
|
|
{ |
38
|
|
|
return [$container]; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Make stored value card payloads for any redeemed |
43
|
|
|
* gift cards |
44
|
|
|
* |
45
|
|
|
* @param Mage_Sales_Model_Order $order |
46
|
|
|
* @param IPaymentContainer $paymentContainer |
47
|
|
|
* @param SplObjectStorage $processedPayments |
48
|
|
|
*/ |
49
|
|
|
public function addPaymentsToPayload( |
50
|
|
|
Mage_Sales_Model_Order $order, |
51
|
|
|
IPaymentContainer $paymentContainer, |
52
|
|
|
SplObjectStorage $processedPayments |
53
|
|
|
) { |
54
|
|
|
foreach ($this->_giftcardContainer->getRedeemedGiftcards() as $giftcard) { |
55
|
|
|
$iterable = $paymentContainer->getPayments(); |
56
|
|
|
$payload = $iterable->getEmptyStoredValueCardPayment(); |
57
|
|
|
$payload |
58
|
|
|
// payment context |
59
|
|
|
->setOrderId($order->getIncrementId()) |
60
|
|
|
->setTenderType($giftcard->getTenderType()) |
61
|
|
|
->setAccountUniqueId($this->getGcPan($giftcard)) |
62
|
|
|
->setPanIsToken($this->isPanTokenize($giftcard)) |
63
|
|
|
// payment data |
64
|
|
|
->setCreateTimestamp($giftcard->getRedeemedAt()) |
65
|
|
|
->setAmount($giftcard->getAmountRedeemed()) |
66
|
|
|
->setPin($giftcard->getPin()) |
67
|
|
|
->setPaymentRequestId($giftcard->getRedeemRequestId()); |
68
|
|
|
// add the new payload |
69
|
|
|
$iterable->OffsetSet($payload, $payload); |
70
|
|
|
// put the payment in the processed payments set |
71
|
|
|
$processedPayments->attach($giftcard); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
protected function _nullCoalesce($key, array $args, $default) |
|
|
|
|
76
|
|
|
{ |
77
|
|
|
return isset($args[$key]) ? $args[$key] : $default; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Determine if the PAN in the giftcard is tokenized. |
82
|
|
|
* |
83
|
|
|
* @param EbayEnterprise_GiftCard_Model_IGiftcard |
84
|
|
|
* @return bool |
85
|
|
|
*/ |
86
|
|
|
protected function isPanTokenize(EbayEnterprise_GiftCard_Model_IGiftcard $giftcard) |
87
|
|
|
{ |
88
|
|
|
return !is_null($giftcard->getTokenizedCardNumber()); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Get the Giftcard PAN. Return the tokenized pan if it is tokenized otherwise |
93
|
|
|
* return the raw PAN. |
94
|
|
|
* |
95
|
|
|
* @param EbayEnterprise_GiftCard_Model_IGiftcard |
96
|
|
|
* @return bool |
|
|
|
|
97
|
|
|
*/ |
98
|
|
|
protected function getGcPan(EbayEnterprise_GiftCard_Model_IGiftcard $giftcard) |
99
|
|
|
{ |
100
|
|
|
return $this->isPanTokenize($giftcard) ? $giftcard->getTokenizedCardNumber() : $giftcard->getCardNumber(); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
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.