mstdmstd's avatar

There are no automatic redirection with paypal/rest-api-sdk-php

Hello, Implementing paypal in my laravel 5.8 app and looking at the code snippet : https://developer.paypal.com/docs/archive/checkout/integrate/?mark=get%20the%20code#set-up-your-development-environment

I do not seer which is returns valid format?

here https://developer.paypal.com/docs/integration/direct/payments/paypal-payments/#create-paypal-payment I found that redirect_urls must be used , so my button definition is :

                        <script>
                            paypal.Button.render({
                                // Configure environment
                                env: 'sandbox',
                                client: {
                                    sandbox: 'CLIENTID',
                                    production: 'demo_production_client_id'
                                },
                                // Customize button (optional)
                                locale: 'en_US',
                                style: {
                                    size: 'small',
                                    color: 'blue',
                                    shape: 'pill',
                                },

                                commit: true,

                                payment: function(data, actions) {
                                    return actions.payment.create({

                                        "note_to_payer": "Contact us for any questions on your order.",

                                        "intent": "sale",
                                        "payer": {
                                            "payment_method": "paypal"
                                        },

                                        redirect_urls : { //redirect_urls
                                            return_url : 'https://www.votes.nilov-sergey-demo-apps.tk/paypal_payment',
                                            cancel_url : 'https://www.votes.nilov-sergey-demo-apps.tk/paypal_payment_cancel'
                                        },
                                        
                                        transactions: [{
                                            amount: {
                                                total: '0.01',
                                                currency: 'USD'
                                            }
                                        }]
                                    });
                                },
                                // Execute the payment
                                onAuthorize: function(data, actions) {
                                    console.log("onAuthorize data::")
                                    console.log( data )

                                    console.log("onAuthorize actions::")
                                    console.log( actions )

                                    return actions.payment.execute().then(function() {
                                        // Show a confirmation message to the buyer

                                        window.alert('Thank you for your purchase! 0');
                                    });
                                }
                            }, '#paypal-button');

                        </script>

I see alert in actions.payment.execute method, but no automatic rederection at url specified in return_url, as I expected. I uploaded my site live at https://www.votes.nilov-sergey-demo-apps.tk under LAMP, Ubuntu 18 , Digital Ocean. Why there are no automatic redirection ?

    $ php artisan --version
    Laravel Framework 5.8.24
In composer.json:
    "paypal/rest-api-sdk-php": "*",

Thanks!

0 likes
3 replies
bobbybouwmann's avatar

I don't see anything strange. Can you see what the payment itself returns

 payment: function(data, actions) {
    var payment = actions.payment.create({
        // Payment details here
    });

    console.log(payment);

    return payment;
}
mstdmstd's avatar

I do not see a difference. You created a var and cionsole it and returned it in method. In my case object returns an object:

                               payment: function(data, actions) {
                                    return actions.payment.create({

                                        "note_to_payer": "Contact us for any questions on your order.",

                                        "intent": "sale",
                                        "payer": {

Has it difference ?

mstdmstd's avatar

I remade in proposed way :

                                    payment: function(data, actions) {
                                        var payment = actions.payment.create({

                                            "note_to_payer": "Contact us for any questions on your order.",

                                            "intent": "sale",
                                            "payer": {
                                                "payment_method": "paypal"
                                            },

                                            redirect_urls : { //redirect_urls
                                                return_url : 'https://www.votes.nilov-sergey-demo-apps.tk/paypal_payment',
                                                cancel_url : 'https://www.votes.nilov-sergey-demo-apps.tk/paypal_payment_cancel'
                                            },
                                            
                                            transactions: [{
                                                amount: {
                                                    total: '0.01',
                                                    currency: 'USD'
                                                }
                                            }]
                                        });

                                        console.log("payment payment::")
                                        console.log(payment);
                                        // alert( "::"+var_dump(-88) )
                                        return payment;
                                        
                                    },

and noteced warnings :

Firefox can’t establish a connection to the server at wss://www.votes.nilov-sergey-demo-apps.tk/app/123?protocol=7&client=js&version=4.3.1&flash=false. app.js:1767:16
The connection to wss://www.votes.nilov-sergey-demo-apps.tk/app/123?protocol=7&client=js&version=4.3.1&flash=false was interrupted while the page was loading.

printscreen with console payment output and and error messages looks like : https://imgur.com/a/znKtMGw

What raised these errors ?

Please or to participate in this conversation.