An authorization transaction.
Inheritance: extends PayPal\Common\PayPalResourceModel
Esempio n. 1
0
 public function testSerializeDeserialize()
 {
     $a1 = $this->authorizations['partial'];
     $a2 = new Authorization();
     $a2->fromJson($a1->toJson());
     $this->assertEquals($a1, $a2);
 }
Esempio n. 2
0
 /**
  * @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());
     }
 }
Esempio n. 3
0
 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());
 }
// # GetCapture
// This sample code demonstrates how you can lookup the details
// of a captured payment.
// API used: /v1/payments/capture/<$captureId>
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Capture;
use PayPal\Api\Amount;
use PayPal\Api\Authorization;
// ### Create a mock Capture
try {
    // create a mock authorization to get authorization Id
    // createAuthorization is defined in common.php
    $authId = createAuthorization($apiContext);
    // Lookup the authorization
    $authorization = Authorization::get($authId, $apiContext);
    ### 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`)
Esempio n. 5
0
 /**
  * Authorize an order by passing the order_id in the request URI. In addition, include an amount object in the body of the request JSON.
  *
  * @param Authorization $authorization Authorization Object with Amount value to be authorized
  * @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 Authorization
  */
 public function authorize($authorization, $apiContext = null, $restCall = null)
 {
     ArgumentValidator::validate($this->getId(), "Id");
     ArgumentValidator::validate($authorization, 'Authorization');
     $payLoad = $authorization->toJSON();
     $json = self::executeCall("/v1/payments/orders/{$this->getId()}/authorize", "POST", $payLoad, null, $apiContext, $restCall);
     $ret = new Authorization();
     $ret->fromJson($json);
     return $ret;
 }
Esempio n. 6
0
 /**
  * Shows details for an authorization, by ID.
  *
  * @param string $authorizationId
  * @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 Authorization
  */
 public static function get($authorizationId, $apiContext = null, $restCall = null)
 {
     ArgumentValidator::validate($authorizationId, 'authorizationId');
     $payLoad = "";
     $json = self::executeCall("/v1/payments/authorization/{$authorizationId}", "GET", $payLoad, null, $apiContext, $restCall);
     $ret = new Authorization();
     $ret->fromJson($json);
     return $ret;
 }
Esempio n. 7
0
 public function testReauthorize()
 {
     $authorization = Authorization::get('7GH53639GA425732B');
     $amount = new Amount();
     $amount->setCurrency("USD");
     $amount->setTotal("1.00");
     $authorization->setAmount($amount);
     try {
         $reauthorization = $authorization->reauthorize();
     } catch (PPConnectionException $ex) {
         $this->assertEquals(strpos($ex->getMessage(), "500"), false);
     }
 }
 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;
     }
 }
