【发布时间】:2021-08-18 00:57:06
【问题描述】:
这可能很简单,但是如何将信息发送到 PayPal 按钮组件? 比如产品名称、总价值?
这就是我所做的,我测试了我的代码并获得了“交易成功”:
// In panierPage, where the user can click on the PayPal button
import PayPal from '../services/PayPal/paypal'
return (
<Grid style={{marginLeft: '2%'}}>
<PayPal/>
</Grid>
);
// PayPal Button component with "default value " for testing
import React, { useEffect, useRef } from 'react';
export default function Paypal() {
const paypal = useRef()
useEffect(() => {
window.paypal.Buttons({
style: {
color: 'gold',
},
createOrder: (data, actions) => {
return actions.order.create({
intent: 'CAPTURE',
purchase_units: [
{
description: 'Une table',
amount: {
currency_code: 'EUR',
value: '10.00'
}
}]
})
},
onApprove: (data, actions) => {
console.log("Transaction Réussite")
return actions.order.capture();
},
onCancel: (data, actions) => {
}
}).render(paypal.current)
}, [])
return (
<div>
<div ref={paypal}></div>
</div>
);
}
因为现在是硬编码的价格和描述。
感谢您的时间和帮助!
【问题讨论】:
标签: javascript reactjs paypal