/** * Add taxes to the ship group for any tax records related to address * level gifting. * * @return self */ public function addGiftTaxesToPayload() { $giftTaxes = $this->_getAddressGiftTaxRecords(); if ($giftTaxes) { $taxContainer = $this->_getTaxContainer(); $taxIterable = $taxContainer->getTaxes(); foreach ($giftTaxes as $giftTax) { $taxPayload = $this->_payloadHelper->taxRecordToTaxPayload($giftTax, $taxIterable->getEmptyTax()); // Somewhat idiosyncratic way of adding to the iterable...required // due to the iterable currently being implemented as an SPLObjectStorage // which requires objects stored to be set as keys, not values. $taxIterable[$taxPayload] = null; } $taxContainer->setTaxes($taxIterable); } return $this; }
/** * Add a tax payload for each tax record to the container. * * @param EbayEnterprise_Tax_Model_Record[] * @param ITaxContainer * @return self */ protected function _addTaxRecordsToContainer(array $taxRecords, ITaxContainer $taxContainer) { $taxIterable = $taxContainer->getTaxes(); foreach ($taxRecords as $taxRecord) { $taxPayload = $this->_payloadHelper->taxRecordToTaxPayload($taxRecord, $taxIterable->getEmptyTax()); $taxIterable[$taxPayload] = null; } $taxContainer->getTaxes($taxIterable); return $this; }
/** * Inject gifting data for the item. * * @return self */ protected function _injectGiftingData() { if ($this->_itemHasGifting()) { // Given payload will be updated to include gifting data from the // item, so no need to handle the return value as the side-effects // of the method will accomplish all that is needed to add gifting // data to the payload. $this->_payloadHelper->giftingItemToGiftingPayload($this->_item, $this->_orderItem); } return $this; }
/** * Create and populate payloads for the address. * * @return self */ protected function _populateRequest() { if ($this->_validateAddressIsDestination()) { $this->_destination = $this->_payloadHelper->customerAddressToMailingAddressPayload($this->_address, $this->_destinationIterable->getEmptyMailingAddress()); // If there is a destination for the address, copy it over to the // address object so it can be metched up to the destination in // the response payloads. $this->_address->setDestinationId($this->_destination->getId()); } if ($this->_validateAddressIsShipGroup()) { $this->_shipGroup = $this->_shipGroupIterable->getEmptyShipGroup()->setDestination($this->_destination)->setChargeType(self::SHIPPING_CHARGE_TYPE); if ($this->_checkAddressHasGifting()) { $this->_payloadHelper->giftingItemToGiftingPayload($this->_address, $this->_shipGroup); } $this->_injectItemData(); } return $this; }
/** * When adding gift taxes to a payload, gifting taxes collected for * the address should be added to the ship group payload. */ public function testAddGiftTaxesToPayload() { // Set up happy path for test - ship group has a tax container... $this->_shipGroup->expects($this->any())->method('getGiftPricing')->will($this->returnValue($this->_taxContainer)); // ...tax collector returns tax records. $this->_taxCollector->expects($this->any())->method('getTaxRecords')->will($this->returnValue([$this->_itemGiftTax, $this->_addressGiftTax, $this->_merchGiftTax])); // Let the tax payload helper return the expected tax payload when // given the expected tax record. $this->_payloadHelper->expects($this->any())->method('taxRecordToTaxPayload')->with($this->identicalTo($this->_addressGiftTax))->will($this->returnValue($this->_completeTaxPayload)); // Side-effect test: the tax payload to be populated with data // must come from the tax iterable it will be added to. There // should be a single record to add for taxes so at least one // tax payload must come from the iterable. $this->_taxIterable->expects($this->atLeastOnce())->method('getEmptyTax')->will($this->returnValue($this->_taxPayload)); // Side-effect tests: ensure the expected, complete tax payload is added // to the tax iterable. $this->_taxIterable->expects($this->once())->method('offsetSet')->with($this->identicalTo($this->_completeTaxPayload), $this->anything())->will($this->returnValue(null)); // Side-effect test: ensure the tax iterable is set to the tax container. $this->_taxContainer->expects($this->once())->method('setTaxes')->with($this->identicalTo($this->_taxIterable))->will($this->returnSelf()); $this->assertSame($this->_shipGroupHandler, $this->_shipGroupHandler->addGiftTaxesToPayload()); }