E
E
Eugene2021-10-01 14:24:29
PHP
Eugene, 2021-10-01 14:24:29

PayPal IPN listener does not send emails. How to fix?

There is a local virtual server. A tunnel will be thrown to it through ngrok. Instant payment notification (IPN) is enabled
in the business account settings https://www.sandbox.paypal.com . Address specified. Through the Instant Payment Notification (IPN) simulator, notifications calmly come.

But. create a payment. I get Approved Link. I confirm the payment from the buyer's account. Goes to the confirm page. Notifications do not come.

public function actionPayment(): string
    {
        $paypal = new PaypalForm();

        if ($paypal->load(Yii::$app->request->post()) && $paypal->validate()) {

            $apiContext = new ApiContext(
                new OAuthTokenCredential(
                    '-----',     // ClientID
                    '-----'  // ClientSecret
                )
            );

            $apiContext->setConfig(
                array(
                    'mode' => 'sandbox',
                )
            );


            $payer = new Payer();
            $payer->setPaymentMethod('paypal');
            $item = new Item();
            $item->setName('test pro 1')
                ->setCurrency('RUB')
                ->setQuantity(1)
                ->setSku("testpro1_01")
                ->setPrice(1000);

            $itemList = new ItemList();
            $itemList->setItems(array($item));

            $payerInfo = new PayerInfo();
            $payerInfo->setEmail('адрес@personal.example.com');
            $payerInfo->setFirstName('Достоевский');
            $payerInfo->setLastName('Александр');
            $payer->setPayerInfo($payerInfo);

            $amount = new Amount();
            $amount->setTotal('1000.00');
            $amount->setCurrency('RUB');

            $transaction = new Transaction();
            $transaction->setAmount($amount)
            ->setItemList($itemList)
            ->setDescription("Payment description");

            $redirectUrls = new RedirectUrls();
            $redirectUrls->setReturnUrl("/client/paypal/confirm")
                ->setCancelUrl("/client/paypal/cancel");

            $payment = new Payment();
            $payment->setIntent('sale')
                ->setPayer($payer)
                ->setTransactions(array($transaction))
                ->setRedirectUrls($redirectUrls);


            try {
                $payment->create($apiContext);

                $billingService = new BillingService(Yii::$app->user->identity->id);
                $billingService->createPayment($payment);
                echo "<pre>";
                echo $payment;

                echo "\n\nRedirect user to approval_url: " . $payment->getApprovalLink() . "\n";
                echo "</pre>";
                die;
            }
            catch (PayPalConnectionException $ex) {
                // This will print the detailed information on the exception.
                //REALLY HELPFUL FOR DEBUGGING
                echo "<pre>";
                echo $ex->getData();
                echo "</pre>";

                die;
            }

        }
        return $this->render('payment', [
            'paypal' => $paypal,
        ]);
    }


Maybe I'm not sending all the data?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question