Esempio n. 9
0
$payment = (require __DIR__ . '/ExecutePayment.php');
use PayPal\Api\Amount;
use PayPal\Api\Authorization;
// ### 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 Authorization Object
    // with Amount in it
    $authorization = new Authorization();
    $authorization->setAmount(new Amount('{
            "total": "2.00",
            "currency": "USD"
        }'));
    try {
        // ### Authorize Order
        // Authorize the order by passing authorization object we created.
        // We will get a new authorization object back.
        $result = $order->authorize($authorization, $apiContext);
        // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
        ResultPrinter::printResult("Authorized Order", "Authorization", $result->getId(), $authorization, $result);
    } catch (Exception $ex) {
        // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
        ResultPrinter::printError("Authorized Order", "Authorization", null, $authorization, $ex);
        exit(1);
 /**
  * @group integration
  */
 public function testReauthorize()
 {
     $authorization = Authorization::get('7GH53639GA425732B');
     $amount = new Amount();
     $amount->setCurrency("USD");
     $amount->setTotal("1.00");
     $authorization->setAmount($amount);
     try {
         $authorization->reauthorize();
     } catch (PayPalConnectionException $ex) {
         //var_dump($ex->getMessage());
         $this->assertEquals(strpos($ex->getMessage(), "500"), false);
     }
     $authorization->setId(null);
     try {
         $authorization->reauthorize();
     } catch (\InvalidArgumentException $ex) {
         $this->assertEquals($ex->getMessage(), "Id cannot be null");
     }
 }
Esempio n. 11
0
 /**
  * Obtain the Authorization transaction resource for the given identifier.
  *
  * @param string $authorizationId
  * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
  * @return Authorization
  */
 public static function get($authorizationId, $apiContext = null)
 {
     ArgumentValidator::validate($authorizationId, 'authorizationId');
     $payLoad = "";
     if ($apiContext == null) {
         $apiContext = new ApiContext(self::$credential);
     }
     $call = new PayPalRestCall($apiContext);
     $json = $call->execute(array('PayPal\\Handler\\RestHandler'), "/v1/payments/authorization/{$authorizationId}", "GET", $payLoad);
     $ret = new Authorization();
     $ret->fromJson($json);
     return $ret;
 }
 /**
  * Void
  *
  * @param \PayPal\Rest\ApiContext|null $apiContext
  *
  * @return Authorization
  * @throws \InvalidArgumentException
  */
 public function void($apiContext = null)
 {
     if ($this->getId() == null) {
         throw new \InvalidArgumentException("Id cannot be null");
     }
     $payLoad = "";
     if ($apiContext == null) {
         $apiContext = new ApiContext(self::$credential);
     }
     $call = new PPRestCall($apiContext);
     $json = $call->execute(array('PayPal\\Rest\\RestHandler'), "/v1/payments/authorization/{$this->getId()}/void", "POST", $payLoad);
     $ret = new Authorization();
     $ret->fromJson($json);
     return $ret;
 }
Esempio n. 13
0
<?php

// ##Reauthorization Sample
// Sample showing how to do a reauthorization
// API used: v1/payments/authorization/{authorization_id}/reauthorize
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Authorization;
use PayPal\Api\Amount;
use PayPal\Exception\PPConnectionException;
// ###Reauthorization
// Retrieve a authorization id from authorization object
// by making a `Payment Using PayPal` with intent
// as `authorize`. You can reauthorize a payment only once 4 to 29
// days after 3-day honor period for the original authorization
// expires.
$authorization = Authorization::get('7GH53639GA425732B', $apiContext);
$amount = new Amount();
$amount->setCurrency("USD");
$amount->setTotal("1.00");
$authorization->setAmount($amount);
try {
    $reauthorization = $authorization->reauthorize($apiContext);
} catch (PPConnectionException $ex) {
    echo "Exception: " . $ex->getMessage() . PHP_EOL;
    var_dump($ex->getData());
    exit(1);
}
?>
<html>
<body>
	<div>
Esempio n. 14
0
<?php

// # GetAuthorization
// This sample code demonstrates how you can get details
// of an authorized payment.
// API used: /v1/payments/authorization/<$authorizationId>
/** @var Authorization $authorization */
$authorization = (require 'AuthorizePayment.php');
$authorizationId = $authorization->getId();
use PayPal\Api\Authorization;
// ### GetAuthorization
// You can retrieve info about an Authorization
// by invoking the Authorization::get method
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
// The return object contains the authorization state.
try {
    // Retrieve the authorization
    $result = Authorization::get($authorizationId, $apiContext);
} catch (Exception $ex) {
    // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
    ResultPrinter::printError("Get Authorization", "Authorization", null, null, $ex);
    exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Get Authorization", "Authorization", $authorizationId, null, $result);
return $result;
Esempio n. 15
0
 /**
  * @dataProvider mockProvider
  * @param Authorization $obj
  */
 public function testReauthorize($obj, $mockApiContext)
 {
     $mockPPRestCall = $this->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock();
     $mockPPRestCall->expects($this->any())->method('execute')->will($this->returnValue(self::getJson()));
     $result = $obj->reauthorize($mockApiContext, $mockPPRestCall);
     $this->assertNotNull($result);
 }
Esempio n. 16
0
 public function voidAuthorizedTransactionRequest(Authorization $authorization)
 {
     $apiContext = $this->contextFactory->createContext();
     return $authorization->void($apiContext);
 }