Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagseguro not delivering coins the way it was configured for #8

Open
PeachieDude opened this issue Feb 19, 2023 · 5 comments
Open

Pagseguro not delivering coins the way it was configured for #8

PeachieDude opened this issue Feb 19, 2023 · 5 comments

Comments

@PeachieDude
Copy link

PeachieDude commented Feb 19, 2023

Hi, was making some tests using sandbox mode and well
here is what i have it configured

$config['pagSeguro'] = array(
        'email' => '',
        'environment' => 'sandbox', // production, sandbox
        'token' => array(
                'production' => 'yourtokenhere',
                'sandbox' => '',
        ),
        'urlRedirect' => '?subtopic=points&action=final', // default should be good
        'productName' => 'Coins', // or Coins
        'productValue' => 1.00,
        'doublePoints' => false, // should points be doubled? for example: for 5 points donated you become 10.
        'donationType' => 'coins', // what should be added to player account? points/coins
        'options' => array( // cost => points/coins
                '5,00' => 100,
                '10,00' => 225,
                '20,00' => 550,
                '40,00' => 1250,
                '60,00' => 2000,
        )
);

the page is also kinda weird cuz it ask how many points instead amount you want to 'pay'
i mean, the point you put there is the amount of money you want to pay.
image
if i enter 550 (for 20 brl) it will charge me 550 BRL instead.

i saw other payment option that uses a drop down menu with fixed values, would be better.

the problem here is also, i did set 60 => 2000 cuz i did imagine that if i enter 60 (points (weird way to make it)) im going to receive 2000 coins, must remember that 60 points will charge me for 60 BRL that should gimme 2000 coins, but i only got 120 coins

@slawkens
Copy link
Owner

Hi,

can you replace content of payments/pagseguro.php with this and then do transaction, and then look into system/logs/pagseguro.log?

<?php
/**
 * Automatic PagSeguro payment system gateway.
 *
 * @name      myaac-pagseguro
 * @author    Ivens Pontes <[email protected]>
 * @author    Slawkens <[email protected]>
 * @website   github.com/slawkens/myaac-pagseguro
 * @website   github.com/ivenspontes/
 * @version   1.1.1
 */

require_once('../common.php');
require_once(SYSTEM . 'functions.php');
require_once(SYSTEM . 'init.php');
require_once(PLUGINS . 'pagseguro/config.php');
require_once(PLUGINS . 'pagseguro/PagSeguroLibrary/PagSeguroLibrary.php');

log_append('pagseguro.log','', $_POST);
if(!isset($config['pagSeguro']) || !count($config['pagSeguro']) || !count($config['pagSeguro']['options'])) {
	echo "PagSeguro is disabled. If you're an admin please configure this script in config.local.php.";
	return;
}

header("access-control-allow-origin: https://pagseguro.uol.com.br");

$method = $_SERVER['REQUEST_METHOD'];
if('post' == strtolower($method)) {
	$type = $_POST['notificationType'];
	$notificationCode = $_POST['notificationCode'];

	if ($type === 'transaction'){
		try {
			$credentials = PagSeguroConfig::getAccountCredentials();
			$transaction = PagSeguroNotificationService::checkTransaction($credentials, $notificationCode);

			$arrayPDO['transaction_code'] = $transaction->getCode();
			$arrayPDO['account'] = $transaction->getReference();
			$arrayPDO['payment_method'] = $transaction->getPaymentMethod()->getType()->getTypeFromValue();
			$arrayPDO['status'] = $transaction->getStatus()->getTypeFromValue();
			$item = $transaction->getItems();
			$arrayPDO['item_count'] = $item[0]->getQuantity();
			$date_now = date('Y-m-d H:i:s');
			$arrayPDO['data'] = $date_now;

			try {
				$conn = new PDO('mysql:host='.$config['database_host'].';dbname='.$config['database_name'].'', $config['database_user'], $config['database_password']);
				$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

				$stmt = $conn->prepare('INSERT into pagseguro_transactions SET transaction_code = :transaction_code, name = :account, payment_method = :payment_method, status = :status, item_count = :item_count, data = :data');
				$stmt->execute($arrayPDO);

				if ($arrayPDO['status'] == 'PAID') {
					if ($config['pagSeguro']['doublePoints']) {
						$arrayPDO['item_count'] = $arrayPDO['item_count'] * 2;
					}
					
					$field = 'premium_points';
					if(strtolower($config['pagSeguro']['donationType']) == 'coins') {
						$field = 'coins';
					}
					
					$stmt = $conn->prepare('UPDATE accounts SET ' . $field . ' = ' . $field . ' + :item_count WHERE ' . (USE_ACCOUNT_NAME ? 'name' : 'id') . ' = :account');
					$stmt->execute(array('item_count' => $arrayPDO['item_count'], 'account' => $arrayPDO['account']));

					$stmt = $conn->prepare("UPDATE pagseguro_transactions SET status = 'DELIVERED' WHERE transaction_code = :transaction_code AND status = 'PAID'");
					$stmt->execute(array('transaction_code' => $arrayPDO['transaction_code']));
				}
			} catch(PDOException $e) {
				log_append('pagseguro.log', $e->getMessage());
				echo 'ERROR: ' . $e->getMessage();
			}
		} catch(PagSeguroServiceException $e) {
			log_append('pagseguro.log', $e->getMessage());
			die($e->getMessage());
		}
	}
}

?>

@PeachieDude
Copy link
Author

Oh, yes, imma make the test now.
saw you on otbr, was alte cuz someone started to help you.. but i'll make the tests here too
didnt answer there cuz i just saw your message and i figured out that this could be the matter

i'll be back with a feedback

I forgot to point out that im using myaac 0.8.6 that lucas changed for canary project though using your pagseguro plugin.

@PeachieDude
Copy link
Author

PeachieDude commented Feb 19, 2023

So i made the change and the transaction gave back 500 as HTTP STATS RECEIVED (the first one gave 200)

Same thing as before using 60 points (to pay 60BRL)
no log generated

ubuntu@novaot:/var/www/html/myaacglobal/system/logs$ ls -la
total 8
drwxr-xr-x  2 www-data www-data 4096 Feb  2 19:19 .
drwxr-xr-x 12 www-data www-data 4096 Feb  2 19:20 ..
-rw-r--r--  1 www-data www-data    0 Feb  2 19:19 index.html
ubuntu@novaot:/var/www/html/myaacglobal/system/logs$

i tried to resent the notification but nothing changed
though the system says the notification was successfully sent to the set url

I saw your message there that youre not into pagseguro thing, if you want i could share the screen on discord to show you step-by-step

@slawkens
Copy link
Owner

Ye, that would be awesome.

My discord: slawkens#7932

@PeachieDude
Copy link
Author

slawkens#7932

just sent a message to you there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants