skip to Main Content

I am trying to integrate paypal api with PHP compared to the old button form that I have used to date on my sites. But there is one thing that is not clear to me, is it more correct to integrate paypal with client_id and secret or through the codes provided in the account panel (api username, api password and signature)? I followed the REST API integration guide (version 2) but they require client_id and secret. So what is the data in the account panel for? Anyone can clarify my ideas? Thank you

2

Answers


  1. The API username, password, and signature is used by the classic NVP/SOAP APIs, which are much older than the REST API. They exist only for backwards compatibility with old shopping cart software and such integrations.

    The v2/checkout/orders API should be used for current PayPal Checkout integrations. Pair two routes on your server (one for create order, one for capture order) that return/output only JSON data (never any HTML or text) with this JS approval flow.

    Login or Signup to reply.
  2. I would go with JS SDK inline integration – requires client-id only and is more flexible than checkout buttons. Also creates nice user experience as if staying on the page (no redirects to 3rd party site). See all demos here.

    paypal.Buttons({
    
        createOrder: function(data, actions) {
            return actions.order.create({
                // note: custom_id (127 chars) will be passed later back in capture
                purchase_units: [{
                    amount: {
                        value: amtDue.toFixed(2),
                        currency: 'EUR'
                    },
                    description : description,
                    custom_id : '<?= $encryptedPaymentData ?>'
                }]
            });
        },
    
        onApprove: function(data, actions) {
            $("#global-spinner").show();
            // set custom capture handler
            return actions.order.capture().then(function(details) {
                $.ajax({
                    type: "POST",
                    url: "/paypal/success",
                    data: ({
                        details : details,
                        ad : amtDue,
                        desc : description,
                        _token : '<?= $csrf ?>'
                    }),
                    success: function(resp) {
                        $("#global-spinner").hide();
                        window.showThankYou(); // some "thank you" function
                    },
                    error: function() {
                        $("#global-spinner").hide();
                        alert("Connection error.");
                    }
                });
            });
        },
    
        onError:  function (err) {
            // some custom function - send error data to server logger
            window.handlePaypalError(err, description, amtDue);
        }
    
    }).render('#paypal-button-container');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search