| @@ -638,16 +638,21 @@ | ||
| 638 | 638 | ]; |
| 639 | 639 | |
| 640 | 640 | if (!empty($pending)) { |
| 641 | 641 | $payment_id = (int) $pending[0]; |
| 642 | - update_post_meta($payment_id, '_status', 'completed'); | |
| 643 | - update_post_meta($payment_id, '_transaction_id', '' !== $txn_id ? $txn_id : get_post_meta($payment_id, '_transaction_id', true)); | |
| 642 | + // The amount PayPal actually settled is written first: the record | |
| 643 | + // was created with the full balance, and listeners that react to | |
| 644 | + // `_status` becoming "completed" (Pro's Partial Payments, for one) | |
| 645 | + // read `_amount` to decide whether the invoice is settled. Flip | |
| 646 | + // the status first and a short payment reads as the full amount. | |
| 644 | 647 | if ($amount > 0) { |
| 645 | 648 | update_post_meta($payment_id, '_amount', $amount); |
| 646 | 649 | } |
| 650 | + update_post_meta($payment_id, '_transaction_id', '' !== $txn_id ? $txn_id : get_post_meta($payment_id, '_transaction_id', true)); | |
| 647 | 651 | update_post_meta($payment_id, '_payment_date', current_time('mysql')); |
| 648 | 652 | update_post_meta($payment_id, '_notes', __('Payment confirmed by PayPal', 'easy-invoice')); |
| 649 | 653 | update_post_meta($payment_id, '_gateway_response', wp_json_encode($gateway_response)); |
| 654 | + update_post_meta($payment_id, '_status', 'completed'); | |
| 650 | 655 | $this->log('Pending PayPal record #' . $payment_id . ' completed for txn ' . $txn_id); |
| 651 | 656 | |
| 652 | 657 | return $payment_id; |
| 653 | 658 | } |