我想直接在自己的页面上,默认加载的时候就显示信用卡支付的业务
如下:
根据要求不能自己写输入框
现在就要在加载页面的时候自动内嵌 paypal 的信用卡业务页面
import { loadScript } from '@paypal/paypal-js';
const clientId = 'xxxxxxxxxxxx'
const orderID = ref('xxxxxxxxx'); // 后端生成的paypal订单id
const initializePaypalFields = async () => {
if (!orderID.value) return; // 确保已经有订单号
try {
// 加载 PayPal SDK
const paypal = await loadScript({
"client-id": clientId, // 替换为你的 PayPal 客户端 ID
components: "hosted-fields", // 只加载 hosted-fields 组件
authorization: '123'
});
if (paypal && paypal.HostedFields) {
// 渲染 Hosted Fields
await paypal.HostedFields.render({
createOrder: async (data, actions) => {
// 使用后端生成的订单号来发起支付
return actions.order.create({
purchase_units: [{
amount: {
value: '10.00', // 支付金额
currency_code: 'USD', // 支付货币类型
},
invoice_id: orderID.value // 使用已知的订单号
}]
});
},
onApprove: async (data, actions) => {
//
}
}, '#paypal-card-fields');
}
} catch (error) {
console.error('Error loading PayPal script:', error);
}
};
onMounted(() => {
initializePaypalFields(); // 初始化 PayPal Hosted Fields
});
现在的问题是不加 authorization
报错:options.authorization is required when instantiating a client.
加了:SDK Validation error: 'Disallowed query param: authorization
现在是用美国沙盒商户 开了 PayPal Payments Pro
这种情况需要开PayPal Payments Pro吗?
或者开了,为什么会出现前面的错误?