Paypal _xclick IPN non risponde

FabrizioCo

Nuovo Utente
11 Dic 2022
2
0
1
Ciao a tutti, avevo integrato paypal con il mio sito e tutto funzionava bene. Oggi ho però dovuto modificare il mio conto paypal e non ha più funzionato nulla. Premetto che sono ancora in modalità sandbox.
Per l'integrazione ho seguito questo chiaro e semplice tutorial. serverguy.com/learn/paypal-integration-in-php Il codice è disponibile in GitHub github.com/EvolutedNewMedia/paypal-example
La pagina payments.php funge da URL di notifica IPN, ne ho inserito l'indirizzo nell'utente business in sandbox.
Riporto il contenuto della pagina.

PHP:
<?php

// For test payments we want to enable the sandbox mode. If you want to put live
// payments through then this setting needs changing to `false`.
$enableSandbox = true;

// Database settings. Change these for your database configuration.
$dbConfig = [
    'host' => '127.0.0.1',
    'username' => 'xxxxxxxxxx',
    'password' => 'xxxxxxxxxxx',
    'name' => 'xxxxxxxxxx'
];

// PayPal settings. Change these to your account details and the relevant URLs
// for your site.
$paypalConfig = [
    'email' => '[email protected]',
    'return_url' => 'http://edencamp.it',
    'cancel_url' => 'http://edencamp.it',
    'notify_url' => 'http://edencamp.it/paypal2/payments.php'
];

$paypalUrl = $enableSandbox ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr';

// Product being purchased.
$itemName = 'Soggiorno';
$itemAmount = 5.00;

// Include Functions
require 'functions.php';

// Check if paypal request or response
if (!isset($_POST["txn_id"]) && !isset($_POST["txn_type"])) {

    // Grab the post data so that we can set up the query string for PayPal.
    // Ideally we'd use a whitelist here to check nothing is being injected into
    // our post data.
    $data = [];
    foreach ($_POST as $key => $value) {
        $data[$key] = stripslashes($value);
    }

    // Set the PayPal account.
    $data['business'] = $paypalConfig['email'];

    // Set the PayPal return addresses.
    $data['return'] = stripslashes($paypalConfig['return_url']);
    $data['cancel_return'] = stripslashes($paypalConfig['cancel_url']);
    $data['notify_url'] = stripslashes($paypalConfig['notify_url']);

    // Set the details about the product being purchased, including the amount
    // and currency so that these aren't overridden by the form data.
    $data['item_name'] = $itemName;
    $data['amount'] = $itemAmount;
    $data['currency_code'] = 'EUR';

    // Add any custom fields for the query string.
    //$data['custom'] = USERID;

    // Build the query string from the data.
    $queryString = http_build_query($data);

    // Redirect to paypal IPN
    header('location:' . $paypalUrl . '?' . $queryString);
    exit();

} else {
    // Handle the PayPal response.

    // Create a connection to the database.
    $db = new mysqli($dbConfig['host'], $dbConfig['username'], $dbConfig['password'], $dbConfig['name']);

    // Assign posted variables to local data array.
    $data = [
        'item_name' => $_POST['item_name'],
        'item_number' => $_POST['item_number'],
        'payment_status' => $_POST['payment_status'],
        'payment_amount' => $_POST['mc_gross'],
        'payment_currency' => $_POST['mc_currency'],
        'txn_id' => $_POST['txn_id'],
        'receiver_email' => $_POST['receiver_email'],
        'payer_email' => $_POST['payer_email'],
        'custom' => $_POST['custom'],
    ];

    // We need to verify the transaction comes from PayPal and check we've not
    // already processed the transaction before adding the payment to our
    // database.
    if (verifyTransaction($_POST) && checkTxnid($data['txn_id'])) {
        if (addPayment($data) !== false) {
            // Payment successfully added.
        }
    }
}

?>

Nella prima parte, se si realizzano le seguenti due condizioni, significa che è il nostro sito a mandare il messaggio all'IPN di Paypal.
PHP:
if (!isset($_POST["txn_id"]) && !isset($_POST["txn_type"])) {

Nel mio caso è questo, non ho molta esperienza ma mi sembra corretto
Codice:
https://edencamp.it/?cmd=_xclick&no_note=1&lc=IT&bn=PP-BuyNowBF%3Abtn_buynow_LG.gif%3ANonHostedGuest&first_name=Customer%27s%20First%20Name&last_name=Customer%27s%20Last%20Name&item_number=123456&submit_x=90&submit_y=35&business=sb-unujw22617153%40business.example.com&return=http%3A%2F%2Fedencamp.it&cancel_return=http%3A%2F%2Fedencamp.it&notify_url=http%3A%2F%2Fedencamp.it%2Fpaypal2%2Fpayments.php&item_name=Soggiorno&amount=5&currency_code=EUR

Nella seconda parte, se non si realizzano le due condizioni, significa che il nostro sito riceve la risposta da IPN e valida il pagamento. Questa parte non funziona, è come se l'IPN avesse smesso di parlare col mio sito e non ne capisco la ragione.

Nel vecchio conto paypal ho cancellato l'url dell'ipn sia in sandbox sia nel conto business. Nel nuovo conto paypal ho inserito l'url sia in sandbox sia nel conto business. Boh, non so più cosa fare, anche perchè, ripeto, prima che facessi questa cavolo di operazione tutto andava a dovere.
Quale potrebbe essere il problema? Grazie infinite
 
Come non detto, doveva forse girare qualche batch. Mah! Mi sono collegato al database e tutte le transazioni di ieri sono comparse. Ora funziona bene.
 

Discussioni simili