Commit 4cc5749e authored by Rouslan Solomakhin's avatar Rouslan Solomakhin Committed by Commit Bot

[Web Payment] No shipping with secure payment confirmation.

Before this patch, invoking PaymentRequest API with secure payment
confirmation method identifier and options to request shipping or
contact information was considered valid.

This patch throws RangeError in PaymentRequest constructor if secure
payment confirmation method identifier is requested together with
shipping or contact information.

After this patch, it's not possible to request secure payment
confirmation method together with shipping or contact information.

Bug: 2348410
Change-Id: I3e01f9b758645a1653533f41da9688c453199b03
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2359554Reviewed-by: default avatarLiquan (Max) Gu <maxlg@chromium.org>
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798755}
parent bdc76d2d
...@@ -681,14 +681,23 @@ void ValidateAndConvertPaymentMethodData( ...@@ -681,14 +681,23 @@ void ValidateAndConvertPaymentMethodData(
if (payment_method_data->supportedMethod() == if (payment_method_data->supportedMethod() ==
kSecurePaymentConfirmationMethod && kSecurePaymentConfirmationMethod &&
input.size() > 1 &&
RuntimeEnabledFeatures::SecurePaymentConfirmationEnabled( RuntimeEnabledFeatures::SecurePaymentConfirmationEnabled(
&execution_context)) { &execution_context)) {
exception_state.ThrowRangeError( if (input.size() > 1) {
String(kSecurePaymentConfirmationMethod) + exception_state.ThrowRangeError(
" must be the only payment method identifier specified in the " String(kSecurePaymentConfirmationMethod) +
"PaymentRequest constructor."); " must be the only payment method identifier specified in the "
return; "PaymentRequest constructor.");
return;
} else if (options->requestShipping() || options->requestPayerName() ||
options->requestPayerEmail() || options->requestPayerPhone()) {
exception_state.ThrowRangeError(
String(kSecurePaymentConfirmationMethod) +
" payment method identifier cannot be used with "
"\"requestShipping\", \"requestPayerName\", \"requestPayerEmail\", "
"or \"requestPayerPhone\" options.");
return;
}
} }
method_names.insert(payment_method_data->supportedMethod()); method_names.insert(payment_method_data->supportedMethod());
......
...@@ -50,6 +50,96 @@ test(() => { ...@@ -50,6 +50,96 @@ test(() => {
}], details); }], details);
}, 'The timeout field is optional.'); }, 'The timeout field is optional.');
test(() => {
assert_throws_js(RangeError, () => {
new PaymentRequest([{
supportedMethods: 'secure-payment-confirmation',
data: {
action: 'authenticate',
instrumentId: 'x',
networkData: Uint8Array.from('x', c => c.charCodeAt(0)),
timeout: 60000,
fallbackUrl: 'https://fallback.example/url'
},
}, {supportedMethods: 'basic-card'}], details);
});
}, 'Extra payment method not allowed afterward.');
test(() => {
assert_throws_js(RangeError, () => {
new PaymentRequest([{supportedMethods: 'basic-card'}, {
supportedMethods: 'secure-payment-confirmation',
data: {
action: 'authenticate',
instrumentId: 'x',
networkData: Uint8Array.from('x', c => c.charCodeAt(0)),
timeout: 60000,
fallbackUrl: 'https://fallback.example/url'
},
}], details);
});
}, 'Extra payment method not allowed beforehand.');
test(() => {
assert_throws_js(RangeError, () => {
new PaymentRequest([{
supportedMethods: 'secure-payment-confirmation',
data: {
action: 'authenticate',
instrumentId: 'x',
networkData: Uint8Array.from('x', c => c.charCodeAt(0)),
timeout: 60000,
fallbackUrl: 'https://fallback.example/url'
},
}], details, {requestShipping: true});
});
}, 'Cannot request shipping information.');
test(() => {
assert_throws_js(RangeError, () => {
new PaymentRequest([{
supportedMethods: 'secure-payment-confirmation',
data: {
action: 'authenticate',
instrumentId: 'x',
networkData: Uint8Array.from('x', c => c.charCodeAt(0)),
timeout: 60000,
fallbackUrl: 'https://fallback.example/url'
},
}], details, {requestPayerName: true});
});
}, 'Cannot request payer name.');
test(() => {
assert_throws_js(RangeError, () => {
new PaymentRequest([{
supportedMethods: 'secure-payment-confirmation',
data: {
action: 'authenticate',
instrumentId: 'x',
networkData: Uint8Array.from('x', c => c.charCodeAt(0)),
timeout: 60000,
fallbackUrl: 'https://fallback.example/url'
},
}], details, {requestPayerEmail: true});
});
}, 'Cannot request payer email.');
test(() => {
assert_throws_js(RangeError, () => {
new PaymentRequest([{
supportedMethods: 'secure-payment-confirmation',
data: {
action: 'authenticate',
instrumentId: 'x',
networkData: Uint8Array.from('x', c => c.charCodeAt(0)),
timeout: 60000,
fallbackUrl: 'https://fallback.example/url'
},
}], details, {requestPayerPhone: true});
});
}, 'Cannot request payer phone.');
test(() => { test(() => {
assert_throws_js(TypeError, () => { assert_throws_js(TypeError, () => {
new PaymentRequest([{ new PaymentRequest([{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment