Lee
Lee

Reputation: 25

paypal IPN and paynow button

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.

Upvotes: 0

Views: 263

Answers (1)

Ajith jojo
Ajith jojo

Reputation: 427

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>

Upvotes: 1

Related Questions