public function refundSale($saleId, $refundAmount, $currency = CurrencyConst::EURO) { $apiContext = $this->connectionService->getApiContext(); $amount = new Amount(); $amount->setCurrency($currency)->setTotal($refundAmount); $refund = new Refund(); $refund->setAmount($amount); $sale = new Sale(); $sale->setId($saleId); $refundSale = $sale->refund($refund, $apiContext); return $refundSale; }
public function testSerializeDeserialize() { $s1 = $this->sale; $s2 = new Sale(); $s2->fromJson($s1->toJson()); $this->assertEquals($s1, $s2); }
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; } }
/** * Obtain the Sale transaction resource for the given identifier. * * @param string $saleId * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. * @param PayPalRestCall $restCall is the Rest Call Service that is used to make rest calls * @return Sale */ public static function get($saleId, $apiContext = null, $restCall = null) { ArgumentValidator::validate($saleId, 'saleId'); $payLoad = ""; $json = self::executeCall("/v1/payments/sale/{$saleId}", "GET", $payLoad, null, $apiContext, $restCall); $ret = new Sale(); $ret->fromJson($json); return $ret; }
/** * Get * * @param int $saleId * @param \PayPal\Rest\ApiContext|null $apiContext * * @return Sale * @throws \InvalidArgumentException */ public static function get($saleId, $apiContext = null) { if ($saleId == null || strlen($saleId) <= 0) { throw new \InvalidArgumentException("saleId cannot be null or empty"); } $payLoad = ""; if ($apiContext == null) { $apiContext = new ApiContext(self::$credential); } $call = new PPRestCall($apiContext); $json = $call->execute(array('PayPal\\Rest\\RestHandler'), "/v1/payments/sale/{$saleId}", "GET", $payLoad); $ret = new Sale(); $ret->fromJson($json); return $ret; }
// 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'); }
/** * @path /v1/payments/sale/:sale-id * @method GET * @param string $saleid */ public static function get($saleid) { if ($saleid == null || strlen($saleid) <= 0) { throw new \InvalidArgumentException("saleid cannot be null or empty"); } $payLoad = ""; $apiContext = new ApiContext(self::$credential); $call = new Call(); $json = $call->execute("/v1/payments/sale/{$saleid}", "GET", $payLoad, $apiContext); $ret = new Sale(); $ret->fromJson($json); return $ret; }
function isSaleComplete($saleId) { $apiContext = $this->getApiContext(); $sale = Sale::get($saleId, $apiContext); $completed = strcmp($sale->getState(), 'completed') == 0; return $completed; }
use PayPal\Api\Refund; use PayPal\Api\Sale; // ### Refund // Create a refund object indicating // refund amount $amt = new Amount(); $amt->setCurrency('USD'); $amt->setTotal('0.01'); $refund = new Refund(); $refund->setAmount($amt); $saleId = '3RM92092UW5126232'; // ###Sale // A sale transaction. // Create a Sale object with the // given sale transaction id. $sale = new Sale(); $sale->setId($saleId); try { // Refund the sale // (See bootstrap.php for more on `ApiContext`) $sale->refund($refund, $apiContext); } catch (\PPConnectionException $ex) { echo "Exception:" . $ex->getMessage() . PHP_EOL; var_dump($ex->getData()); exit(1); } ?> <html> <body> <div>Refunding sale id: <?php echo $saleId;
/** * @dataProvider mockProvider * @param Sale $obj */ public function testRefund($obj, $mockApiContext) { $mockPPRestCall = $this->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock(); $mockPPRestCall->expects($this->any())->method('execute')->will($this->returnValue(RefundTest::getJson())); $refund = RefundTest::getObject(); $result = $obj->refund($refund, $mockApiContext, $mockPPRestCall); $this->assertNotNull($result); }
use PayPal\Api\Refund; use PayPal\Api\Sale; // ### Refund amount // Includes both the refunded amount (to Payer) // and refunded fee (to Payee). Use the $amt->details // field to mention fees refund details. $amt = new Amount(); $amt->setCurrency('USD')->setTotal(0.01); // ### Refund object $refund = new Refund(); $refund->setAmount($amt); // ###Sale // A sale transaction. // Create a Sale object with the // given sale transaction id. $sale = new Sale(); $sale->setId($saleId); try { // Create a new apiContext object so we send a new // PayPal-Request-Id (idempotency) header for this resource $apiContext = getApiContext($clientId, $clientSecret); // Refund the sale // (See bootstrap.php for more on `ApiContext`) $refundedSale = $sale->refund($refund, $apiContext); } catch (Exception $ex) { // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY ResultPrinter::printError("Refund Sale", "Sale", $refundedSale->getId(), $refund, $ex); exit(1); } // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY ResultPrinter::printResult("Refund Sale", "Sale", $refundedSale->getId(), $refund, $refundedSale);
use PayPal\Api\RefundRequest; use PayPal\Api\Sale; // ### Refund amount // Includes both the refunded amount (to Payer) // and refunded fee (to Payee). Use the $amt->details // field to mention fees refund details. $amt = new Amount(); $amt->setCurrency('USD')->setTotal(0.01); // ### Refund object $refundRequest = new RefundRequest(); $refundRequest->setAmount($amt); // ###Sale // A sale transaction. // Create a Sale object with the // given sale transaction id. $sale = new Sale(); $sale->setId($saleId); try { // Create a new apiContext object so we send a new // PayPal-Request-Id (idempotency) header for this resource $apiContext = getApiContext($clientId, $clientSecret); // Refund the sale // (See bootstrap.php for more on `ApiContext`) $refundedSale = $sale->refundSale($refundRequest, $apiContext); } catch (Exception $ex) { // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY ResultPrinter::printError("Refund Sale", "Sale", null, $refundRequest, $ex); exit(1); } // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY ResultPrinter::printResult("Refund Sale", "Sale", $refundedSale->getId(), $refundRequest, $refundedSale);