public static function maybe_remove_deposit(SI_Payment $payment, SI_Checkouts $checkout) { $invoice_id = $payment->get_invoice_id(); $invoice = SI_Invoice::get_instance($invoice_id); $payment_amount = $payment->get_amount(); $invoice_deposit = $invoice->get_deposit(); if ($payment_amount >= $invoice_deposit) { // Reset the deposit since the payment made covers it. $invoice->set_deposit(''); } }
public function capture_payment(SI_Payment $payment) { // is this the right payment processor? does the payment still need processing? if ($payment->get_payment_method() == $this->get_payment_method() && $payment->get_status() != SI_Payment::STATUS_COMPLETE) { $data = $payment->get_data(); // Do we have a transaction ID to use for the capture? if (isset($data['api_response']['TRANSACTIONID']) && $data['api_response']['TRANSACTIONID']) { $transaction_id = $data['api_response']['TRANSACTIONID']; $post_data = $this->capture_nvp_data($transaction_id, $payment->get_amount(), $payment->get_invoice_id()); do_action('si_log', __CLASS__ . '::' . __FUNCTION__ . ' - PayPal EC DoCapture Request', $post_data); $response = wp_safe_remote_post($this->get_api_url(), array('httpversion' => '1.1', 'body' => $post_data, 'timeout' => apply_filters('http_request_timeout', 15), 'sslverify' => false)); if (!is_wp_error($response) && $response['response']['code'] == '200') { $response = wp_parse_args(wp_remote_retrieve_body($response)); do_action('si_log', __CLASS__ . '::' . __FUNCTION__ . ' - PayPal WPP DoCapture Response', $response); if (strpos($response['ACK'], 'Success') === 0) { $payment->set_status(SI_Payment::STATUS_COMPLETE); do_action('payment_complete', $payment); } else { $error = array('payment_id' => $payment->get_id(), 'response' => $response); do_action('si_error', __CLASS__ . '::' . __FUNCTION__ . ' - capture response error', $error); if ($response['L_ERRORCODE0'] == 10601 || 10602) { // authorization expired or authorization complete $payment->set_status(SI_Payment::STATUS_VOID); } } } } } }
public static function payment_data(SI_Payment $payment) { $payment_data = array('title' => $payment->get_title(), 'id' => $payment->get_id(), 'status' => $payment->get_status(), 'payment_method' => $payment->get_payment_method(), 'amount' => $payment->get_amount(), 'invoice_id' => $payment->get_invoice_id(), 'data' => $payment->get_data()); $invoice = SI_Invoice::get_instance($payment->get_invoice_id()); if (is_a($invoice, 'SI_Invoice')) { $payment_data['invoice_data'] = self::invoice_data($invoice); } return $payment_data; }
/** * Send the admin a notification when a payment is received. * @param SI_Payment $payment * @param array $args * @return */ public static function admin_payment_notification(SI_Payment $payment, $args = array()) { $payment_method = $payment->get_payment_method(); // A notification shouldn't be sent to the admin when s/he created it if ($payment_method == SI_Admin_Payment::PAYMENT_METHOD) { return; } $invoice_id = $payment->get_invoice_id(); $invoice = SI_Invoice::get_instance($invoice_id); if (!is_a($invoice, 'SI_Invoice')) { do_action('si_error', 'Admin Payment Notification Not Sent to Client; No Invoice Found: ' . $invoice_id, $payment->get_id()); return; } $client = $invoice->get_client(); // Admin email $data = array('payment' => $payment, 'invoice' => $invoice, 'client' => $client); $admin_to = self::admin_email($data); self::send_notification('payment_notification', $data, $admin_to); }