Smart Payment Buttons redirect implementation.

felipejt
Contributor
Contributor

Hi, actually I do a little implementation with Paypal Smart Buttons SDK and Paypal Checkout Java SDK, and I need to redirect to a success page. Can it is possible? Actually I'm tried to use Side Server application context configuration.

 

paypal.Buttons({
                createOrder: (data, actions) => {
                    // Set up the transaction
                    return fetch('${contextPath}/paypalCreateOrder', {
                        method: 'post',
                        headers: {
                            'content-type': 'application/json'
                        }
                    }).then(function (res) {
                        return res.json();
                    }).then(function (data) {
                        return data.orderID;
                    });
                },
                onApprove: (data, actions) => {
                    // Capture the funds from the transaction
                    return actions.order.capture().then(function (details) {
                        // Show a success message to your buyer
                        console.log('Transaction completed by ' + details.payer.name.given_name);
                        return fetch('${contextPath}/paypalValidation', {
                            method: 'post',
                            headers: {
                                'content-type': 'application/json'
                            },
                            body: JSON.stringify({
                                orderID: data.orderID
                            })
                        }).then(function (res){
                            return res.json();
                        }).then(function (data){
                            actions.redirect();
                            return data;
                        });
                    });
                },
                onCancel: (data, actions) => {
                    return actions.redirect();
                }
            }).render('#paypal-checkout-buttons');

 This implementation is development under a Spring Boot Application.

Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.