Exemple #1
0
 public function index($s = null)
 {
     $greencoin = new Greencoin('http://' . GREENCOIN_WALLET_SERVER . ':' . GREENCOIN_WALLET_PORT, GREENCOIN_WALLET_USERNAME, GREENCOIN_WALLET_PASSWORD);
     $paytxfee = Parameters::find('first');
     $txfee = $paytxfee['payxgctxfee'];
     $getrawtransaction = $greencoin->getrawtransaction($s);
     $decoderawtransaction = $greencoin->decoderawtransaction($getrawtransaction);
     foreach ($decoderawtransaction['vout'] as $out) {
         foreach ($out['scriptPubKey']['addresses'] as $address) {
             $username = $greencoin->getaccount($address);
             $Amount = (double) $out['value'];
             if ($greencoin->getaccount($address) != "") {
                 $Transactions = Transactions::find('first', array('conditions' => array('TransactionHash' => $s)));
                 if ($Transactions['_id'] == "") {
                     $t = Transactions::create();
                     $Amount = $Amount;
                     $comment = "Move from User: "******"; Address: " . GREENCOINX_ADDRESS . "; Amount:" . $Amount . ";";
                     $transfer = $greencoin->sendfrom($username, GREENCOINX_ADDRESS, (double) $Amount, (int) 0, $comment);
                     if (isset($transfer['error'])) {
                         $error = $transfer['error'];
                     } else {
                         $error = $transfer;
                     }
                     $data = array('DateTime' => new \MongoDate(), 'TransactionHash' => $s, 'username' => $username, 'address' => $address, 'Currency' => 'XGC', 'Amount' => $Amount, 'Added' => true, 'Transfer' => $comment);
                     $t->save($data);
                     $userName = str_replace("SiiCrypto-", "", $username);
                     $details = Details::find('first', array('conditions' => array('username' => (string) $userName)));
                     $dataDetails = array('balance.XGC' => (double) ((double) $details['balance.XGC'] + (double) $Amount), 'XGCnewaddress' => 'Yes');
                     $details = Details::find('all', array('conditions' => array('username' => (string) $userName)))->save($dataDetails);
                 } else {
                     $Transactions = Transactions::find('first', array('conditions' => array('TransactionHash' => $s)))->save($data);
                 }
             }
         }
     }
 }
 public function PrepareTransaction()
 {
     $user = Session::read('default');
     if ($user == "") {
         return $this->redirect('wallet::login');
     }
     $wallet = Users::find("first", array("conditions" => array("walletid" => $user['walletid'])));
     $greencoinAddress = $wallet['greencoinAddress'][0];
     $addresses = Addresses::find("first", array('conditions' => array('a_id' => $greencoinAddress)));
     $balance = $addresses['balance'] / 100000000;
     $address = $this->request->query['address'];
     $email = $this->request->query['email'];
     $phone = $this->request->query['phone'];
     $privKey = $this->request->query['priv'];
     $totalSendXGC = $this->request->query['totalSendXGC'];
     $greencoin = new Greencoin('http://' . GREENCOIN_WALLET_SERVER . ':' . GREENCOIN_WALLET_PORT, GREENCOIN_WALLET_USERNAME, GREENCOIN_WALLET_PASSWORD);
     $listunspent = $greencoin->listunspent();
     if (count($listunspent) == 0) {
         return $this->render(array('json' => array('success' => 0)));
     } else {
         $i = 0;
         $finalListUnspent = array();
         $finallistunspent = array();
         foreach ($listunspent as $ls) {
             if ($ls['address'] == $address) {
                 array_push($finalListUnspent, $ls);
             }
         }
     }
     $totalCalculated = 0;
     $balance = 0;
     foreach ($finalListUnspent as $lu) {
         if ($totalCalculated < $totalSendXGC) {
             $totalCalculated = $totalCalculated + $lu['amount'];
             $balance = $balance + $lu['amount'];
             array_push($finallistunspent, $lu);
         }
     }
     //			print_r($finallistunspent);
     if (count($finallistunspent) == 0) {
         return $this->render(array('json' => array('success' => 0)));
     }
     $passon = $this->request->query['passon'];
     $fee = $this->request->query['fee'];
     $passonArray = split(",", $passon);
     $SendTo = array();
     foreach ($passonArray as $pa) {
         $S = split("#", $pa);
         array_push($SendTo, $S);
     }
     $createData = array();
     $amount = 0;
     foreach ($SendTo as $st) {
         $amount = $amount + $st[1];
     }
     $amount = $amount + $fee;
     $lastCreateList = array();
     $finalCreate = array();
     $k = 0;
     foreach ($finallistunspent as $fc) {
         $lastCreateList[$k]['txid'] = $fc['txid'];
         $lastCreateList[$k]['vout'] = $fc['vout'];
         $k++;
     }
     array_push($finalCreate, $lastCreateList);
     if ((double) round($balance - $amount - $fee, 8) > 0) {
         $createData = array($greencoinAddress => (double) round($balance - $amount - $fee, 8));
     }
     foreach ($SendTo as $st) {
         $createData = array_merge($createData, array($st[0] => (double) $st[1]));
     }
     //		print_r($createData);
     $createrawtransaction = $greencoin->createrawtransaction((array) $lastCreateList, (array) $createData);
     //		print_r($createrawtransaction);
     $decoderawtransaction = $greencoin->decoderawtransaction($createrawtransaction);
     //		print_r($decoderawtransaction);
     $finalSignList = array();
     $k = 0;
     foreach ($decoderawtransaction['vout'] as $decodevout) {
         $finalSignList[$k]['txid'] = $decoderawtransaction['txid'];
         $finalSignList[$k]['vout'] = $decodevout['n'];
         $finalSignList[$k]['scriptPubKey'] = $decodevout['scriptPubKey']['hex'];
         $k++;
     }
     //		print_r($createrawtransaction);
     //		print_r($finalSignList);
     //		print_r($privKey);
     $signrawtransaction = $greencoin->signrawtransaction($createrawtransaction, $finalSignList, array($privKey));
     if ($signrawtransaction['complete'] != 1) {
         return $this->render(array('json' => array('success' => 0)));
     } else {
         $sendrawtransaction = $greencoin->sendrawtransaction($signrawtransaction['hex']);
     }
     if (strlen($sendrawtransaction) == 64) {
         return $this->render(array('json' => array('success' => 1, 'txid' => $sendrawtransaction)));
     }
     $data = array('walletid' => $user['walletid'], 'rawtransaction' => $createrawtransaction, 'sendtransaction' => $sendrawtransaction, 'signlist' => $finalSignList, 'signed' => 'No', 'email' => $email, 'phone' => $phone, 'created' => new \MongoDate());
     $transactions = Transactions::create($data)->save();
     return $this->render(array('json' => $rawtransaction));
 }
Exemple #3
0
 public function withdraw()
 {
     $title = "Withdraw";
     $user = Session::read('default');
     if ($user == "") {
         return $this->redirect('/login');
     }
     $id = $user['_id'];
     $details = Details::find('first', array('conditions' => array('user_id' => (string) $id)));
     if ($this->request->data) {
         $AccountName = $this->request->data['AccountName'];
         $SortCode = $this->request->data['SortCode'];
         $AccountNumber = $this->request->data['AccountNumber'];
         $AccountNameBuss = $this->request->data['AccountNameBuss'];
         $SortCodeBuss = $this->request->data['SortCodeBuss'];
         $AccountNumberBuss = $this->request->data['AccountNumberv'];
         $CompanyNameBuss = $this->request->data['CompanyNameBuss'];
         $CompanyNumberBuss = $this->request->data['CompanyNumberBuss'];
         $PostalName = $this->request->data['PostalName'];
         $PostalStreet = $this->request->data['PostalStreet'];
         $PostalCity = $this->request->data['PostalCity'];
         $PostalAddress = $this->request->data['PostalAddress'];
         $PostalZip = $this->request->data['PostalZip'];
         $PostalCountry = $this->request->data['PostalCountry'];
         $WithdrawalMethod = $this->request->data['WithdrawalMethod'];
         $WithdrawalCharges = $this->request->data['WithdrawalCharges'];
         $amountFiat = $this->request->data['WithdrawAmountFiat'];
         $Currency = $this->request->data['WithdrawCurrency'];
         $Reference = $this->request->data['WithdrawReference'];
         $okpayEmail = $this->request->data['okpay_email'];
         $data = array('DateTime' => new \MongoDate(), 'username' => $details['username'], 'Amount' => (double) $amountFiat, 'Currency' => $Currency, 'Added' => false, 'Reference' => $Reference, 'AccountName' => $AccountName, 'SortCode' => $SortCode, 'AccountNumber' => $AccountNumber, 'AccountNameBuss' => $AccountNameBuss, 'SortCodeBuss' => $SortCodeBuss, 'AccountNumberBuss' => $AccountNumberBuss, 'CompanyNumberBuss' => $CompanyNumberBuss, 'CompanyNameBuss' => $CompanyNameBuss, 'WithdrawalMethod' => $WithdrawalMethod, 'WithdrawalCharges' => $WithdrawalCharges, 'okpayEmail' => $okpayEmail, 'Postal' => array('Name' => $PostalName, 'Address' => $PostalAddress, 'Street' => $PostalStreet, 'City' => $PostalCity, 'Zip' => $PostalZip, 'Country' => $PostalCountry), 'Approved' => 'No');
         $tx = Transactions::create();
         $tx->save($data);
         $view = new View(array('loader' => 'File', 'renderer' => 'File', 'paths' => array('template' => '{:library}/views/{:controller}/{:template}.{:type}.php')));
         $body = $view->render('template', compact('details', 'data', 'user'), array('controller' => 'users', 'template' => 'withdraw', 'type' => 'mail', 'layout' => false));
         $transport = Swift_MailTransport::newInstance();
         $mailer = Swift_Mailer::newInstance($transport);
         $message = Swift_Message::newInstance();
         $message->setSubject("Withdraw from " . COMPANY_URL);
         $message->setFrom(array(NOREPLY => 'Withdraw from ' . COMPANY_URL));
         $message->setTo($user['email']);
         $message->addBcc(MAIL_1);
         $message->addBcc(MAIL_2);
         $message->addBcc(MAIL_3);
         $message->setBody($body, 'text/html');
         $mailer->send($message);
     }
     return compact('title', 'details', 'data', 'user');
 }
 public function ok(Request $request)
 {
     $data = session('product_info');
     if ($request->has('paymentId') && $request->has('PayerID')) {
         $payment = Paypalpayment::getById($request->input('paymentId'), $this->_apiContext);
         $execution = Paypalpayment::PaymentExecution();
         $execution->setPayerId($request->input('PayerID'));
         $payment->execute($execution, $this->_apiContext);
     } else {
         return redirect('paypal/error');
     }
     $payment = Paypalpayment::getById($request->input('paymentId'), $this->_apiContext);
     $lastId = Transactions::create(['paymentId' => $payment->id, 'cart' => $payment->cart, 'payer_email' => $payment->payer->payer_info->email, 'payer_first_name' => $payment->payer->payer_info->first_name, 'payer_last_name' => $payment->payer->payer_info->last_name, 'payer_id' => $payment->payer->payer_info->payer_id, 'shipping_recipient_name' => $payment->payer->payer_info->shipping_address->recipient_name, 'shipping_city' => $payment->payer->payer_info->shipping_address->city, 'country_code' => $payment->payer->payer_info->country_code, 'amount_total' => $payment->transactions[0]->amount->total, 'invoice_number' => $payment->transactions[0]->invoice_number]);
     $lastId = $lastId->id;
     foreach ($payment->transactions[0]->item_list->items as $item) {
         $qart_info = $data[$item->description]['qart_info'];
         DB::table('shopping_card')->where('id', '=', $qart_info)->delete();
         $product = DB::table('products')->where('id', $item->description)->get();
         $productNewQuantity = $product[0]->quantity - $item->quantity;
         DB::table('products')->where('id', $item->description)->update(['quantity' => $productNewQuantity]);
         PurchasedProducts::create(['transaction_id' => $lastId, 'product_name' => $item->name, 'quantity' => $item->quantity, 'description' => $item->description, 'tax' => $item->tax]);
     }
     Session::forget('product_info');
     return redirect('/')->with('message', 'Everything ok');
 }