Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- print_r('Receive...');
- $order = Order::where('hash', '=', $_GET['hash'])->where('hash_secret', '=', $_GET['hash_secret'])->first();
- if(empty($order)) {
- die();
- }
- $transaction = Transaction::where('transaction', '=', $_GET['transaction_hash'])->first();
- if(!isset($_GET['confirmations']) || empty($_GET['confirmations'])) {
- $_GET['confirmations'] = 0;
- }
- if(empty($transaction)) {
- $transaction = new Transaction();
- $transaction->transaction = $_GET['transaction_hash'];
- }
- $transaction->confirmations = $_GET['confirmations'];
- $transaction->received = $_GET['value'] / 100000000;
- $transaction->order_id = $order->id;
- $transaction->save();
- if($order->paid == false || $order->confirmed < Config::get()->confirmations) {
- $transactions = Transaction::where('order_id', '=', $order->id)->get();
- $total = 0;
- if($order->total_eur < 4) {
- $conformations = Config::get()->confirmations;
- foreach($transactions as $transaction) {
- $total += $transaction->received;
- }
- } else {
- $conformations = 1000;
- foreach($transactions as $transaction) {
- $total += $transaction->received;
- if($transaction->confirmations < $conformations) {
- $conformations = $transaction->confirmations;
- }
- }
- }
- $wasPaid = $order->paid;
- if($total < 0 || $order->total_btc < 0) {
- Log::wirte('order_error', array('total_btc'=>$order->total_btc, 'total_transaction'=>$total, 'order'=>$order->id, 'user'=>$order->user_id));
- die();
- }
- $difference = $order->total_btc - $total;
- if($difference <= 0.0002) {
- if($order->paid == false) {
- $records = $order->records()->get();
- foreach($records as $record) {
- $record->bought_at = timestamp();
- $record->save();
- }
- }
- $order->paid = true;
- }
- $order->confirmed = $conformations;
- $order->save();
- if($order->paid == true && $order->notified == false && Config::get()->confirmations <= $order->confirmed) {
- $order->notified = true;
- $order->save();
- // $product = Product::where('id', '=', $order->product_id)->first();
- // $seller = Seller::where('id', '=', $product->seller_id);
- //
- // $url = "https://blockchain.info/de/merchant/" . Config::get()->guid . "/payment?password=" . Config::get()->password . "&to=" . $seller->wallet . "&amount=''" . (($order->amount * $seller->percentage) * 100000000);
- // $url = "https://blockchain.info/de/merchant/" . Config::get()->guid . "/payment?password=" . Config::get()->password . "&to=" . $seller->wallet . "&amount=" . . "&from=" . $seller-> . "&fee=$fee¬e=$note";
- //$payment = new Payment();
- $product = Product::where('id', '=', $order->product_id)->first();
- if($product->type == 'storecredit') {
- $numRecords = $order->amount;
- while($numRecords--) {
- $record = new Record();
- $record->bought_at = timestamp();
- $record->redeemed_at = minutesAgo(60 * 72);
- $record->order_id = $order->id;
- $record->value = $product->format;
- $record->save();
- $value = json_decode($product->format, true);
- $btc = $value['Guthaben']['Wert'];
- $user = User::where('id', '=', $order->user_id)->first();
- if($btc > 0) {
- Log::write('credit', array('user'=>$user->id, 'value_eur'=> $value['Guthaben']['Wert'], 'value_btc'=> $btc, 'new'=> $user->credit + $value['Guthaben']['Wert'] * Config::get()->btc, 'old'=>$user->credit, 'raw'=>$product->format));
- $user->credit += $value['Guthaben']['Wert'];
- $user->save();
- } else {
- Log::write('credit_error', array('user'=>$user->id, 'value_eur'=> $value['Guthaben']['Wert'], 'value_btc'=> $btc, 'new'=> $user->credit + $value['Guthaben']['Wert'] * Config::get()->btc, 'old'=>$user->credit, 'raw'=>$product->format));}
- }
- }
- // $seller = Seller::where('id', '=', $product->seller_id)->first();
- // $payment->seller_id = $seller->id;
- // $payment->transaction_id = $transaction->id;
- // $payment->amount = $transaction->received;
- // $payment->paid = 0;
- // $payment->available_at = minutesAgo(-$product->replace_time);
- // $payment->save();
- // if($seller->email) {
- // $subject = 'Du hast etwas verkauft!';
- // $message = '';
- // $message .= "Produkt: {$product->name}\n";
- // $message .= "Menge: {$order->amount}\n";
- // $message .= 'Gesamtpreis: ' . floatToCurrency($order->total_eur) . "\n";
- // $message .= 'Dein Anteil: ' . floatToCurrency($order->total_eur * $seller->percentage) . '(' . $seller->percentage * 100 . ' %)' . "\n\n";
- // $message .= 'Das Geld wird auf deine angegebene Wallet (' . $seller->wallet . ') gesendet.';
- // sendMail($subject, $message, $seller->email);
- // }
- $user = User::where('id', '=', $order->user_id)->first();
- $mail = null;
- if($user && $user->email) {
- $mail = $user->email;
- }
- //Notification::add($user->user_id, 'order.complete', $order->id, array('order_id'=>$order->id, 'amount'=>$order->amount, 'product_name'=>$product->name));
- if($mail) {
- $subject = 'Deine Bestellung ' . $order->hash . ' ist bereit!';
- $message = '';
- $message .= "Bestellung: {$order->hash}\n";
- $message .= "Password: {$order->password}\n";
- $message .= "Produkt: {$product->name}\n";
- $message .= "Menge: {$order->amount}\n";
- $message .= "Link: " . Config::get()->url . '/details#hash=' . $order->hash . '&password=' . $order->password . "\n\n";
- $message .= 'Bitte beachte, dass sobald du einen der nachfolgenden Links öffnest, die Datensätze nur innerhalb von ' . Config::get()->replace_time . ' Minuten ersetzt werden können!' . "\n";
- foreach($records as $record) {
- $message .= 'Datensatz ' . $record->id . ': ' . Config::get()->url . '/action/record?hash=' . $order->hash . '&password=' . $order->password . '&record=' . $record->id . '&dl=true' . "\n";
- }
- $message .= "\n";
- $message .= 'Alle Datensätze: ' . Config::get()->url . '/action/record?hash=' . $order->hash . '&password=' . $order->password . '&dl=true' . "\n";
- sendMail($subject, $message, $mail);
- }
- }
- }
- print_r('Success');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement