Webengine and paypal/credits issue

Results 1 to 6 of 6
  1. #1
    Newbie imberesta is offline
    MemberRank
    Aug 2021 Join Date
    2Posts

    Support Webengine and paypal/credits issue

    Hello all,

    I have an issue with Credit system on my website.
    When credits are bought on website they do not appear on the history and no credits are awarded. I get money minus fee on paypal account.
    Paypal history is empty, no credits altered.

    I can add/subtract them manually via adminCP.

    What should my troubleshooting steps be? Where should i start looking?

    Regards,
    Martynas


  2. #2
    cMuServices cMu is offline
    True MemberRank
    Jan 2017 Join Date
    412Posts

    Re: Webengine and paypal/credits issue

    while paypal history is empty, means the IPN listener is probably die during the process.
    check your php error log.

  3. #3
    Newbie imberesta is offline
    MemberRank
    Aug 2021 Join Date
    2Posts

    Re: Webengine and paypal/credits issue

    Hello cMu,
    Thanks for quick reply.
    This is what i found:
    PHP Code:
    [13-Sep-2021 08:29:28 UTCPHP Notice:  Undefined indexsubmit_changes in /public_html/admincp/modules/mconfig/paypal.php on line 48
    [13-Sep-2021 08:30:06 UTCPHP Fatal error:  Uncaught ExceptionMissing POST Data in /public_html/includes/classes/paypal/PaypalIPN.php:64
    Stack trace
    :
    #0 /public_html/api/paypal.php(40): PaypalIPN->verifyIPN()
    #1 {main}
      
    thrown in /public_html/includes/classes/paypal/PaypalIPN.php on line 64 
    You are probably right about IPN bit. Any thoughts on next step?

  4. #4
    cMuServices cMu is offline
    True MemberRank
    Jan 2017 Join Date
    412Posts

    Re: Webengine and paypal/credits issue

    Quote Originally Posted by imberesta View Post
    Hello cMu,
    Thanks for quick reply.
    This is what i found:
    PHP Code:
    [13-Sep-2021 08:29:28 UTCPHP Notice:  Undefined indexsubmit_changes in /public_html/admincp/modules/mconfig/paypal.php on line 48
    [13-Sep-2021 08:30:06 UTCPHP Fatal error:  Uncaught ExceptionMissing POST Data in /public_html/includes/classes/paypal/PaypalIPN.php:64
    Stack trace
    :
    #0 /public_html/api/paypal.php(40): PaypalIPN->verifyIPN()
    #1 {main}
      
    thrown in /public_html/includes/classes/paypal/PaypalIPN.php on line 64 
    You are probably right about IPN bit. Any thoughts on next step?
    seems like the IPN does not get all the required POST that he needs. You can run advanced debug (such as listing all arriving POSTS into .txt file through the PHP, and start debugging.)

  5. #5
    Would You Kindly? Bola is offline
    DeveloperRank
    Dec 2011 Join Date
    BrazilLocation
    1,710Posts

    Re: Webengine and paypal/credits issue

    i'm not sure if this is something about the paypal API or what, but i never was able to put IPN to work properly, so i decide to use other approach like Rest API, for me works perfect and just required to set payment details, then right after user make the payment, you need to execute it in order to finish the trade, with this proccess complete you already can delivery the player reward, i'll drop here my class for paypal rest API.

    pay attention that most of Settings::get() bring some data from main settings and Donate:: bring me model from database for donation.

    PHP Code:
    <?php

    namespace App\Payments;

    use 
    Setting;
    use 
    App\Models\Donate;
    use 
    PayPal\Rest\ApiContext;
    use 
    PayPal\Auth\OAuthTokenCredential;
    use 
    PayPal\Api\Amount;
    use 
    PayPal\Api\Item;
    use 
    PayPal\Api\ItemList;
    use 
    PayPal\Api\Payer;
    use 
    PayPal\Api\Payment;
    use 
    PayPal\Api\RedirectUrls;
    use 
    PayPal\Api\Transaction;
    use 
    PayPal\Api\PaymentExecution;

    class 
    PayPal implements GatewayInterface {

        use 
    Processor;

        private 
    $client_id "";
        private 
    $secret "";
        private 
    $api null;
        
    //sandbox - live 
        
    private $env "live";
        private 
    $PAYPALstatus = [
            
    'created' => self::STATUS_CREATED,
            
    'approved' => self::STATUS_APPROVED,
            
    'failed' => self::STATUS_CANCEL
        
    ];

        public function 
    __construct() {
            if (
    Setting::get('paypal_enable')) {
                
    $this->client_id Setting::get('paypal_clientid');
                
    $this->secret Setting::get('paypal_secret');
                
    $this->api = new ApiContext(
                        new 
    OAuthTokenCredential($this->client_id$this->secret)
                );
                
    $this->api->setConfig([
                    
    //   'log.LogEnabled' => true,
                    //  'log.FileName' => 'PayPal.log',
                    // 'log.LogLevel' => 'DEBUG',
                    
    'mode' => $this->env
                
    ]);
            }
        }

        public function 
    createPayment(\App\Models\Donate $donate) {
            
    $payer = new Payer();
            
    $payer->setPaymentMethod("paypal");
            
    $item1 = new Item();
            
    $item1->setName(trans('strings.donation') . " - " Setting::get('servername') . ' - ' $donate->login ' - ' $donate->reward " " . ($donate->type === self::PACKAGE_TYPE_CASH trans('strings.golds') : trans('strings.coins')), 1.00doubleval($donate->price))
                    ->
    setCurrency(Setting::get('currency'))
                    ->
    setQuantity(1)
                    ->
    setPrice(doubleval($donate->price));
            
    $itemList = new ItemList();
            
    $itemList->setItems(array($item1));

            
    $amount = new Amount();
            
    $amount->setCurrency(Setting::get('currency'))
                    ->
    setTotal(doubleval($donate->price));
            
    $transaction = new Transaction();
            
    $transaction->setAmount($amount)
                    ->
    setItemList($itemList)
                    ->
    setDescription(trans('strings.donation') . Setting::get('servername'))
                    ->
    setInvoiceNumber($donate->internal_code);
            
    $redirectUrls = new RedirectUrls();
            
    $redirectUrls->setReturnUrl(route('paypal::execute'))
                    ->
    setCancelUrl(route('paypal::cancel'));
            
    $payment = new Payment();
            
    $payment->setIntent("sale")
                    ->
    setPayer($payer)
                    ->
    setRedirectUrls($redirectUrls)
                    ->
    setTransactions(array($transaction));
            try {
                
    $payment->create($this->api);
            } catch (
    Exception $ex) {
                
    dd($ex);
            }
            
    $donate->transaction_code $payment->getToken();
            
    $donate->save();
            
    $approvalUrl $payment->getApprovalLink();
            return 
    $approvalUrl;
        }

        public function 
    notification() {
            
    $request request();
            
    $paymentId $request->paymentId;
            
    $payment Payment::get($paymentId$this->api);
            
    $execution = new PaymentExecution();
            
    $execution->setPayerId($request->PayerID);
            try {
                
    $result $payment->execute($execution$this->api);
                
    $transactions $result->getTransactions();

                
    $donate Donate::where('internal_code'$transactions[0]->getInvoiceNumber())->first();
                if (
    is_null($donate)) {
                    die;
                } else {
                    
    $this->updatePayment($donate$result);
                }
            } catch (
    Exception $ex) {
                \
    Log::debug((array) $ex);
            }
            return 
    $payment;
        }

        public function 
    updatePayment($donate$request) {
            
    $donate->transaction_code $request->getId();
            
    $donate->status $this->PAYPALstatus[$request->getState()];
            
    $donate->save();
            
    $this->processor($donate);
        }

        public function 
    executeBan(\App\Models\User $user) {
            
        }

    }

  6. #6
    cMuServices cMu is offline
    True MemberRank
    Jan 2017 Join Date
    412Posts

    Re: Webengine and paypal/credits issue

    Quote Originally Posted by Bola View Post
    i'm not sure if this is something about the paypal API or what, but i never was able to put IPN to work properly, so i decide to use other approach like Rest API, for me works perfect and just required to set payment details, then right after user make the payment, you need to execute it in order to finish the trade, with this proccess complete you already can delivery the player reward, i'll drop here my class for paypal rest API.

    pay attention that most of Settings::get() bring some data from main settings and Donate:: bring me model from database for donation.

    PHP Code:
    <?php

    namespace App\Payments;

    use 
    Setting;
    use 
    App\Models\Donate;
    use 
    PayPal\Rest\ApiContext;
    use 
    PayPal\Auth\OAuthTokenCredential;
    use 
    PayPal\Api\Amount;
    use 
    PayPal\Api\Item;
    use 
    PayPal\Api\ItemList;
    use 
    PayPal\Api\Payer;
    use 
    PayPal\Api\Payment;
    use 
    PayPal\Api\RedirectUrls;
    use 
    PayPal\Api\Transaction;
    use 
    PayPal\Api\PaymentExecution;

    class 
    PayPal implements GatewayInterface {

        use 
    Processor;

        private 
    $client_id "";
        private 
    $secret "";
        private 
    $api null;
        
    //sandbox - live 
        
    private $env "live";
        private 
    $PAYPALstatus = [
            
    'created' => self::STATUS_CREATED,
            
    'approved' => self::STATUS_APPROVED,
            
    'failed' => self::STATUS_CANCEL
        
    ];

        public function 
    __construct() {
            if (
    Setting::get('paypal_enable')) {
                
    $this->client_id Setting::get('paypal_clientid');
                
    $this->secret Setting::get('paypal_secret');
                
    $this->api = new ApiContext(
                        new 
    OAuthTokenCredential($this->client_id$this->secret)
                );
                
    $this->api->setConfig([
                    
    //   'log.LogEnabled' => true,
                    //  'log.FileName' => 'PayPal.log',
                    // 'log.LogLevel' => 'DEBUG',
                    
    'mode' => $this->env
                
    ]);
            }
        }

        public function 
    createPayment(\App\Models\Donate $donate) {
            
    $payer = new Payer();
            
    $payer->setPaymentMethod("paypal");
            
    $item1 = new Item();
            
    $item1->setName(trans('strings.donation') . " - " Setting::get('servername') . ' - ' $donate->login ' - ' $donate->reward " " . ($donate->type === self::PACKAGE_TYPE_CASH trans('strings.golds') : trans('strings.coins')), 1.00doubleval($donate->price))
                    ->
    setCurrency(Setting::get('currency'))
                    ->
    setQuantity(1)
                    ->
    setPrice(doubleval($donate->price));
            
    $itemList = new ItemList();
            
    $itemList->setItems(array($item1));

            
    $amount = new Amount();
            
    $amount->setCurrency(Setting::get('currency'))
                    ->
    setTotal(doubleval($donate->price));
            
    $transaction = new Transaction();
            
    $transaction->setAmount($amount)
                    ->
    setItemList($itemList)
                    ->
    setDescription(trans('strings.donation') . Setting::get('servername'))
                    ->
    setInvoiceNumber($donate->internal_code);
            
    $redirectUrls = new RedirectUrls();
            
    $redirectUrls->setReturnUrl(route('paypal::execute'))
                    ->
    setCancelUrl(route('paypal::cancel'));
            
    $payment = new Payment();
            
    $payment->setIntent("sale")
                    ->
    setPayer($payer)
                    ->
    setRedirectUrls($redirectUrls)
                    ->
    setTransactions(array($transaction));
            try {
                
    $payment->create($this->api);
            } catch (
    Exception $ex) {
                
    dd($ex);
            }
            
    $donate->transaction_code $payment->getToken();
            
    $donate->save();
            
    $approvalUrl $payment->getApprovalLink();
            return 
    $approvalUrl;
        }

        public function 
    notification() {
            
    $request request();
            
    $paymentId $request->paymentId;
            
    $payment Payment::get($paymentId$this->api);
            
    $execution = new PaymentExecution();
            
    $execution->setPayerId($request->PayerID);
            try {
                
    $result $payment->execute($execution$this->api);
                
    $transactions $result->getTransactions();

                
    $donate Donate::where('internal_code'$transactions[0]->getInvoiceNumber())->first();
                if (
    is_null($donate)) {
                    die;
                } else {
                    
    $this->updatePayment($donate$result);
                }
            } catch (
    Exception $ex) {
                \
    Log::debug((array) $ex);
            }
            return 
    $payment;
        }

        public function 
    updatePayment($donate$request) {
            
    $donate->transaction_code $request->getId();
            
    $donate->status $this->PAYPALstatus[$request->getState()];
            
    $donate->save();
            
    $this->processor($donate);
        }

        public function 
    executeBan(\App\Models\User $user) {
            
        }

    }
    here is the IPN listener from my CMS, and now just work with it:
    PHP Code:
    <?php    require 'autoloader.php';        date_default_timezone_set("America/Chicago");    $Database = new Database;    $Website = new Website;    $Account = new Account;    $req 'cmd=_notify-validate';    foreach($_POST as $key => $value){        if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() == 1){            $value stripslashes($value);        }        $value urlencode($value);        $req .= "&$key=$value";    }    $ch curl_init('https://ipnpb.paypal.com/cgi-bin/webscr');    curl_setopt($chCURLOPT_HTTP_VERSIONCURL_HTTP_VERSION_1_1);    curl_setopt($chCURLOPT_POST1);    curl_setopt($chCURLOPT_RETURNTRANSFER1);    curl_setopt($chCURLOPT_POSTFIELDS$req);    curl_setopt($chCURLOPT_SSLVERSION6);    curl_setopt($chCURLOPT_SSL_VERIFYPEER1);    curl_setopt($chCURLOPT_SSL_VERIFYHOST2);    curl_setopt($chCURLOPT_CAINFO__DIR__ '/cert/cacert.pem');    curl_setopt($chCURLOPT_FORBID_REUSE1);    curl_setopt($chCURLOPT_CONNECTTIMEOUT30);    curl_setopt($chCURLOPT_HTTPHEADER, array(        'User-Agent: PHP-IPN-Verification-Script',        'Connection: Close',    ));    $res = @curl_exec($ch);    if(!$res){        writelog('cURL error: ['.curl_errno($ch).'] '.curl_error($ch).'''Paypal');        die();    }    $info curl_getinfo($ch);    if($info['http_code'] != 200){        writelog('PayPal responded with http code '.$info['http_code'].'''Paypal');        die();    }    curl_close($ch);



Advertisement