Skip to content

Commit

Permalink
[Web Payment] Return true in canMakePayment().
Browse files Browse the repository at this point in the history
Before this patch, calling PaymentRequest.canMakePayment() after its
value has been calculated would return "false", ignoring the fact that
secure payment confirmation is being requested, for which
canMakePayment() should return "true" if an authenticator device is
available, even if there are no credentials on file.

This patch changes PaymentRequestState::CanMakePayment() to use
GetCanMakePaymentValue() after all apps have finished queried. This
method takes into account whether secure payment confirmation is being
requested and an authenticator is available.

After this patch, PaymentRequestState.canMakePayment() always returns
"true" for secure payment confirmation when an authenticator is
available (if the secure payment confirmation feature is enabled).

Bug: 1123148
Change-Id: I4bb4895cbc1c7db1d84a19c9d753d5766769ad84
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2383693
Reviewed-by: Nick Burris <nburris@chromium.org>
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#802927}
  • Loading branch information
rsolomakhin authored and Commit Bot committed Aug 29, 2020
1 parent 2ee75d9 commit 159e513
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Expand Up @@ -220,6 +220,11 @@ IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationTest,
base::StringPrintf("canMakePaymentForMethodData(%s)", kTestMethodData);
EXPECT_EQ("true", content::EvalJs(GetActiveWebContents(), snippet));
}
{
std::string snippet = base::StringPrintf(
"canMakePaymentForMethodDataTwice(%s)", kTestMethodData);
EXPECT_EQ("true", content::EvalJs(GetActiveWebContents(), snippet));
}
{
std::string snippet = base::StringPrintf(
"hasEnrolledInstrumentForMethodData(%s)", kTestMethodData);
Expand Down
2 changes: 1 addition & 1 deletion components/payments/content/payment_request_state.cc
Expand Up @@ -300,7 +300,7 @@ void PaymentRequestState::CanMakePayment(StatusCallback callback) {
return;
}

PostStatusCallback(std::move(callback), are_requested_methods_supported_);
PostStatusCallback(std::move(callback), GetCanMakePaymentValue());
}

void PaymentRequestState::HasEnrolledInstrument(StatusCallback callback) {
Expand Down
17 changes: 17 additions & 0 deletions components/test/data/payments/can_make_payment_checker.js
Expand Up @@ -38,6 +38,23 @@ async function canMakePaymentForMethodData(methodData) { // eslint-disable-line
}
}

/**
* Creates a PaymentRequest with |methodData|, checks canMakePayment twice, and
* returns the second value.
* @param {object} methodData - The payment method data to build the request.
* @return {string} - 'true', 'false', or error message on failure.
*/
async function canMakePaymentForMethodDataTwice(methodData) { // eslint-disable-line no-unused-vars, max-len
try {
const request = new PaymentRequest(methodData, kDetails);
await request.canMakePayment(); // Discard first result.
const result = await request.canMakePayment();
return result ? 'true' : 'false';
} catch (e) {
return e.message;
}
}

/**
* Creates a PaymentRequest with |methodData| and checks hasEnrolledInstrument.
* @param {object} methodData - The payment method data to build the request.
Expand Down

0 comments on commit 159e513

Please sign in to comment.