• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Znote AAC - Paypal

Schwarzbeere

BraveOnline Developer
Joined
Feb 16, 2017
Messages
68
Reaction score
3
Location
Germany
Hey @Znote ,

can you help me?

I got a payment via Paypal but the points are not added.

Got this error-message in database znote_paypal.

ERROR: Invalid data. cmd=_notify-validate&transaction_subject=&txn_type=web_accept&payment_date=15%3A51%3A03+Jun+17%2C+2017+PDT&last_name=B%F6lian&residence_country=DE&pending_reason=unilateral&item_name=250+coins+on+DESCENTIA&payment_gross=&mc_currency=E

Thanks for your help.

Code:
    //////////////
    /// PAYPAL ///
    //////////////

    // Write your paypal address here, and what currency you want to recieve money in.
    $config['paypal'] = array(
        'enabled' => true,
        'email' => 'myemailadress', // Example: [email protected]
        'currency' => 'EUR',
        'points_per_currency' => 10, // 1 currency = ? points? [ONLY used to calculate bonuses]
        'success' => "http://".$_SERVER['HTTP_HOST']."/success.php",
        'failed' => "http://".$_SERVER['HTTP_HOST']."/failed.php",
        'ipn' => "http://".$_SERVER['HTTP_HOST']."/ipn.php",
        'showBonus' => false,
    );

    // Configure the "buy now" buttons prices, first write price, then how many points you get.
    // Giving some bonus points for higher donations will tempt users to donate more.
    $config['paypal_prices'] = array(
    //    price => points,
        1 => 250, // -10% bonus
        12 => 500, // 0% bonus
        30 => 1500, // +10% bonus
        60 => 3000, // +20% bonus
    );

@Znote maybe this part of my config.php file is necessary for you to get the problem :-/

do I need to edit something in the ipn.php?

Code:
<?php
    if (gethostbyaddr($_SERVER['REMOTE_ADDR']) !== 'notify.paypal.com') {
        exit();
    }

    // Require the functions to connect to database and fetch config values
    require 'config.php';
    require 'engine/database/connect.php';
   
    // Fetch and sanitize POST and GET values
    function getValue($value) {
        return (!empty($value)) ? sanitize($value) : false;
    }
    function sanitize($data) {
        return htmlentities(strip_tags(mysql_znote_escape_string($data)));
    }
   
    function VerifyPaypalIPN(array $IPN = null){
        if(empty($IPN)){
            $IPN = $_POST;
        }
        if(empty($IPN['verify_sign'])){
            return null;
        }
        $IPN['cmd'] = '_notify-validate';
        $PaypalHost = (empty($IPN['test_ipn']) ? 'www' : 'www.sandbox').'.paypal.com';
        $cURL = curl_init();
        curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($cURL, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($cURL, CURLOPT_URL, "https://{$PaypalHost}/cgi-bin/webscr");
        curl_setopt($cURL, CURLOPT_ENCODING, 'gzip');
        curl_setopt($cURL, CURLOPT_BINARYTRANSFER, true);
        curl_setopt($cURL, CURLOPT_POST, true); // POST back
        curl_setopt($cURL, CURLOPT_POSTFIELDS, $IPN); // the $IPN
        curl_setopt($cURL, CURLOPT_HEADER, false);
        curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($cURL, CURLOPT_FORBID_REUSE, true);
        curl_setopt($cURL, CURLOPT_FRESH_CONNECT, true);
        curl_setopt($cURL, CURLOPT_CONNECTTIMEOUT, 30);
        curl_setopt($cURL, CURLOPT_TIMEOUT, 60);
        curl_setopt($cURL, CURLINFO_HEADER_OUT, true);
        curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
            'Connection: close',
            'Expect: ',
        ));
        $Response = curl_exec($cURL);
        $Status = (int)curl_getinfo($cURL, CURLINFO_HTTP_CODE);
        curl_close($cURL);
        if(empty($Response) or !preg_match('~^(VERIFIED|INVALID)$~i', $Response = trim($Response)) or !$Status){
            return null;
        }
        if(intval($Status / 100) != 2){
            return false;
        }
        return !strcasecmp($Response, 'VERIFIED');
    }

    // Fetch paypal configurations
    $paypal = $config['paypal'];
    $prices = $config['paypal_prices'];
   
    // Send an empty HTTP 200 OK response to acknowledge receipt of the notification
    header('HTTP/1.1 200 OK');

    // Build the required acknowledgement message out of the notification just received
    $req = 'cmd=_notify-validate';
    foreach ($_POST as $key => $value) {
        $value = urlencode(stripslashes($value));
        $req  .= "&$key=$value";
    }
    $postdata = $req;
   
    // Assign payment notification values to local variables
    $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           = getValue($_POST['txn_id']);
    $receiver_email   = getValue($_POST['receiver_email']);
    $payer_email      = getValue($_POST['payer_email']);
    $custom           = (int)$_POST['custom'];

    $connectedIp = $_SERVER['REMOTE_ADDR'];
    mysql_insert("INSERT INTO `znote_paypal` VALUES ('0', '$txn_id', 'Connection from IP: $connectedIp', '0', '0', '0')");
   
    $status = VerifyPaypalIPN();
    if ($status) {
        // Check that the payment_status is Completed
        if ($payment_status == 'Completed') {

           
            // Check that txn_id has not been previously processed
            $txn_id_check = mysql_select_single("SELECT `txn_id` FROM `znote_paypal` WHERE `txn_id`='$txn_id'");
            if ($txn_id_check !== false) {
                // Check that receiver_email is your Primary PayPal email
                if ($receiver_email == $paypal['email']) {
                   
                    $status = true;
                    $paidMoney = 0;
                    $paidPoints = 0;

                    foreach ($prices as $priceValue => $pointsValue) {
                        if ($priceValue == $payment_amount) {
                            $paidMoney = $priceValue;
                            $paidPoints = $pointsValue;
                        }
                    }

                    if ($paidMoney == 0) $status = false; // Wrong ammount of money
                    if ($payment_currency != $paypal['currency']) $status = false; // Wrong currency
                   
                    // Verify that the user havent messed around with POST data
                    if ($status) {
                        // transaction log
                        mysql_insert("INSERT INTO `znote_paypal` VALUES ('0', '$txn_id', '$payer_email', '$custom', '".$paidMoney."', '".$paidPoints."')");
                       
                        // Process payment
                        $data = mysql_select_single("SELECT `points` AS `old_points` FROM `znote_accounts` WHERE `account_id`='$custom';");

                        // Give points to user
                        $new_points = $data['old_points'] + $paidPoints;
                        mysql_update("UPDATE `znote_accounts` SET `points`='$new_points' WHERE `account_id`='$custom'");
                    }
                }  else {
                    $pmail = $paypal['email'];
                    mysql_insert("INSERT INTO `znote_paypal` VALUES ('0', '$txn_id', 'ERROR: Wrong mail. Received: $receiver_email, configured: $pmail', '0', '0', '0')");
                }
            }
        }
    } else {
        // Something is wrong
        mysql_insert("INSERT INTO `znote_paypal` VALUES ('0', '$txn_id', 'ERROR: Invalid data. $postdata', '0', '0', '0')");
    }
?>
 
Last edited by a moderator:
Solution
I havent had time to look properly into this, but my quick thoughts are:

After you have changed from sandbox to live, you need to change the paypal URLs to the live urls.
After that, you also need to make sure that the sandbox option is disabled in the paypal developer app center~ (Is it a toggle option there?)

Then after this, in theory you should be running live. But if you did testing in the sandbox, your experience_profile_id is probably related to the sandbox environment, which means you need to generate a new profile_id for the live version
When I have time to continue working on this, I intend to extend the functionality, detect when it returns INVALID_EXPERIENCE_PROFILE_ID, and automatically generate a new experience profile...
Try out the new paypal system by replacing and creating these files:
Znote AAC Paypal REST API prototype · GitHub

Login with your paypal account at:
developer.paypal.com

create a new REST API app
configure client_id and secret_id in config.php

delete old znote_paypal table in database, and add the table.sql code in phpmyadmin --> database -> SQL to add the table for new system.

This system uses cURL, to enable cURL in uniserver (web server) follow this guide: Paypal Php uniserver help

let me know how it works
 
Hey @Znote

did everything like you wrote it, when i click on purchase this is displayed:
Payment link ERROR
Print: -

cURL is enabled, looked in the php info

cURL support enabled
cURL Information 7.38.0

In the Paypal REST API, I choose the LIVE version, right?

When I use the Sandbox Version (client_id & secret_id) this error shows on:
Code:
Payment link ERROR
Print: - stdClass Object
(
    [name] => INVALID_EXPERIENCE_PROFILE_ID
    [message] => The requested experience profile ID was not found
    [information_link] => https://developer.paypal.com/docs/api/payments/#errors
    [debug_id] => e6245b508c012
)

bump
 
Last edited by a moderator:
Sorry for the late reply, but I had some private issues.
Code:
Request
Print: - Array
(
    [amount] => 1
    [PHPSESSID] => 0f43700335a84802ad1645d5f5d8d62c
)


Payment token
Print: - stdClass Object
(
    [scope] => https://uri.paypal.com/services/subscriptions https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/vault/credit-card https://uri.paypal.com/services/applications/webhooks openid https://uri.paypal.com/payments/payouts https://api.paypal.com/v1/vault/credit-card/.*
    [nonce] => 2017-09-22T13:20:28Z1yxISjdkkGZMT72cJPIa_xRb36D5ztlPYwZuS2K6KRA
    [access_token] => A21AAHeB6cPnnKIk5wmppnHZD_x_R8BVCwzhu7MNOkfUufk0DP31LJk0spVkoW_2vX01e6YaHEBB-e9zRYA94Gt5PqW9dJjxA
    [token_type] => Bearer
    [app_id] => APP-80W284485P519543T
    [expires_in] => 32051
)


Payment data
Print: - Array
(
    [intent] => sale
    [payer] => Array
        (
            [payment_method] => paypal
        )

    [transactions] => Array
        (
            [0] => Array
                (
                    [amount] => Array
                        (
                            [currency] => EUR
                            [total] => 1
                        )

                    [description] => Shop points on DESCENTIA
                    [item_list] => Array
                        (
                            [items] => Array
                                (
                                    [0] => Array
                                        (
                                            [quantity] => 1
                                            [name] => 250 shop points.
                                            [price] => 1
                                            [currency] => EUR
                                        )

                                )

                        )

                )

        )

    [experience_profile_id] => XP-QVHM-88XN-YHPC-V9CE
    [redirect_urls] => Array
        (
            [return_url] => http://www.descentia.com/paypal_process.php
            [cancel_url] => http://www.descentia.com/failed.php
        )

)


Payment link ERROR
Print: - stdClass Object
(
    [name] => INVALID_EXPERIENCE_PROFILE_ID
    [message] => The requested experience profile ID was not found
    [information_link] => https://developer.paypal.com/docs/api/payments/#errors
    [debug_id] => da609f92852b6
)

That is the log.

@Znote
BUMP :)
 
Last edited by a moderator:
Sorry for the late reply, but I had some private issues.
Code:
Request
Print: - Array
(
    [amount] => 1
    [PHPSESSID] => 0f43700335a84802ad1645d5f5d8d62c
)


