Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.97 KB | None | 0 0
  1. <?php
  2.    
  3.     if(isset($_POST['generatePayment'])) {
  4.         $shopId             = intval(111);
  5.         $description        = strval('Opłata za fakturę');
  6.         $control            = strval(1234576948);
  7.         $price              = floatval(100);
  8.         $notifyURL          = strval('xxxxx');
  9.         $returnUrlSuccess   = strval('xxxxx');
  10.         $hash               = 'hash';
  11.      
  12.         $data   = $hash . "|" . $shopId . "|" . sprintf("%.2f", $price);
  13.      
  14.         if ($control != null && $control != "") {
  15.             $data .= "|" . $control;
  16.         }
  17.      
  18.         if ($description != null && $description != "") {
  19.             $data .= "|" . $description;
  20.         }
  21.      
  22.         if ($notifyURL != null && $notifyURL != "") {
  23.             $data .= "|" . $notifyURL;
  24.         }
  25.      
  26.         if ($returnUrlSuccess != null && $returnUrlSuccess != "") {
  27.             $data .= "|" . $returnUrlSuccess;
  28.         }
  29.      
  30.         $signature = hash('sha256', $data);
  31.      
  32.         $paybylinkData  = [
  33.             'shopId'            => $shopId,
  34.             'price'             => $price,
  35.             'control'           => $control,
  36.             'description'       => $description,
  37.             'notifyURL'         => $notifyURL,
  38.             'returnUrlSuccess'  => $returnUrlSuccess,
  39.             'signature'         => $signature
  40.         ];
  41.      
  42.         $data_string = json_encode($paybylinkData);                                                                                  
  43.                                                                                                                                      
  44.         $ch = curl_init('https://secure.pbl.pl/api/v1/transfer/generate');                                                                      
  45.         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                    
  46.         curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
  47.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
  48.         curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
  49.             'Content-Type: application/json',                                                                                
  50.             'Content-Length: ' . strlen($data_string))                                                                      
  51.         );    
  52.      
  53.         $result = curl_exec($ch);
  54.         $result = json_decode($result);
  55.      
  56.         if(isset($result->transactionId) AND !empty($result->transactionId)) {
  57.             header('https://secure.pbl.pl/transfer/' . $result->transactionId)
  58.         } else {
  59.             echo 'Wystąpił błąd.';
  60.         }
  61.     }
  62. ?>
  63.  
  64. <form method="post">
  65.     <input type="hidden" name="generatePayment">
  66.     <input type="submit" value="Zapłać">
  67. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement