0
votes

I have a paypal button with the code in a file name paypaltest.php:

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<!--<input type="hidden" name="custom" value="<?php //echo $id ?>">-->
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

I also have a paypal ipn php file name listener.php in the same location on my web hosting server directory.

I want to know how would i link the two to know if a transaction was Verified or not. Should i replace the sandbox url on the form with the listener.php file.

1
add a hidden input named "notify_url" and set its value to your ipn listener e.g., <input type="hidden" name="notify_url" value="myserver.com/shop/listener.php">JBart
I see thanks. I hope that is secure way of doing it thoughLee
You CAN set the notify URL in your Paypal profile, so it is not publicly exposed. However, it means you can only have one IPN listener. In any event, you should not depend on people not knowing what your listener is for security. The script itself should verify the data. Tip: Don't try to write the verification code yourself, instead use paypal's code on github.JBart
Thanks alot i got it to work using the code on paypal site. I just need to figure out how to pass in an amount to charge now, rather than setting a static amount.Lee
can you elaborate your questionAjith jojo

1 Answers

1
votes

I can help you with single page PayPal pay now button actually I use this one of my projects

<script src="https://www.paypal.com/sdk/js?client-id=XXXXXXXXXXXXXXXXX">
  </script> 

<div id="paypal-button-container"> </div>


 <script>
  paypal.Buttons({
    createOrder: function(data, actions) {
      return actions.order.create({
        purchase_units: [{
          amount: {
            value: '1230'
          }
        }]
      });
    },
    onApprove: function(data, actions) {
      return actions.order.capture().then(function(details) {
        alert('Transaction completed');
        // Call your server to save the transaction
        return fetch('codes/paypalapi.php?invo=123', {
          method: 'post',
          headers: {
            'content-type': 'application/json'
          },
          body: JSON.stringify({
            orderID: data.orderID,
            amount: data.amount
          })         
        });
      });
    }
  }).render('#paypal-button-container');
</script>