Shows details for a sale, by ID. Returns only sales that were created through the REST API.
public static get ( string $saleId, |
||
$saleId | string | |
$apiContext | is the APIContext for this call. It can be used to pass dynamic configuration and credentials. | |
$restCall | PayPalRestCall | is the Rest Call Service that is used to make rest calls |
Résultat |
public function stupdate($transactionId, $apiContext) { if ($transactionId) { $sale = Sale::get($transactionId, $apiContext); $data = array('state' => $sale->getState()); $this->getDbTable()->update($data, array('transaction_id = ?' => $transactionId)); return $data['state']; } }
/** * @depends testGet * @param $payment Payment * @return Sale */ public function testGetSale($payment) { $transactions = $payment->getTransactions(); $transaction = $transactions[0]; $relatedResources = $transaction->getRelatedResources(); $resource = $relatedResources[0]; $result = Sale::get($resource->getSale()->getId(), $this->apiContext, $this->mockPayPalRestCall); $this->assertNotNull($result); $this->assertEquals($resource->getSale()->getId(), $result->getId()); return $result; }
public function testOperations() { $payment = PaymentTest::createNewPayment(); $payment->create(); $transactions = $payment->getTransactions(); $resources = $transactions[0]->getRelated_resources(); $saleId = $resources[0]->getSale()->getId(); $sale = Sale::get($saleId); $this->assertNotNull($sale); $refund = new Refund(); $refund->setAmount(AmountTest::createAmount()); $sale->refund($refund); $this->setExpectedException('\\InvalidArgumentException'); $sale->refund(NULL); }
<?php // # Get Sale sample // Sale transactions are nothing but completed payments. // This sample code demonstrates how you can retrieve // details of completed Sale Transaction. // API used: /v1/payments/sale/{sale-id} /** @var Payment $payment */ $payment = (require __DIR__ . '/../payments/CreatePayment.php'); use PayPal\Api\Sale; use PayPal\Api\Payment; // ### Get Sale From Created Payment // You can retrieve the sale Id from Related Resources for each transactions. $transactions = $payment->getTransactions(); $relatedResources = $transactions[0]->getRelatedResources(); $sale = $relatedResources[0]->getSale(); $saleId = $sale->getId(); try { // ### Retrieve the sale object // Pass the ID of the sale // transaction from your payment resource. $sale = Sale::get($saleId, $apiContext); } catch (Exception $ex) { // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY ResultPrinter::printError("Look Up A Sale", "Sale", $sale->getId(), null, $ex); exit(1); } // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY ResultPrinter::printResult("Look Up A Sale", "Sale", $sale->getId(), null, $sale); return $sale;
function get_transaction($id) { // auth $apiContext = $this->apiContext(); try { $payment = Sale::get($id, $apiContext); $valid = true; } catch (Exception $ex) { $this->LoggingManager->log(print_r($ex, true), 'DEBUG'); $valid = false; } if ($valid === true) { return $payment; } try { $payment = Authorization::get($id, $apiContext); $valid = true; } catch (Exception $ex) { $this->LoggingManager->log(print_r($ex, true), 'DEBUG'); $valid = false; } if ($valid === true) { return $payment; } try { $payment = Capture::get($id, $apiContext); $valid = true; } catch (Exception $ex) { $this->LoggingManager->log(print_r($ex, true), 'DEBUG'); $valid = false; } if ($valid === true) { return $payment; } try { $payment = Refund::get($id, $apiContext); $valid = true; } catch (Exception $ex) { $this->LoggingManager->log(print_r($ex, true), 'DEBUG'); $valid = false; } if ($valid === true) { return $payment; } }
public function getSale($paymentId) { $apiContext = $this->connectionService->getApiContext(); $payment = $this->get($paymentId); $transactions = $payment->getTransactions(); $relatedResources = $transactions[0]->getRelatedResources(); $sale = $relatedResources[0]->getSale(); $saleId = $sale->getId(); $sale = Sale::get($saleId, $apiContext); return $sale; }
/** * @dataProvider mockProvider * @param Sale $obj */ public function testGet($obj, $mockApiContext) { $mockPPRestCall = $this->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock(); $mockPPRestCall->expects($this->any())->method('execute')->will($this->returnValue(SaleTest::getJson())); $result = $obj->get("saleId", $mockApiContext, $mockPPRestCall); $this->assertNotNull($result); }
// details of completed Sale Transaction. // API used: /v1/payments/sale/{sale-id} require __DIR__ . '/../bootstrap.php'; use PayPal\Api\Sale; $saleId = '3RM92092UW5126232'; // ### Authentication // Pass in a `OAuthTokenCredential` object // explicilty to authenticate the call. // If you skip this step, the client id/secret // set in the config file will be used. Sale::setCredential($cred); try { // ### Retrieve the sale object // Pass the ID of the sale // transaction from your payment resource. $sale = Sale::get($saleId); } catch (\PPConnectionException $ex) { echo "Exception:" . $ex->getMessage() . PHP_EOL; var_dump($ex->getData()); exit(1); } ?> <html> <body> <div>Retrieving sale id: <?php echo $saleId; ?> </div> <pre><?php var_dump($sale); ?>
public function exepaypalAction() { if (isset($_GET['success']) && $_GET['success'] == 'true') { $paymentId = $_GET['paymentId']; $token = $_GET['token']; $PayerID = $_GET['PayerID']; require_once APPLICATION_PATH . "/../library/My/paypal_bootstrap.php"; $payment = Payment::get($paymentId, $apiContext); $execution = new PaymentExecution(); $execution->setPayerId($PayerID); $result = $payment->execute($execution, $apiContext); $payment = Payment::get($paymentId, $apiContext); if ($payment->getState() == 'approved') { $transactions = $payment->getTransactions(); $relatedResources = $transactions[0]->getRelatedResources(); $sale = $relatedResources[0]->getSale(); $saleId = $sale->getId(); $sale = Sale::get($saleId, $apiContext); //var_dump($transactions[0], $sale); $order_id = $transactions[0]->getCustom(); $userMapper = new Application_Model_UserMapper(); $db_adapter = $userMapper->getDbTable()->getAdapter(); $db = Zend_Db::factory('Mysqli', $db_adapter->getConfig()); $data = array('state' => $sale->getState(), 'transaction_id' => $saleId); $db->update('orders', $data, array('id = ?' => $order_id)); $row = $db->fetchRow($db->select('user_id')->from('orders')->where('id = ?', $order_id)); $db->delete('shoppingcarts', array('user_id = ?' => $row['user_id'])); $this->_helper->getHelper('FlashMessenger')->addMessage('Order Complete', 'success'); } } else { $this->_helper->getHelper('FlashMessenger')->addMessage('You close the payment', 'error'); } return $this->_helper->redirector('mycart'); }
function isSaleComplete($saleId) { $apiContext = $this->getApiContext(); $sale = Sale::get($saleId, $apiContext); $completed = strcmp($sale->getState(), 'completed') == 0; return $completed; }