Exemplo n.º 1
0
 public function reciver($data, $system, $status, $mr)
 {
     if ($system) {
         $merchant = \Money\Merchant::get($system, 'object_name');
     } else {
         $merchant = false;
     }
     if ($merchant) {
         $this->currentMerchant = $system;
     }
     $className = 'Money\\MerchantHelper\\' . $this->currentMerchant;
     $result = $className::reciver($data, $status);
     $result['pay'] = null;
     if (!empty($result['payId'])) {
         $result['pay'] = Money\Pay::get($result['payId']);
         $mr->pay_id = $result['payId'];
     }
     if ($result['pay'] && $result['pay']->pay_status_id == 1) {
         $statuses = \Money\Pay\Status::getList(['key' => 'code']);
         if (!empty($statuses[$result['status']])) {
             $result['pay']->pay_status_id = $statuses[$result['status']]->id;
         }
         $result['pay']->date_recive = date('Y-m-d H:i:s');
         $result['pay']->save();
         if ($result['status'] == 'success' && $result['pay']->callback_module && $result['pay']->callback_method) {
             App::$cur->{$result['pay']->callback_module}->{$result['pay']->callback_method}($result);
         }
     }
     if (!empty($result['callback'])) {
         echo $result['callback'];
         $mr->result_callback = $result['callback'];
     }
     if (!empty($result['status'])) {
         $mr->status = $result['status'];
     }
     $mr->save();
 }
Exemplo n.º 2
0
 public function walletPayAction($payId, $walletId)
 {
     $pay = Money\Pay::get((int) $payId);
     if (!$pay || $pay->user_id != \Users\User::$cur->id) {
         Tools::redirect('/money/merchants/pay/', 'Такой счет не найден');
     }
     $wallet = Money\Wallet::get((int) $walletId);
     if (!$wallet || $wallet->user_id != \Users\User::$cur->id) {
         Tools::redirect('/money/merchants/pay/' . $pay->id, 'Такой кошелек не найден');
     }
     if ($pay->currency_id != $wallet->currency_id) {
         $rate = \Money\Currency\ExchangeRate::get([['currency_id', $wallet->currency_id], ['target_currency_id', $pay->currency_id]]);
         if (!$rate) {
             Tools::redirect('/money/merchants/pay/' . $pay->id, 'Нет возможности оплатить счет в валюте ' . $pay->currency->name() . ' валютой ' . $wallet->currency->name());
         }
         $sum = $pay->sum / $rate->rate;
     } else {
         $sum = $pay->sum;
     }
     if ($sum > $wallet->amount) {
         Tools::redirect('/money/merchants/pay/' . $pay->id, 'На вашем счете недостаточно средств', 'danger');
     }
     $wallet->diff(-$sum, 'Оплата счета №' . $payId);
     $statuses = \Money\Pay\Status::getList(['key' => 'code']);
     if (!empty($statuses['success'])) {
         $pay->pay_status_id = $statuses['success']->id;
     }
     $pay->date_recive = date('Y-m-d H:i:s');
     $pay->save();
     if ($pay->callback_module && $pay->callback_method) {
         App::$cur->{$pay->callback_module}->{$pay->callback_method}(['status' => 'success', 'payId' => $pay->id, 'pay' => $pay]);
     }
     Tools::redirect('/users/cabinet', 'Вы успешно оплатили счет', 'success');
 }