7
votes

I have the following code from https://developer.paypal.com/demo/checkout/#/pattern/confirm

The code is working as the Paypal checkout page shows and I'm able to enter all of my information. The issue that I'm having is that the onAuthorize() does NOT get called at all. Even when I complete a transaction, the only thing that gets called is the onCancel() function.

NOTE: I'm using the test credit cards from here https://www.paypalobjects.com/en_US/vhelp/paypalmanager_help/credit_card_numbers.htm

        paypal.Button.render({
          // Set your environment
          env: 'sandbox', // sandbox | production
          // Create a PayPal app: https://developer.paypal.com/developer/applications/create
          client: {
            sandbox:    'AY2UxZoOkoWQ0-******',
            production: '' // This is not set
          },
          commit: true, // Set to 'Pay Now'
          payment: function() { // Wait for the PayPal button to be clicked
            // Make a client-side call to the REST api to create the payment
            return paypal.rest.payment.create(this.props.env, this.props.client, {
              transactions: [
                {
                  amount: { total: '10.00', currency: 'USD' }
                }
              ]
            });
          },
          // Wait for the payment to be authorized by the customer
          onAuthorize: function(data, actions) {
            console.log('onAuthorize');
          },
          onCancel: function(data, actions) {
            console.log('onCancel');
            console.log(data);
          }
        }, '#paypal-button-container');

The response when I print the data object from onCancel() is the following:

{
    cancelUrl: "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&xo_node_fallback=true&force_sa=true&fallback=1&token=EC-90M952801L841090P",
    intent: "sale",
    paymentToken: "EC-90M952801L841090P"
}
1
Do you see the same result when using the button directly on the demo site?bluepnume
@bluepnume Yes, the exact same. Only onCancel() will get called once added. Take a look if that helps.zee
But if you don't add onCancel it works? Or just nothing happensbluepnume
@bluepnume Then it won't do anything at all. Still won't get into onAuthorize()zee
@bluepnume Not sure if it makes a difference, but I'm using the test credit cards from here paypalobjects.com/en_US/vhelp/paypalmanager_help/…zee

1 Answers

0
votes

I was right now working on that issue. I realized while during tests and thanks to you @zee (I read that "Only onCancel() will get called once added.." that made me think) that ONLY IN SANBOX checkout.js will call onCancel() ALWAYS (or at least, always for me and all my tests). I was (10 minutes ago) thinking to implement an horrible "IF" in the onCancel() to handle the response and call my server like I wanted to do inside onAutorize() (after payment execution etc...). Before that i tried once with the production keys and.... it worked!! onAutorize() was called and all was running as expected. I was on this issue till yesterday and was burning, I hope this will help somebody.

Simone