public function credit_card() { $card = new \PayPal\Api\CreditCard(); $card->setType($this->card_type)->setNumber($this->card_number)->setExpireMonth($this->card_month)->setExpireYear($this->card_year)->setCvv2($this->card_cvv)->setFirstName($this->card_fname)->setLastName($this->card_lname); $fi = new \PayPal\Api\FundingInstrument(); $fi->setCreditCard($card); $payer = new \PayPal\Api\Payer(); $payer->setPaymentMethod('credit_card')->setFundingInstruments(array($fi)); $items = array(); foreach ($this->items as $item) { $item2 = new \PayPal\Api\Item(); $item2->setName($item[0])->setDescription($item[1])->setCurrency(CURRENCY)->setQuantity($item[2])->setPrice($item[3]); $items[] = $item2; } $itemList = new \PayPal\Api\ItemList(); $itemList->setItems($items); $amount = new \PayPal\Api\Amount(); $amount->setCurrency(CURRENCY)->setTotal($this->total); $transaction = new \PayPal\Api\Transaction(); $transaction->setAmount($amount)->setItemList($itemList)->setDescription($this->description); $payment = new \PayPal\Api\Payment(); $payment->setIntent($this->intent)->setPayer($payer)->setTransactions(array($transaction)); try { $payment->create($this->apiContext); return array('id' => $payment->getId(), 'total' => $this->total, 'items' => $this->items, 'details' => $this->description, 'state' => $payment->getstate()); } catch (Exception $e) { throw new \Exception('PayPal error: ' . $e->getMessage()); } }