Jump to content
COMFIED

Integrating Paypal Payment Script

Recommended Posts

I am trying to integrate PayPal payment buttons using the script below via W3DIVHtmlElement.InnerHTML

The app fails to run when I embed the script. How can I can use the PayPal script in the app?

 

<div id="paypal-button-container"></div>
<script src="https://www.paypal.com/sdk/js?client-id=XXXYYYZZZ&currency=USD" data-sdk-integration-source="button-factory"></script>
<script>
  paypal.Buttons({
      style: {
          shape: 'rect',
          color: 'gold',
          layout: 'vertical',
          label: 'pay',
          
      },
      createOrder: function(data, actions) {
          return actions.order.create({
              purchase_units: [{
                  amount: {
                      value: '30'
                  }
              }]
          });
      },
      onApprove: function(data, actions) {
          return actions.order.capture().then(function(details) {
              alert('Transaction completed by ' + details.payer.name.given_name + '!');
          });
      }
  }).render('#paypal-button-container');
</script>
 

Share this post


Link to post
Share on other sites

Your code should work, except for the script placement.

The below code is pretty much the same as yours, just embedded in a button click handler (which you might have done too)

    var W3Button : TW3Button := TW3Button.Create(W3Panel);
    W3Button.SetBounds(580,-10+160*(cartitems.length+1),200,40);
    W3Button.Caption := 'Make Payment';
    W3Button.OnClick := procedure(sender:TObject)
    begin

      var PayPal : TW3Panel := TW3Panel.Create(W3Panel);
      Paypal.SetBounds(140,100 + 160*(cartitems.length+1),400,800);    //position below cart  
      Paypal.StyleClass := 'DIV';                                      //removes all smart's style info
      Paypal.handle.id := 'paypal-button-container';
      Paypal.NativeScrolling := true;
      var paypalamount : string := StrAfter(currencytotal,'A$');

      asm
        paypal.Buttons({
          createOrder: function(data, actions) {
            // This function sets up the details of the transaction, including the amount and line item details.
            return actions.order.create({
              purchase_units: [{
                amount: {
                  value: @paypalamount
                }
              }]
            });
          },
          onApprove: function(data, actions) {
            // This function captures the funds from the transaction.
            return actions.order.capture().then(function(details) {
              // This function shows a transaction success message to your buyer.
              alert('Transaction completed by ' + details.payer.name.given_name);
            });
          }
        }).render('#paypal-button-container');
        //This function displays Smart Payment Buttons on your web page.
      end;


as for the script, put it in the body of your custom template

<body>
    <script src="https://www.paypal.com/sdk/js?client-id=xxx&currency=AUD">


 

Share this post


Link to post
Share on other sites

do something like this (max control)

  var Script := browserapi.document.createElement('script');
  Script.src := 'https://.......your script url ........';

  browserapi.document.head.appendChild(Script);
  Script.onload := procedure
  begin
    showmessage('loaded');
    ... do your thing ...
  end;

this can be part of a button click handler
 

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...