Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.69 KB | None | 0 0
  1. <?php
  2. print_r('Receive...');
  3. $order = Order::where('hash', '=', $_GET['hash'])->where('hash_secret', '=', $_GET['hash_secret'])->first();
  4. if(empty($order)) {
  5. die();
  6. }
  7. $transaction = Transaction::where('transaction', '=', $_GET['transaction_hash'])->first();
  8.  
  9. if(!isset($_GET['confirmations']) || empty($_GET['confirmations'])) {
  10. $_GET['confirmations'] = 0;
  11. }
  12.  
  13. if(empty($transaction)) {
  14. $transaction = new Transaction();
  15. $transaction->transaction = $_GET['transaction_hash'];
  16. }
  17. $transaction->confirmations = $_GET['confirmations'];
  18. $transaction->received = $_GET['value'] / 100000000;
  19. $transaction->order_id = $order->id;
  20. $transaction->save();
  21.  
  22. if($order->paid == false || $order->confirmed < Config::get()->confirmations) {
  23. $transactions = Transaction::where('order_id', '=', $order->id)->get();
  24. $total = 0;
  25.  
  26. if($order->total_eur < 4) {
  27. $conformations = Config::get()->confirmations;
  28. foreach($transactions as $transaction) {
  29. $total += $transaction->received;
  30. }
  31. } else {
  32. $conformations = 1000;
  33. foreach($transactions as $transaction) {
  34. $total += $transaction->received;
  35. if($transaction->confirmations < $conformations) {
  36. $conformations = $transaction->confirmations;
  37. }
  38. }
  39. }
  40.  
  41. $wasPaid = $order->paid;
  42.  
  43. if($total < 0 || $order->total_btc < 0) {
  44. Log::wirte('order_error', array('total_btc'=>$order->total_btc, 'total_transaction'=>$total, 'order'=>$order->id, 'user'=>$order->user_id));
  45. die();
  46. }
  47.  
  48. $difference = $order->total_btc - $total;
  49. if($difference <= 0.0002) {
  50. if($order->paid == false) {
  51. $records = $order->records()->get();
  52. foreach($records as $record) {
  53. $record->bought_at = timestamp();
  54. $record->save();
  55. }
  56.  
  57. }
  58.  
  59. $order->paid = true;
  60. }
  61.  
  62. $order->confirmed = $conformations;
  63. $order->save();
  64.  
  65. if($order->paid == true && $order->notified == false && Config::get()->confirmations <= $order->confirmed) {
  66. $order->notified = true;
  67. $order->save();
  68.  
  69. // $product = Product::where('id', '=', $order->product_id)->first();
  70. // $seller = Seller::where('id', '=', $product->seller_id);
  71. //
  72. // $url = "https://blockchain.info/de/merchant/" . Config::get()->guid . "/payment?password=" . Config::get()->password . "&to=" . $seller->wallet . "&amount=''" . (($order->amount * $seller->percentage) * 100000000);
  73. // $url = "https://blockchain.info/de/merchant/" . Config::get()->guid . "/payment?password=" . Config::get()->password . "&to=" . $seller->wallet . "&amount=" . . "&from=" . $seller-> . "&fee=$fee&note=$note";
  74.  
  75. //$payment = new Payment();
  76.  
  77. $product = Product::where('id', '=', $order->product_id)->first();
  78.  
  79. if($product->type == 'storecredit') {
  80. $numRecords = $order->amount;
  81. while($numRecords--) {
  82. $record = new Record();
  83. $record->bought_at = timestamp();
  84. $record->redeemed_at = minutesAgo(60 * 72);
  85. $record->order_id = $order->id;
  86. $record->value = $product->format;
  87. $record->save();
  88.  
  89. $value = json_decode($product->format, true);
  90. $btc = $value['Guthaben']['Wert'];
  91.  
  92. $user = User::where('id', '=', $order->user_id)->first();
  93.  
  94. if($btc > 0) {
  95. 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));
  96. $user->credit += $value['Guthaben']['Wert'];
  97. $user->save();
  98.  
  99. } else {
  100. 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));}
  101. }
  102. }
  103. // $seller = Seller::where('id', '=', $product->seller_id)->first();
  104.  
  105. // $payment->seller_id = $seller->id;
  106. // $payment->transaction_id = $transaction->id;
  107. // $payment->amount = $transaction->received;
  108. // $payment->paid = 0;
  109. // $payment->available_at = minutesAgo(-$product->replace_time);
  110. // $payment->save();
  111.  
  112. // if($seller->email) {
  113. // $subject = 'Du hast etwas verkauft!';
  114. // $message = '';
  115. // $message .= "Produkt: {$product->name}\n";
  116. // $message .= "Menge: {$order->amount}\n";
  117. // $message .= 'Gesamtpreis: ' . floatToCurrency($order->total_eur) . "\n";
  118. // $message .= 'Dein Anteil: ' . floatToCurrency($order->total_eur * $seller->percentage) . '(' . $seller->percentage * 100 . ' %)' . "\n\n";
  119. // $message .= 'Das Geld wird auf deine angegebene Wallet (' . $seller->wallet . ') gesendet.';
  120. // sendMail($subject, $message, $seller->email);
  121. // }
  122.  
  123. $user = User::where('id', '=', $order->user_id)->first();
  124. $mail = null;
  125. if($user && $user->email) {
  126. $mail = $user->email;
  127. }
  128.  
  129. //Notification::add($user->user_id, 'order.complete', $order->id, array('order_id'=>$order->id, 'amount'=>$order->amount, 'product_name'=>$product->name));
  130.  
  131. if($mail) {
  132. $subject = 'Deine Bestellung ' . $order->hash . ' ist bereit!';
  133. $message = '';
  134. $message .= "Bestellung: {$order->hash}\n";
  135. $message .= "Password: {$order->password}\n";
  136. $message .= "Produkt: {$product->name}\n";
  137. $message .= "Menge: {$order->amount}\n";
  138. $message .= "Link: " . Config::get()->url . '/details#hash=' . $order->hash . '&password=' . $order->password . "\n\n";
  139. $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";
  140.  
  141. foreach($records as $record) {
  142. $message .= 'Datensatz ' . $record->id . ': ' . Config::get()->url . '/action/record?hash=' . $order->hash . '&password=' . $order->password . '&record=' . $record->id . '&dl=true' . "\n";
  143. }
  144.  
  145. $message .= "\n";
  146. $message .= 'Alle Datensätze: ' . Config::get()->url . '/action/record?hash=' . $order->hash . '&password=' . $order->password . '&dl=true' . "\n";
  147. sendMail($subject, $message, $mail);
  148. }
  149. }
  150. }
  151. print_r('Success');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement