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; }
public function update($creditCardToken, array $updateInfo) { $apiContext = $this->connectionService->getApiContext(); $dispatcher = $this->connectionService->getDispatcher(); $creditCard = $this->getDetails($creditCardToken); $creditCardEvent = new CreditCardEvent($creditCard); $dispatcher->dispatch(CreditCardEvent::UPDATE_START, $creditCardEvent); $patchRequest = new PatchRequest(); foreach ($updateInfo as $operation => $fields) { $allowedOperation = Validation::updateOP($operation); if ($allowedOperation) { $patch = new Patch(); $patch->setOp($operation); foreach ($fields as $key => $value) { $patch->setPath($key)->setValue($value); } $patchRequest->addPatch(clone $patch); } } $result = $creditCard->update($patchRequest, $apiContext); $creditCardEvent = new CreditCardEvent($result); $dispatcher->dispatch(CreditCardEvent::UPDATE_END, $creditCardEvent); return true; }