PayPal checkout handle onError message to display for client

thecoorum
New Community Member

Is there any valid/good way to display an Error Message to User (not a reach with error codes and so on)

Here is the code that I'm using now for sandbox

function _renderButton() {
    // Global utility variables
    var _env,
        _envState = !%paypal_is_sandbox%!;

    console.log(_envState);

    // Checking the environment state
    if (_envState === true) {
        _env = "sandbox"
    } else if (_envState === false) {
        _env = "production"
    } else {
        alert("PayPal environment should be true or false")
    }

    // Testing variables (must be changed to dynamic in production)
    var transactionTotal = "1.00"

    var account_shipping_address_recipient_name = "sa_recipient_name";
    var account_shipping_address_line1 = "sa_line1";
    var account_shipping_address_line2 = "sa_line2";
    var account_shipping_address_city = 'San Jose';
    var account_shipping_address_country = "US";
    var account_shipping_address_postal_code = "95131";
    var account_shipping_address_phone = "011862212345678";
    var account_shipping_address_state = "CA";

    // Rendering PayPal Button
    paypal.Button.render({
            // Setting the environment (Sandbox/Production)
            env: _env,
            // Keys for Sandbox and Production environments
            client: {
                sandbox: "!%paypal_sandbox_id%!",
                production: "!%paypal_production_id%!"
            },
            // Setting the locale of the botton
            locale: "en_US",
            // Styling the button
            style: {
                size: 'medium',
                color: 'black',
                shape: 'pill',
                fundingicons: true
            },
            funding: {
                allowed: [paypal.FUNDING.CARD],
                disallowed: [paypal.FUNDING.CREDIT]
            },
            payment: function (data, actions) {
                // Creating payment
                return actions.payment.create({
                        transactions: [{
                            // Amount and currency of transactions
                            amount: {
                                total: transactionTotal,
                                currency: "!%paypal_currency_code%!"
                            },
                            // Values for PayPal shipping checkout pop-up (must be dynamic) 
                            item_list: {
                                shipping_address: {
                                    recipient_name: account_shipping_address_recipient_name,
                                    line1: account_shipping_address_line1,
                                    line2: account_shipping_address_line2,
                                    city: account_shipping_address_city,
                                    country_code: account_shipping_address_country,
                                    postal_code: account_shipping_address_postal_code,
                                    phone: account_shipping_address_phone,
                                    state: account_shipping_address_state
                                }
                            }
                        }]
                        //note_to_payer: 'Contact us for any questions on your order.'
                    })
                    .then(function (resp) {
                        console.log("Response", resp)
                    })
            },
            onAuthorize: function (data, actions) {
                return actions.payment.execute()
                    .then(function () {
                        window.alert("Thank you for your purchase!");
                        console.log("Successful transaction answer", data);

                        notification.show({
                            message: "Transaction Successful"
                        }, "upload-success");
                    })
            },
            onError: function (err) {
                console.log("Error here");
                console.log(err);
                notification.show({
                    title: "Transaction Failed",
                    message: "Transaction Error"
                }, "error");
            },
            onCancel: function (data, actions) {
                console.log(data);
                notification.show({
                    title: "Transaction Failed",
                    message: "Transaction was cancelled by the client"
                }, "error");
            }
        },
        "#paypal-button")
}

* The !% ... %! is a syntax of custom parser

So the environment is sandbox

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.