/** * @depends testSerializationDeserialization * @param Item $obj */ public function testGetters($obj) { $this->assertEquals($obj->getQuantity(), "TestSample"); $this->assertEquals($obj->getName(), "TestSample"); $this->assertEquals($obj->getDescription(), "TestSample"); $this->assertEquals($obj->getPrice(), "12.34"); $this->assertEquals($obj->getTax(), "12.34"); $this->assertEquals($obj->getCurrency(), "TestSample"); $this->assertEquals($obj->getSku(), "TestSample"); $this->assertEquals($obj->getUrl(), "http://www.google.com"); $this->assertEquals($obj->getCategory(), "TestSample"); $this->assertEquals($obj->getWeight(), MeasurementTest::getObject()); $this->assertEquals($obj->getLength(), MeasurementTest::getObject()); $this->assertEquals($obj->getHeight(), MeasurementTest::getObject()); $this->assertEquals($obj->getWidth(), MeasurementTest::getObject()); $this->assertEquals($obj->getSupplementaryData(), NameValuePairTest::getObject()); $this->assertEquals($obj->getPostbackData(), NameValuePairTest::getObject()); }
public static function create($items, Details $shippingDetails, $paymentIntent, $paymentMethod, $fi = null) { $payer = new Payer(); $payer->setPaymentMethod($paymentMethod); if ($fi !== null) { $payer->setFundingInstruments(array($fi)); } $fullList = array(); foreach ($items as $item) { if (!$item instanceof ItemInterface) { throw new Exception('All the item created for the payment MUST implement the ItemInterface'); } $singleItem = new Item(); $singleItem->setName($item->getName()); $singleItem->setSku($item->getSku()); $singleItem->setCurrency($item->getCurrency()); $singleItem->setPrice($item->getPrice()); $singleItem->setQuantity($item->getQuantity()); $fullList[] = $singleItem; } $itemList = new ItemList(); $itemList->setItems($fullList); $details = $shippingDetails; $subtotal = 0.0; /** @var Item $singleItem */ foreach ($fullList as $singleItem) { $subtotal += floatval($singleItem->getPrice()) * floatval($singleItem->getQuantity()); } $details->setSubtotal($subtotal); $total = $subtotal + floatval($details->getTax()) + floatval($details->getShipping()); $currencyMode = Validation::currencyMode($items); $amount = new Amount(); $amount->setCurrency($currencyMode)->setTotal($total)->setDetails($details); $transaction = new Transaction(); $transaction->setAmount($amount)->setItemList($itemList); $payment = new Payment(); $payment->setIntent($paymentIntent)->setPayer($payer)->setTransactions(array($transaction)); return $payment; }