Advertisement
Guest User

CashBill BartQ

a guest
Jul 27th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.78 KB | None | 0 0
  1. <?php
  2. class CashBill_SMS {
  3.     private static $CASHBILL_URL = "https://sms.cashbill.pl/code";
  4.     private $token, $connection;
  5.     public function __construct($token) {
  6.         $this->token = $token;
  7.         $this->connection = curl_init ();
  8.     }
  9.     public function validateCode($code) {
  10.         curl_setopt_array ( $this->connection, array (
  11.                 CURLOPT_URL => self::$CASHBILL_URL . "/" . $this->token . "/" . $code,
  12.                 CURLOPT_RETURNTRANSFER => true
  13.         ) );
  14.        
  15.         return json_decode ( curl_exec ( $this->connection ) );
  16.     }
  17.     function __destruct() {
  18.         curl_close ( $this->connection );
  19.     }
  20. }
  21.  
  22. $cashbill_token = "Twój Token";
  23.  
  24. $cashbill_configuration = array (
  25.        
  26.         "71XX" => array (
  27.                 "name" => "TEST NAME 1",
  28.                 "withoutTax" => 2.00,
  29.                 "withTax" => 2.46,
  30.                 "description" => "Treść SMS'a CashBill",
  31.                 "userGain" => 1
  32.         ),
  33.         "74XX" => array (
  34.                 "name" => "TEST NAME 2",
  35.                 "withoutTax" => 4.00,
  36.                 "withTax" => 4.92,
  37.                 "description" => "Treść SMS'a CashBill",
  38.                 "userGain" => 2
  39.         )
  40. );
  41.  
  42. $cashbill = new CashBill_SMS ( $cashbill_token );
  43.  
  44. if (isset ( $_POST ['code'] )) {
  45.    
  46.     $codeInfo = $cashbill->validateCode ( $_POST ['code'] );
  47.    
  48.     if (isset ( $codeInfo->error )) {
  49.         echo '<div class="alert alert-dismissable alert-warning">
  50.                     <button type="button" class="close" data-dismiss="alert">×</button>
  51.                     <p>Wpisałeś zły kod.</p>
  52.                 </div>';
  53.     } else if ($codeInfo->active == true) {
  54.        
  55.         $serviceData = $cashbill_configuration [$codeInfo->number];
  56.        
  57.         echo '<div class="alert alert-dismissable alert-success">
  58.                     <button type="button" class="close" data-dismiss="alert">×</button>
  59.                     <p>Doładowałeś konto swoje konto o ' . $serviceData ['userGain'] . ' pkt</p>
  60.                 </div>';
  61.         $LS->updateUser ( array (
  62.                 "portfel" => "portfel" + $serviceData ['userGain']
  63.         ) );
  64.     } else {
  65.        
  66.         echo '<div class="alert alert-dismissable alert-warning">
  67.                     <button type="button" class="close" data-dismiss="alert">×</button>
  68.                     <p>Podany kod został już wykorzystany.</p>
  69.               </div>';
  70.     }
  71. }
  72.  
  73. ?>
  74. <table class="table table-striped table-hover ">
  75.     <thead>
  76.         <tr>
  77.             <th>Numer smsa</th>
  78.             <th>Treść smsa</th>
  79.             <th>Koszt smsa</th>
  80.             <th>Dostaniesz</th>
  81.         </tr>
  82.     </thead>
  83.     <tbody>
  84. <?php
  85. foreach ( $cashbill_configuration as $key => $v )
  86.     echo '<tr class="active">
  87.                 <td>' . $key . '</td>
  88.                 <td>' . $v ['description'] . '</td>
  89.                 <td>' . $v ['withouTax'] . 'zł+VAT (' . $v ['withTax'] . 'zł)</td>
  90.                 <td>' . $v ['userGain'] . ' zł</td>';
  91. ?>
  92.   </tbody>
  93. </table>
  94. <div class="text-center">
  95.     <form method="post" action="">
  96.         <input
  97.             style="border: 1px solid rgb(76, 175, 80); border-bottom-width: 2px; width: 150px;"
  98.             type="text" size="8" name="code"> <input class="btn btn-success"
  99.             type="submit" value="Doładuj konto">
  100.     </form>
  101. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement