├── method ├── .gitignore ├── .gitattributes ├── web │ ├── index.jsp │ └── webpkiorg.png ├── empty.lib │ └── .gitignore ├── signer-certificate.cer ├── .settings │ └── org.eclipse.ltk.core.refactoring.prefs ├── androidpaymentappmethod.properties ├── .project ├── .classpath ├── src │ └── org │ │ └── webpki │ │ └── webapp │ │ └── androidpaymentappmethod │ │ ├── PaymentManifestServlet.java │ │ ├── PaymentAppMethodServlet.java │ │ └── PaymentAppMethodService.java ├── web.xml └── build.xml └── payreq ├── .gitignore ├── .gitattributes ├── web ├── index.jsp ├── webpkiorg.png ├── style.css ├── pr.html ├── pr.js └── util.js ├── .tmp ├── org │ └── webpki │ │ └── webapp │ │ └── androidpaymentapprequest │ │ ├── PaymentAppRequestService.class │ │ └── PaymentAppRequestServlet.class └── web.xml ├── .project ├── .classpath ├── web.xml ├── src └── org │ └── webpki │ └── webapp │ └── androidpaymentapprequest │ ├── PaymentAppRequestServlet.java │ └── PaymentAppRequestService.java └── build.xml /method/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | .tmp/ 3 | /dist/ 4 | -------------------------------------------------------------------------------- /payreq/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | .tmp/ 3 | /dist/ 4 | -------------------------------------------------------------------------------- /method/.gitattributes: -------------------------------------------------------------------------------- 1 | # Disable LF normalization for all files 2 | * -text -------------------------------------------------------------------------------- /payreq/.gitattributes: -------------------------------------------------------------------------------- 1 | # Disable LF normalization for all files 2 | * -text -------------------------------------------------------------------------------- /method/web/index.jsp: -------------------------------------------------------------------------------- 1 | <%@page session="false"%><%response.sendRedirect ("method");%> 2 | -------------------------------------------------------------------------------- /payreq/web/index.jsp: -------------------------------------------------------------------------------- 1 | <%@page session="false"%><%response.sendRedirect ("pr.html");%> 2 | -------------------------------------------------------------------------------- /method/empty.lib/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore -------------------------------------------------------------------------------- /method/web/webpkiorg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberphone/paymentrequest-web/master/method/web/webpkiorg.png -------------------------------------------------------------------------------- /payreq/web/webpkiorg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberphone/paymentrequest-web/master/payreq/web/webpkiorg.png -------------------------------------------------------------------------------- /method/signer-certificate.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberphone/paymentrequest-web/master/method/signer-certificate.cer -------------------------------------------------------------------------------- /method/.settings/org.eclipse.ltk.core.refactoring.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false 3 | -------------------------------------------------------------------------------- /payreq/.tmp/org/webpki/webapp/androidpaymentapprequest/PaymentAppRequestService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberphone/paymentrequest-web/master/payreq/.tmp/org/webpki/webapp/androidpaymentapprequest/PaymentAppRequestService.class -------------------------------------------------------------------------------- /payreq/.tmp/org/webpki/webapp/androidpaymentapprequest/PaymentAppRequestServlet.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberphone/paymentrequest-web/master/payreq/.tmp/org/webpki/webapp/androidpaymentapprequest/PaymentAppRequestServlet.class -------------------------------------------------------------------------------- /method/androidpaymentappmethod.properties: -------------------------------------------------------------------------------- 1 | # Lots of stuff is fetched from here 2 | 3 | openkeystore=../../openkeystore 4 | 5 | @methodpath=w3cpay 6 | 7 | @localhost=192.168.1.79 8 | 9 | @methodhost=https://${@localhost}:8442 10 | -------------------------------------------------------------------------------- /payreq/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | payreq 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /method/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | method 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /method/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /payreq/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /payreq/web/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | overflow: hidden; 3 | } 4 | 5 | div { 6 | margin-top: 10px; 7 | } 8 | 9 | .error { 10 | animation-duration: 0.5s; 11 | animation-name: popup; 12 | color: red; 13 | } 14 | 15 | @keyframes popup { 16 | from { 17 | margin-top: 20px; 18 | opacity: 0; 19 | } 20 | 50% { 21 | opacity: 1; 22 | } 23 | } 24 | 25 | .error-hide { 26 | animation-duration: 0.5s; 27 | animation-name: popdown; 28 | color: red; 29 | } 30 | 31 | @keyframes popdown { 32 | to { 33 | margin-top: 20px; 34 | opacity: 0; 35 | } 36 | } 37 | .info { 38 | color: green; 39 | } 40 | 41 | .warning { 42 | background: yellow; 43 | padding: 20px; 44 | font-weight: bold; 45 | text-align: center; 46 | } 47 | 48 | #spinner { 49 | display: none; 50 | } 51 | -------------------------------------------------------------------------------- /payreq/web/pr.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Credit Suisse Test 8 | 9 | 10 | 11 | 12 | 13 |
14 |

Credit Suisse Test

15 |

This page can be used to test the Credit Suisse app only. 16 | No payment will be processed. View source.

17 |

Price: USD $1.00

18 |

19 |
20 |

21 |   
22 |   
23 |   
24 | 
25 | 
26 | 


--------------------------------------------------------------------------------
/payreq/web.xml:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 6 | 
 7 |     
 8 |         For payment method creation
 9 |         host_path
10 |         @host-path@
11 |     
12 | 
13 |     
14 |         org.webpki.webapp.androidpaymentapprequest.PaymentAppRequestService
15 |     
16 | 
17 |     
18 |         PaymentAppRequestServlet
19 |         org.webpki.webapp.androidpaymentapprequest.PaymentAppRequestServlet
20 |     
21 | 
22 |     
23 |         PaymentAppRequestServlet
24 |         /home
25 |     
26 | 
27 |     
28 |       
29 |         The app
30 |         /*
31 |       
32 |       
33 |         CONFIDENTIAL
34 |       
35 |     
36 | 
37 | 
38 | 


--------------------------------------------------------------------------------
/payreq/.tmp/web.xml:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 6 | 
 7 |     
 8 |         For payment method creation
 9 |         host_path
10 |         https://192.168.1.79:8442/w3cpay
11 |     
12 | 
13 |     
14 |         org.webpki.webapp.androidpaymentapprequest.PaymentAppRequestService
15 |     
16 | 
17 |     
18 |         PaymentAppRequestServlet
19 |         org.webpki.webapp.androidpaymentapprequest.PaymentAppRequestServlet
20 |     
21 | 
22 |     
23 |         PaymentAppRequestServlet
24 |         /home
25 |     
26 | 
27 |     
28 |       
29 |         The app
30 |         /*
31 |       
32 |       
33 |         CONFIDENTIAL
34 |       
35 |     
36 | 
37 | 
38 | 


--------------------------------------------------------------------------------
/method/src/org/webpki/webapp/androidpaymentappmethod/PaymentManifestServlet.java:
--------------------------------------------------------------------------------
 1 | /*
 2 |  *  Copyright 2015-2018 WebPKI.org (http://webpki.org).
 3 |  *
 4 |  *  Licensed under the Apache License, Version 2.0 (the "License");
 5 |  *  you may not use this file except in compliance with the License.
 6 |  *  You may obtain a copy of the License at
 7 |  *
 8 |  *      https://www.apache.org/licenses/LICENSE-2.0
 9 |  *
10 |  *  Unless required by applicable law or agreed to in writing, software
11 |  *  distributed under the License is distributed on an "AS IS" BASIS,
12 |  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 |  *  See the License for the specific language governing permissions and
14 |  *  limitations under the License.
15 |  *
16 |  */
17 | package org.webpki.webapp.androidpaymentappmethod;
18 | 
19 | import java.io.IOException;
20 | 
21 | import java.util.logging.Logger;
22 | 
23 | import javax.servlet.ServletException;
24 | 
25 | import javax.servlet.http.HttpServlet;
26 | import javax.servlet.http.HttpServletRequest;
27 | import javax.servlet.http.HttpServletResponse;
28 | 
29 | public class PaymentManifestServlet extends HttpServlet {
30 | 
31 |     private static final long serialVersionUID = 1L;
32 |     
33 |     static Logger logger = Logger.getLogger(PaymentManifestServlet.class.getCanonicalName());
34 | 
35 |     @Override
36 |     public void doGet(HttpServletRequest request, HttpServletResponse response) 
37 |     throws IOException, ServletException {
38 |         logger.info("GET");
39 |         response.setContentType("application/manifest+json");
40 |         response.getOutputStream().write(PaymentAppMethodService.paymentManifest);
41 |     }
42 | }
43 | 


