public function capture_payment($order_id)
{
$order = wc_get_order($order_id);
if ('paypal' === $order->get_payment_method() && 'pending' === get_post_meta($order->get_id(), '_paypal_status', true) && $order->get_transaction_id()) {
$this->init_api();
$result = WC_Gateway_Paypal_API_Handler::do_capture($order);
if (is_wp_error($result)) {
$this->log('Capture Failed: ' . $result->get_error_message());
$order->add_order_note(sprintf(__('Payment could not captured: %s', 'woocommerce'), $result->get_error_message()));
return;
}
$this->log('Capture Result: ' . print_r($result, true));
if (!empty($result->PAYMENTSTATUS)) {
switch ($result->PAYMENTSTATUS) {
case 'Completed':
$order->add_order_note(sprintf(__('Payment of %1$s was captured - Auth ID: %2$s, Transaction ID: %3$s', 'woocommerce'), $result->AMT, $result->AUTHORIZATIONID, $result->TRANSACTIONID));
update_post_meta($order->get_id(), '_paypal_status', $result->PAYMENTSTATUS);
update_post_meta($order->get_id(), '_transaction_id', $result->TRANSACTIONID);
break;
default:
$order->add_order_note(sprintf(__('Payment could not captured - Auth ID: %1$s, Status: %2$s', 'woocommerce'), $result->AUTHORIZATIONID, $result->PAYMENTSTATUS));
break;
}
}
}
}