public function testSerializeDeserialize() { $c1 = $this->captures['partial']; $c2 = new Capture(); $c2->fromJson($c1->toJson()); $this->assertEquals($c1, $c2); }
/** * @dataProvider mockProvider * @param Capture $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); }
/** * @group integration */ public function testOperations() { try { $authId = AuthorizationTest::authorize(); $auth = Authorization::get($authId); $amount = new Amount(); $amount->setCurrency("USD"); $amount->setTotal("1.00"); $captr = new Capture(); $captr->setId($authId); $captr->setAmount($amount); $capt = $auth->capture($captr); $captureId = $capt->getId(); $this->assertNotNull($captureId); $refund = new Refund(); $refund->setId($captureId); $refund->setAmount($amount); $capture = Capture::get($captureId); $this->assertNotNull($capture->getId()); $retund = $capture->refund($refund); $this->assertNotNull($retund->getId()); } catch (PayPalConnectionException $ex) { $this->markTestSkipped('Tests failing because of intermittent failures in Paypal Sandbox environment.' . $ex->getMessage()); } }
public function testOperations() { $authId = AuthorizationTest::authorize(); $auth = Authorization::get($authId); $amount = new Amount(); $amount->setCurrency("USD"); $amount->setTotal("1.00"); $captr = new Capture(); $captr->setId($authId); $captr->setAmount($amount); $capt = $auth->capture($captr); $captureId = $capt->getId(); $this->assertNotNull($captureId); $refund = new Refund(); $refund->setId($captureId); $refund->setAmount($amount); $capture = Capture::get($captureId); $this->assertNotNull($capture->getId()); $retund = $capture->refund($refund); $this->assertNotNull($retund->getId()); }
public function testOperations() { $authId = self::authorize(); $auth = Authorization::get($authId); $this->assertNotNull($auth->getId()); $amount = new Amount(); $amount->setCurrency("USD"); $amount->setTotal("1.00"); $captur = new Capture(); $captur->setId($authId); $captur->setAmount($amount); $capt = $auth->capture($captur); $this->assertNotNull($capt->getId()); $authId = self::authorize(); $auth = Authorization::get($authId); $void = $auth->void(); $this->assertNotNull($void->getId()); }
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; } }
/** * @group integration */ public function testOperations() { try { $authId = self::authorize(); $auth = Authorization::get($authId); $this->assertNotNull($auth->getId()); $amount = new Amount(); $amount->setCurrency("USD"); $amount->setTotal("1.00"); $captur = new Capture(); $captur->setId($authId); $captur->setAmount($amount); $capt = $auth->capture($captur); $this->assertNotNull($capt->getId()); $authId = self::authorize(); $auth = Authorization::get($authId); $void = $auth->void(); $this->assertNotNull($void->getId()); $auth->setId(null); try { $auth->void(); } catch (\InvalidArgumentException $ex) { $this->assertEquals($ex->getMessage(), "Id cannot be null"); } } catch (PayPalConnectionException $ex) { $this->markTestSkipped('Tests failing because of intermittent failures in Paypal Sandbox environment.' . $ex->getMessage()); } }
public function getCapture($captureId) { $apiContext = $this->contextFactory->createContext(); $capture = Capture::get($captureId, $apiContext); return $capture; }
$amt = new Amount(); $amt->setCurrency("USD")->setTotal("1.00"); // Create a capture $captureInfo = new Capture(); $captureInfo->setId($authId)->setAmount($amt); $capture = $authorization->capture($captureInfo, $apiContext); } catch (PayPal\Exception\PPConnectionException $ex) { echo "Exception: " . $ex->getMessage() . PHP_EOL; var_dump($ex->getData()); exit(1); } // ### Retrieve Capture details // You can look up a capture by invoking the Capture::get method // with a valid ApiContext (See bootstrap.php for more on `ApiContext`) try { $capture = Capture::get($capture->getId(), $apiContext); } catch (PayPal\Exception\PPConnectionException $ex) { echo "Exception: " . $ex->getMessage() . PHP_EOL; var_dump($ex->getData()); exit(1); } ?> <html> <head> <title>Lookup a capture</title> </head> <body> <div> Capture Id: <?php echo $capture->getId();
<?php // # GetCapture // This sample code demonstrates how you can lookup the details // of a captured payment. // API used: /v1/payments/capture/<$captureId> /** @var Capture $request */ $request = (require 'AuthorizationCapture.php'); use PayPal\Api\Capture; use PayPal\Api\Amount; use PayPal\Api\Authorization; // ### Retrieve Capture details // You can look up a capture by invoking the Capture::get method // with a valid ApiContext (See bootstrap.php for more on `ApiContext`) try { $capture = Capture::get($request->getId(), $apiContext); } catch (Exception $ex) { // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY ResultPrinter::printError("Get Captured Payment", "Capture", $request->getId(), null, $ex); exit(1); } // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY ResultPrinter::printResult("Get Captured Payment", "Capture", $capture->getId(), null, $capture);
/** * Creates (and processes) a new Capture Transaction added as a related resource. * * @param Capture $capture * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. * @return Capture */ public function capture($capture, $apiContext = null) { ArgumentValidator::validate($this->getId(), "Id"); ArgumentValidator::validate($capture, 'capture'); $payLoad = $capture->toJSON(); if ($apiContext == null) { $apiContext = new ApiContext(self::$credential); } $call = new PayPalRestCall($apiContext); $json = $call->execute(array('PayPal\\Handler\\RestHandler'), "/v1/payments/authorization/{$this->getId()}/capture", "POST", $payLoad); $ret = new Capture(); $ret->fromJson($json); return $ret; }
/** * Capture * * @param \Paypal\Api\Capture $capture * @param \PayPal\Rest\ApiContext|null $apiContext * * @return Capture * @throws \InvalidArgumentException */ public function capture($capture, $apiContext = null) { if ($this->getId() == null) { throw new \InvalidArgumentException("Id cannot be null"); } if ($capture == null) { throw new \InvalidArgumentException("capture cannot be null or empty"); } $payLoad = $capture->toJSON(); if ($apiContext == null) { $apiContext = new ApiContext(self::$credential); } $call = new PPRestCall($apiContext); $json = $call->execute(array('PayPal\\Rest\\RestHandler'), "/v1/payments/authorization/{$this->getId()}/capture", "POST", $payLoad); $ret = new Capture(); $ret->fromJson($json); return $ret; }
require __DIR__ . '/../bootstrap.php'; use PayPal\Api\Authorization; use PayPal\Api\Capture; use PayPal\Api\Refund; use PayPal\Api\Amount; use PayPal\Rest\ApiContext; try { // Create a mock authorization to get authorization Id $authId = createAuthorization($apiContext); // Get the authorization $authorization = Authorization::get($authId, $apiContext); // ### Capture $amt = new Amount(); $amt->setCurrency("USD")->setTotal("1.00"); // Create a capture $captureInfo = new Capture(); $captureInfo->setAmount($amt); $capture = $authorization->capture($captureInfo, $apiContext); } catch (PayPal\Exception\PPConnectionException $ex) { echo "Exception: " . $ex->getMessage() . PHP_EOL; var_dump($ex->getData()); exit(1); } // ### Refund // Create a refund object indicating // refund amount and call the refund method $refund = new Refund(); $refund->setAmount($amt); try { // Create a new apiContext object so we send a new // PayPal-Request-Id (idempotency) header for this resource
public function testOperations() { $authId = self::authorize(); $auth = Authorization::get($authId); $this->assertNotNull($auth->getId()); $amount = new Amount(); $amount->setCurrency("USD"); $amount->setTotal("1.00"); $captur = new Capture(); $captur->setId($authId); $captur->setAmount($amount); $capt = $auth->capture($captur); $this->assertNotNull($capt->getId()); $authId = self::authorize(); $auth = Authorization::get($authId); $void = $auth->void(); $this->assertNotNull($void->getId()); $auth->setId(null); try { $auth->void(); } catch (\InvalidArgumentException $ex) { $this->assertEquals($ex->getMessage(), "Id cannot be null"); } }
/** * Retrieve details about a captured payment by passing the capture_id in the request URI. * * @param string $captureId * @param 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 Capture */ public static function get($captureId, $apiContext = null, $restCall = null) { ArgumentValidator::validate($captureId, 'captureId'); $payLoad = ""; $json = self::executeCall("/v1/payments/capture/{$captureId}", "GET", $payLoad, null, $apiContext, $restCall); $ret = new Capture(); $ret->fromJson($json); return $ret; }
/** * Get * * @param int $captureId * @param \PayPal\Rest\ApiContext|null $apiContext * * @return Capture * @throws \InvalidArgumentException */ public static function get($captureId, $apiContext = null) { if ($captureId == null || strlen($captureId) <= 0) { throw new \InvalidArgumentException("captureId 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/capture/{$captureId}", "GET", $payLoad); $ret = new Capture(); $ret->fromJson($json); return $ret; }
/** * Capture a payment. In addition, include the amount of the payment and indicate whether this is a final capture for the given authorization in the body of the request JSON. * * @param Capture $capture * @param 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 Capture */ public function capture($capture, $apiContext = null, $restCall = null) { ArgumentValidator::validate($this->getId(), "Id"); ArgumentValidator::validate($capture, 'capture'); $payLoad = $capture->toJSON(); $json = self::executeCall("/v1/payments/orders/{$this->getId()}/capture", "POST", $payLoad, null, $apiContext, $restCall); $ret = new Capture(); $ret->fromJson($json); return $ret; }
$payment = (require __DIR__ . '/ExecutePayment.php'); use PayPal\Api\Amount; use PayPal\Api\Capture; // ### Approval Status // Determine if the user approved the payment or not if (isset($_GET['success']) && $_GET['success'] == 'true') { // ### Retrieve the order // OrderId could be retrieved by parsing the object inside related_resources. $transactions = $payment->getTransactions(); $transaction = $transactions[0]; $relatedResources = $transaction->getRelatedResources(); $relatedResource = $relatedResources[0]; $order = $relatedResource->getOrder(); // ### Create Capture Object // with Amount in it $capture = new Capture(); $capture->setIsFinalCapture(true); $capture->setAmount(new Amount('{ "total": "2.00", "currency": "USD" }')); try { // ### Capture Order // Capture the order by passing capture object we created. // We will get a new capture object back. $result = $order->capture($capture, $apiContext); // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY ResultPrinter::printResult("Captured Order", "Capture", $result->getId(), $capture, $result); } catch (Exception $ex) { // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY ResultPrinter::printError("Captured Order", "Capture", null, $capture, $ex);
// # AuthorizationCapture // This sample code demonstrates how you can capture // a previously authorized payment. // API used: /v1/payments/payment // https://developer.paypal.com/webapps/developer/docs/api/#capture-an-authorization /** @var Authorization $authorization */ $authorization = (require 'GetAuthorization.php'); use PayPal\Api\Amount; use PayPal\Api\Capture; use PayPal\Api\Authorization; // ### Capture Payment // You can capture and process a previously created authorization // by invoking the $authorization->capture method // with a valid ApiContext (See bootstrap.php for more on `ApiContext`) try { $authId = $authorization->getId(); $amt = new Amount(); $amt->setCurrency("USD")->setTotal(1); ### Capture $capture = new Capture(); $capture->setAmount($amt); // Perform a capture $getCapture = $authorization->capture($capture, $apiContext); } catch (Exception $ex) { // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY ResultPrinter::printError("Capture Payment", "Authorization", null, $capture, $ex); exit(1); } // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY ResultPrinter::printResult("Capture Payment", "Authorization", $getCapture->getId(), $capture, $getCapture); return $getCapture;
/** * Obtain the Capture transaction resource for the given identifier. * * @param string $captureId * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. * @return Capture */ public static function get($captureId, $apiContext = null) { ArgumentValidator::validate($captureId, 'captureId'); $payLoad = ""; if ($apiContext == null) { $apiContext = new ApiContext(self::$credential); } $call = new PayPalRestCall($apiContext); $json = $call->execute(array('PayPal\\Handler\\RestHandler'), "/v1/payments/capture/{$captureId}", "GET", $payLoad); $ret = new Capture(); $ret->fromJson($json); return $ret; }