gpt4 book ai didi

javascript - React 的 Paypal Checkout 按钮不允许登录

转载 作者:太空宇宙 更新时间:2023-11-03 16:05:04 25 4
gpt4 key购买 nike

我在使用沙箱将 Paypal 与我的 React 应用程序集成时遇到问题。当我单击该按钮时,会打开一个 PayPal 弹出窗口,当我输入我的凭据进行登录时,出现以下错误:

Paypal popup Paypal error

我可以看到登录表单,但它不会让我登录,相反我会看到该消息。

App.js

import PaypalButton from './PaypalButton';

const CLIENT = {
sandbox: 'xxxxx',
production: 'xxxxx',
};

const ENV = process.env.NODE_ENV === 'production' ? 'production' : 'sandbox';

render() {
const onSuccess = (payment) =>
console.log('Successful payment!', payment);

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

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

return(
<div>
<PaypalButton
client={CLIENT}
env={ENV}
commit={true}
currency={'USD'}
total={500.00}
onSuccess={onSuccess}
onError={onError}
onCancel={onCancel}
/>
</div>
)
}

PaypalButton

import React from 'react';
import ReactDOM from 'react-dom';
import scriptLoader from 'react-async-script-loader';

class PaypalButton extends React.Component {
constructor(props) {
super(props);

this.state = {
showButton: false,
};

window.React = React;
window.ReactDOM = ReactDOM;
}

componentDidMount() {
const {
isScriptLoaded,
isScriptLoadSucceed
} = this.props;

if (isScriptLoaded && isScriptLoadSucceed) {
this.setState({ showButton: true });
}
}

componentWillReceiveProps(nextProps) {
const {
isScriptLoaded,
isScriptLoadSucceed,
} = nextProps;

const isLoadedButWasntLoadedBefore =
!this.state.showButton &&
!this.props.isScriptLoaded &&
isScriptLoaded;

if (isLoadedButWasntLoadedBefore) {
if (isScriptLoadSucceed) {
this.setState({ showButton: true });
}
}
}

render() {
const {
total,
currency,
env,
commit,
client,
onSuccess,
onError,
onCancel,
} = this.props;

const {
showButton,
} = this.state;

const payment = () =>
paypal.rest.payment.create(env, client, {
transactions: [
{
amount: {
total,
currency,
}
},
],
});

const onAuthorize = (data, actions) =>
actions.payment.execute()
.then(() => {
const payment = {
paid: true,
cancelled: false,
payerID: data.payerID,
paymentID: data.paymentID,
paymentToken: data.paymentToken,
returnUrl: data.returnUrl,
};

onSuccess(payment);
});

return (
<div>
{showButton && <paypal.Button.react
env={env}
client={client}
commit={commit}
payment={payment}
onAuthorize={onAuthorize}
onCancel={onCancel}
onError={onError}
/>}
</div>
);
}
}

export default scriptLoader('https://www.paypalobjects.com/api/checkout.js')(PaypalButton);

有人可以帮我解决这个问题吗?

最佳答案

我上周遇到了同样的问题。工作了一段时间后,沙箱开始给我这个错误。我恢复了所有提交以确保这不是我的代码的问题。一两天后,它又开始工作了。

这似乎是 PayPal 沙盒环境的问题。 (Apparently it happens to the best of us)。

如果您发送的数据不正确,您会看到错误的 console.log

关于javascript - React 的 Paypal Checkout 按钮不允许登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52060943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com