public static function PM_transaction_o_complete()
 {
     $id = Core::validate($_GET['id']);
     $hash = Core::validate($_GET['hash']);
     $at = new AtPm();
     if (!$at->findById($id)) {
         header('Location: ' . URL_WRONG_DATA_INPUT);
         exit;
     }
     if ($hash != self::hash_for_money_output_link($at->getId(), $at->getUID())) {
         header('Location: ' . URL_WRONG_DATA_INPUT);
         exit;
     }
     $amount = $at->getAmount();
     $wallets = self::PM_MinAndMaxWallets($at->getUnits());
     if ($wallets['max'] == null || $wallets['max']['current_balance'] < $amount) {
         header('Location: ' . URL_SERVER_ERROR);
         exit;
     }
     $wallet = new WalletsPm();
     $wallet->findById($wallets['max']['id']);
     $perfectMoney = new PerfectMoney();
     $perfectMoney->setAccountID($wallet->getAccountId());
     $perfectMoney->setPassPhrase($wallet->getPassPhrase());
     $resp = $perfectMoney->transfer($wallet->getAccount(), $at->getPayeeAccount(), $amount, 'Transfer from bitmonex', false);
     if ($resp == null) {
         header('Location: ' . URL_SERVER_ERROR);
         exit;
     }
     $currency = new Currency();
     $currency->findBy(array('Name' => $at->getUnits()));
     $limits = self::transactionLimits($currency->getId(), 'PM', 1);
     $feeVolume = $amount * $limits['fee'];
     $feeVolume = Core::round_up($feeVolume, 2);
     $purses = Purse::findBy(array('UID' => $at->getUID(), 'CurId' => $currency->getId()));
     $purse = new Purse();
     $purse->findById($purses[0]['id']);
     $purse->addValue(-($amount + $feeVolume));
     $purse->save();
     $systemFeeVolume = $amount * $limits['system_fee'];
     $systemFeeVolume = Core::round_up($systemFeeVolume, 2);
     $profit = ($feeVolume - $systemFeeVolume) * $wallet->getShare();
     $wallet->setProfit($wallet->getProfit() + $profit);
     $wallet->save();
     $at->setStatus(1);
     $at->setPayerAccount($wallet->getAccount());
     $at->setBatchNum($resp['PAYMENT_BATCH_NUM']);
     $at->setTimestamp(Core::timestamp_gmp());
     $at->save();
     header('Location: ' . URL_SUCCESS_PAYMENT);
 }