コード例 #1
0
ファイル: payments-api.php プロジェクト: sabdev1/ljcdevsab
 /**
  * Handler for awpcp-transaction-status-updated action
  *
  * XXX: Make sure the user has enough credit to pay for the plans.
  *  We already check that at the beginning of the transaction but I
  *  think is necessary to check again here.
  *  We need a way to mark individual items as paid or unpaid so
  *  other parts of the plugin can decide what to do.
  */
 public function update_account_balance($transaction)
 {
     if (awpcp_user_is_admin($transaction->user_id)) {
         return;
     }
     if ($transaction->payment_is_completed() || $transaction->payment_is_pending()) {
         $this->maybe_increase_account_balance($transaction);
     }
     if ($transaction->was_payment_successful() && $transaction->is_completed()) {
         $this->maybe_decrease_account_balance($transaction);
     }
 }
コード例 #2
0
 public function user_has_enough_credit(&$balance = null)
 {
     if (awpcp_current_user_is_admin()) {
         return true;
     }
     if (awpcp_user_is_admin($this->user_id)) {
         return true;
     }
     $totals = $this->get_totals();
     $credits = $totals['credits'];
     // no need for credits
     if ($credits === 0) {
         return true;
     }
     $payments = awpcp_payments_api();
     if (!$payments->is_credit_accepted()) {
         return false;
     }
     $balance = $payments->get_account_balance($this->user_id);
     $plan = $payments->get_credit_plan($this->get('credit-plan'));
     $balance = $balance - $credits;
     if ($balance < 0) {
         if (is_null($plan)) {
             return false;
         }
         $balance = $balance + $plan->credits;
         if ($balance < 0) {
             return false;
         }
     }
     return true;
 }