Пример #1
0
 /**
  * @param int $amount
  * @param string $currency
  * @return ShipmentRate
  */
 public function getShipmentRate($amount = 500, $currency = 'USD')
 {
     $shipmentRate = new ShipmentRate(new Money($amount, $currency));
     $shipmentRate->setExternalId('rate_' . $this->getRandomToken());
     $shipmentRate->setCarrier('UPS');
     $shipmentRate->setService('Ground');
     $shipmentRate->setListRate(new Money($amount * 1.05, $currency));
     $shipmentRate->setRetailRate(new Money($amount * 1.15, $currency));
     $shipmentRate->setDeliveryDate(new DateTime());
     return $shipmentRate;
 }
Пример #2
0
 private function getShipmentRateFromEasyPostRate($rate)
 {
     $shipmentRate = new ShipmentRate(new Money($rate->rate * 100, $rate->currency));
     $shipmentRate->setExternalId($rate->id);
     $shipmentRate->setShipmentExternalId($rate->shipment_id);
     $shipmentRate->setCarrier($rate->carrier);
     $shipmentRate->setService($rate->service);
     $shipmentRate->setIsDeliveryDateGuaranteed($rate->delivery_date_guaranteed);
     if ($rate->list_rate !== null) {
         $shipmentRate->setListRate(new Money($rate->list_rate * 100, $rate->list_currency));
     }
     if ($rate->retail_rate !== null) {
         $shipmentRate->setRetailRate(new Money($rate->retail_rate * 100, $rate->retail_currency));
     }
     if (!empty($rate->delivery_date)) {
         $shipmentRate->setDeliveryDate(new DateTime($rate->delivery_date));
     }
     if (!empty($rate->delivery_days)) {
         $shipmentRate->setDeliveryDays($rate->delivery_days);
     }
     return $shipmentRate;
 }
Пример #3
0
 public function testCreate()
 {
     $rate = $this->dummyData->getMoney(907);
     $deliveryDate = new DateTime();
     $shipmentRate = new ShipmentRate($rate);
     $shipmentRate->setExternalId('rate_xxxxxx');
     $shipmentRate->setShipmentExternalId('shp_xxxxxx');
     $shipmentRate->setCarrier('UPS');
     $shipmentRate->setService('Ground');
     $shipmentRate->setListRate($this->dummyData->getMoney(986));
     $shipmentRate->setRetailRate($this->dummyData->getMoney(1196));
     $shipmentRate->setDeliveryDate($deliveryDate);
     $shipmentRate->setIsDeliveryDateGuaranteed(true);
     $shipmentRate->setDeliveryDays(5);
     $shipmentRate->setEstDeliveryDays(5);
     $this->assertEntityValid($shipmentRate);
     $this->assertSame('rate_xxxxxx', $shipmentRate->getExternalId());
     $this->assertSame('shp_xxxxxx', $shipmentRate->getShipmentExternalId());
     $this->assertSame('UPS', $shipmentRate->getCarrier());
     $this->assertSame('Ground', $shipmentRate->getService());
     $this->assertSame($rate, $shipmentRate->getRate());
     $this->assertSame(907, $shipmentRate->getRate()->getAmount());
     $this->assertSame(986, $shipmentRate->getListRate()->getAmount());
     $this->assertSame(1196, $shipmentRate->getRetailRate()->getAmount());
     $this->assertEquals($deliveryDate, $shipmentRate->getDeliveryDate());
     $this->assertSame(5, $shipmentRate->getDeliveryDays());
     $this->assertSame(true, $shipmentRate->isDeliveryDateGuaranteed());
     $this->assertSame(5, $shipmentRate->getEstDeliveryDays());
     $this->assertTrue($shipmentRate->getDeliveryMethod()->isStandard());
 }
 public function __construct(ShipmentRate $shipmentRate, DTOBuilderFactoryInterface $dtoBuilderFactory)
 {
     $this->entity = $shipmentRate;
     $this->dtoBuilderFactory = $dtoBuilderFactory;
     $this->entityDTO = new ShipmentRateDTO();
     $this->entityDTO->externalId = $this->entity->getExternalId();
     $this->entityDTO->shipmentExternalId = $this->entity->getShipmentExternalId();
     $this->entityDTO->service = $this->entity->getService();
     $this->entityDTO->carrier = $this->entity->getCarrier();
     $this->entityDTO->rate = $this->dtoBuilderFactory->getMoneyDTOBuilder($this->entity->getRate())->build();
     $this->entityDTO->isDeliveryDateGuaranteed = $this->entity->isDeliveryDateGuaranteed();
     $this->entityDTO->deliveryDays = $this->entity->getDeliveryDays();
     $this->entityDTO->estDeliveryDays = $this->entity->getEstDeliveryDays();
     if ($this->entity->getDeliveryMethod()->getId() !== null) {
         $this->entityDTO->deliveryMethod = $this->dtoBuilderFactory->getDeliveryMethodTypeDTOBuilder($this->entity->getDeliveryMethod())->build();
     }
     if ($this->entity->getDeliveryDate() !== null) {
         $this->entityDTO->deliveryDate = $this->entity->getDeliveryDate();
     }
     if ($this->entity->getListRate() !== null) {
         $this->entityDTO->listRate = $this->dtoBuilderFactory->getMoneyDTOBuilder($this->entity->getListRate())->build();
     }
     if ($this->entity->getRetailRate() !== null) {
         $this->entityDTO->retailRate = $this->dtoBuilderFactory->getMoneyDTOBuilder($this->entity->getRetailRate())->build();
     }
 }