Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Przelewy24 konfiguracja plik
login90
post
Post #1





Grupa: Zarejestrowani
Postów: 52
Pomógł: 0
Dołączył: 8.02.2016

Ostrzeżenie: (0%)
-----


Witam.

W necie na forum znalazłem coś takiego. Czy ktoś wie jak przerobić tak aby wiedzień, który użytkownik zapłacił. np. wchodzi na moje konto, potem w plik zapłać za ogłoszenie http://localhost/strona/pay/1/user pay to nazwa pliku, 1 to id, a user to nazwa. I jak zrobił aby po kliknięciu zapłać i po dokonaniu tranzakcjii do bazy danych wbiła się id tranzakcji, nazwa, id użytkownika z serwisu do bazy danych.


Przelewy24_API.php
  1. <?php
  2.  
  3. define('PRZELEWY24_MERCHANT_ID', 'Twój nr sprzedawcy');
  4. define('PRZELEWY24_CRC', 'Twój kod CRC');
  5. // sandbox - środowisko testowe, secure - środowisko produkcyjne
  6. define('PRZELEWY24_TYPE', 'sandbox');
  7.  
  8. class Przelewy24_API
  9. {
  10. public function CreateToken($p24_amount = null, $p24_description = null, $p24_email = null, $p24_url_return = null, $p24_url_status = null)
  11. {
  12. $p24_session_id = uniqid();
  13.  
  14. $headers[] = 'p24_merchant_id=' . PRZELEWY24_MERCHANT_ID;
  15. $headers[] = 'p24_pos_id=' . PRZELEWY24_MERCHANT_ID;
  16. $headers[] = 'p24_crc=' . PRZELEWY24_CRC;
  17. $headers[] = 'p24_session_id=' . $p24_session_id;
  18. $headers[] = 'p24_amount=' . $p24_amount;
  19. $headers[] = 'p24_currency=PLN';
  20. $headers[] = 'p24_description=' . $p24_description;
  21. $headers[] = 'p24_country=PL';
  22. $headers[] = 'p24_url_return=' . urlencode($p24_url_return);
  23. $headers[] = 'p24_url_status=' . urlencode($p24_url_status);
  24. $headers[] = 'p24_api_version=3.2';
  25. $headers[] = 'p24_sign=' . md5($p24_session_id . '|' . PRZELEWY24_MERCHANT_ID . '|' . $p24_amount . '|PLN|' . PRZELEWY24_CRC);
  26. $headers[] = 'p24_email=' . $p24_email;
  27.  
  28. $oCURL = curl_init();
  29. curl_setopt($oCURL, CURLOPT_POST, 1);
  30. curl_setopt($oCURL, CURLOPT_SSL_CIPHER_LIST, 'TLSv1');
  31. curl_setopt($oCURL, CURLOPT_POSTFIELDS, implode('&', $headers));
  32. curl_setopt($oCURL, CURLOPT_URL, 'https://' . PRZELEWY24_TYPE . '.przelewy24.pl/trnRegister');
  33. curl_setopt($oCURL, CURLOPT_SSL_VERIFYHOST, 2);
  34. curl_setopt($oCURL, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  35. curl_setopt($oCURL, CURLOPT_RETURNTRANSFER, 1);
  36. curl_setopt($oCURL, CURLOPT_SSL_VERIFYPEER, false);
  37. $response = curl_exec($oCURL);
  38. curl_close($oCURL);
  39.  
  40. parse_str($response, $output);
  41. return isset($output['token']) ? $output['token'] : 0;
  42. }
  43.  
  44. public function Pay($p24_amount = null, $p24_description = null, $p24_email = null, $p24_url_return = null, $p24_url_status = null)
  45. {
  46. $token = $this->CreateToken($p24_amount, $p24_description, $p24_email, $p24_url_return, $p24_url_status);
  47. return 'https://' . PRZELEWY24_TYPE . '.przelewy24.pl/trnRequest/' . $token;
  48. }
  49.  
  50. public function Verify($data = null)
  51. {
  52. $headers[] = 'p24_merchant_id=' . $data['p24_merchant_id'];
  53. $headers[] = 'p24_pos_id=' . $data['p24_pos_id'];
  54. $headers[] = 'p24_session_id=' . $data['p24_session_id'];
  55. $headers[] = 'p24_amount=' . $data['p24_amount'];
  56. $headers[] = 'p24_currency=PLN';
  57. $headers[] = 'p24_order_id=' . $data['p24_order_id'];
  58. $headers[] = 'p24_sign=' . md5($data['p24_session_id'] . '|' . $data['p24_order_id'] . '|' . $data['p24_amount'] . '|PLN|' . PRZELEWY24_CRC);
  59.  
  60. $oCURL = curl_init();
  61. curl_setopt($oCURL, CURLOPT_POST, 1);
  62. curl_setopt($oCURL, CURLOPT_SSL_CIPHER_LIST, 'TLSv1');
  63. curl_setopt($oCURL, CURLOPT_POSTFIELDS, implode('&', $headers));
  64. curl_setopt($oCURL, CURLOPT_URL, 'https://' . PRZELEWY24_TYPE . '.przelewy24.pl/trnVerify');
  65. curl_setopt($oCURL, CURLOPT_SSL_VERIFYHOST, 2);
  66. curl_setopt($oCURL, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  67. curl_setopt($oCURL, CURLOPT_RETURNTRANSFER, 1);
  68. curl_setopt($oCURL, CURLOPT_SSL_VERIFYPEER, false);
  69. $response = curl_exec($oCURL);
  70. curl_close($oCURL);
  71.  
  72. parse_str($response, $output);
  73. return ($output['error'] == '0') ? true : false;
  74. }
  75. }?>

payments.php
  1. <?php
  2.  
  3.  
  4. include_once('Przelewy24_API.php');
  5. $oPrzelewy24_API = new Przelewy24_API();
  6.  
  7. if (isset($_POST['p24_merchant_id']) AND isset($_POST['p24_sign'])) {
  8. if ($oPrzelewy24_API->Verify($_POST) === true) {
  9. // Tutaj dokonujemy aktywacji usługi, która jest opłacana
  10. }
  11. } else {
  12. // Powrotny adres URL
  13. $p24_url_return = 'http://twoja-strona.com/payments.php';
  14.  
  15. // Adres dla weryfikacji płatności
  16. $p24_url_status = 'http://twoja-strona.com/payments.php';
  17.  
  18. // Kwota do zapłaty musi być pomnożona razy 100.
  19. // Czyli, jeżeli użytkownik ma zapłacić 499 złotych, to kwota do zapłaty
  20. // to 499 * 100 (wyrażona w groszach)
  21. $redirect = $oPrzelewy24_API->Pay('Tutaj wstaw kwotę do zapłaty', 'Tutaj wstaw tytuł płatności', 'Tutaj adres e-mail osoby płacącej', $p24_url_return, $p24_url_status);
  22. Header('Location: ' . $redirect); exit;
  23. }?>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 25.09.2025 - 16:44