简体   繁体   中英

PayPal React Integration not creating transaction

I'm trying to integrate with PayPal checkout using the react library (@paypal/react-paypal-js), the response of the payment is successful, but when I use the live client id it doesn't bill from my credit card.


import { api } from "../services/api";
import { PayPalButtons, PayPalScriptProvider } from "@paypal/react-paypal-js";


export default function Pagamento() {

  function createOrder(data, actions) {
    return actions.order.create({
      intent: "CAPTURE",
      purchase_units: [
        {
          amount: {
            value: "2.00",
          },
        },
      ],
    });
  }

  function onApprove(data, actions) {
    console.log(data);
    const paymentID = data.paymentID;
    const orderID = data.orderID;
    const payerID = data.payerID;

    api
      .get("update_pacientes", {
        params: {
          username: username,
          column: "status",
          paymentID: paymentID,
          orderID: orderID,
          payerID: payerID,
        },
      })
      .then((response) => {
        console.log(response);
        // , location.reload();
      });
  }


  return (
    <div id="pagamento_wrapper">
      
        <PayPalScriptProvider
          options={{
            "client-id": OMMITED FOR SECURITY REASONS
             ,
            currency: "BRL",
          }}
        >
          <PayPalButtons
            style={{ color: "blue", shape: "pill", label: "pay", height: 40 }}
            createOrder={(data, actions) => createOrder(data, actions)}
            onApprove={(data, actions) => onApprove(data, actions)}
          />
        </PayPalScriptProvider>
      </div>
    </div>
  );
}

Your onApprove function is not capturing the order after the payer approves it, so there is no PayPal transaction created.

Since from inside createOrder you used actions.order.create to create on the client side, you should also capture on the client side via actions.order.capture (from inside onApprove )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM