付款请求API:收款人账户是什么?
Payment Request API: What is the Payee Account?
我正在查看付款请求 API,它显然在某些浏览器上可用,但我想知道,where/how 您是否设置了接收付款的帐户?我在以下代码中找不到指定成功后将付款发送到的帐户的代码:
function onBuyClicked() {
if (!window.PaymentRequest) {
// PaymentRequest API is not available. Forwarding to
// legacy form based experience.
location.href = '/checkout';
return;
}
// Supported payment methods
var supportedInstruments = [{
supportedMethods: ['basic-card']
data: {
supportedNetworks: [
'visa', 'mastercard', 'amex', 'discover',
'diners', 'jcb', 'unionpay'
]
}
}];
// Checkout details
var details = {
displayItems: [{
label: 'Original donation amount',
amount: { currency: 'USD', value: '65.00' }
}, {
label: 'Friends and family discount',
amount: { currency: 'USD', value: '-10.00' }
}],
total: {
label: 'Total due',
amount: { currency: 'USD', value : '55.00' }
}
};
// 1. Create a `PaymentRequest` instance
var request = new PaymentRequest(supportedInstruments, details);
// 2. Show the native UI with `.show()`
request.show()
// 3. Process the payment
.then(result => {
// POST the payment information to the server
return fetch('/pay', {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(result.toJSON())
}).then(response => {
// 4. Display payment results
if (response.status === 200) {
// Payment successful
return result.complete('success');
} else {
// Payment failure
return result.complete('fail');
}
}).catch(() => {
return result.complete('fail');
});
});
}
document.querySelector('#start').addEventListener('click', onBuyClicked);
长话短说:你没有。
支付请求API不是支付处理器的替代品。浏览器本身无法处理向您帐户的资金转帐 - 它甚至无法验证提供的付款方式是否有效(尽管 Android Pay 可以做到这一点)。
根据 Introducing the Payment Request API 文档(强调我的):
...
The browser then presents the payments UI to the user, who selects a
payment method and authorizes the transaction. A payment method can be
as straightforward as a credit card that is already stored by the
browser, or as esoteric as third-party application written
specifically to deliver payments to the site (this functionality is
coming soon). After the user authorizes the transaction, all the
necessary payment details are sent directly back to the site. For
example, for a credit card payment, the site will get back a card
number, a cardholder name, an expiration date, and a CVC.
...
换句话说,付款请求 API 只是您收集用户卡号和处理付款所需的其他信息的一种更简单、更安全的方式。一旦您收到此信息,就好像用户通过普通表单提交它一样。您仍然需要支付处理器(或类似的东西)来实际创建交易。
我正在查看付款请求 API,它显然在某些浏览器上可用,但我想知道,where/how 您是否设置了接收付款的帐户?我在以下代码中找不到指定成功后将付款发送到的帐户的代码:
function onBuyClicked() {
if (!window.PaymentRequest) {
// PaymentRequest API is not available. Forwarding to
// legacy form based experience.
location.href = '/checkout';
return;
}
// Supported payment methods
var supportedInstruments = [{
supportedMethods: ['basic-card']
data: {
supportedNetworks: [
'visa', 'mastercard', 'amex', 'discover',
'diners', 'jcb', 'unionpay'
]
}
}];
// Checkout details
var details = {
displayItems: [{
label: 'Original donation amount',
amount: { currency: 'USD', value: '65.00' }
}, {
label: 'Friends and family discount',
amount: { currency: 'USD', value: '-10.00' }
}],
total: {
label: 'Total due',
amount: { currency: 'USD', value : '55.00' }
}
};
// 1. Create a `PaymentRequest` instance
var request = new PaymentRequest(supportedInstruments, details);
// 2. Show the native UI with `.show()`
request.show()
// 3. Process the payment
.then(result => {
// POST the payment information to the server
return fetch('/pay', {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(result.toJSON())
}).then(response => {
// 4. Display payment results
if (response.status === 200) {
// Payment successful
return result.complete('success');
} else {
// Payment failure
return result.complete('fail');
}
}).catch(() => {
return result.complete('fail');
});
});
}
document.querySelector('#start').addEventListener('click', onBuyClicked);
长话短说:你没有。
支付请求API不是支付处理器的替代品。浏览器本身无法处理向您帐户的资金转帐 - 它甚至无法验证提供的付款方式是否有效(尽管 Android Pay 可以做到这一点)。
根据 Introducing the Payment Request API 文档(强调我的):
...
The browser then presents the payments UI to the user, who selects a payment method and authorizes the transaction. A payment method can be as straightforward as a credit card that is already stored by the browser, or as esoteric as third-party application written specifically to deliver payments to the site (this functionality is coming soon). After the user authorizes the transaction, all the necessary payment details are sent directly back to the site. For example, for a credit card payment, the site will get back a card number, a cardholder name, an expiration date, and a CVC.
...
换句话说,付款请求 API 只是您收集用户卡号和处理付款所需的其他信息的一种更简单、更安全的方式。一旦您收到此信息,就好像用户通过普通表单提交它一样。您仍然需要支付处理器(或类似的东西)来实际创建交易。