--------------------------------------------------------------------------------
/payreq/src/org/webpki/webapp/androidpaymentapprequest/PaymentAppRequestServlet.java:
--------------------------------------------------------------------------------
 1 | /*
 2 |  *  Copyright 2015-2018 WebPKI.org (http://webpki.org).
 3 |  *
 4 |  *  Licensed under the Apache License, Version 2.0 (the "License");
 5 |  *  you may not use this file except in compliance with the License.
 6 |  *  You may obtain a copy of the License at
 7 |  *
 8 |  *      https://www.apache.org/licenses/LICENSE-2.0
 9 |  *
10 |  *  Unless required by applicable law or agreed to in writing, software
11 |  *  distributed under the License is distributed on an "AS IS" BASIS,
12 |  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 |  *  See the License for the specific language governing permissions and
14 |  *  limitations under the License.
15 |  *
16 |  */
17 | package org.webpki.webapp.androidpaymentapprequest;
18 | 
19 | import java.io.IOException;
20 | 
21 | import java.util.logging.Logger;
22 | 
23 | import javax.servlet.ServletException;
24 | 
25 | import javax.servlet.http.HttpServlet;
26 | import javax.servlet.http.HttpServletRequest;
27 | import javax.servlet.http.HttpServletResponse;
28 | 
29 | import org.webpki.json.JSONOutputFormats;
30 | import org.webpki.json.JSONParser;
31 | 
32 | public class PaymentAppRequestServlet extends HttpServlet {
33 | 
34 |     private static final long serialVersionUID = 1L;
35 | 
36 |     static Logger logger = Logger.getLogger(PaymentAppRequestServlet.class.getCanonicalName());
37 | 
38 |     @Override
39 |     public void doGet(HttpServletRequest request, HttpServletResponse response) 
40 |             throws IOException, ServletException {
41 |         logger.info("GET");
42 |         response.setContentType("text/plain");
43 |     }
44 | }
45 | 


--------------------------------------------------------------------------------
/payreq/src/org/webpki/webapp/androidpaymentapprequest/PaymentAppRequestService.java:
--------------------------------------------------------------------------------
 1 | /*
 2 |  *  Copyright 2015-2018 WebPKI.org (http://webpki.org).
 3 |  *
 4 |  *  Licensed under the Apache License, Version 2.0 (the "License");
 5 |  *  you may not use this file except in compliance with the License.
 6 |  *  You may obtain a copy of the License at
 7 |  *
 8 |  *      https://www.apache.org/licenses/LICENSE-2.0
 9 |  *
10 |  *  Unless required by applicable law or agreed to in writing, software
11 |  *  distributed under the License is distributed on an "AS IS" BASIS,
12 |  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 |  *  See the License for the specific language governing permissions and
14 |  *  limitations under the License.
15 |  *
16 |  */
17 | package org.webpki.webapp.androidpaymentapprequest;
18 | 
19 | import java.util.logging.Level;
20 | import java.util.logging.Logger;
21 | 
22 | import javax.servlet.ServletContextEvent;
23 | import javax.servlet.ServletContextListener;
24 | 
25 | import org.webpki.webutil.InitPropertyReader;
26 | 
27 | 
28 | public class PaymentAppRequestService extends InitPropertyReader implements ServletContextListener {
29 | 
30 |     static Logger logger = Logger.getLogger(PaymentAppRequestService.class.getCanonicalName());
31 |     
32 |     static final String HOST_PATH                    = "host_path";
33 | 
34 |     static String paymentMethodUrl;
35 | 
36 |     @Override
37 |     public void contextDestroyed(ServletContextEvent sce) {
38 |     }
39 | 
40 |     @Override
41 |     public void contextInitialized(ServletContextEvent sce) {
42 |         initProperties (sce);
43 |         try {
44 |             paymentMethodUrl = getPropertyString(HOST_PATH) + "/method";
45 | 
46 |             logger.info("W3C/Android Payment App Request initiated");
47 |         } catch (Exception e) {
48 |             logger.log(Level.SEVERE, "********\n" + e.getMessage() + "\n********", e);
49 |         }
50 |     }
51 | }
52 | 


