-1

If you create an order id, and then create a button adding the order is like this:

paypal.buttons({
    createOrder: function(data, actions) {
        return orderId;
    },
    .
    .
}).render('#my-paypal-container');

Then create a second order id, passing an object with a different createOrder method that returns a different order ID. Will the customer be charged for two orders or just the second one?

If the customer is charged for both orders, how do I clean up the first button/order before initiating the second one?

Dom
  • 2,980
  • 2
  • 28
  • 41

1 Answers1

1

The createOrder function is called when a button is clicked. No one is charged unless (1) they finish approving the order, and (2) the order is captured.

That first step is done by the user by entering all their information and confirming their approval. The last step is then done from the onApprove function.

Preston PHX
  • 27,642
  • 4
  • 24
  • 44
  • Thanks for the input. What happens if you make a second call to `paypay.buttons()` with an object a createOrder method that contains a new payment id, but without the first button having been clicked? Does it ovewrite the existing button, does it append the new order to the existing button? – Dom Feb 01 '21 at 14:55
  • A second button is rendered, assuming you call .render(). If you want to do something with the first button, save it to a variable before calling .render(). Then you can `.close()` it later. – Preston PHX Feb 01 '21 at 15:20
  • But that shouldn't be useful or necessary. Your createOrder function should simply get the correct id when clicked, https://developer.paypal.com/demo/checkout/#/pattern/server – Preston PHX Feb 01 '21 at 15:38
  • Can you edit your answer with your second comment so I can accept it? – Dom Feb 01 '21 at 16:19