Indicates whether to release all remaining funds that the authorization holds in the funding instrument. Default is false.
public setIsFinalCapture ( boolean $is_final_capture ) | ||
$is_final_capture | boolean |
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'); } }
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); exit(1);