【发布时间】:2020-07-23 10:37:24
【问题描述】:
我是 Meteor 和集成 Paypal 的新手(我从未做过)。
from Client side in meteor -
我在点击按钮时调用方法。
<MDBBtn onClick={(e) => callPaypal(e)} color="primary" type="submit">
Add and Continue to PayPal
</MDBBtn>
还有这个 callpaypal() 方法 ->
import { Link as ReactRouterLink } from 'react-router-dom'
const callPaypal = (e) => {
e.preventDefault();
Meteor.call('createPayalPayment', (err, res) => {
console.log(res[1].href) **FIRST CONSOLE**
if (res) {
let link = res[1];
if (link.href) {
return <ReactRouterLink to={`${link.href}`} />
}
}
})
}
从服务器调用 createPayalPayment 方法 ->
import { Config } from "./paypal_config";
createPayalPayment() {
var data = {
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"redirect_urls": {
// "return_url": `${Meteor.absoluteUrl('/execute'), { "replaceLocalhost": "true" }}`,
"return_url": "http://127.0.0.1:3000/execute",
"cancel_url": "http://172.20.10.5:3000/cancel"
},
"transactions": [{
"amount": {
"currency": "USD",
"total": "1.00"
},
"description": "This is the payment description."
}]
};
paypal.configure(Config);
var ppCreate = Meteor.wrapAsync(paypal.payment.create.bind(paypal.payment));
var ppExecute = Meteor.wrapAsync(paypal.payment.execute.bind(paypal.payment));
var response = ppCreate(data);
if (response.state !== 'created') {
console.log('not created!!!!!!!!!!!!!!!!')
}
else {
console.log(response); **SECOND CONSOLE**
return response.links;
}
}
这是我的 Paypal 配置 ->
export const Config = {
'mode': 'sandbox',
'client_id': 'client_Id',
'client_secret': 'secret'
};
第一个控制台 --> 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-1HR12649X9688931M'
第二个控制台 -->>
{ id: 'PAYID-L2IJO4I8GE24787GF168351L',
intent: 'sale',
state: 'created',
payer: { payment_method: 'paypal' },
transactions:
[ { amount: [Object],
description: 'This is the payment description.',
related_resources: [] } ],
create_time: '2020-04-10T15:57:37Z',
links:
[ { href: 'https://api.sandbox.paypal.com/v1/payments/payment/PAYID-L2IJO4I8GE24787GF168351L',
rel: 'self',
method: 'GET' },
{ href: 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-1HR12649X9688931M',
rel: 'approval_url',
method: 'REDIRECT' },
{ href: 'https://api.sandbox.paypal.com/v1/payments/payment/PAYID-L2IJO4I8GE24787GF168351L/execute',
rel: 'execute',
method: 'POST' } ],
httpStatusCode: 201
}
因为 links[2].href 是 URL,paypal 应该被重定向到这里并且用户可以登录到帐户。但它不是重定向。所以我在First console 下方的callPaypal() 方法 中手动重定向到此链接。
但是路由器仍然无法重定向到链接,可能是外部域问题,或者即使它没有显示错误。
请问有什么办法可以让paypal自己重定向到paypal登录?我已经在这上面浪费了我的 2 天时间,但仍然一无所获。
谢谢。
我在我的 paypal 开发者帐户中为这个项目添加了重定向 URL。
【问题讨论】:
-
嗨,我没有时间深入研究,但就您的控制台输出在使用 res[1].href 时显示正确的 URL 而言 - 我想这只是一个 React 路由问题。希望您在这里找到答案:medium.com/@bsangars15/… 或在这里:stackoverflow.com/questions/44877821/… - 干杯,汤姆