thephpleague / omnipay-paypal

PayPal driver for the Omnipay PHP payment processing library
MIT License
295 stars 174 forks source link

notifyUrl doesn't work! #264

Open MarcoHijacker opened 1 year ago

MarcoHijacker commented 1 year ago

Dear omnipay-paypal community,

Recently PayPal contacted me to upgrade my 'old-style' CodeIgniter e-commerce cart (an old standard paypal gateway with a simple form to related paypal endpoint) to a solution with access token and client_id + secret. I used omnipay-paypal, following a guide like this:

https://artisansweb.net/paypal-payment-gateway-integration-in-php-using-paypal-rest-api/

And everything seems working fine, but with old standard cart I used a notifyUrl to send payment post data to a controller that made something like this:

foreach ($_POST as $key => $value) {
$request .= '&' . $key . '=' . urlencode(html_entity_decode($value, ENT_QUOTES, 'UTF-8'));
}

$curl = curl_init('https://www.paypal.com/cgi-bin/webscr');

curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_TIMEOUT, 120);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$response = curl_exec($curl);

If that $response is VERIFIED, I enable related order for delivery (paid). Issue is that notifyUrl isn't triggered at all with Omnipay and this avoids to fit the shoe.

I tried to setup notifyUrl parameter on purchase, completePurchase method, but nothing to do: no call is sent after payment confirmation and no payment data in the related $_POST object.

Someone could give me some hint or help?

sersart commented 1 year ago

Hi Marco, Please let me know if you found solution?

MarcoHijacker commented 1 year ago

I'm sorry, but no solutions and never any response from omnipay community. I had to switch libraries.

ixperiencenl commented 1 year ago

For PayPal, you need the IPN being set in the APP settings in the PayPal dashboard. I also struggled with this, but with this package (and using the Rest implementation), you cannot change the IPN on the fly, and even if you could, it should be the same as you've set in the PayPal app settings.

MarcoHijacker commented 1 year ago

I know that, but I needed a dynamic notifyUrl, which couldn't obviously be done fixing it into PayPal settings. Then I resolved the problem using another package.

ixperiencenl commented 1 year ago

Ah,yeah then this package doesn't look suitable. Please share the package name you're using, in case anyone walks into the same problems and need a proper solution :)

Thanks and good night :)

MarcoHijacker commented 1 year ago

Sure: https://github.com/paypal/Checkout-PHP-SDK

sersart commented 1 year ago

Hi Marco, I finally implemented paypal and I used both Paypal Standard (For Sales Tax reason) and rest api (For refund). Please check this code I always passing notifyUrl. $data = []; $data['business'] = $twz_digital_download_paypal_email; $data['currency_code'] = $twz_dd_default_currency; $data['cmd'] = '_cart'; $data['upload'] = '1'; $data['rm'] = '2'; $data['bn'] = 'Themewizz_SC_DD_USA';

        // Set the PayPal return addresses.
        $data['return'] = $return_url;
        $data['cancel_return'] = $cancel_url;
        $data['notify_url'] = $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.
        $count = 1;
        $items = $twz_digital_download_cart->get_items();
        foreach ($items as $key => $item) {
            $data['item_name_' . $count] = esc_attr($item->get_name());
            $data['amount_' . $count] = Twz_Digital_Download_Price_Utils::format_price($item->get_price());
            $data['quantity_' . $count] =  esc_attr($item->get_quantity());
            $data['item_number_' . $count] = esc_attr($item->get_item_number());
            $count++;
        }

        // Add any custom fields for the query string.
        $data['custom'] = json_encode($twz_digital_download_cart->get_cart_custom_values());

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

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

Please let me know, if you need help

MarcoHijacker commented 1 year ago

Hi sersart,

First of all, thanks for your help. At the time, I needed this package to make what notifyUrl was supposed to do: doing a call to notifyUrl. I used to attach a specific array to validate payment on proper PayPal endpoint, before activating order on my e-commerce.

I suppose Omnipay hasn't been updated since creation of this thread and giving a quick look to your code, it seems you simply 'moved issue' providing payload in GET with header fn.

At first I thought that I was missing something, but I took a deep look into Omnipay seeing that notifyUrl notification wasn't handled at all.