Payment token
Print: - stdClass Object
(
    [scope] => https://uri.paypal.com/services/subscriptions https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/vault/credit-card https://uri.paypal.com/services/applications/webhooks openid https://uri.paypal.com/payments/payouts https://api.paypal.com/v1/vault/credit-card/.*
    [nonce] => 2017-09-22T13:20:28Z1yxISjdkkGZMT72cJPIa_xRb36D5ztlPYwZuS2K6KRA
    [access_token] => A21AAHeB6cPnnKIk5wmppnHZD_x_R8BVCwzhu7MNOkfUufk0DP31LJk0spVkoW_2vX01e6YaHEBB-e9zRYA94Gt5PqW9dJjxA
    [token_type] => Bearer
    [app_id] => APP-80W284485P519543T
    [expires_in] => 32051
)


Payment data
Print: - Array
(
    [intent] => sale
    [payer] => Array
        (
            [payment_method] => paypal
        )

    [transactions] => Array
        (
            [0] => Array
                (
                    [amount] => Array
                        (
                            [currency] => EUR
                            [total] => 1
                        )

                    [description] => Shop points on DESCENTIA
                    [item_list] => Array
                        (
                            [items] => Array
                                (
                                    [0] => Array
                                        (
                                            [quantity] => 1
                                            [name] => 250 shop points.
                                            [price] => 1
                                            [currency] => EUR
                                        )

                                )

                        )

                )

        )

    [experience_profile_id] => XP-QVHM-88XN-YHPC-V9CE
    [redirect_urls] => Array
        (
            [return_url] => http://www.descentia.com/paypal_process.php
            [cancel_url] => http://www.descentia.com/failed.php
        )

)


Payment link ERROR
Print: - stdClass Object
(
    [name] => INVALID_EXPERIENCE_PROFILE_ID
    [message] => The requested experience profile ID was not found
    [information_link] => https://developer.paypal.com/docs/api/payments/#errors
    [debug_id] => da609f92852b6
)

That is the log.

Experience profile ID is invalid, try to generate a new profile:
In your database, find the table znote_global_storage, and look for storage key paypal_profile_id, delete it.
Try a new payment, see if you get a new ID. Current ID is (XP-QVHM-88XN-YHPC-V9CE).
 
I created an new Sandbox Account and new REST API, but it's getting the same experience ID, can you help me fixing it? - maybe you can configurate my PayPal account? - If yes, just write me P.M.

If I try to buy points on the Website, this error shows up:

Code:
Request
Print: - Array
(
    [amount] => 1
    [PHPSESSID] => de65467c062e2e49a9f965344b6a6a06
)


Payment token
Print: - stdClass Object
(
    [scope] => https://uri.paypal.com/services/subscriptions https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/vault/credit-card https://uri.paypal.com/services/applications/webhooks openid https://uri.paypal.com/payments/payouts https://api.paypal.com/v1/vault/credit-card/.*
    [nonce] => 2017-10-02T18:22:22Z_t3YtvyS8ePOdgcpJmUxGIRRChGYEeGAZ2HfPJeGFOY
    [access_token] => A21AAEbcvFgh2gN0RkfFdE3i-FKs-Zo3f8_gkDInKMl7gnhUST7-IMsscfeVN8qrNT6zPxjPG1XNcTqVnEPJpIzLuBp6nK82A
    [token_type] => Bearer
    [app_id] => APP-80W284485P519543T
    [expires_in] => 32400
)


Profile return data
Print: - stdClass Object
(
    [id] => XP-DCFR-XRDB-4D84-RSA3
    [name] => paypalProfile
    [temporary] =>
    [input_fields] => stdClass Object
        (
            [no_shipping] => 1
            [address_override] => 1
        )

)


Payment data
Print: - Array
(
    [intent] => sale
    [payer] => Array
        (
            [payment_method] => paypal
        )

    [transactions] => Array
        (
            [0] => Array
                (
                    [amount] => Array
                        (
                            [currency] => EUR
                            [total] => 1
                        )

                    [description] => Shop points on DESCENTIA
                    [item_list] => Array
                        (
                            [items] => Array
                                (
                                    [0] => Array
                                        (
                                            [quantity] => 1
                                            [name] => 250 shop points.
                                            [price] => 1
                                            [currency] => EUR
                                        )

                                )

                        )

                )

        )

    [experience_profile_id] => XP-DCFR-XRDB-4D84-RSA3
    [redirect_urls] => Array
        (
            [return_url] => http://www.descentia.com/paypal_process.php
            [cancel_url] => http://www.descentia.com/failed.php
        )

)


Payment link success
Print: - stdClass Object
(
    [id] => PAY-38E4762336884602YLHJIHYY
    [intent] => sale
    [state] => created
    [payer] => stdClass Object
        (
            [payment_method] => paypal
        )

    [transactions] => Array
        (
            [0] => stdClass Object
                (
                    [amount] => stdClass Object
                        (
                            [total] => 1.00
                            [currency] => EUR
                        )

                    [description] => Shop points on DESCENTIA
                    [item_list] => stdClass Object
                        (
                            [items] => Array
                                (
                                    [0] => stdClass Object
                                        (
                                            [name] => 250 shop points.
                                            [price] => 1.00
                                            [currency] => EUR
                                            [quantity] => 1
                                        )

                                )

                        )

                    [related_resources] => Array
                        (
                        )

                )

        )

    [experience_profile_id] => XP-DCFR-XRDB-4D84-RSA3
    [create_time] => 2017-10-02T18:22:27Z
    [links] => Array
        (
            [0] => stdClass Object
                (
                    [href] => https://api.sandbox.paypal.com/v1/payments/payment/PAY-38E4762336884602YLHJIHYY
                    [rel] => self
                    [method] => GET
                )

            [1] => stdClass Object
                (
                    [href] => https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-77R65911ET687090J
                    [rel] => approval_url
                    [method] => REDIRECT
                )

            [2] => stdClass Object
                (
                    [href] => https://api.sandbox.paypal.com/v1/payments/payment/PAY-38E4762336884602YLHJIHYY/execute
                    [rel] => execute
                    [method] => POST
                )

        )

)

@Znote got any idea or can you help me directly?
 
Last edited by a moderator:
Hi guys!
@Znote I've tested your app and it works fine, but in live mode (using live credentials) I receive this error:

Code:
Request
Print: - Array

    [amount] => 1
)


Payment token
Print: - stdClass Object
(
    [error] => invalid_client
    [error_description] => Client Authentication failed
)

Payment data
Print: - Array
(
    [intent] => sale
    [payer] => Array
        (
            [payment_method] => paypal
        )
   [transactions] => Array
        (
            [0] => Array
                (
                    [amount] => Array
                        (
                            [currency] => EUR
                            [total] => 1
                       

> )

                    [description] => Shop points on example.net
                    [item_list] => Array
                        (
                            [items] => Array
                                (
                                    [0] => Array
                                        (
                                            [quantity] => 1
                                            [name] => 10 shop points.
                                            [price] => 1
                                            [currency] => EUR
                                        )

                                )

                        )

                )

        )

    [experience_profile_id] => XP-9HUW-8XHP-G5C2-MXXX
    [redirect_urls] => Array
        (
            [return_url] => http://example.net/paypal_process.php
            [cancel_url] => http://example.net/failed.php
        )

I tried to add array mode => live to $config['paypal'] it doesn't work. Could you help me?
 
Hi guys!
@Znote I've tested your app and it works fine, but in live mode (using live credentials) I receive this error:

Code:
Request
Print: - Array

    [amount] => 1
)


Payment token
Print: - stdClass Object
(
    [error] => invalid_client
    [error_description] => Client Authentication failed
)

