setAmount() public method

The amount to capture. If the amount matches the orginally authorized amount, the state of the authorization changes to captured. If not, the state of the authorization changes to partially_captured.
public setAmount ( Amount $amount )
$amount Amount
Esempio n. 1
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. 2
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());
 }
// # 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;
Esempio n. 4
0
 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 capture_payment($payment, $order_id = '', $total = '', $final = true)
 {
     global $insert_id;
     if ($order_id == '') {
         $order_id = $insert_id;
     }
     // auth
     $apiContext = $this->apiContext();
     try {
         // get transaction
         $transactions = $payment->getTransactions();
         $transaction = $transactions[0];
         $relatedResources = $transaction->getRelatedResources();
         for ($i = 0, $n = count($relatedResources); $i < $n; $i++) {
             $relatedResource = $relatedResources[$i];
             if ($relatedResource->__isset('sale')) {
                 $resource = $relatedResource->getSale($relatedResource);
                 break;
             }
             if ($relatedResource->__isset('order')) {
                 $resource = $relatedResource->getOrder($relatedResource);
                 break;
             }
             if ($relatedResource->__isset('authorization')) {
                 $resource = $relatedResource->getAuthorization($relatedResource);
                 break;
             }
         }
         if (is_object($resource)) {
             $this->amount = $resource->getAmount();
             $this->amount->__unset('details');
             if ($total != '' && $total > 0) {
                 $this->amount->setTotal($total);
             }
             // set capture
             $capture = new Capture();
             $capture->setIsFinalCapture($final);
             $capture->setAmount($this->amount);
             try {
                 // capture
                 $resource->capture($capture, $apiContext);
                 $success = true;
             } catch (Exception $ex) {
                 $this->LoggingManager->log(print_r($ex, true), 'DEBUG');
                 $success = false;
                 if (defined('RUN_MODE_ADMIN') && $ex instanceof \PayPal\Exception\PayPalConnectionException) {
                     $error_json = $ex->getData();
                     $error = json_decode($error_json, true);
                     $_SESSION['pp_error'] = $error['message'];
                 }
             }
             if ($success === true) {
                 if ($this->order_status_capture < 0) {
                     $check_query = xtc_db_query("SELECT orders_status\n                                           FROM " . TABLE_ORDERS . " \n                                          WHERE orders_id = '" . (int) $order_id . "'");
                     $check = xtc_db_fetch_array($check_query);
                     $this->order_status_capture = $check['orders_status'];
                 }
                 $this->update_order(TEXT_PAYPAL_CAPTURED, $this->order_status_capture, $order_id);
             }
         }
     } catch (Exception $ex) {
         $this->LoggingManager->log(print_r($ex, true), 'DEBUG');
     }
 }
 /**
  * @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());
     }
 }
Esempio n. 7
0
// ### 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);
        exit(1);
    }
    return $result;
} else {
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
    $apiContext = getApiContext();
 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");
     }
 }