vpjm3.0
vpjm3.0

Reputation: 53

PayPal Smart Payment Buttons Dynamic Payment Amount

I am trying to integrate the smart payment buttons into a checkout flow where the final payment amount can be variable. I can’t declare the payment amount in actions.order.create because at the time the buttons are rendered, I don’t know the final amount yet. I followed the same set up as the Basic Integration Guide (https://developer.paypal.com/docs/checkout/integrate/) and searched extensively for a solution to this issue.

Basically, my integration is a seminar registration form where the registration and payment all happens on the same page. A user enters how many people will be attending and what age range they are. Based on this info, the final amount is determined. Currently, the Smart Payment Buttons are rendered on the load of this page since that is what is indicated in the basic integration guide. I don’t want to have the registration form on one page and then make them click a button to get to a “checkout” page just so I can load the final amount into the actions.order.create call. That seems like bad design. Is there any way to render the buttons without giving them an amount and then dynamically update that amount at a later time after the user has interacted with the page?

Upvotes: 1

Views: 996

Answers (1)

Preston PHX
Preston PHX

Reputation: 30467

The purchase_units array is not evaluated when the button is rendered, it is evaluated when the button is clicked. So, the value of the amount can be a function call to document.getElementbyId().value or whatever function you want to use to obtain the number.

Upvotes: 2

Related Questions