--------------------------------------------------------------------------------
/method/web.xml:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 6 | 
 7 |     
 8 |         For payment manifest creation
 9 |         host_path
10 |         @host-path@
11 |     
12 | 
13 |     
14 |         org.webpki.webapp.androidpaymentappmethod.PaymentAppMethodService
15 |     
16 | 
17 |     
18 |         PaymentAppMethodServlet
19 |         org.webpki.webapp.androidpaymentappmethod.PaymentAppMethodServlet
20 |     
21 | 
22 |     
23 |         PaymentManifestServlet
24 |         org.webpki.webapp.androidpaymentappmethod.PaymentManifestServlet
25 |     
26 | 
27 |     
28 |         AppManifestServlet
29 |         org.webpki.webapp.androidpaymentappmethod.AppManifestServlet
30 |     
31 | 
32 |     
33 |         PaymentAppMethodServlet
34 |         /method
35 |     
36 | 
37 |     
38 |         PaymentManifestServlet
39 |         /payment-manifest.json
40 |     
41 | 
42 |     
43 |       
44 |         The app
45 |         /*
46 |       
47 |       
48 |         CONFIDENTIAL
49 |       
50 |     
51 | 
52 | 
53 | 


--------------------------------------------------------------------------------
/method/src/org/webpki/webapp/androidpaymentappmethod/PaymentAppMethodServlet.java:
--------------------------------------------------------------------------------
 1 | /*
 2 |  *  Copyright 2015-2018 WebPKI.org (http://webpki.org).
 3 |  *
 4 |  *  Licensed under the Apache License, Version 2.0 (the "License");
 5 |  *  you may not use this file except in compliance with the License.
 6 |  *  You may obtain a copy of the License at
 7 |  *
 8 |  *      https://www.apache.org/licenses/LICENSE-2.0
 9 |  *
10 |  *  Unless required by applicable law or agreed to in writing, software
11 |  *  distributed under the License is distributed on an "AS IS" BASIS,
12 |  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 |  *  See the License for the specific language governing permissions and
14 |  *  limitations under the License.
15 |  *
16 |  */
17 | package org.webpki.webapp.androidpaymentappmethod;
18 | 
19 | import java.io.IOException;
20 | 
21 | import java.util.logging.Logger;
22 | 
23 | import javax.servlet.ServletException;
24 | 
25 | import javax.servlet.http.HttpServlet;
26 | import javax.servlet.http.HttpServletRequest;
27 | import javax.servlet.http.HttpServletResponse;
28 | 
29 | import org.webpki.json.JSONOutputFormats;
30 | import org.webpki.json.JSONParser;
31 | 
32 | public class PaymentAppMethodServlet extends HttpServlet {
33 | 
34 |     private static final long serialVersionUID = 1L;
35 | 
36 |     static Logger logger = Logger.getLogger(PaymentAppMethodServlet.class.getCanonicalName());
37 | 
38 |     @Override
39 |     public void doGet(HttpServletRequest request, HttpServletResponse response) 
40 |             throws IOException, ServletException {
41 |         logger.info("GET");
42 |         response.setContentType("text/plain");
43 |         response.getOutputStream().write(
44 |             JSONParser.parse(
45 |                 PaymentAppMethodService.paymentManifest).serializeToBytes(JSONOutputFormats.PRETTY_PRINT));
46 |     }
47 | 
48 |     @Override
49 |     public void doHead(HttpServletRequest request, HttpServletResponse response) 
50 |             throws IOException, ServletException {
51 |         logger.info("HEAD");
52 |         response.setHeader("Link", "; rel=\"payment-method-manifest\"");
53 |     }
54 | }
55 | 


--------------------------------------------------------------------------------
/payreq/web/pr.js:
--------------------------------------------------------------------------------
 1 | /**
 2 |  * Initializes the payment request object.
 3 |  * @return {PaymentRequest} The payment request object.
 4 |  */
 5 | function buildPaymentRequest() {
 6 |   if (!window.PaymentRequest) {
 7 |     return null;
 8 |   }
 9 | 
10 |   const supportedInstruments = [{
11 | 	  supportedMethods: 'https://192.168.1.79:8442/w3cpay/method',
12 | 	  data: {fancy: true}
13 |   }];
14 | 
15 |   const details = {
16 |     total: {
17 |       label: 'Donation',
18 |       amount: {
19 |         currency: 'USD',
20 |         value: '55.00',
21 |       },
22 |     },
23 |     displayItems: [{
24 |       label: 'Original donation amount',
25 |       amount: {
26 |         currency: 'USD',
27 |         value: '65.00',
28 |       },
29 |     }, {
30 |       label: 'Friends and family discount',
31 |       amount: {
32 |         currency: 'USD',
33 |         value: '-10.00',
34 |       },
35 |     }],
36 |   };
37 | 
38 |   let request = null;
39 | 
40 |   try {
41 |     request = new PaymentRequest(supportedInstruments, details);
42 |     if (request.canMakePayment) {
43 |       request.canMakePayment().then(function(result) {
44 |         info(result ? 'Can make payment' : 'Cannot make payment');
45 |       }).catch(function(err) {
46 |         error(err);
47 |       });
48 |     }
49 |   } catch (e) {
50 |     error('Developer mistake: \'' + e.message + '\'');
51 |   }
52 | 
53 |   return request;
54 | }
55 | 
56 | let request = buildPaymentRequest();
57 | 
58 | /**
59 |  * Handles the response from PaymentRequest.show().
60 |  */
61 | function handlePaymentResponse(response) {
62 |   window.setTimeout(function() {
63 |     response.complete('success')
64 |       .then(function() {
65 |         done('This is a demo website. No payment will be processed.', response);
66 |       })
67 |       .catch(function(err) {
68 |         error(err);
69 |         request = buildPaymentRequest();
70 |       });
71 |   }, 500);
72 | }
73 | 
74 | /**
75 |  * Launches payment request for Bob Pay.
76 |  */
77 | function onBuyClicked() { // eslint-disable-line no-unused-vars
78 |   if (!window.PaymentRequest || !request) {
79 |     error('PaymentRequest API is not supported.');
80 |     return;
81 |   }
82 | 
83 |   try {
84 |     request.show()
85 |       .then(handlePaymentResponse)
86 |       .catch(function(err) {
87 |         error(err);
88 |         request = buildPaymentRequest();
89 |       });
90 |   } catch (e) {
91 |     error('Developer mistake: \'' + e.message + '\'');
92 |     request = buildPaymentRequest();
93 |   }
94 | }


--------------------------------------------------------------------------------
/payreq/build.xml:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 |   
 4 |   
 5 |   
 6 |   
 7 |   
 8 |   
 9 |   
10 |   
11 |   
12 |   
13 |   
14 |   
15 |   
16 |   
17 |   
18 |   
19 | 
20 |   
21 |   
22 | 
23 |   
24 |       
25 |   
26 | 
27 |   
28 |      
29 |     
30 |       
31 |     
32 |     
33 | 
34 |   
35 | 
36 |   
37 |   	
38 |     
39 |   
40 | 
41 |   
42 |     
43 |     
44 |     
45 |     
51 |     
52 |     
58 | 		
59 | 			  
60 | 		        
61 | 		     
62 | 			 
63 |                 
64 | 			 
65 | 		
66 |     
67 |     
68 |       
69 |     
70 |     
71 |       
72 |          
73 |       
74 |       
75 |          
76 |          
77 |       
78 |       
79 | 
82 |       
83 |     
84 |   
85 |   
86 | 
87 | 


--------------------------------------------------------------------------------
/method/build.xml:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 |   
 4 |   
 5 |   
 6 |   
 7 |   
 8 |   
 9 |   
10 |   
11 |   
12 |   
13 |   
14 |   
15 |   
16 |   
17 |   
18 | 
19 |   
20 |   
21 | 
22 |   
23 |       
24 |   
25 | 
26 |   
27 |      
28 |     
29 |       
30 |     
31 |     
32 | 
33 |   
34 | 
35 |   
36 |   	
37 |     
38 |   
39 | 
40 |   
41 |     
42 |     
43 |     
44 |     
50 |     
51 |     
57 | 		
58 | 			  
59 | 		        
60 | 		     
61 | 			 
62 |                 
63 | 			 
64 | 		
65 |     
66 |     
67 |       
68 |     
69 |     
70 |       
71 |          
72 |       
73 |       
74 |          
75 |          
76 |       
77 |       
78 | 
81 |       
82 |     
83 |   
84 |   
85 | 
86 | 


--------------------------------------------------------------------------------
/payreq/web/util.js:
--------------------------------------------------------------------------------
  1 | var timeoutID1;
  2 | var timeoutID2;
  3 | 
  4 | /**
  5 |  * Prints the given error message.
  6 |  * @param {string} msg - The error message to print.
  7 |  */
  8 | function error(msg) {  // eslint-disable-line no-unused-vars
  9 |   if (timeoutID1) {
 10 |     window.clearTimeout(timeoutID1);
 11 |   }
 12 |   if (timeoutID2) {
 13 |     window.clearTimeout(timeoutID2);
 14 |   }
 15 |   let element = document.createElement('pre');
 16 |   element.innerHTML = msg;
 17 |   element.className = 'error';
 18 |   document.getElementById('msg').appendChild(element);
 19 |   timeoutID1 = window.setTimeout(function() {
 20 |     if (element.className !== 'error') {
 21 |       return;
 22 |     }
 23 |     element.className = 'error-hide';
 24 |     timeoutID2 = window.setTimeout(function() {
 25 |       element.innerHTML = '';
 26 |       element.className = '';
 27 |     }, 500);
 28 |   }, 10000);
 29 | }
 30 | 
 31 | /**
 32 |  * Prints the given informational message.
 33 |  * @param {string} msg - The information message to print.
 34 |  */
 35 | function info(msg) {
 36 |   let element = document.createElement('pre');
 37 |   element.innerHTML = msg;
 38 |   element.className = 'info';
 39 |   document.getElementById('msg').appendChild(element);
 40 | }
 41 | 
 42 | /**
 43 |  * Converts an address object into a dictionary.
 44 |  * @param {PaymentAddress} addr - The address to convert.
 45 |  * @return {object} The resulting dictionary.
 46 |  */
 47 | function toDictionary(addr) {  // eslint-disable-line no-unused-vars
 48 |   let dict = {};
 49 |   if (addr) {
 50 |     if (addr.toJSON) {
 51 |       return addr;
 52 |     }
 53 |     dict.country = addr.country;
 54 |     dict.region = addr.region;
 55 |     dict.city = addr.city;
 56 |     dict.dependentLocality = addr.dependentLocality;
 57 |     dict.addressLine = addr.addressLine;
 58 |     dict.postalCode = addr.postalCode;
 59 |     dict.sortingCode = addr.sortingCode;
 60 |     dict.languageCode = addr.languageCode;
 61 |     dict.organization = addr.organization;
 62 |     dict.recipient = addr.recipient;
 63 |     dict.phone = addr.phone;
 64 |   }
 65 |   return dict;
 66 | }
 67 | 
 68 | /**
 69 |  * Called when the payment request is complete.
 70 |  * @param {string} message - The human readable message to display.
 71 |  * @param {PaymentResponse} resp - The payment response.
 72 |  */
 73 | function done(message, resp) {  // eslint-disable-line no-unused-vars
 74 |   let element = document.getElementById('contents');
 75 |   element.innerHTML = message;
 76 | 
 77 |   if (resp.toJSON) {
 78 |     info(JSON.stringify(resp, undefined, 2));
 79 |     return;
 80 |   }
 81 | 
 82 |   let shippingOption = resp.shippingOption ?
 83 |       'shipping, delivery, pickup option: ' + resp.shippingOption + '
' : 84 | ''; 85 | 86 | let shippingAddress = resp.shippingAddress ? 87 | 'shipping, delivery, pickup address: ' + 88 | JSON.stringify(toDictionary(resp.shippingAddress), undefined, 2) + 89 | '
' : 90 | ''; 91 | 92 | let instrument = 93 | 'instrument:' + JSON.stringify(resp.details, undefined, 2) + '
'; 94 | 95 | let method = 'method: ' + resp.methodName + '
'; 96 | let email = resp.payerEmail ? 'email: ' + resp.payerEmail + '
' : ''; 97 | let phone = resp.payerPhone ? 'phone: ' + resp.payerPhone + '
' : ''; 98 | let name = resp.payerName ? 'name: ' + resp.payerName + '
' : ''; 99 | 100 | 101 | info(email + phone + name + shippingOption + shippingAddress + method + 102 | instrument); 103 | } 104 | -------------------------------------------------------------------------------- /method/src/org/webpki/webapp/androidpaymentappmethod/PaymentAppMethodService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 WebPKI.org (http://webpki.org). 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package org.webpki.webapp.androidpaymentappmethod; 18 | 19 | import java.io.IOException; 20 | 21 | import java.util.logging.Level; 22 | import java.util.logging.Logger; 23 | 24 | import javax.servlet.ServletContextEvent; 25 | import javax.servlet.ServletContextListener; 26 | 27 | import org.webpki.crypto.CertificateUtil; 28 | import org.webpki.crypto.HashAlgorithms; 29 | 30 | import org.webpki.json.JSONObjectWriter; 31 | import org.webpki.json.JSONOutputFormats; 32 | 33 | import org.webpki.util.ArrayUtil; 34 | 35 | import org.webpki.webutil.InitPropertyReader; 36 | 37 | public class PaymentAppMethodService extends InitPropertyReader implements ServletContextListener { 38 | 39 | static Logger logger = Logger.getLogger(PaymentAppMethodService.class.getCanonicalName()); 40 | 41 | static final String SIGNER_CERTIFICATE = "signer-certificate.cer"; 42 | 43 | static final String HOST_PATH = "host_path"; 44 | 45 | static byte[] paymentManifest; 46 | 47 | byte[] getBinary(String name) throws IOException { 48 | return ArrayUtil.getByteArrayFromInputStream(this.getClass().getResourceAsStream(name)); 49 | } 50 | 51 | @Override 52 | public void contextDestroyed(ServletContextEvent sce) { 53 | } 54 | 55 | @Override 56 | public void contextInitialized(ServletContextEvent sce) { 57 | initProperties (sce); 58 | try { 59 | byte[] certificate = getBinary(SIGNER_CERTIFICATE); 60 | 61 | JSONObjectWriter temp = new JSONObjectWriter(); 62 | temp.setArray("default_applications") 63 | .setString(getPropertyString(HOST_PATH) + "/payment-manifest.json"); 64 | temp.setArray("related_applications").setObject() 65 | .setString("platform", "play") 66 | .setString("id", "org.webpki.androidpay") 67 | .setString("min_version", "1") 68 | .setArray("fingerprints") 69 | .setObject() 70 | .setString("type", "sha256_cert") 71 | .setString("value", 72 | ArrayUtil.toHexString(HashAlgorithms.SHA256.digest(certificate), 73 | 0, 74 | -1, 75 | true, 76 | ':')); 77 | temp.setString("supported_origins", "*"); 78 | paymentManifest = temp.serializeToBytes(JSONOutputFormats.NORMALIZED); 79 | 80 | logger.info("W3C/Android Payment App Method initiated\nSubject=" + 81 | CertificateUtil.getCertificateFromBlob(certificate).getSubjectDN()); 82 | } catch (Exception e) { 83 | logger.log(Level.SEVERE, "********\n" + e.getMessage() + "\n********", e); 84 | } 85 | } 86 | } 87 | --------------------------------------------------------------------------------