我已经在服务器端(nodejs)中创建了paypal的OrderCreateRequest,并且具有批准链接“ https://www.sandbox.paypal.com/checkoutnow?token=88K34845N63744150”。我需要批准此批准链接。我该怎么做?我的客户端是Reactjs。我所拥有的是:
服务器端
payment.js
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
addWelcomeLabel()
}
func addWelcomeLabel() {
let welcomeLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 500, height: 100))
welcomeLabel.alpha = 0.0
welcomeLabel.center = CGPoint(x: self.view.center.x, y: self.view.center.y)
welcomeLabel.text = "Welcome"
welcomeLabel.textAlignment = .center
welcomeLabel.font = UIFont.boldSystemFont(ofSize: 50)
welcomeLabel.textColor = UIColor(displayP3Red: 160/255, green: 160/255, blue: 160/255, alpha: 160/255)
view.addSubview(welcomeLabel)
fadeViewInThenOut(view: welcomeLabel, delay: 5, afterCompletion: hello())
}
func fadeViewInThenOut(view: UILabel, delay: TimeInterval, afterCompletion: (())) {
let animationDuration = 1.00
let action = afterCompletion
UIView.animate(
withDuration: animationDuration,
delay: 1,
animations: { () -> Void in view.alpha = 1}) { (Bool) -> Void in
UIView.animate(
withDuration: animationDuration,
delay: delay,
animations: { () -> Void in view.alpha = 0},
completion: { finished in action //insert here what i want it to do after
print("action")
})
}
}
func hello(){
print("yes")
}
}
ClientSide(反应js)
test.js
import paypal from "@paypal/checkout-server-sdk";
const clientId = "CLIENT_ID";
const clientSecret = "SECRET";
const environment = new paypal.core.SandboxEnvironment(clientId, clientSecret);
const client = new paypal.core.PayPalHttpClient(environment);
export const processInvoicePaypalPayment = async (user, data) => {
let request = new paypal.orders.OrdersCreateRequest();
try{
request.body = {
intent: "CAPTURE",
redirect_urls: {
return_url: "http://localhost:3000",
cancel_url: "http://localhost:3000"
},
purchase_units: [
{
amount: {
currency_code: "USD",
value: "**AMOUNT***"
},
description: "This is the payment transaction description."
}]};
const createOrder = async () => {
const response = await client.execute(request);
console.log(`Order: ${JSON.stringify(response.result)}`);// This response.result.links contain approval links
return { ok: true, data: { payment: response.result } };
}
const result = await createOrder();
return result;
}catch(err){}
由于我对此较新,因此我担心的是这是批准链接的正确方法。如果不是,我该怎么做?通过这种方式打开newpopup实际上给我的是,在我登录并完成付款过程后,它不会重定向回我的网站。我得到的是:
我该如何解决这个问题?
答案 0 :(得分:0)
最好不要将订单ID /代币传递到PayPal Checkout集成的客户端UI:https://developer.paypal.com/docs/checkout/
这是一个演示模式:https://developer.paypal.com/demo/checkout/#/pattern/server
画龙点睛的是,一旦一切顺利,就不要忽视处理/宣传资金失败的情况,这样,如果付款捕获/执行失败(例如,如果他们的第一张卡被拒收),买家可以选择其他资金):https://developer.paypal.com/docs/checkout/integration-features/funding-failure/