Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Unified Diff: chrome/test/data/payments/basic_card.js

Issue 2659083003: Relax card type handling. (Closed)
Patch Set: Clarify comment Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/payments/basic_card.js
diff --git a/chrome/test/data/payments/basic_card.js b/chrome/test/data/payments/basic_card.js
index ce2201404e94af48c0ed7d99b9e037472117b92f..c921aa9f5c548beef1d7654b02ced36b17e658c1 100644
--- a/chrome/test/data/payments/basic_card.js
+++ b/chrome/test/data/payments/basic_card.js
@@ -5,17 +5,14 @@
*/
/**
- * Merchant checks for ability to pay using debit cards.
+ * Calls PaymentRequest.canMakePayment() and prints out the result.
+ * @param {sequence<PaymentMethodData>} methodData The supported methods.
+ * @private
*/
-function checkBasicDebit() { // eslint-disable-line no-unused-vars
+function canMakePaymentHelper(methodData) {
try {
new PaymentRequest(
- [{
- supportedMethods: ['basic-card'],
- data: {
- supportedTypes: ['debit'],
- },
- }], {
+ methodData, {
total: {
label: 'Total',
amount: {
@@ -37,36 +34,38 @@ function checkBasicDebit() { // eslint-disable-line no-unused-vars
}
/**
+ * Merchant checks for ability to pay using "basic-card" regardless of issuer
+ * network.
+ */
+function checkBasicCard() { // eslint-disable-line no-unused-vars
+ canMakePaymentHelper([{
+ supportedMethods: ['basic-card'],
+ }]);
+}
+
+/**
+ * Merchant checks for ability to pay using debit cards.
+ */
+function checkBasicDebit() { // eslint-disable-line no-unused-vars
+ canMakePaymentHelper([{
+ supportedMethods: ['basic-card'],
+ data: {
+ supportedTypes: ['debit'],
+ },
+ }]);
+}
+
+/**
* Merchant checks for ability to pay using "basic-card" with "mastercard" as
* the supported network.
*/
function checkBasicMasterCard() { // eslint-disable-line no-unused-vars
- try {
- new PaymentRequest(
- [{
- supportedMethods: ['basic-card'],
- data: {
- supportedNetworks: ['mastercard'],
- },
- }], {
- total: {
- label: 'Total',
- amount: {
- currency: 'USD',
- value: '5.00',
- },
- },
- })
- .canMakePayment()
- .then(function(result) {
- print(result);
- })
- .catch(function(error) {
- print(error);
- });
- } catch (error) {
- print(error);
- }
+ canMakePaymentHelper([{
+ supportedMethods: ['basic-card'],
+ data: {
+ supportedNetworks: ['mastercard'],
+ },
+ }]);
}
/**
@@ -74,83 +73,57 @@ function checkBasicMasterCard() { // eslint-disable-line no-unused-vars
* supported network.
*/
function checkBasicVisa() { // eslint-disable-line no-unused-vars
- try {
- new PaymentRequest(
- [{
- supportedMethods: ['basic-card'],
- data: {
- supportedNetworks: ['visa'],
- },
- }], {
- total: {
- label: 'Total',
- amount: {
- currency: 'USD',
- value: '5.00',
- },
- },
- })
- .canMakePayment()
- .then(function(result) {
- print(result);
- })
- .catch(function(error) {
- print(error);
- });
- } catch (error) {
- print(error);
- }
+ canMakePaymentHelper([{
+ supportedMethods: ['basic-card'],
+ data: {
+ supportedNetworks: ['visa'],
+ },
+ }]);
}
/**
* Merchant checks for ability to pay using "mastercard".
*/
function checkMasterCard() { // eslint-disable-line no-unused-vars
- try {
- new PaymentRequest(
- [{
- supportedMethods: ['mastercard'],
- }], {
- total: {
- label: 'Total',
- amount: {
- currency: 'USD',
- value: '5.00',
- },
- },
- })
- .canMakePayment()
- .then(function(result) {
- print(result);
- })
- .catch(function(error) {
- print(error);
- });
- } catch (error) {
- print(error);
- }
+ canMakePaymentHelper([{
+ supportedMethods: ['mastercard'],
+ }]);
}
/**
* Merchant checks for ability to pay using "visa".
*/
function checkVisa() { // eslint-disable-line no-unused-vars
+ canMakePaymentHelper([{
+ supportedMethods: ['visa'],
+ }]);
+}
+
+/**
+ * Calls PaymentRequest.show() and prints out the result.
+ * @param {sequence<PaymentMethodData>} methodData The supported methods.
+ * @private
+ */
+function buyHelper(methodData) {
try {
- new PaymentRequest(
- [{
- supportedMethods: ['visa'],
- }], {
- total: {
- label: 'Total',
- amount: {
- currency: 'USD',
- value: '5.00',
- },
+ new PaymentRequest(methodData, {
+ total: {
+ label: 'Total',
+ amount: {
+ currency: 'USD',
+ value: '5.00',
},
- })
- .canMakePayment()
- .then(function(result) {
- print(result);
+ },
+ })
+ .show()
+ .then(function(response) {
+ response.complete('success')
+ .then(function() {
+ print(JSON.stringify(response, undefined, 2));
+ })
+ .catch(function(error) {
+ print(error);
+ });
})
.catch(function(error) {
print(error);
@@ -165,38 +138,26 @@ function checkVisa() { // eslint-disable-line no-unused-vars
* as the supported network.
*/
function buy() { // eslint-disable-line no-unused-vars
- try {
- new PaymentRequest(
- [{
- supportedMethods: ['mastercard'],
- }, {
- supportedMethods: ['basic-card'],
- data: {
- supportedNetworks: ['visa'],
- },
- }], {
- total: {
- label: 'Total',
- amount: {
- currency: 'USD',
- value: '5.00',
- },
- },
- })
- .show()
- .then(function(response) {
- response.complete('success').then(function() {
- print(JSON.stringify(response, undefined, 2));
- }).catch(function(error) {
- print(error);
- });
- })
- .catch(function(error) {
- print(error);
- });
- } catch (error) {
- print(error);
- }
+ buyHelper([{
+ supportedMethods: ['mastercard'],
+ }, {
+ supportedMethods: ['basic-card'],
+ data: {
+ supportedNetworks: ['visa'],
+ },
+ }]);
+}
+
+/**
+ * Merchant requests payment via "basic-card" with any issuer network.
+ */
+function buyBasicCard() { // eslint-disable-line no-unused-vars
+ buyHelper([{
+ supportedMethods: ['basic-card'],
+ data: {
+ supportedTypes: ['debit'],
+ },
+ }]);
}
/**
@@ -204,36 +165,25 @@ function buy() { // eslint-disable-line no-unused-vars
* type.
*/
function buyBasicDebit() { // eslint-disable-line no-unused-vars
- try {
- new PaymentRequest(
- [{
- supportedMethods: ['basic-card'],
- data: {
- supportedTypes: ['debit'],
- },
- }], {
- total: {
- label: 'Total',
- amount: {
- currency: 'USD',
- value: '5.00',
- },
- },
- })
- .show()
- .then(function(response) {
- response.complete('success').then(function() {
- print(JSON.stringify(response, undefined, 2));
- }).catch(function(error) {
- print(error);
- });
- })
- .catch(function(error) {
- print(error);
- });
- } catch (error) {
- print(error);
- }
+ buyHelper([{
+ supportedMethods: ['basic-card'],
+ data: {
+ supportedTypes: ['debit'],
+ },
+ }]);
+}
+
+/**
+ * Merchant requests payment via "basic-card" with "debit" as the supported card
+ * type.
+ */
+function buyBasicDebit() { // eslint-disable-line no-unused-vars
+ buyHelper([{
+ supportedMethods: ['basic-card'],
+ data: {
+ supportedTypes: ['debit'],
+ },
+ }]);
}
/**
@@ -241,34 +191,10 @@ function buyBasicDebit() { // eslint-disable-line no-unused-vars
* as the only supported network.
*/
function buyBasicMasterCard() { // eslint-disable-line no-unused-vars
- try {
- new PaymentRequest(
- [{
- supportedMethods: ['basic-card'],
- data: {
- supportedNetworks: ['mastercard'],
- },
- }], {
- total: {
- label: 'Total',
- amount: {
- currency: 'USD',
- value: '5.00',
- },
- },
- })
- .show()
- .then(function(response) {
- response.complete('success').then(function() {
- print(JSON.stringify(response, undefined, 2));
- }).catch(function(error) {
- print(error);
- });
- })
- .catch(function(error) {
- print(error);
- });
- } catch (error) {
- print(error);
- }
+ buyHelper([{
+ supportedMethods: ['basic-card'],
+ data: {
+ supportedNetworks: ['mastercard'],
+ },
+ }]);
}

Powered by Google App Engine
This is Rietveld 408576698