/** * @depends testSerializationDeserialization * @param Payment $obj */ public function testGetters($obj) { $this->assertEquals($obj->getId(), "TestSample"); $this->assertEquals($obj->getIntent(), "TestSample"); $this->assertEquals($obj->getPayer(), PayerTest::getObject()); $this->assertEquals($obj->getPayee(), PayeeTest::getObject()); $this->assertEquals($obj->getCart(), "TestSample"); $this->assertEquals($obj->getTransactions(), TransactionTest::getObject()); $this->assertEquals($obj->getFailedTransactions(), ErrorTest::getObject()); $this->assertEquals($obj->getPaymentInstruction(), PaymentInstructionTest::getObject()); $this->assertEquals($obj->getState(), "TestSample"); $this->assertEquals($obj->getExperienceProfileId(), "TestSample"); $this->assertEquals($obj->getRedirectUrls(), RedirectUrlsTest::getObject()); $this->assertEquals($obj->getCreateTime(), "TestSample"); $this->assertEquals($obj->getUpdateTime(), "TestSample"); $this->assertEquals($obj->getLinks(), LinksTest::getObject()); }
/** * @depends testSerializationDeserialization * @param Payment $obj */ public function testGetters($obj) { $this->assertEquals($obj->getId(), "TestSample"); $this->assertEquals($obj->getIntent(), "TestSample"); $this->assertEquals($obj->getPayer(), PayerTest::getObject()); $this->assertEquals($obj->getPotentialPayerInfo(), PotentialPayerInfoTest::getObject()); $this->assertEquals($obj->getPayee(), PayeeTest::getObject()); $this->assertEquals($obj->getCart(), "TestSample"); $this->assertEquals($obj->getTransactions(), array(TransactionTest::getObject())); $this->assertEquals($obj->getFailedTransactions(), ErrorTest::getObject()); $this->assertEquals($obj->getBillingAgreementTokens(), array("TestSample")); $this->assertEquals($obj->getCreditFinancingOffered(), CreditFinancingOfferedTest::getObject()); $this->assertEquals($obj->getPaymentInstruction(), PaymentInstructionTest::getObject()); $this->assertEquals($obj->getState(), "TestSample"); $this->assertEquals($obj->getExperienceProfileId(), "TestSample"); $this->assertEquals($obj->getNoteToPayer(), "TestSample"); $this->assertEquals($obj->getRedirectUrls(), RedirectUrlsTest::getObject()); $this->assertEquals($obj->getFailureReason(), "TestSample"); $this->assertEquals($obj->getCreateTime(), "TestSample"); $this->assertEquals($obj->getUpdateTime(), "TestSample"); $this->assertEquals($obj->getLinks(), LinksTest::getObject()); }
public function createPayment($orderid, $userid) { if ($orderid > 0) { $orderid = (int) $orderid; $paypalCredentials = $this->getPaypalCredentials(); $apiContext = new ApiContext(new OAuthTokenCredential($paypalCredentials["clientid"], $paypalCredentials["secret"])); $apiContext->setConfig($this->paypalConfig); $payer = new Payer(); $payer->setPayment_method("paypal"); $order = new Orders(); $orderdetail = $order->getOrderDetail($orderid); //Setting up items for the paypal order detail //On future version this will have multiple packages based on cart content //When items were added api were responding abnormal /* $item = new Item(); $item->setName($orderdetail["title"]); $item->setCurrency($orderdetail["currency"]); $item->setQuantity($orderdetail["quantity"]); $item->setPrice($orderdetail["package_price"]); $item->setSku($orderdetail["package_guid"]); $itemList = new ItemList(); $itemList->setItems(array($item)); */ $amount = new Amount(); $amount->setCurrency($orderdetail["currency"]); $amount->setTotal($orderdetail["total"]); $orderDescription = "Qty: " . $orderdetail["quantity"] . " for " . $orderdetail["title"] . " - " . $orderdetail["title_summary"]; $transaction = new Transaction(); $transaction->setDescription($orderDescription); $transaction->setAmount($amount); //$transaction->setItemlist($itemList); $redirectUrls = new RedirectUrls(); $humanorderid = $order->getHumanOrderId($orderid); $redirectUrls->setReturn_url($paypalCredentials["returnurl"] . "&orderid=" . $humanorderid); $redirectUrls->setCancel_url($paypalCredentials["cancelurl"] . "&orderid=" . $humanorderid); $payment = new Payment(); $payment->setIntent("sale"); $payment->setPayer($payer); $payment->setRedirect_urls($redirectUrls); $payment->setTransactions(array($transaction)); try { $payment->create($apiContext); $this->setPaypalInfoOrder($orderid, $payment->getId(), $payment->getCreateTime(), $payment->getUpdateTime(), $payment->getState(), $userid); // Retrieve buyer approval url from the `payment` object. foreach ($payment->getLinks() as $link) { if ($link->getRel() == 'approval_url') { $approvalUrl = $link->getHref(); } } $result = array("status" => true, "approval_url" => $approvalUrl); return $result; } catch (PayPal\Exception\PPConnectionException $ex) { //Logging error $this->log->addError($ex->getMessage() . LOG_LINESEPARATOR . "TRACE: " . $ex->getTraceAsString() . LOG_LINESEPARATOR); $result = array("status" => false, "approval_url" => ""); return $result; } } else { //Logging error $this->log->addWarning("Invalid or null order id." . LOG_LINESEPARATOR); $result = array("status" => false, "approval_url" => ""); return $result; } }