public function testGetterSetter() { $this->assertEquals(AmountTest::$currency, $this->transaction->getAmount()->getCurrency()); $this->assertEquals(self::$description, $this->transaction->getDescription()); $this->assertEquals(self::$invoiceNumber, $this->transaction->getInvoiceNumber()); $this->assertEquals(self::$custom, $this->transaction->getCustom()); $this->assertEquals(self::$softDescriptor, $this->transaction->getSoftDescriptor()); $items = $this->transaction->getItemList()->getItems(); $this->assertEquals(ItemTest::$quantity, $items[0]->getQuantity()); $this->assertEquals(PayeeTest::$email, $this->transaction->getPayee()->getEmail()); $resources = $this->transaction->getRelatedResources(); $this->assertEquals(AuthorizationTest::$create_time, $resources[0]->getAuthorization()->getCreateTime()); }
public function getLinkCheckOut($params = null) { if (!$params) { return false; } /*Payer A resource representing a Payer that funds a payment For paypal account payments, set payment method to 'paypal'. */ $payer = new Payer(); $payer->setPaymentMethod("paypal"); $itemList = new ItemList(); // Item must be a array and has one or more item. if (!$params['items']) { return false; } $arrItem = []; foreach ($params['items'] as $key => $item) { $it = new Item(); $it->setName($item['name'])->setCurrency($params['currency'])->setQuantity($item['quantity'])->setPrice($item['price']); $arrItem[] = $it; } $itemList->setItems($arrItem); $amount = new Amount(); $amount->setCurrency($params['currency'])->setTotal($params['total_price']); $transaction = new Transaction(); $transaction->setAmount($amount)->setItemList($itemList)->setDescription($params['description']); // ### Redirect urls // Set the urls that the buyer must be redirected to after // payment approval/ cancellation. $redirectUrls = new RedirectUrls(); $baseUrl = $this->getBaseUrl(); $redirectUrls->setReturnUrl($baseUrl . $this->successUrl)->setCancelUrl($baseUrl . $this->cancelUrl); // ### Payment // A Payment Resource; create one using // the above types and intent set to 'sale' $payment = new Payment(); $payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions([$transaction]); // ### Create Payment // Create a payment by calling the 'create' method // passing it a valid apiContext. try { $payment->create($this->config); } catch (PayPal\Exception\PPConnectionException $ex) { throw new \DataErrorException($ex->getData(), $ex->getMessage()); } // ### Get redirect url $redirectUrl = $payment->getApprovalLink(); return ['payment_id' => $payment->getId(), 'status' => $payment->getState(), 'redirect_url' => $redirectUrl, 'description' => $transaction->getDescription()]; }