Payment Request API 实现一键支付
Payment Request API 如何简化 Web 支付流程?如何构造 PaymentRequest 对象?支付方法、配送信息和联系方式如何处理?与 Stripe/支付宝 SDK 有何区别?
回答
专业代码师
new PaymentRequest(methods, details, options)。methods: [{supportedMethods:'basic-card', data:{supportedNetworks:['visa','mastercard']}}] 或 'https://google.com/pay'。details: {id:'order-123', total:{label:'总计', amount:{currency:'CNY', value:'99.00'}}, displayItems:[...]}。options: {requestPayerName:true, requestShipping:true, shippingType:'shipping'}。request.show() 弹出 UI,用户确认返回 PaymentResponse。对比:Payment Request 是浏览器原生标准化 API;Stripe SDK 功能更丰富但需嵌入三方代码。