Payment data
Print: - Array
(
    [intent] => sale
    [payer] => Array
        (
            [payment_method] => paypal
        )
   [transactions] => Array
        (
            [0] => Array
                (
                    [amount] => Array
                        (
                            [currency] => EUR
                            [total] => 1
                      

> )

                    [description] => Shop points on example.net
                    [item_list] => Array
                        (
                            [items] => Array
                                (
                                    [0] => Array
                                        (
                                            [quantity] => 1
                                            [name] => 10 shop points.
                                            [price] => 1
                                            [currency] => EUR
                                        )

                                )

                        )

                )

        )

    [experience_profile_id] => XP-9HUW-8XHP-G5C2-MXXX
    [redirect_urls] => Array
        (
            [return_url] => http://example.net/paypal_process.php
            [cancel_url] => http://example.net/failed.php
        )

I tried to add array mode => live to $config['paypal'] it doesn't work. Could you help me?

Did you replace the sandbox URL:s with the live URL?

This one for example: Znote AAC Paypal REST API prototype · GitHub
 
Thanks for advice. Yes, I've tried, even after your reply to be sure , but maybe used wrong. How should they looks like or where can I find them?
 
You were right, I've missed links in :oops: paypal_process.php. Now I'm getting this:

Code:
Payment link ERROR
Print: - stdClass Object
(
    [name] => INVALID_EXPERIENCE_PROFILE_ID
    [message] => The requested experience profile ID was not found
    [information_link] => https://developer.paypal.com/docs/api/payments/#errors
    [debug_id] => dff5bb503129c
)

Thanks a lot. :) I will check this, and write if new problems occurs. I Hope they will not.
 
I havent had time to look properly into this, but my quick thoughts are:

After you have changed from sandbox to live, you need to change the paypal URLs to the live urls.
After that, you also need to make sure that the sandbox option is disabled in the paypal developer app center~ (Is it a toggle option there?)

Then after this, in theory you should be running live. But if you did testing in the sandbox, your experience_profile_id is probably related to the sandbox environment, which means you need to generate a new profile_id for the live version
When I have time to continue working on this, I intend to extend the functionality, detect when it returns INVALID_EXPERIENCE_PROFILE_ID, and automatically generate a new experience profile id.

For now, I think it should generate a new experience profile id by removing the current profile_id in our database. (Reference code: Znote AAC Paypal REST API prototype · GitHub )
znote said:
In your database, find the table znote_global_storage, and look for storage key paypal_profile_id, delete it.

However it seems @Schwarzbeere tried this, and it just loaded the invalid profile id from the API?
I would try to force a new profile id by changing this name:
Znote AAC Paypal REST API prototype · GitHub

Instead of paypalProfile, call it like myotserverPaypalProfile, just so the paypal API is unable to find the profile id in their end and return an old invalid one. (It sounds weird that paypal is returning invalid profile ids tho...)
 
Solution
Thanks for your reply @Znote. You made a lot of good work. Everything is working fine now, and I really like idea of invalid EPID detector . I would like to help, but It's out of my range at the moment. :)
 
Hello @Znote im using this new method with rest api and ur new files and eveyrthing works kinda good!

But I had this issue;
Error 0: Paypal account is not verified, and thus considered untrusted.

I removed this by
$errors[] = "Paypal account is not verified, and thus considered untrusted.";
removing that and now unverified accs can buy too it loooks like

i know its bad to enable unverified accounts but i want it to be enabled.

And I also get this errors when somebody buys points, how can I fix?

Notice: Undefined index: price in /home/otsmanager/www/paypal_process.php on line 186

Notice: Undefined index: currency in /home/otsmanager/www/paypal_process.php on line 187


How I fix this?
 
Last edited:
Hello @Znote im using this new method with rest api and ur new files and eveyrthing works kinda good!

But I had this issue;
Error 0: Paypal account is not verified, and thus considered untrusted.

I removed this by
$errors[] = "Paypal account is not verified, and thus considered untrusted.";
removing that and now unverified accs can buy too it loooks like

i know its bad to enable unverified accounts but i want it to be enabled.

And I also get this errors when somebody buys points, how can I fix?

Notice: Undefined index: price in /home/otsmanager/www/paypal_process.php on line 186

Notice
: Undefined index: currency in /home/otsmanager/www/paypal_process.php on line 187


How I fix this?

I'm getting this exact same error
 
Back
Top