Exemplo n.º 1
0
 public function makeTransaction($amount, $description, $txid = NULL, $status = 1)
 {
     //status: 0 = error 1 = success 2 = pending
     $transaction = new Transaction();
     if ($txid == NULL) {
         // generating txid
         $txid = "";
         $seed = str_split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789');
         while (true) {
             shuffle($seed);
             foreach (array_rand($seed, 9) as $k) {
                 $txid .= $seed[$k];
             }
             try {
                 $t = Transaction::findorfail(array('txid', $txid));
             } catch (ModelNotFoundException $e) {
                 break;
             }
         }
     }
     // insert transaction record
     $transaction->txid = $txid;
     $transaction->user_id = $this->id;
     $transaction->amount = $amount;
     $transaction->description = $description;
     $transaction->status = $status;
     // process yeah
     $transaction->save();
 }