Guest User

Untitled

a guest
Apr 15th, 2021
133
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. ### DONT TOUCH IN THIS CODE ###
  4. ### WORKING FINE 19/08/2006 ###
  5. ### IVENSPONTES ###
  6. ### github.com/ivenspontes/ ###
  7.  
  8. header("access-control-allow-origin: https://pagseguro.uol.com.br");
  9. require_once 'custom_scripts/PagSeguroLibrary/PagSeguroLibrary.php';
  10. require 'config/config.php';
  11.  
  12. $method = $_SERVER['REQUEST_METHOD'];
  13.  
  14. if('POST' == $method){
  15.  
  16. $type = $_POST['notificationType'];
  17.  
  18. $notificationCode = $_POST['notificationCode'];
  19.  
  20. if ($type === 'transaction'){
  21.  
  22. try {
  23. $credentials = PagSeguroConfig::getAccountCredentials();
  24. $transaction = PagSeguroNotificationService::checkTransaction($credentials, $notificationCode);
  25.  
  26. $arrayPDO['transaction_code'] = $transaction->getCode();
  27. $arrayPDO['name'] = $transaction->getReference();
  28. $arrayPDO['payment_method'] = $transaction->getPaymentMethod()->getType()->getTypeFromValue();
  29. $arrayPDO['status'] = $transaction->getStatus()->getTypeFromValue();
  30. $item = $transaction->getItems();
  31. $arrayPDO['item_count'] = $item[0]->getQuantity();
  32. $date_now = date('Y-m-d H:i:s');
  33. $arrayPDO['data'] = $date_now;
  34.  
  35. try {
  36. $conn = new PDO('mysql:host='.$config['pagSeguro']['host'].';dbname='.$config['pagSeguro']['database'].'', $config['pagSeguro']['databaseUser'], $config['pagSeguro']['databasePass']);
  37. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  38.  
  39. $stmt = $conn->prepare('INSERT into pagseguro_transactions SET transaction_code = :transaction_code, name = :name, payment_method = :payment_method, status = :status, item_count = :item_count, data = :data');
  40. $stmt->execute($arrayPDO);
  41.  
  42. if ($arrayPDO['status'] == 'PAID') {
  43. if ($config['pagSeguro']['doublePoints']) {
  44. $arrayPDO['item_count'] = $arrayPDO['item_count']*2;
  45. }
  46. $stmt = $conn->prepare('UPDATE accounts SET premium_points = premium_points + :item_count WHERE name = :name');
  47. $stmt->execute(array('item_count' => $arrayPDO['item_count'], 'name' => $arrayPDO['name']));
  48.  
  49. $stmt = $conn->prepare("UPDATE pagseguro_transactions SET status = 'DELIVERED' WHERE transaction_code = :transaction_code AND status = 'PAID'");
  50. $stmt->execute(array('transaction_code' => $arrayPDO['transaction_code']));
  51. }
  52.  
  53. } catch(PDOException $e) {
  54. echo 'ERROR: ' . $e->getMessage();
  55. }
  56.  
  57. } catch(PagSeguroServiceException $e) {
  58. die($e->getMessage());
  59. }
  60.  
  61.  
  62. }
  63. }
  64.  
RAW Paste Data