title: How to set up Paypal Smart Buttons with Flask?
body: <p>I already did a server-side setup for Paypal Payments. I get the product price from the Html form and then creates a payment with <strong>paypalrestsdk module</strong>. Important Chunk of code from the whole system is here:-</p>
  
  <pre><code>payment = paypalrestsdk.Payment({
          "intent": "sale",
          # Set payment method
          "payer": {
              "payment_method": "paypal"
          },
          # Set redirect URLs
          "redirect_urls": {
              "return_url": url_for('after_payment_done_2_sol', hash_id=hash_id, user_id=current_user.user_id, _external=True),
              "cancel_url": url_for('topup', _external=True)
          },
          # Set transaction object
          "transactions": [{
              "amount": {
                  "total": query.total_price,
                  "currency": "USD"
              },
              "description": f"Payment Method for paying {query.total_price} for Top Up"
          }]
      })
      if payment.create():
          print('Payment "{}" created successfully'.format(payment.id))
          for link in payment.links:
              if link.method == "REDIRECT":
                  redirect_url = str(link.href)
                  print('Redirect for approval: {}'.format(redirect_url))
                  return redirect(redirect_url)
  </code></pre>
  
  <p>So this will create a link to "Pay X Amount via Paypal". But i want to integrate smart Buttons like here
  <a href="https://developer.paypal.com/demo/checkout/#/pattern/server" rel="nofollow noreferrer">https://developer.paypal.com/demo/checkout/#/pattern/server</a>. Now here there is a codeblocks like:</p>
  
  <pre><code> &lt;script&gt;
      // Render the PayPal button into #paypal-button-container
      paypal.Buttons({
          // How Does this work?????????????????????
          // Set up the transaction
          createOrder: function(data, actions) {
              return fetch('/demo/checkout/api/paypal/order/create/', {
                  method: 'post'
              }).then(function(res) {
                  return res.json();
              }).then(function(data) {
                  return data.orderID;
              });
          },
          // ???????????????????????????????????????? How does this Work?????
          // Finalize the transaction
          onApprove: function(data, actions) {
              return fetch('/demo/checkout/api/paypal/order/' + data.orderID + '/capture/', {
                  method: 'post'
              }).then(function(res) {
                  return res.json();
              }).then(function(details) {
                  // Show a success message to the buyer
                  alert('Transaction completed by ' + details.payer.name.given_name + '!');
              });
          }
  
  
      }).render('#paypal-button-container');
  &lt;/script&gt;
  </code></pre>
  
  <p>So here <strong>how does onAprrove and createOrder Works? And how should i set up my route in flask?</strong> Any help Please!</p>