我的应用程式中的ppxo_no_token_passed_to_payment

时间:2019-02-17 02:30:50

标签: javascript reactjs firebase paypal

Paypay按钮不起作用 example 控制台说的是错误,我找不到解决方案。 我正在使用React,并且在Firebase托管和Firebase函数中托管所有内容。 我正在使用公共文件夹来托管react应用程序,并使用文件夹函数来托管API 上市     反应应用 功能     api

import React, { Component } from "react";
import ReactDOM from "react-dom";
import './App.css';

    const CLIENT = {
      sandbox:
        "AVLCLwSpOM3Tg2Ouav2XD7easntAAFwvyAFANVAxLVqGVg2N_hgbUujcAvTRlhaerDS0H63jF8AkfB6n",
      production:
        "AbUU24FJYR_RkLtlY4lgs-v-1pghFgZUnkJAgs0PFkdtWLsgoxAuAAoC6qvvquAAmc_gronz7ISuDqCa"
    };
    const ENV = "sandbox";

    class App extends Component {
      render() {
        const payment = (data, actions) => {
          return actions.request
            .post("/paypal/create-payment", {
              price: "10",
              eventName: "Test",
              return_url: "http://localhost:3000/",
              cancel_url: "http://localhost:3000/cancel"
            })
            .then(res => res.id)
            .catch(err => {
              this.setState({
                reschedule: "Booking failed - cannot initialize payment"
              });
            });
        };

        const onError = error =>
        console.log("Erroneous payment OR failed to load script!", error);

      const onCancel = data => console.log("Cancelled payment!", data);

        // Execute the payment:
        // 1. Add an onAuthorize callback
        const onAuthorize = (data, actions) => {
          //2. Make a request to your server
          return actions.request.post("/paypal/execute-payment", {
            paymentID: data.paymentID,
            payerID: data.payerID
          }).then(function(res) {
            // 3. Show the buyer a confirmation message.
          });
        }

        const PayPalButton = window.paypal.Button.driver("react", {
          React,
          ReactDOM
        });

        return (
          <div>
            <PayPalButton
              client={CLIENT}
              env={ENV}
              commit={true}
              payment={payment}
              onAuthorize={onAuthorize}
              onError={onError}
              onCancel={onCancel}
            />
          </div>
        );
      }
    }

    export default App;

0 个答案:

没有答案