0

Please help me.

I'm trying to integrate omnipay/paypal to process payments. Everythings works great until i need to verify my payment. How i register payment:

            $gateway = Omnipay::create('PayPal_Rest');
            $gateway->initialize(array(
                'clientId' => $config['paypal_client_id'],
                'secret'   => $config['paypal_secret'],
                'testMode' => true, // Or false when you are ready for live transactions
            ));
            $response = $gateway->purchase(array(
                'amount'        => $data['price_sum'],
                'currency'      => 'PLN',
                'description'   => 'NNŻ: ' . $description . $data['order_id'],
                'transactionId' => $data['order_id'],
                'returnUrl'     => $app_url . 'basket/pay?token=' . $data['token'],
                'cancelUrl'     => $app_url . 'basket/pay?token=' . $data['token'],
                'notifyUrl'     => $app_url . 'payment/verify-basket-paypal'
            ))->send();


            //print_r( get_class_methods( $response ) );

            // Process response
            if ($response->isSuccessful()) {
                $transaction_id = $response->getTransactionReference();
                Kernel::log('paypal.log' , $transaction_id);
                return ['url' => $response->getRedirectUrl(), 'paypal' => true ];

            } elseif ($response->isRedirect()) {

                // Redirect to offsite payment gateway
                $response->redirect();

            } else {

                // Payment failed
                echo $response->getMessage();
            }

On html page i've added button with url ($response->getRedirectUrl()) after that, i'm redirected to same page, where i want to verify, if payment is booked right.

Url has additional GET params:

/payment/verify-basket-paypal?paymentId=PAYID-L37QMOY42K85628E4550351P&token=EC-3SM080895T541133U&PayerID=Y3DZ53CGGL47N

I've try something like this:

$gateway = Omnipay::create('PayPal_Rest');
$gateway->initialize(array(
    'clientId' => $config['paypal_client_id'],
    'secret'   => $config['paypal_secret'],
    'testMode' => true, // Or false when you are ready for live transactions
));

$transaction = $gateway->fetchTransaction([
    'paymentId' => $request->get['paymentId'],
    'token' => $request->get['token'],
    'PayerID' => $request->get['PayerID']
]);

but it isn't working. Please help, how can i verify payment. There are no additional documentation on their page. Thanks a lot.

  • Have you created/executed a transaction? Returning from PayPal with those parameters means a payment has been approved. It does not mean a transaction has been created. – Preston PHX Jul 03 '20 at 12:44
  • Yes. I click button with created url, then pay and its return to returnUrl. Now when i have those params i want to verify this payment (check if its complete). I can't find any working example - with transaction verification. – Grzegorz Miśkiewicz Jul 03 '20 at 13:15
  • The payment get approves at PayPal, this does not create a transaction. After returning to the returnUrl, the payment attempt must be executed (with an API call) to create a transaction. – Preston PHX Jul 03 '20 at 17:42
  • Ok i understand, but whitch waypoint i must execute ? – Grzegorz Miśkiewicz Jul 06 '20 at 09:39
  • 1
    You'll have to consult the documentation for these Omnipay PayPal methods you are calling. The underlying PayPal HTTPS API operation to execute a transaction is https://developer.paypal.com/docs/api/payments/v1/#payment_execute , and it gets called with the `payer_id` right after returning to e.g. /payment/verify-basket-paypal?paymentId=PAYID-L37QMOY42K85628E4550351P&token=EC-3SM080895T541133U&PayerID=Y3DZ53CGGL47N . So, make sure your implementation does that, to execute the PAYID and return a sale object witha PayPal transaction Id. – Preston PHX Jul 06 '20 at 09:48
  • Thank You a lot. I will check this later :-) – Grzegorz Miśkiewicz Jul 06 '20 at 10:51
  • Ok i found method completePurchase with this - i've now got ...[payer] => Array ( [payment_method] => paypal [status] => VERIFIED ... as transactionReference i enter paymentId and as payerId PayerId from GET. I will try make it old way using CURL. – Grzegorz Miśkiewicz Jul 07 '20 at 09:48
  • It sounds like you have an existing Omnipay code path that does what you need. No reason to be using curl. – Preston PHX Jul 07 '20 at 09:52
  • Yeah i found state complete on $data['transactions'][0]['related_resources'][0]['sale']['state']. Looks its done. Thanks !! – Grzegorz Miśkiewicz Jul 07 '20 at 10:36
  • Please, how you used this $data['transactions'][0]['related_resources'][0]['sale']['state'] or completePurchase because no affecting happen on my fake balance just after i go to paypal and buy redirect to success can you sample code or what i can write to my url becuse that what i get http://127.0.0.1:8000/paypal/success?paymentId=PAYID-MNUP5XI29U599894T70835 – Abdallah Nov 07 '22 at 15:17
  • I only check if stament: if ($data['transactions'][0]['related_resources'][0]['sale']['state'] == 'completed') to be clearly sure – Grzegorz Miśkiewicz Nov 10 '22 at 08:50

0 Answers0