Problème intégration

tom59000
Contributeur
Contributeur

Bonjour,

j'ai un problème pour récupérer le statut de la transaction avec paypal.

Mon code :

 

<script src="https://www.paypal.com/sdk/js?client-id=xxxxxx&currency=EUR"></script>
  <!-- Set up a container element for the button -->
  <div id="paypal-button-container"></div>
  <script>
    paypal.Buttons({
      // Sets up the transaction when a payment button is clicked
      createOrder: (data, actions) => {
        return actions.order.create({
          purchase_units: [{
            amount: {
              value: '77.44' // Can also reference a variable or function
            }
          }]
        });
      },
      // Finalize the transaction after payer approval
     onApprove(data) {
          return fetch("/my-server/capture-paypal-order", {
            method: "post",
            body: JSON.stringify({
              orderID: data.orderID
            })
          })
          .then((response) => response.json())
          .then((orderData) => {
            // Successful capture! For dev/demo purposes:
            console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
            const transaction = orderData.purchase_units[0].payments.captures[0];
            alert(`Transaction ${transaction.status}: ${transaction.id}\n\nSee console for all available details`);
            // When ready to go live, remove the alert and show a success message within this page. For example:
            // const element = document.getElementById('paypal-button-container');
            // element.innerHTML = '<h3>Thank you for your payment!</h3>';
            // Or go to another URL:  window.location.href = 'thank_you.html';
          });
        }
    }).render('#paypal-button-container');
</script>

 

J'ai bien le message envoyer par "alert".

Mais j'aimerais bien afficher en php avec "echo" le statut de la transaction dans ma page, pour après repartir en php (insertion BDD etc...)

J'ai pas un gros niveau de programmation, surtout avec les api.

Merci de votre aide.

 

Login to Me Too
0 RÉPONSES 0

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.